Skip to content

Stop IM replies leaking background results across chats - #1953

Merged
Fei2411 merged 3 commits into
devfrom
fix/im-background-origin-leak
Nov 21, 2026
Merged

Fei2411 merged 3 commits into
devfrom
fix/im-background-origin-leak

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Issue

Fixes the regression from #1920 that Devin Review flagged on #1917 (finding). Two IM chats can share one Bot Session. If a background job or subagent started in chat A's turn finishes (tool-jobs / subagent-settled) during chat B's turn, the reply that uses A's result is sent to B. Since #1920, the claimed IM origin holds for the whole turn, so nothing in that turn withdraws it. The same leak happens in IM groups: when a group member Bot takes in such a result, its group reply goes out through the room's Session.

What changed / 改了什么

  • ds-bot/src/host/im/index.js: a job or subagent completion that can't be shown to belong to the active IM claim drops the origin through the existing dropOrigin path. In a group, the drop also covers the room Session's claim, and a pending reset can't turn delivery back on later in that turn. For the rest of that turn, no IM output is sent; nothing is redirected. Every other input, Desktop/Web and card answers included, keeps Keep a turn's IM origin when other sources join it #1920's whole-turn behavior.
  • The subagent child id is not used as proof of ownership. One child can run more than once, and its notice does not say which run finished. DSH's tool-jobs notice has no job id or launch-turn id either, so routing the result back to A would need that capability from DSH.
  • ds-bot/test/im.test.js: new direct-chat regressions use a real DSH job completion and subagent notices that arrive before or after B claims the turn. New group regressions send a job notice and a subagent notice to a member, one before the room claims the turn and one after the relay turn ends. Before this fix they leaked to dev (B got A's job output) or to the group (g1 got the member's earlier result). Each test also checks that the next clean turn can still reply.
  • docs/plans/2026-11-04-im.md: documents the exception.

Changelog

IM replies no longer send a background job or subagent result to a different direct chat or IM group that shares the same Bot or room Session.

How I checked it / 怎么验证的

  • npm test (in ds-bot/): 3611 tests, 3607 pass, 0 fail, 4 skipped
  • node scripts/build-client.mjs --check
  • npm run lint: 0 errors, 89 warnings (same as dev)
  • Smoke test: all 56 steps passed
  • Screenshot attached, for interface changes / 界面改动已附截图 (no interface change)

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 改了 src/client/ 就已重新 build 并提交 client.js。 (src/client/ 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 Check cross-chat IM reply leak on dev after 1920
Review with Devin · Open in Devin Desktop


Use the harness job registry and IM test adapter to expose the cross-chat reply routing on dev after PR #1920.
A job or child run from an earlier turn can report into the next chat on the same Session. Suppress outbound IM for the receiving turn when a notice cannot establish its launch turn, while leaving other input sources unchanged.
@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 21, 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-21T09:39:02.037519Z 60d15e5 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

@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.

Review at 60d15e5: one fix is needed before lulu merges.

The direct-Bot fix is correct. A tool-jobs or subagent-settled notice now drops the origin both before and after the claim, and the next clean turn can claim again. steer.js detached calls also use tool-jobs, so they are covered. Dropping instead of trying to prove ownership is the right call while DSH notices carry no job or launch-turn id. test/im.test.js passes 98/98, and lint and --check are clean.

Must fix: group member Sessions are not covered. In a group, room lines go out through originOf(room.sessionId). The new branch, however, calls dropOrigin(session.id) on the member's Session, which holds no origin, so the room's origin stays. I confirmed this with a probe: during an IM round in g1, member Session member-session (in groupOwners for r1) admits a tool-jobs notice and a subagent-settled notice. The member's room line reply using desktop job secret was still sent to g1. So a job or subagent started in an earlier desktop round, or in a round from another IM chat bound to the same room, can still reach the IM group. That is the same class as the P0-B "must never leak" case. Suggested direction: when the Session is a group member (rt.groupOwners.get(session.id)), also drop the origin of that room's Session. Add a group test like the direct ones.

Note, not blocking: a turn's own background job finishing mid-turn in the same chat now also withholds the rest of that IM reply. That matches dev before #1920, and the PR description explains it (DSH has no launch id). It means #1917's goal can't land as written: #1917 conflicts with this PR in im/index.js and should be closed, or wait for a DSH job/launch id.

Merge order: this PR and #1750 merge together cleanly. Land this first, then #1750 merges dev. #1917: see above.

Written by Devin

Group messages use the room Session's origin, so dropping only a member's origin leaves background job and subagent results visible to an unrelated IM round. Drop the room's claim as well, without letting its pending reset re-enable delivery in the same turn.

@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.

Re-review at 9e65daf: pass, ready for lulu.

My group finding is fixed. When a group member takes in a tool-jobs or subagent-settled notice, IM delivery now also stops on the room Session (rt.sessionOfRoom(...)), the same Session originOf uses for room lines. Clearing pendingReset for that room means a late room turn can't reopen IM in the same round. I reran my earlier probe on this head and nothing reached g1. The new tests cover both orders (notice before and after the claim) and show the next fresh group round still reaches g1. test/im.test.js passes 100/100, and lint and --check are clean.

Note, not blocking: if a member takes in such a notice while the room still counts as working (a member's turn is still running), the following IM round can't claim until the room's next idle turn/start. This fails closed and matches the doc.

Merge order: unchanged from my last review. Land this before #1750; the two merge cleanly. #1917 conflicts with this PR and should be closed.

Written by Devin

@Fei2411
Fei2411 merged commit 6827b91 into dev Nov 21, 2026
15 checks passed
@Fei2411
Fei2411 deleted the fix/im-background-origin-leak branch November 21, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant