Skip to content

Keep a turn's IM origin when other sources join it - #1920

Merged
Fei2411 merged 5 commits into
devfrom
fix/1869-im-origin-whole-turn
Nov 21, 2026
Merged

Fei2411 merged 5 commits into
devfrom
fix/1869-im-origin-whole-turn

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Issue

Fixes #1869
Fixes #1886

What changed / 改了什么

Bug: once any non-IM message entered an IM turn (a card answered on desktop or phone, a Web message, the fallback else), the classifier called dropOrigin(). That set mixed, so the rest of the turn's replies never reached the IM chat (#1886). If the non-IM message came first, the later IM message could no longer claim the turn (#1869, both orders).

Per the maintainer's decision, an IM origin claimed in a turn now holds for the whole turn:

  • ds-bot/src/host/im/index.js: non-IM input (including REPLY_KIND) can neither claim nor withdraw the origin, and it no longer marks the turn mixed, whether it arrives before or after the IM message. A turn with no IM claim still never sends to IM. Fail-closed cases stay as they were: a conflicting IM claim (different connection, chat or sender), an unknown im: rpcId, a stale binding, an unpaired sender. Group task reports follow the same rule and can't reopen a round that a conflicting IM claim closed. A genuinely new turn still clears held part-switch origins.
  • docs/plans/2026-11-04-im.md ("什么发回聊天软件"): updated to the new rule.
  • ds-bot/test/im.test.js: new regression tests for [Bug] 同一轮里先在桌面端答了 ask_user 卡片,微信消息的答复被静默丢弃(0.3.8) #1869 (card answer before and after the IM message, in direct and group turns) and [Bug] IM 端只收到 Agent 的第一条回复,同一回合后续多条消息全部丢失 #1886 (several replies after mid-turn non-IM input). Old Web-mixing and part-switch tests now expect the new rule; conflicting-IM isolation is still covered.

Related work:

Changelog

Replies to an IM message now reach the chat for the whole turn, even after a card is answered in the app or another message joins the turn.

How I checked it / 怎么验证的

  • npm test (in ds-bot/), after merging dev: 3513 pass, 0 fail, 4 skipped. The 6 new regression tests fail on the unfixed code and pass with the fix.
  • 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)

The leak scan also passes, with 0 must-fix findings. Not tested with a real IM account.

Checklist / 检查

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


Let non-IM input join before or after an IM message without withdrawing the reply destination. Keep conflicting and unknown IM claims fail-closed, including task reports and part-switch handoffs, and update the decided policy and regression coverage.
@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-21T02:57:23.888302Z 51116d8 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.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

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

Devin Review

…le-turn

# Conflicts:
#	ds-bot/src/host/im/index.js
#	ds-bot/test/im.test.js

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

Verdict: one fix needed before lulu merges. The direct-Bot path implements the whole-turn rule correctly, but in groups the IM origin now also carries into a new round started from the desktop/Web when a member still has work going from the IM round. That is a new turn, not input joining the IM turn, and dev keeps it in the app.

Must fix: a desktop round after an IM group round leaks to the IM group

For a group's own Session, turn/start only arms pendingReset when nothing is working:

const working = rt.roomActive?.(room.id) || (rt.roomWorkView?.()[room.id] ?? []).length > 0
if (!working) pendingReset.add(session.id)

roomWorkView includes member background tasks (activeRoomTasks), subagents and switch jobs, so it often stays non-empty after the IM round ends. Before this PR the else branch called dropOrigin() for the desktop message, so the new round sent nothing. Now that branch is a no-op, and the room origin from the earlier IM round answers the new desktop round.

Repro (append to test/im.test.js):

for (const working of [true, false]) test(`desktop round after IM group round, member work=${working}`, async (t) => {
  const s = await start()
  t.after(s.stop)
  const { one } = await pairedConn(s)
  one.chats.g1 = { kind: 'group', title: 'G', target: { roomId: 'r1' }, at: 1 }
  await s.rt.save()
  await gm(s, 'u1', 'hello group')
  s.imTurn('r1')
  s.emitEvent('r1', 'turn/end', {})
  s.rt.roomActive = () => false
  s.rt.roomWorkView = () => (working ? { r1: [{ botId: 'b', since: Date.now(), tool: 'task' }] } : {})
  s.fake.sent.length = 0
  s.emitEvent('r1', 'turn/start', {})
  s.emitEvent('r1', 'user/message', { source: { kind: 'user' }, content: [{ type: 'text', text: 'private desktop question' }] })
  s.rt.logRoom(s.rt.roomOf('r1'), { who: 'Writer', botId: 'b', text: 'private desktop answer' })
  await s.flush()
  assert.deepEqual(s.fake.sent, [])
})
work=true work=false
dev nothing sent nothing sent
this PR g1: **Writer**: private desktop answer nothing sent

This also breaks the PR's own wording ("its origin lives until a new round starts in the group") and the updated plan line "没有认领 IM 来源的轮次不向 IM 外发".

Suggested direction: when a non-IM message (not a member post/task-report/task-handoff) opens a group turn that is not joining a running round, reset the room origin (forgetHeldOrigins + resetOrigin) instead of keeping it. A later IM message in that round can still claim it, as the rule wants. Note that simply arming pendingReset whenever !rt.roomActive(room.id) is not enough: I tried it, and it breaks case 5 of the overflow/folder-switch test (Web input during a group folder switch should keep the origin). So switch jobs (and possibly a member's turn that is still running) have to count as ongoing work, while a leftover background task should not.

Please confirm with lulu: a desktop-started task report into a group

The P0-B test now expects Desktop secret result. (a task started from the desktop, with no imOrigin) to reach g1, because an earlier IM task report restored the room origin in a turn that had already ended. On dev this was an explicit "must never leak" assertion. If lulu's rule only covers input that joins the IM turn, this case is the same kind of new work as above and should stay in the app. If she wants it forwarded, fine, but the decision should be explicit because it reverses a P0 privacy test.

Fine as is

  • Direct Bots: turn/start still resets the origin for every new turn, so Web/phone/peer/schedule input only joins the running turn. Conflicting IM claims, unknown im: rpcIds, a stale binding and an unpaired sender still fail closed, and mixed blocks any later reclaim, including through task reports and held part-switch origins (forgetHeldOrigins on a real new turn is a good catch).
  • #1908's consumed-rpcId dedup and the one-per-turn withheld warning are kept. Switching the warning tests to an unknown rpcId is the right trigger now.
  • REPLY_KIND import removal: it has no other users in this file.
  • test/im.test.js passes locally on this head (90/90). PR body has Agent: Devin (Cognition).

Overlaps

  • #1917 (draft, OWN_WORK_KINDS mid-turn, split from #1750): this PR makes it redundant for the origin rule. It already conflicts with dev and conflicts with this PR in im/index.js. Land this one first, then close #1917 or cut it down to just its regression tests.
  • #1750 (attached-context sources return early): conflicts with this PR only in test/im.test.js. After this PR, its early return still matters only because it skips a group's pendingReset. Rebase it after this one.
  • #1817, #1201, #1302, #1298 (contributor PRs) also touch IM files but already conflict with dev. They are not blockers here.

Written by Devin

Treat only an active round, a running member turn or a part switch as ongoing group work. Leftover background tasks must not preserve the previous round's IM destination. Restore desktop-started group task report isolation while keeping in-round input and later legitimate IM claims working.
A desktop task report withdraws an existing room origin, but must not mix a room that has no origin. Keep invalid persisted IM claims fail-closed and preserve desktop task report privacy.

@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 found 1 finding. Devin automatically fixed it.

Fixed by Devin (1)
  • Group task report blocks later IM replies — A desktop task report now withdraws only a live room origin and no longer marks an unclaimed room mixed, so a later IM message in the same round can still claim it. Regression test added.

View findings in Devin Review · Follow Devin's work

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.

Re-review at 6eb15959: passes, ready for lulu. Both points from my earlier review are resolved.

  • Group desktop-round leak: fixed. A new group turn now counts as ongoing only when the round is active, a member's own Session has a running turn (groupOwners + rt.live), or a part switch is running for the room. Leftover background tasks no longer count. My repro is now a test (both member work=true/false). The new "Web input joining an ongoing group round/member" test keeps the origin when the input does join the IM turn, and the overflow/folder-switch test still passes.
  • P0-B: restored. A desktop-started group task report stays in the app again, and the design doc says so.
  • Unclaimed-room fix: correct. A desktop report in a room with no origin no longer marks it mixed, so a later IM message in the same round can still claim it. That is tested too.

Checked on this head: npm test 3551 pass, 0 fail, 4 skipped. npm run lint and --check are clean. It merges cleanly into current dev.

Note, not blocking: a desktop-started task report that arrives during an active IM-claimed group round marks the round mixed. The report stays out of IM, and so do the round's later replies. I confirmed this with a probe. This fails closed, and it matches the new doc line ("没有 IM 来源的群任务报告留在 App"), because room lines can't be split by source. I'm noting it so the behavior is known, not asking for a change.

Merge order: land this first. Draft #1917 conflicts with it in im/index.js and is mostly redundant after it. #1750 should merge dev after this lands, since it touches the same classifier and im.test.js.

Written by Devin

@Fei2411
Fei2411 merged commit 8dccdf5 into dev Nov 21, 2026
15 checks passed
@Fei2411
Fei2411 deleted the fix/1869-im-origin-whole-turn branch November 21, 2026 08:58
klarkxy pushed a commit to klarkxy/DeepSeek-Bot that referenced this pull request Nov 21, 2026
Use the harness job registry and IM test adapter to expose the cross-chat reply routing on dev after PR Fei2411#1920.
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