buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(relay): tombstone workflow definition events on NIP-09 deletion

Open Pratikkale26 opened this issue 3 months ago • 0 comments

Summary

buzz workflows delete reported success but didn't actually remove anything users could see: the workflow stayed in workflows list/get, and a later workflows update brought it back to life with a freshly issued webhook secret.

Fixes #4864.

Reproduction

Against a local relay on main:

$ buzz workflows delete --workflow 04542aa7-…
{"accepted":true,"event_id":"fa99cb55…","message":""}
# relay log: INFO Workflow deleted via NIP-09 a-tag (UUID) workflow_id=04542aa7-…

$ buzz workflows list --channel <ch>      # ❌ still there
[{"workflow_id":"04542aa7-…","content":"name: repro-4864\n…"}]

$ buzz workflows get --workflow 04542aa7-…  # ❌ still there
{"workflow_id":"04542aa7-…", …}

$ buzz workflows update --channel <ch> --workflow 04542aa7-… --yaml '…'
{"accepted":true,"message":"response:{\"webhook_secret\":\"a72a890c-…\"}"}  # ❌ resurrected

That last line is the part worth highlighting beyond the original report: a deleted workflow's webhook trigger can be silently re-armed with a new secret.

Root cause

handle_a_tag_deletion's workflow branch (crates/buzz-relay/src/handlers/side_effects.rs) drops the workflows row that drives execution, but leaves the kind:30620 definition event live.

Every client reads definitions by querying kind:30620 events, so nothing observable changes:

  • crates/buzz-cli/src/commands/workflows.rs — cmd_list_workflows, cmd_get_workflow
  • desktop/src-tauri/src/commands/workflows.rs — get_channel_workflows, get_channels_workflows, get_workflow

Because the event survives, publishing a new definition with the same d-tag re-upserts the row from it, which is the resurrection.

The fix

Relay — tombstone the definition event. The generic NIP-33 branch immediately below already does exactly this via soft_delete_by_coordinate; the workflow branch just never called it. The coordinate is scoped to actor_bytes — the same owner check delete_workflow_for_owner already applies — so an a-tag naming another author's pubkey cannot tombstone their definition.

This fixes list and get for every client at once (CLI, desktop, mobile, any Nostr client), rather than patching each one.

CLI — stop update from resurrecting. kind:30620 is parameterized-replaceable, so republishing a definition after deletion is a legitimate NIP-33 republish at the protocol level — the relay must keep accepting it. Rejecting it relay-side would violate the NIP. So this is fixed where the semantics actually live: update means "modify an existing workflow", so it now returns not_found (exit 1) when no live definition exists instead of silently creating one.

A note on the "by design" comment

The generic branch carried this comment:

Listed after the workflow branch so workflow's bespoke deletion (which doesn't soft-delete the events row by design — that's a separate concern) takes precedence.

I've updated it. The reasoning holds for the workflows row being a separate concern, but leaving the definition event queryable is what produced this bug — a delete that leaves the thing fully visible and revivable isn't a delete. Happy to discuss if the original intent was load-bearing in a way I've missed.

Testing

New crates/buzz-test-client/tests/e2e_workflow_delete.rs:

Test Asserts
test_workflow_a_tag_deletion_tombstones_definition_event The definition disappears from REQ results after an a-tag deletion
test_workflow_a_tag_deletion_cannot_delete_another_authors_workflow A deletion signed by a different author leaves the owner's definition intact

The regression test was validated by reverting the relay fix and re-running — it fails with a-tag deletion should remove the workflow definition from REQ results (got 1 events) and passes with the fix in place.

Also verified against a live local relay: all three reported symptoms resolved, update on a live workflow still works normally, and workflows previously orphaned by this bug can now be deleted cleanly.

cargo fmt --all -- --check       ✅
cargo clippy --workspace --all-targets -- -D warnings   ✅
just test-unit                   ✅ 8/8 suites
RELAY_URL=ws://localhost:3000 cargo test -p buzz-test-client \
  --test e2e_workflow_delete -- --ignored   ✅ 2 passed

Related

Searched open PRs for #4864 — none found.

Pratikkale26 avatar Aug 05 '26 12:08 Pratikkale26