Skip to content

fix(feishu): anchor mention replacement so a shorter key can't match inside a longer one - #96284

Closed
ly-wang19 wants to merge 1 commit into
openclaw:mainfrom
ly-wang19:fix/feishu-mention-prefix-collision
Closed

ly-wang19 wants to merge 1 commit into
openclaw:mainfrom
ly-wang19:fix/feishu-mention-prefix-collision

Conversation

@ly-wang19

@ly-wang19 ly-wang19 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Feishu assigns sequential, non-zero-padded mention keys — @_user_1, … @_user_10, @_user_11. normalizeMentions (extensions/feishu/src/bot-content.ts) replaced each key with new RegExp(escaped(mention.key), "g") — a global match with no right-side boundary. So when a message mentions 10+ users, the regex for @_user_1 also matches the @_user_1 prefix inside @_user_10/@_user_11/…, substituting the shorter mention's replacement into the longer key (e.g. @_user_10 becomes <at user_id="ou_alice">Alice</at>0). The longer key's own regex then no longer matches, so users 10–19 are silently lost/mis-attributed.

normalizeMentions runs on every inbound Feishu text message (parseFeishuMessageEvent); the returned text is what the agent/model sees.

Changes

  • bot-content.ts — anchor the per-key match with a (?![\w]) negative lookahead so a shorter key cannot match inside a longer one.
  • bot-content.test.ts — new colocated prefix-collision test.

Real behavior proof

Behavior addressed: a Feishu message mentioning both @_user_1 and @_user_1X lost/mis-attributed users 10–19; after the fix each keeps its own <at> tag.

Real environment tested: Node 22.22.1, macOS, no network/model. Vitest exercises the real exported normalizeMentions. BEFORE is origin/main's bot-content.ts (swapped via git show).

Exact steps or command run after this patch:

node scripts/run-vitest.mjs extensions/feishu/src/bot-content.test.ts

Evidence after fix:

input: "Standup: @_user_1 @_user_10 @_user_11 done"  (Alice=@_user_1, Judy=@_user_10, Kevin=@_user_11)
BEFORE: 'Standup: <at ou_alice>Alice</at> <at ou_alice>Alice</at>0 <at ou_alice>Alice</at>1 done'  (Judy & Kevin lost)
AFTER:  'Standup: <at ou_alice>Alice</at> <at ou_judy>Judy</at> <at ou_kevin>Kevin</at> done'        (each correct)

Observed result after fix: each mention resolves to its own user; the new test fails on origin/main, passes after.

What was not tested: a live Feishu group round-trip (the test drives the real normalizeMentions that parseFeishuMessageEvent calls). Existing bot.stripBotMention.test.ts stays green.

Additional checks

  • node scripts/run-vitest.mjs extensions/feishu/src/bot-content.test.ts passes; fail-before verified by swapping in origin/main's file. bot.stripBotMention.test.ts stays green. Extension oxlint clean.

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XS labels Jun 24, 2026
@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR as superseded: the useful Feishu mention-prefix fix is now owned by an open, mergeable, maintainer-labeled replacement PR with the same longer-key-first strategy and focused coverage.

Root-cause cluster
Relationship: superseded
Canonical: #96311
Summary: The current PR and the maintainer replacement PR target the same Feishu normalizeMentions prefix collision; the replacement PR explicitly supersedes this branch and is the canonical landing path.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Land or close the maintainer-owned #96311 as the canonical fix, optionally carrying over this PR's extra adjacent-longer-key test if desired.

So I’m closing this here and keeping the remaining discussion on #96311.

Review details

Best possible solution:

Land or close the maintainer-owned #96311 as the canonical fix, optionally carrying over this PR's extra adjacent-longer-key test if desired.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main passes parsed Feishu text and message.mentions into normalizeMentions, whose current replacement loop can rewrite @_user_1 inside @_user_10 before the longer key is processed. I did not run tests because this review is read-only.

Is this the best way to solve the issue?

Yes for the algorithm, but no for this duplicate branch as the landing path: descending key length fixes the collision without delimiter assumptions, and the maintainer-owned replacement PR is the safer canonical route.

Security review:

Security review cleared: The diff only changes Feishu TypeScript mention normalization and colocated tests; no dependency, workflow, lockfile, secret, permission, or downloaded-code surface is touched.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md and scoped extensions/AGENTS.md were read fully; their deep-review, plugin-boundary, and proof guidance applied to this PR review. (AGENTS.md:1, 74214000bf48)
  • Current main source behavior: Current main still iterates Feishu mentions in event order and globally replaces each escaped mention key, which lets a shorter key rewrite the prefix of a longer key before the longer key is processed. (extensions/feishu/src/bot-content.ts:281, 74214000bf48)
  • Runtime entry point: parseFeishuMessageEvent passes parsed Feishu text and message.mentions into normalizeMentions, so the helper controls agent-visible inbound mention text. (extensions/feishu/src/bot.ts:293, 74214000bf48)
  • Current PR patch shape: This PR now uses descending key length replacement and adds tests for @_user_1 with @_user_10/@_user_11 plus a longer-key adjacent text case. (extensions/feishu/src/bot-content.ts:281, 484a007ab846)
  • Canonical replacement PR: The related maintainer-labeled PR is open, mergeable, explicitly says it supersedes this approach, and carries the same longer-key-first fix with focused tests and a ClawSweeper ready-for-maintainer-look review. (e2014169708f)
  • Canonical diff comparison: The replacement PR changes the same normalizeMentions loop to sort by descending key length and adds prefix-sharing plus adjacent-text coverage, so it owns the same central fix. (extensions/feishu/src/bot-content.ts:278, e2014169708f)

Likely related people:

  • Lanfei: PR metadata and git history show this account authored the merged Feishu inbound mention-normalization work that introduced model-visible mention tags and normalizeMentions behavior. (role: introduced related behavior; confidence: high; commits: 9083a3f2e308; files: extensions/feishu/src/bot.ts, extensions/feishu/src/bot.stripBotMention.test.ts)
  • steipete: History shows this account split the Feishu content helper into the current bot-content.ts module and previously refactored mention regex escaping. (role: recent adjacent owner; confidence: medium; commits: b86bc9de95d0, f4b288b8f7be; files: extensions/feishu/src/bot-content.ts, extensions/feishu/src/bot.ts, extensions/feishu/src/mention.ts)
  • vincentkoc: Current-main blame points at this account for the latest recreation/carry-forward of the normalizeMentions helper in bot-content.ts, though the behavior predates that commit. (role: recent area contributor; confidence: medium; commits: bdc6e37503fc, 2b96f53f9782; files: extensions/feishu/src/bot-content.ts, extensions/feishu/src/bot.ts)
  • sliverp: This account opened the maintainer-labeled replacement PR that explicitly supersedes this PR and owns the same Feishu mention-prefix fix path. (role: canonical replacement author; confidence: high; commits: e2014169708f; files: extensions/feishu/src/bot-content.ts, extensions/feishu/src/bot-content.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 74214000bf48.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 24, 2026
…ions

Feishu assigns sequential, non-zero-padded mention keys (@_user_1, @_user_2, ...
@_user_10, @_user_11). normalizeMentions replaced each key with a global regex,
so once a message mentions 10+ users the @_user_1 replacement also matched the
@_user_1 prefix inside @_user_10/@_user_11/..., corrupting the longer-keyed
users. Replace longer keys first so a shorter key can never match inside a
longer one (the longer key is already substituted by the time the shorter key's
turn comes), which also correctly handles a key immediately followed by text.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ly-wang19
ly-wang19 force-pushed the fix/feishu-mention-prefix-collision branch from 44447e0 to 484a007 Compare June 24, 2026 05:39
@ly-wang19

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — addressed the rank-up: replaced the lookahead with a longer-key-first algorithm (sort mention keys by length descending, then global replace) so a shorter key can never match inside a longer one, and added a test covering a key immediately followed by ASCII text (@_user_10pinned) which the lookahead got wrong. Proof note: normalizeMentions is a pure function; the colocated Vitest drives the exact production function parseFeishuMessageEvent calls on every inbound text message — requesting a maintainer proof override for this pure-helper path if the unit proof is insufficient.

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@sliverp sliverp assigned steipete and unassigned steipete Jun 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 24, 2026
@ly-wang19

Copy link
Copy Markdown
Contributor Author

Closing to stay under the repo's active-PR limit and keep my queue focused on changes I can fully prove headlessly. This channel fix needs live-channel proof I can't generate in my current environment; the code change itself stands and I'll resubmit with live proof when I can run the channel.

@ly-wang19 ly-wang19 closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants