fix(adapter): propagate mentions to all split chunks#1153
Conversation
When a bot reply exceeds Discord's 2000-char limit and is split into multiple messages, only the first chunk carries the original @mention. Receiving bots with allow_bot_messages = "mentions" reject the subsequent chunks, losing content. Add extract_mentions() to collect all Discord mentions (<@uid>, <@!UID>, <@&RoleID>) from the final content, then propagate_mentions_to_chunks() appends missing mentions to each subsequent chunk after split_message. This ensures all pieces pass the receiving bot's mention gate and get batched into a single ACP turn via per-thread mode.
|
LGTM ✅ — Clean, minimal fix for a real-world silent message loss when split chunks miss the mention gate. What This PR DoesWhen a bot reply exceeds Discord's 2000-char limit and gets split into multiple messages, only the first chunk carried the original How It Works
Findings
What's Good (🟢)
Baseline Check
Minor Note (non-blocking)Appending mentions after |
…lize Addresses all 🔴 Critical and 🟡 Important findings from team review: - Remove chunk 0 skip — all chunks get mentions propagated (PD1/F3) - Pre-deduct mention_reserve from split limit so appended mentions never exceed Discord's 2000 char hard limit (F1/PD3) - Safety cap: if chunk + footer would still exceed limit, skip append - Skip mentions inside fenced code blocks (F4/PD4) - Normalize <@!UID> to <@uid> for deduplication (PD6) - Gate propagation to Discord only (Slack doesn't need it) - Add mention_footer_len() helper - Add chunk_contains_mention() for clarity - Updated and expanded test coverage (15 tests)
Team Review — Round 1 Findings & ResolutionVerdict: CHANGES REQUESTED Findings Table
Architecture Confirmation
Key Design Decisions
Second-round ReviewLGTM ✅ — all four critical fixes verified:
Closes #1151. |
- pipeline_split_then_propagate: end-to-end split + propagate integration - extract_mentions_unclosed_fence: unclosed code fence edge case - saturating_sub_large_reserve: extreme reserve exceeding limit - role_vs_user_mention_distinction: <@&ID> vs <@id> are distinct
Summary
Fixes #1151 — when a bot reply exceeds Discord's 2000-char limit and gets split into multiple messages, only the first chunk carries the original
@mention. Receiving bots withallow_bot_messages = "mentions"reject the subsequent chunks, silently dropping content.Changes
src/adapter.rs:extract_mentions(content)— extracts all Discord mentions (<@UID>,<@!UID>,<@&RoleID>) from content, deduplicated in appearance orderpropagate_mentions_to_chunks(chunks, mentions)— appends missing mentions to each chunk after the firstsplit_message()and chunk deliveryHow it works
Testing
Related