Skip to content

perf(workflows): bound verified mention alias cost - #9686

Merged
cshtdd merged 2 commits into
camilos/fix-workflow-verified-mentionsfrom
fix-9624-mention-cost
Nov 19, 2026
Merged

cshtdd merged 2 commits into
camilos/fix-workflow-verified-mentionsfrom
fix-9624-mention-cost

Conversation

@brow

@brow brow commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #9685 (verified profile aliases in workflow mentions), targeting its branch.

#9685 makes every workflow send_message load each channel member's full kind:30382 verified-profile event, parse it into a nostr::Event while holding the writer connection, and scan the message for about five times as many names, on a tokio worker. That cost lands on every workflow send, including ones that mention no one. It also reads verified names even when the community no longer advertises verified profiles, so leftover profile heads can make an ordinary @Name ambiguous after an operator turns the feature off.

This keeps the same output tags and:

  • Skips mention resolution when the rendered text has no @. No @ means no p or buzz:workflow-mention tag can result, so the member and alias reads are skipped.
  • Projects only the three name tags in SQL (display_name, username, full_name, the same jsonb_path_query_first expression profile search uses) instead of shipping and parsing whole events. Identical case-folded names for one member are deduplicated. A malformed head no longer fails the send.
  • Tries names only at mention anchors. The resolver collects the positions of @ at a left boundary once and matches each name only there, so its cost is names × mentions instead of names × characters. Matching rules are unchanged.
  • Reads verified names only where the community advertises them, using the same verified_profiles::discovery check as profile search. Otherwise the heads join is skipped.

Validation

  • Extended the existing workflow alias test (workflow_send_message_binds_authority_to_authored_mentions): it now runs with verified profiles advertised, adds a message with no @, and repeats two cases on the same roster without the advertisement (@alex notifies no one, @Alex Example notifies the ordinary member).
  • The existing resolver unit tests cover the anchor-only scan.

Regressions

None expected. Output tags are identical for every advertised community. In a community that does not advertise verified profiles, workflow mentions fall back to ordinary names, which is what they matched before #9685.

Skip mention resolution when the rendered text has no @, project only
the three verified name tags in SQL instead of parsing whole kind:30382
events, deduplicate folded aliases per member, try names only at mention
anchors, and read verified names only where the community advertises
verified profiles.

Signed-off-by: Tom Brow <tomb@block.xyz>
@brow
brow marked this pull request as ready for review November 19, 2026 01:06
@brow
brow requested a review from a team as a code owner November 19, 2026 01:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T01:07:48.753028Z e0526e6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0526e62c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/buzz-relay/src/workflow_sink.rs Resolved

@jedwards27 jedwards27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 :bot: Jude’s code review agent — blocking code finding at e0526e62c8f70a1b55b50e0f2d5d160337197c34 (base 3e0cdfa13fd1638e8469e4fb96b6d3fa6ba66c19). This review is filed as a comment per this repository's AGENTS.md review policy; it is not a merge clearance.

P2 — a DB authorization lookup failure silently loses a workflow mention. crates/buzz-relay/src/workflow_sink.rs:543–545 now treats verified_profiles::discovery(...).await.is_some() == false as verified aliases disabled. In DB-backed NIP-FI mode, crates/buzz-relay/src/verified_profiles.rs:130–136 turns a failed binding lookup into the same None (.await.ok().flatten()), even though crates/buzz-db/src/store/nip_fi_binding.rs:157–185 returns a real database error. If that query fails transiently but later roster/name/event writes succeed, an authored verified-only @alias is persisted without p or buzz:workflow-mention tags, while crates/buzz-workflow/src/executor.rs:700–740 records sent: true. The named agent never wakes and the run reports success. The swallowed error existed in discovery, but using discovery as a send-time authorization gate is introduced here. Author action: make this sink's advertisement lookup fallible and propagate uncertainty before event persistence (without changing discovery's external compatibility behavior); add an injected lookup-failure test through the production send seam asserting no false-success persisted event, plus advertised/unadvertised recovery cases. Verification owner: author for fix/test; reviewer for changed-head integration.

Performance contract/test gap: the added no-at-sign case at workflow_sink.rs:1785 asserts output tags, but would still pass if the new text.contains('@') read-skip guard were removed. Please make that optimization falsifiable with a production-seam zero-member/alias-read assertion or equivalent query-count evidence; this is a coverage request, not a second observed runtime failure.

Scope/validation: changed files are relay sink and DB name projection/observability; no UI files or native journey. Independently traced workflow send → membership/names → signed event persist → executor outcome, verified-name gating and SQL projection. At the clean local e0526e62c tree git diff --check passed. GitHub's exact-head check rollup reports Rust Unit Tests, PostgreSQL Tests, Backend Integration, Relay E2E and Desktop E2E Integration successful; no personal full-suite or fault-injected live-relay run was performed. CI success does not exercise the outage condition above. No native artifact was tested. Re-review the fix at its new exact head.

A failed binding lookup made the sink treat verified profiles as not
advertised, so an authored verified-only mention lost its tags while the
run reported success. Propagate the error like the roster and name reads
beside it; discovery() keeps its fail-closed behavior for its other callers.

Signed-off-by: Tom Brow <tomb@block.xyz>
@brow

brow commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 Re Jude's review agent's findings:

  • P2, discovery lookup failure: addressed in e1c954b. The sink calls a new fallible verified_profiles::try_discovery and maps a binding-lookup error to ActionSinkError::Database before persisting, matching the member and mention-name reads in the same block. discovery() is now try_discovery(..).ok().flatten(), so NIP-11 and profile search are unchanged. I skipped the injected-failure test: the send seam has no way to fail only the binding lookup without adding test-only store plumbing.
  • Coverage for the @ guard: declining as optional. The guard is a cost property, not a correctness one (output tags are identical either way, which the no-at-sign row checks), and a read-count assertion would need a test-only seam in the store.

@cshtdd
cshtdd merged commit 89938da into camilos/fix-workflow-verified-mentions Nov 19, 2026
83 checks passed
@cshtdd
cshtdd deleted the fix-9624-mention-cost branch November 19, 2026 17:40

@jedwards27 jedwards27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 :bot: Jude’s code review agent — recommend changes at e1c954bb3979adda9fbcb94b770e1b400aa1c6e4 (base 3e0cdfa13fd1638e8469e4fb96b6d3fa6ba66c19). Per this repo’s AGENTS.md, this is a comment review, not a GitHub Request Changes event or merge clearance.

P2 — the outage-vs-disabled fix lacks a falsifiable send-path regression (crates/buzz-relay/src/workflow_sink.rs:545–548; verified_profiles.rs:127–153). The current implementation is sound: try_discovery propagates a database binding-lookup error and send_message returns before signing/persisting the event. The workflow executor records failure rather than sent: true; after DB recovery, the run must be retried. However, the extended workflow_send_message_binds_authority_to_authored_mentions case uses an Env-sourced advertised community. It does not induce CommunitySource::Database binding-lookup failure, so reverting the call to the old fallible-looking discovery() would leave these tests green while reviving silent mention loss. TESTING.md:25–31 requires regressions to bind the production seam and fail when the guard is removed. Author action: add a production RelayActionSink::send_message regression with DB-backed NIP-FI and an injected failed binding lookup; assert the action fails and no event persists (then verify successful routing after recovery if practical). Verification owner: author for the test; reviewer/tooling for rerun and local relay journey. This is a coverage finding, not a claim that the current code misroutes mentions.

Other contract checks: verified names remain gated by community advertisement (channel_members.rs:2762–2773); a no-@ message skips mention resolution. An optional query-count assertion would make that performance claim falsifiable; it is not a separate blocking defect. The code delta is confined to verified_profiles.rs and workflow_sink.rs after the earlier review; no new schema or client behavior was introduced by this fix.

Validation at the clean exact head: independently checked the two-file fix and live PR/check rollup. Local cargo fmt --all --check passed; cargo test -p buzz-db passed (library 219, source-policy integration 44, doctests 5); cargo test -p buzz-relay --lib workflow_sink::tests -- --test-threads=1 passed (23); git diff --check passed. The full cargo test -p buzz-relay was incomplete: access::tests::read_lines_warn_only_on_error failed and config tests stalled, so the run was stopped; no cause was established or attributed to this PR. GitHub’s exact-head Rust Unit Tests, PostgreSQL Tests, Backend Integration (relay e2e), Relay E2E, Rust Lint and DCO checks report success. The Postgres-backed workflow send journey was not run locally because Postgres/Redis and Docker were unavailable; no native/client artifact was tested. CI does not exercise the injected binding outage. No broader full local just ci/just test claim is made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants