fix(relay): soft-delete kind:30620 events row on workflow a-tag delete - #5132
Open
iroiro147 wants to merge 1 commit into
Open
fix(relay): soft-delete kind:30620 events row on workflow a-tag delete#5132iroiro147 wants to merge 1 commit into
iroiro147 wants to merge 1 commit into
Conversation
'workflows list' reads the kind:30620 event store directly. Before this change, 'workflows delete' removed only the operational `workflows` row (via `handle_a_tag_deletion`) but left the kind:30620 `events` row live, so a successfully deleted workflow kept showing up as a zombie entry in the list. The generic NIP-33 path (`k if is_parameterized_replaceable(k)`) already applies `soft_delete_by_coordinate` for every other addressable kind. KIND_WORKFLOW_DEF was deliberately branched ahead of it — the comment noted the `events` row was a separate concern — and the branch never got the mirror soft-delete. Apply the same `(kind, pubkey, d_tag)` soft-delete to the workflow arm once the operational delete succeeds. Keep it best-effort: if the `events`-row lookup fails the deletion is still complete (the scheduler cannot fire the workflow), only `workflows list` keeps showing the zombie — log a warn so operators can investigate. Resolves block#5077. Signed-off-by: iroiro147 <sarthak.singh@mastersunion.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
buzz workflows listshows deleted workflows indefinitely because the kind:30620eventsrow survives an otherwise-successfulworkflows delete.Resolves #5077.
Root cause
handle_a_tag_deletionspecial-casesKIND_WORKFLOW_DEFahead of the generic NIP-33 arm. The custom branch callsdelete_workflow_for_owner(which removes the operationalworkflowstable row and invalidates the schedule cache) and then returns without soft-deleting the(kind:30620, pubkey, d_tag)row inevents. The comment there even calls this out — "which doesn't soft-delete theeventsrow by design — that's a separate concern."That design holds for relay authority (the workflow can no longer fire), but it leaks through the CLI:
cmd_list_workflows(crates/buzz-cli/src/commands/workflows.rs) issues a Nostr REQ forkinds:[30620]+#h+ channel id directly against the event store. With theeventsrow undeleted, the deleted workflow keeps showing up inlistoutput long afterdeletesucceeded.The generic NIP-33 arm (
k if is_parameterized_replaceable(k)) already soft-deletes theeventsrow for every other addressable kind viasoft_delete_by_coordinate. KIND_WORKFLOW_DEF wouldn't be matched by that arm anyway because the workflow match runs first — but the workflow arm simply never called the mirror soft-delete.Fix
After the operational delete succeeds (UUID or name path — both reach the same tail), apply the same
(kind, pubkey, d_tag)soft-delete for kind:30620, using the a-tag coordinate'spubkey(the real event author) and the tombstone'screated_atas the soft-delete ceiling (same pattern as the generic arm — NIP-09 scoping so a stale replayed tombstone can never erase a newer replacement head).The soft-delete is best-effort, never fatal: the operational
workflowsrow is already gone at that point, so the scheduler cannot re-fire the workflow. If theevents-row update fails (transient DB error, malformed a-tag pubkey), the worst case is the zombie entry persists — same behavior as today, but with atracing::warntrail so operators can see and clean up. Reflected in the comment on the fix site.What did NOT change
delete_workflow_for_ownermatchingactor_bytes(the effective author incl. ACP agent override) againstworkflows.owner_pubkey. If the caller doesn't own the workflow, the branch returns before the soft-delete.invalidate_channel_workflowsstill runs on success,call_webhookauthority checks still gated by role inhandle_workflow_def, triggers still read theworkflowstable only.listbehavior past deletion — works correctly post-fix because it reads the sameeventsstore the tombstone now hides. No CLI diff required.Tests
cargo fmt --check,cargo clippy --all-targets -- -D warningsclean.cargo test --lib -p buzz-relay— 849 pass, 9 pre-existingapi::admin/api::mediafailures (verified same failures reproduce on the untouched base branch).I did not add an integration test: the existing NIP-09 a-tag suites (
e2e_team,e2e_project,e2e_managed_agent) cover the pattern but only for non-workflow kinds, andKIND_WORKFLOW_DEFingest additionally requiresh-tag channel + channel membership + valid YAML, so a regression test would need fresh channel-bootstrap scaffolding. Happy to add one if you prefer — flagged here so reviewers can decide.Compatibility
Pure deletion-side behavioral fix. No schema, no API surface change, no migration. Existing deleted workflows keep their zombie
eventsrows (same as today) — a separate cleanup migration can sweep them if desired, but this PR does not require it.