Repository navigation
fix(slack): decode bot self mention, content-based is_mention, bot author ids, email/is_system (#209) - #286
Conversation
…thor ids, author email/is_system (#209) Part (a) of #209. Ports vercel/chat 51322dde (#891), 683eadc1 (#947), c2b6bff0 (#883), bb7cd124 (#716) and the Slack half of 80def3ab (#707). The mrkdwn normalization, channel.post thread ids and Socket Mode retries are split out to #283. - _resolve_inline_mentions resolves the bot's own id like any other user - _detect_self_mention classifies is_mention from blocks / text / non-unfurl attachments in both parse paths; the app_mention override is gone (tri-state: None when the bot id is unknown and not app_mention) - author user_id prefers bot_profile.user_id over bot_id; self detection matches bot_profile.user_id; author.email from users.info; is_system for USLACK - linear-time mention-token matching and an iterative block walk
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 5 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…uild parts beside blocks like upstream (#209)
# Conflicts: # CHANGELOG.md # docs/UPSTREAM_SYNC.md
|
Merge gate: CI green on 1a74e11 (Lint & Type Check, test (3.12), test (3.13), CodeQL, Analyze (python), Analyze (actions)); local Codex review (gpt-6-astra, xhigh, --base origin/main) on c3d958d: "No actionable regressions found. The full test suite passed (6,949 passed, 24 skipped), along with type checking and lint/format checks for changed Python files."; 2 astra rounds (f2cf21b, c3d958d), both clean. 1a74e11 only merges origin/main (#279 Telegram, #232 Linear); conflicts were limited to CHANGELOG.md and docs/UPSTREAM_SYNC.md, and the PR's src/tests/scripts delta vs main is byte-identical to the reviewed c3d958d delta, so no re-review was needed. Local full validation on 1a74e11: 6996 passed, strict fidelity 733/733, pyrefly 0 errors, target report 151 -> 151 (+0). Bots: CodeRabbit rate-limited (no review); no other bot findings. Merging with --admin (Protect Main requires a code-owner approval). |
Summary
This is part (a) of #209: Slack inbound mentions and authors. The full port came to about 2k changed lines, over the issue's 1.5k split threshold, so it is split along the issue's own Metadata line. Part (b) (mrkdwn normalization,
channel.postthread ids, Socket Mode retries) is #283. Its implementation and tests are already written onwip/4.41-sl4-full(unreviewed)._resolve_inline_mentionsnow resolves the bot's own<@U_BOT>like any other user, through_lookup_user_name, and falls back to the id when the lookup fails.skip_self_mentionis removed.is_mention: new_detect_self_mention(event, raw_text, attachments) -> bool | None, with module helpers_mention_token_pattern,_MentionMatcher,_classify_mrkdwn_mention,_classify_blocks_mention,_classify_attachment_part, and a minimal private attachment extractor (_author_attachments/_attachment_content: blocks plusmrkdwn_inparts; [4.41/SL5] Slack inbound: pasted tables and alert attachments in message content #210 extends it for rendering). Both parse paths setis_mention, and theapp_mentionoverride is deleted. It is tri-state:Nonewhen the bot id is unknown and the event is not anapp_mention. The request-scopedRequestContext.bot_user_idwins in multi-workspace mode.user_id = user or bot_profile.user_id or bot_id or "unknown", with a guard for a non-dictbot_profile. Self detection matchesuser or bot_profile.user_id.emailcomes from theusers.infocache on the async path, andis_system = user == "USLACK"on both paths.SlackEventgainsbot_profile.Upstream commits mapped
51322dde683eadc1detectSelfMentionand the attachment/block classificationc2b6bff0bb7cd124author.email80def3abis_systemforUSLACK(the core field is #192)e71bfead,44423bdc,c3118279,92530dd3,0b63791b(Slack half)Tests ported
tests/test_slack_inbound_mentions.py, 51 tests, all upstream names fromadapter-slack/src/index.test.tsunless marked Python:is_mentiononly, because table text is [4.41/SL5] Slack inbound: pasted tables and alert attachments in message content #210), "falls back to the bot's user ID when users.info fails for its own mention", "resolves request-scoped self mention in multi-workspace mode".raw_textcell case assertsis_mentiononly, because cell text is [4.41/SL5] Slack inbound: pasted tables and alert attachments in message content #210.isMention falsecases, and the 7mention routingcases through a realChat.incoming author emailcases. 80def3ab: the 4USLACK/isSystemcases.parse_messagereturnsis_mention is Nonewhen the bot id is unknown.bot_profilefalls back tobot_id.I checked that the new tests fail against
main's adapter. 44 of the 56 tests in the full set failed there; the ones that passed are upstream regression guards whose behaviour is unchanged.Fidelity
TS_ROOT=…/vercel-chat-4.41.1 uv run python scripts/verify_test_fidelity.py --report-target:(Regenerated after merging
mainat c3d958d.)index.test.tsis not fidelity-mapped, andscripts/fidelity_target.jsonis unchanged.Divergences
None new. Two implementation choices give the same results as upstream; both are documented in
docs/UPSTREAM_SYNC.mdunder "Slack inbound mentions and authors":/<@!?id(?:\|[^>]*)?>/iwith one regex. Here it is a prefix regex plus a tail check, because the single regex took about 1.3 s on a 50k run of unclosed<@U_BOT|. Fuzzing 20k random strings against the reference regex gave identical results.RecursionError.Consumer impact (Slack)
message.text/formatteddecode the bot's own mention:<@U_BOT> hi→@BotName hi(or@U_BOT hiifusers.infofails). Useis_mentionorraw, not id-stripping.`<@bot>`that Slack sends asapp_mentionno longer reacheson_mention; it goes toon_messagepatterns. When the bot id is known, ordinary messages report a definitiveis_mention=False, so a display name in plain text no longer counts. Two cases still count as a mention: anapp_mentionwhose content never shows the known id (an Enterprise GridW…id), and anyapp_mentionwhen the bot id is unknown.B…changes toU…whenbot_profile.user_idis present.author.email(async path) andauthor.is_system(USLACK).@botmust still trigger in a channel and in a DM, and a code-only`<@bot>`must not.Validation
audit_test_quality(0 hard failures), andverify_test_fidelity --check-docsall pass.main).Part of #209
Part of #184
Merge gate
Review findings (2 robustness-test reviewers)
TestMentionMatcherpins the token forms (<@U_BOT2>, unclosed<@U_BOT,<@U_BOT|bot>,<@!U_BOT>,<@u_bot>, a|form with no later>). It also covers six ~50k-char adversarial inputs, asserting the output and not a timer, plus a 5000-deep nested block. The adversarial cases call_detect_self_mentiondirectly. Going throughparse_messagetakes about 20 s on one of them, and all of that time is spent in the sharedmarkdown_parser._parse_inline(renderingtext), not in mention detection. This PR does not touch that code.TestAttachmentPartRulescovers pretext with and withoutmrkdwn_in, title, title +title_link(pins the escape), fields with and withoutmrkdwn_in, fallback-only, fallback suppressed by another part, and whitespace-only trimming._attachment_contentno longer returns early when the attachment has blocks. Upstream (adapter-slack/src/index.ts:929) builds parts whentables.length === 0, and without table extraction ([4.41/SL5] Slack inbound: pasted tables and alert attachments in message content #210) that gate is always open. Detection is unchanged because parts are ignored for attachments with blocks. The docstring anddocs/UPSTREAM_SYNC.mdnow say [4.41/SL5] Slack inbound: pasted tables and alert attachments in message content #210 restores the tables gate.TestBlockMentionRulescovers a code span in a mrkdwn section, a mention in sectionfields, and auserelement insiderich_text_preformatted, which covers both the preformatted rule and in-code inheritance.|branch,last_close, block masking, fields walk, preformatted, in-code inheritance, pretext/title/escape/fields/fallback/trim, blocks early-return) are now killed bytests/test_slack_inbound_mentions.py.gpt-6-astra: 1 round on c3d958d, verdict "No actionable regressions found."
Bots: CodeRabbit skipped the review while the PR was a draft and posted no actionable comments. No gemini comments.
CI on c3d958d: Tests (3.12, 3.13), CodeQL and Analyze passed. Lint & Type Check was skipped on the draft
pull_requestrun, so it was run withworkflow_dispatchon the branch (run 36822035866) and passed.Local validation: ruff check/format, audit (0 hard failures),
--check-docs, strict fidelity 733/733, pytest 6949 passed, and pyrefly 0 errors.