buzz icon indicating copy to clipboard operation
buzz copied to clipboard

workflow_sink's @-mention parser is a third divergent implementation — workflow-emitted **@Name** emits zero p tags

Open bosoud opened this issue 4 months ago • 3 comments

Split out of #2526 — noted by @SeanGearin while reviewing #2547.

Problem

#2526 identified two divergent @-mention parsers (Rust buzz-sdk/src/mentions.rs and TS desktop/src/features/messages/lib/hasMention.ts). There is a third: resolve_mention_pubkeys in crates/buzz-relay/src/workflow_sink.rs, whose doc comment says it "defines the matching contract" for workflow-emitted kind:9 p tags.

Its left-boundary check accepts only start-of-string, whitespace, or (:

let is_left_boundary = |i: usize| i == 0 || chars[i - 1].is_whitespace() || chars[i - 1] == '(';

So a workflow-generated **@Robby** emits zero p tags. Those p tags gate ACP agent wake (event_mentions_agent, crates/buzz-acp/src/lib.rs), which reproduces the exact stalled-handoff failure mode from #2526 on a surface where the text is machine-generated — an agent or template emitting emphasis around a mention is not a user typo, it's routine markdown.

The right side of this parser is already emphasis-tolerant (it rejects only name-continuation chars, alphanumeric | _), so only the left boundary needs widening. Note the _ wrinkle: a trailing _ after a name is a name-continuation char here, so _@robby_ has a second, smaller divergence too.

Suggested direction

After #2547 lands, buzz-sdk::mentions::is_mention_lead is the shared definition of "what may precede an @" (whitespace, (, *, _, |, start). buzz-relay already depends on buzz-sdk, so workflow_sink.rs can call it directly instead of keeping a private boundary rule — that would take the parser count needing manual sync from three to two.

Longer term (already noted in #2526): the Rust and TS implementations should be one contract with shared test vectors, or this class of drift recurs.

bosoud avatar Jul 24 '26 08:07 bosoud

Fix in #: widen workflow mention left-boundary for markdown emphasis.

chessing234 avatar Jul 24 '26 08:07 chessing234

Supporting data point, distinct sub-case (not markdown-boundary related — flagging here rather than as a new issue since it's the same parser and file):

Tested a workflow send_message step with the mention written as plain inline text, no markdown emphasis at all: "@StayLogic Feedback Intake inline-mention-wake-test ..." (target agent's display name is the three-word "StayLogic Feedback Intake"). Result: zero p tags emitted for that agent — only the usual workflow-owner attribution tag (see #3638). Since there was no **/emphasis involved, this doesn't look like the left-boundary issue described above; more likely resolve_mention_pubkeys only matches a single whitespace-delimited token after @ and never attempts to resolve against multi-word display names at all, so "@StayLogic" alone (or the whole thing) simply doesn't match any channel member. If that's the actual behavior, worth a test vector for multi-word display names specifically alongside the emphasis-boundary fix already proposed here.

silveyy avatar Aug 06 '26 23:08 silveyy

Thanks @silveyy - real one, and worth a vector, but I read it as a separate fix from the boundary widening and would keep them apart so the open PR stays narrow.

Two different failure modes in the same function:

  • Left boundary (this issue's original case): a character-class problem - what may precede @. **@Robby** fails only because * isn't in {start, whitespace, (}. The fix is widening that predicate, and post-#2547 the predicate is is_mention_lead, so workflow_sink should call it rather than keep its own rule. Small, and it takes the parser count from 3 to 2.
  • Multi-word display names (your case): worth a vector, but I read workflow_sink.rs before saying more and it isn't a matching-strategy gap - match_name_len already folds the full member name including spaces, and names are matched longest-first, so a three-word display name is attempted. Your zero-p-tags result is real, but the cause is likely upstream of the parser: worth checking whether the members slice actually carries "StayLogic Feedback Intake" as the name key, or only a handle. Either way it's separate from the boundary widening.

So: land the boundary fix as-is, don't scope-creep the open PR, and take the multi-word case as its own thread once we know where it actually breaks.

And worth confirming the boundary bug is workflow_sink-specific - if buzz-sdk's Rust parser and the TS hasMention also reject */_ before @, it's a shared-contract gap and belongs in the shared definition #2526 points at, not three separate patches.

SeanGearin avatar Aug 07 '26 00:08 SeanGearin