Skip to content

Keep IM replies when an IM message event is redelivered - #1908

Merged
Fei2411 merged 1 commit into
devfrom
fix/1869-im-droporigin-replies
Nov 21, 2026
Merged

Fei2411 merged 1 commit into
devfrom
fix/1869-im-droporigin-replies

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Issue

Fixes #1904
Refs #1869, #1886 (these wait on a maintainer decision, see below)

What changed / 改了什么

Bug: when the same IM user/message event (same im: rpcId) arrived a second time, requests had already dropped that rpcId. The classifier then took asked === undefined → dropOrigin(), which set mixed and silently stopped the whole turn's replies from going to IM.

Overlap with #1750: same classifier in session/event, just before these branches. #1750 skips attached-context sources and explicitly excludes REPLY_KIND and rpcId sources, so it does not cover this path. The two changes don't conflict in meaning, but because they edit nearby lines, the second to merge may need scripts/merge-dev.sh.

Changelog

Replies to an IM message are no longer lost when the platform delivers the same message twice.

How I checked it / 怎么验证的

  • npm test (in ds-bot/): 3480 pass, 0 fail, 4 skipped. The 4 new redelivery and warning tests fail on the unfixed code and pass with the fix; a 5th test checks the 200-id limit.
  • node scripts/build-client.mjs --check
  • npm run lint (0 errors)
  • Smoke test: DSH dsh-v0.2.2-rc.1, mock model, all 56 steps passed
  • Screenshot attached, for interface changes / 界面改动已附截图 (no interface change)

Also ran the leak scan (scripts/scan.mjs): must fix 0. Not verified: a real WeChat redelivery. The issue's production trace doesn't prove one happened.

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 改了 src/client/ 就已重新 build 并提交 client.js。 (not changed)
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息,截图里也没有。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。

Agent: Devin (Cognition)


Product Engineer opened this PR for Lulu
Implemented in session Fix IM replies dropped by dropOrigin
Review with Devin · Open in Devin Desktop


Keep a bounded process-local record of admitted IM RPC IDs so repeated events cannot withdraw an active origin or reclaim a later turn. Preserve unknown-request and mixed-turn isolation, and warn once when mixed-origin output is withheld.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-20T16:39:18.087410Z 73a9820 PR opened
ℹ️ 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.

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code Reaper review (comments only): ready for the maintainer. No blocking issues.

Does what it says

  • On dev, a second user/message with an already-used im: rpcId hits requests.get() === undefined → dropOrigin(), sets mixed, and the rest of the turn's replies are silently dropped. The new consumedRequests check returns before classification, so a duplicate no longer claims, drops or consumes pendingReset. A truly unknown rpcId (after a restart) still fails closed.
  • No false collisions: every IM rpcId is im:<platform>:<randomUUID> (rememberRequest, the card-answer path), so the 200-entry set cannot match a different message.
  • The warning fires only when an origin really was withdrawn or a claim was refused in this turn (withheldOrigins is set from dropOrigin only when an origin existed, and from a refused claimOrigin), and it is cleared by resetOrigin at turn start/end. A plain Web turn after an IM turn does not warn, because turn/start resets the origin first. No message text or ids are logged.

Verified on 73a98202

  • npm test: 3480 pass, 0 fail, 4 skipped (Windows-only). test/im.test.js: 78/78. npm run lint exits 0 (warnings only). build-client --check OK.
  • PR body has Agent: Devin (Cognition) and Fixes #1904. I did not rerun the bench smoke test.

Non-blocking notes

  1. The code comment says consumed ids are ignored "including redelivery after their turn ended". In that case turn/start has already reset the origin and cleared withheldOrigins, so that new turn's replies are withheld without the new warning. Not sending a second answer to IM for a duplicate is reasonable, but the log gap is exactly the case #1904 wants to see. Consider warning (or a debug line) when a consumed rpcId is ignored, so the next production trace shows whether a redelivery happened.
  2. The fix is defensive: nothing in DS Bot re-sends an IM rpcId (retryTurn builds a fresh source; carryOriginSource in parts.js strips rpcId), so the duplicate would have to come from DSH. The PR body says this honestly; keep #1904 open until the warning confirms the cause, or close it on merge with that caveat.

Overlap with #1750

  • Both add an early return as the first line of the user/message branch in session/event, so they conflict textually (one hunk). Resolution is to keep both lines; they are independent because isAttachedContextSource() excludes any source with an rpcId. I resolved it that way locally and re-ran test/im.test.js (1908 + 1750 combined: 90/90 pass).
  • Suggested order: land #1750 first (older, already re-reviewed, wider impact on every IM turn with a context snapshot), then bring this branch up to date with scripts/merge-dev.sh.
  • Other open PRs touching im/index.js (#1817, #1302, #1201) already conflict with dev; no new overlap from this PR.

Written by Devin

@Fei2411 Fei2411 added agent/devin Opened by Devin review/approved Independent review passed — ready to merge labels Nov 21, 2026
@Fei2411 Fei2411 added this to the v0.3.9 milestone Nov 21, 2026
@Fei2411 Fei2411 added the reviewed-by/devin Reviewed by Devin label Nov 21, 2026
@Fei2411

Fei2411 commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Review: approved
Reviewer: Antigravity (Claude Sonnet 5.5) @ 73a9820

Independent first-principles review passed:

  • Bounded FIFO consumedRequests (200 entries) ignores redelivered im:<platform>:<uuid> user/message events without poisoning the active turn origin, re-claiming a later turn, or consuming pendingReset; unknown rpcIds still fail closed.
  • Per-turn withheldOrigins warning logs once without leaking message content or IDs, and does not alter existing REPLY_KIND or mixed-turn policy.
  • Regression tests cover redelivery, single warning per turn, unknown rpcId fail-closed, group redelivery, and eviction; CI green.

@Fei2411 Fei2411 added the reviewed-by/antigravity Reviewed by Antigravity label Nov 21, 2026
@Fei2411
Fei2411 merged commit f7c15e5 into dev Nov 21, 2026
15 checks passed
@Fei2411
Fei2411 deleted the fix/1869-im-droporigin-replies branch November 21, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/devin Opened by Devin review/approved Independent review passed — ready to merge reviewed-by/antigravity Reviewed by Antigravity reviewed-by/devin Reviewed by Devin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant