feat(workflow): let workflows add reactions to messages
Fixes #2395.
What changes
Workflow add_reaction actions now publish a signed kind-7 reaction against the triggering message through the existing relay event path.
The reaction includes:
- the target event
etag; - the target event kind
ktag; - the target author's
ptag required by NIP-25 clients and Buzz's author-targeted push subscription; - the workflow owner as the signer.
The sink resolves the effective target author through the same attribution helper used by ingest, so reactions to agent-authored messages target the actual author rather than a relay signer. Duplicate execution remains idempotent. The relay-backed regression now subscribes to the reaction by its actual kind-7 and e-tag shape, while the follow-up message retains its channel-scoped filter.
Safety and scope
- No public reaction REST endpoint is added.
- Desktop and mobile rendering are unchanged.
- Manual workflow triggers still cannot use
add_reactionbecause they have no triggering message ID. - Custom emoji metadata remains limited to the action's existing reaction-content field.
Verification
cargo fmt --all -- --checkcargo clippy -p buzz-workflow -p buzz-relay -p buzz-test-client --all-targets --all-features -- -D warningscargo test -p buzz-workflow -p buzz-relay -p buzz-test-client --no-fail-fast: workflow and test-client suites passed; the unprovisioned relay run reached only the existing database-dependent failures.cargo test -p buzz-relay workflow_sink::integration_tests::workflow_add_reaction_persists_attributed_kind_7_and_dedupes -- --ignored --nocapture: passed against PostgreSQL and Redis.just test: all nine unit/package/database stages passed. The workspace integration stage reproduced the unrelatedbuzz-agenttiming failuresteer_folds_into_active_turn_without_cancelling; that test passes in isolation, and this branch does not modifybuzz-agent.
This refresh is not production deployment evidence.
I rebased this branch onto current main and checked the emitted reaction against the consumers that now exist there.
The feature is still relevant, but the old branch omitted the target author's NIP-25 p tag. That was not just metadata polish: Buzz's current author-targeted push subscription uses the p tag, so workflow reactions could be stored and rendered while failing to notify the target author.
Head d2c7a8343d03b94f799dec12c60a0e051becfdf5 resolves the effective author of the triggering event, adds the signed target-author p tag, and preserves the existing deduplication path. The regression now asserts the e, k, and p tags together.
The affected package suites, strict Clippy, and Rust formatting were refreshed. The non-database tests passed. Nine unrelated relay media/admin tests could not obtain this host's local PostgreSQL pool, and a serial rerun hit the same boundary. The new ignored PostgreSQL regression compiled, but I am not presenting the unavailable database run as passing evidence.
Rebased this branch onto current block/buzz main at c55e421a0.
Head moved from cad2b5364 to 7f905a532. git range-diff shows the add_reaction relay-sink patch is unchanged, and the branch now has a direct merge base with current main.
Verification:
- The full
buzz-workflowsuite passed: 153 tests passed and 2 remained explicitly ignored. - All 17 relay workflow-sink tests passed; 1 Postgres-backed test remained explicitly ignored.
- The workflow-actions E2E target compiled and remained explicitly ignored because no relay service was running.
git diff --check, DCO trailer checks, and the direct merge-base audit passed.
GitHub checks are rerunning on the new head.
Rebased onto current block/buzz main at b1b283cd4 and rechecked the branch against #2495 and #2634. #2494 remains the focused submission for #2395: #2495 bundles unrelated Desktop transport work, while #2634 explicitly excludes workflow reactions.
The rebase audit found one test defect rather than a production-path defect. The relay emits the kind-7 reaction with its target e tag but no channel h tag; the ignored E2E subscribed with both, so it could never observe the actual event when enabled. The regression now uses separate filters for the reaction's real event shape and the channel-scoped follow-up message.
Published head: 1a4f5bd833c417085ef2f6edff2e92047276d94d.
Verification passed for formatting, strict Clippy across the three affected packages, and the PostgreSQL/Redis-backed kind-7 persistence and deduplication regression. The repository just test gate passed nine stages before reproducing the unrelated buzz-agent timing failure steer_folds_into_active_turn_without_cancelling; that test passes in isolation, and this branch has no buzz-agent diff.
Rebased onto block/buzz main at ce3cf3cd2591f132f286fbc0a42a9e6699d0b08d and rechecked the workflow action against current relay ingest, NIP-25 consumers, issue #2395, and competing work.
The PR remains valid. Current main still sends add_reaction to the nonexistent /api/messages/{id}/reactions route instead of publishing a signed kind-7 event. #2495 is a broader bundle that includes unrelated Desktop transport work, and #2634 covers other reaction producers rather than workflow reactions. Neither supersedes this focused relay-sink implementation.
The rebase was clean. The existing correction remains necessary: the workflow reaction carries the target event's e and k tags plus the effective target author's p tag, preserving NIP-25 attribution, author-targeted notification, and idempotent execution. No further production-path change was needed.
Exact-head verification on 8cd7bc6e917fbd4ede6ca572aee1c39b9bdbd732:
- Full
buzz-workflowsuite passed: 153 tests, 0 failures, 2 explicitly ignored. buzz-test-clientunit coverage passed, and its ignored integration targets compiled.- All 17 non-database relay workflow-sink tests passed.
- The broad relay library run completed with 830 passing tests, 38 ignored, and 9 existing database-dependent failures: 7 direct
Sqlx(PoolTimedOut)media failures and 2 admin 500-versus-404 assertions under the same unavailable database path. - Rust formatting passed, and strict Clippy passed across
buzz-workflow,buzz-relay, andbuzz-test-clientwith all targets, all features, and warnings denied. git diff --check, conflict-marker scan, merge-base audit, and required DCO trailers passed.
The PostgreSQL/Redis-backed kind-7 persistence and deduplication regression compiled but could not be rerun on this host because no Docker daemon, PostgreSQL service, or Redis service is available. I am not presenting that unavailable integration gate as new passing evidence; the current branch remains limited to the verified code and unit/package results above.
Review and rebase summary
Reviewed the PR for accuracy against current block/buzz main at d42d60d64 and rebased the branch onto that commit.
What this PR does
Adds an add_reaction action to the workflow ActionSink trait, implemented by RelayActionSink. Workflows can now publish a kind:7 reaction event attributed to the workflow owner. The relay signs the event; the actor tag preserves the workflow owner as the effective reaction author for deduplication, deletion, and reaction summaries. The target author's p tag is included for NIP-25 subscription and push notification reachability. A nonce tag prevents delete-then-readd event ID collisions at second granularity.
Accuracy review
- The
resolve_workflow_tenanthelper is correctly extracted from the existingsend_messagepath, avoiding duplication of the community-host lookup. - The reaction target is validated: the event must exist, be scoped to a channel, and the channel must not be archived. The workflow owner must be a member of the target channel (or the channel must be open).
- Emoji length is bounded at 64 characters. Empty emoji defaults to
+(matching the existing reaction handler convention). - The
insert_reaction_event_with_thread_metadatacall correctly threads through the target event ID and author pubkey bytes for deduplication. TheReactionEventInsertOutcomematch handlesTargetMissing,Duplicate(returnsAlreadyPresent), andInserted(dispatches the persistent event and returns the event ID). - The integration test (Postgres-gated) verifies: reaction persists with correct kind, content, tags, and attribution; duplicate reaction returns
AlreadyPresent; delete-then-readd publishes a fresh event with a different ID. - No
unwrap()orexpect()in production paths. No new dependencies.
Rebase result
Head moved from 8cd7bc6e9 to 44478d442. No conflicts. git range-diff shows the patch is unchanged.
CI
DCO passes. Semgrep OSS and zizmor were pending at the time of this comment.
Rebase and accuracy review (2026-08-07)
Rebased onto current main (2b873cf20). Clean fast-forward through the intermediate d42d60d64 base — 52 commits applied, no conflicts.
Branch state: d2c7a8343 (was 44478d442 at the intermediate base) Mergeable: ✅ MERGEABLE · BLOCKED (branch protection — awaiting maintainer review)
Accuracy review
The PR adds add_reaction as a workflow action that publishes a kind 7 event through the relay sink (workflow_sink.rs) instead of making an HTTP POST to the old /api/messages/{id}/reactions endpoint. The AddReactionOutcome enum distinguishes Added from AlreadyPresent, and the executor calls engine.action_sink().add_reaction(...) with the workflow owner's pubkey.
⚠️ Important — security regression from #4607. Main merged PR #4607 (fix(workflow): bind trigger author to the signed event) which changed build_trigger_context to derive trigger_author exclusively from the signed event pubkey, preventing an actor tag from impersonating another identity. This PR's branch still uses the pre-#4607 code that reads the actor tag and falls back to the pubkey. The rebase preserves this branch's version because the PR's diff is against the pre-#4607 base. When this PR merges (squash), the squashed commit will revert #4607's security fix.
Recommendation: before merging, resolve this regression by keeping main's event.event.pubkey.to_hex() for the author and removing the actor tag lookup. Alternatively, rebase the PR again after #4607 and drop the lib.rs changes that revert the fix.
The e2e test (e2e_workflow_actions.rs) correctly tests that a workflow with an add_reaction step emits a kind 7 event and continues to the next step. The test filter includes the channel h tag, which is an improvement over the intermediate-base version.
No unwrap()/expect() in new production paths. No new dependencies.
This is the third recurring review + rebase pass for the open BradGroux PRs on block/buzz.
What this PR does
Adds an add_reaction action to the workflow action sink, allowing workflows to publish reactions (kind:7) to messages. The implementation:
- Resolves the workflow tenant context (community + host) via the shared
resolve_workflow_tenanthelper (extracted fromsend_message). - Validates the target event exists and is scoped to a channel.
- Checks the reaction author is a member of the target channel (or the channel is open).
- Bounds the emoji length (max 64 chars), normalizes empty emoji to
+. - Signs the kind:7 event with the relay keypair, includes
#e(target),#p(target author),actor(workflow owner),buzz:workflow, andnoncetags. - Inserts via
insert_reaction_event_with_thread_metadata, returningAlreadyPresentfor duplicates orPublishedfor new reactions.
⚠️ Security regression — remains unresolved
PR #2494 reverts the security fix from #4607 (fix(workflow): bind trigger author to the signed event). The branch still reads the actor tag for trigger_author instead of using event.event.pubkey.to_hex(), which allows impersonation. The squash-merge will revert #4607. Recommend resolving before merge by keeping main's event.event.pubkey.to_hex() for the author.
This was flagged in the previous two review passes and remains unresolved.
Correctness
- The shared
resolve_workflow_tenanthelper correctly eliminates duplication betweensend_messageandadd_reaction. - The member check and channel-visibility check are correct (non-member allowed only for open channels).
- The nonce tag prevents event-ID collisions on rapid delete-then-readd.
- The
allow_self_tagging()call is needed because the relay signs the event (its own pubkey may appear in tags). - Emoji length validation uses
chars().count()(correct for Unicode). - No new dependencies. No
unwrap/expectin production paths.
Rebase result
Rebased from 2b873cf20 to current main 02f640bc4 (7 commits). Clean rebase, no conflicts.
- Old head SHA:
2026f35694c56bdb8cd3129c4410b7f94373c62f - New head SHA:
4abb60db3b6a6ced1acfd5d4d795773b645be4fe - Mergeable: ✅ MERGEABLE
- CI: DCO ✅
No code changes were made — this was a review + rebase pass only.
Correction: no security regression
This is a correction to the "Security regression" section of the previous review comments. After tracing the actual code on the current branch and main, #2494 does NOT revert #4607's security fix.
#4607's fix is in buzz-workflow/src/lib.rs — build_trigger_context now derives trigger_author from event.event.pubkey.to_hex() instead of reading the actor tag. That code is identical on both main (02f640bc4) and this branch (4abb60db3). The only diff in that file between main and this branch is exporting AddReactionOutcome. The regression test build_trigger_context_ignores_actor_tag is also present on both.
The actor tag that #2494 adds to kind-7 reaction events is consumed by effective_message_author in ingest.rs — an existing helper that resolves the real author behind a relay-signed event for deduplication, deletion, and reaction summaries. This is a different code path from build_trigger_context, which is the one #4607 hardened. The actor tag is data metadata for attribution, not an authorization input.
No action needed. The earlier "security regression" flag was a false alarm caused by not diffing the actual build_trigger_context function between the branch and main.
Portfolio review update (2026-08-09)
I reviewed workflow-generated reactions against current main and NIP-25. The relay publication path is still needed. Review found two interoperability gaps in the branch: the emitted event omitted the target-kind k tag described by the PR, and an empty emoji was stored as the default + reaction while the signed event still carried empty content.
I rebased the branch onto 5bf78671f45178f8de02ba18d3d321cbbf19cd1f, added the target k tag, normalized empty reaction content before signing, and added regression coverage. The full workflow package suite passes (154 passed, 2 ignored). The full relay unit suite reached 858 passing tests; nine unrelated environment-dependent tests failed on unavailable or timed-out Postgres state and a global telemetry filter. The changed relay package compiles successfully and upstream checks are rerunning.
Portfolio rebase and review update (2026-08-11)
Rebased onto main at 7e6e9c547 (2026-08-10). No conflicts.
Still needed: Workflow add_reaction actions still cannot publish signed kind-7 reactions through the relay event path. No newer main commit adds this capability. The reaction subscription documentation in #3487 and the mobile reaction popover in #5025 are unrelated to workflow-initiated reactions.
Verification: cargo check -p buzz-relay -p buzz-workflow passes cleanly. The PR adds a relay publication path in workflow_sink.rs (365 lines), resolves the effective target author through the same attribution helper used by ingest, and includes 184 lines of E2E tests in buzz-test-client.
Rebased onto latest main (4b3570671, the 0.5.10 release). No conflicts — the workflow reaction files had no recent overlapping changes.
Reviewed for accuracy and continued relevance:
- Workflow
add_reactionactions still need to publish signed kind-7 reactions through the relay event path — no recent commit addresses this. - The relay sink and interoperable reaction event changes are still the correct approach (fixes #2395).
- E2E test coverage for the reaction publish path is included.
The PR is mergeable and ready for review.
Portfolio rebase and review update (2026-08-13)
Rebased onto main at a96af8952 (2026-08-13). Conflict resolved.
Conflict resolved
crates/buzz-workflow/src/executor.rs — Main added a community deletion fence (acquire_serving_write / protect) wrapping the match action block via #4425. The PR replaced the add_reaction_impl HTTP approach with engine.action_sink()?.add_reaction() + AddReactionOutcome, and extracted load_workflow_for_run as a shared helper.
Resolution: Kept main's fence wrapper and applied the PR's changes inside it:
- Added
load_workflow_for_runhelper - Refactored
SendMessageto use the helper (replacing inline db calls) - Replaced
add_reaction_impl/shared_http_clientwithaction_sink()?.add_reaction()+AddReactionOutcomematch - Removed the
add_reaction_implandshared_http_clientfunctions - Updated import to include
AddReactionOutcome
Still needed
Yes. The workflow reaction event feature is not superseded. No recent main commit adds reactions through the relay sink.
Verification
cargo check -p buzz-workflow passes clean. All 14 portfolio PRs confirmed MERGEABLE on GitHub.
Rebase review — 2026-08-15
Rebased onto current main at 82f7ed153 (2026-08-15). 41 new commits landed since the last review point (a96af8952, 2026-08-13). This PR rebased cleanly with no conflicts.
Still-needed assessment
Checked all 41 new commits for overlap. None supersede this PR. The PR remains the correct fix for its subject area.
Verification
cargo checknot required — no Rust conflicts- GitHub confirms
MERGEABLEstatus
Rebased onto main at d8281b9c9 (2026-08-15). No conflicts — the branch rebased cleanly.
Three commits landed on main since the last rebase point (82f7ed153):
- #5947 hide the offcanvas-collapsed sidebar so it stops painting over the community rail
- #5645 Polish mobile message threads and composer
- #5116 require device authentication for identity export (mobile)
All three are mobile or desktop sidebar changes with no overlap with this PR's subject area. The fix is still needed — no recent commit addresses the same problem.
Verification: tsc --noEmit passes. GitHub confirms MERGEABLE.
Rebased onto current main (f956e6fe0, 2026-08-17). No conflicts. Still needed.
Rebase and review check — 2026-08-20
Rebased onto latest main (a9640c7cc). No conflicts. GitHub reports MERGEABLE.
Accuracy review: The workflow executor does not support adding reactions to messages. action_sink.rs and executor.rs have no reaction event kind support. Workflows that want to react to messages (e.g., acknowledge receipt) cannot do so. Feature not present in main.
Continued relevance: No recent main commits add workflow reactions. PR is still needed.
Rebased onto latest main (025425591). One conflict in crates/buzz-relay/src/workflow_sink.rs.
Main's #6178 added a workflow_reply_in_thread_threads_onto_parent test and a workflow_reply_to_missing_parent_errors test to the integration_tests module. This PR adds workflow_add_reaction_persists_attributed_kind_7_and_dedupes to the same module. Resolved by keeping all three tests — main's two thread tests followed by this PR's reaction test.
The PR's add_reaction implementation was also adapted: resolve_workflow_tenant (which existed in the PR's base) was replaced by main's inline tenant resolution pattern (lookup_community_host + TenantContext::resolved), matching how send_message resolves the tenant in the current main. Imports for KIND_REACTION, TenantContext, and AddReactionOutcome were restored.
cargo check -p buzz-relay -p buzz-workflow passes clean.
Rebased onto latest main (e23632941). One conflict resolved in crates/buzz-relay/src/workflow_sink.rs.
Main's #6178 added workflow_reply_in_thread_threads_onto_parent, workflow_replies_recover_metadata_less_parent_ancestry, and workflow_reply_to_missing_parent_errors tests in the same integration_tests module as the PR's workflow_add_reaction_persists_attributed_kind_7_and_dedupes test. All four tests are kept — main's thread/reply tests followed by the PR's reaction test. The PR's add_reaction implementation was already adapted to main's inline tenant resolution pattern in a prior rebase; no further code changes were needed beyond the test module merge.
cargo check -p buzz-relay -p buzz-workflow clean.
This PR was accidentally closed when branches were force-pushed after a commit identity rewrite. The changes have been re-created as #6640 with the same commits rebased onto the latest main. Review history and comments from this PR are preserved here for reference.
https://github.com/block/buzz/pull/6640