Repository navigation
Keep a turn's IM origin when other sources join it - #1920
Conversation
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.
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…le-turn # Conflicts: # ds-bot/src/host/im/index.js # ds-bot/test/im.test.js
Fei2411
left a comment
There was a problem hiding this comment.
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/startstill resets the origin for every new turn, so Web/phone/peer/schedule input only joins the running turn. Conflicting IM claims, unknownim:rpcIds, a stale binding and an unpaired sender still fail closed, andmixedblocks any later reclaim, including through task reports and held part-switch origins (forgetHeldOriginson 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_KINDimport removal: it has no other users in this file.test/im.test.jspasses locally on this head (90/90). PR body hasAgent: Devin (Cognition).
Overlaps
- #1917 (draft,
OWN_WORK_KINDSmid-turn, split from #1750): this PR makes it redundant for the origin rule. It already conflicts withdevand conflicts with this PR inim/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'spendingReset. 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.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 (bothmember 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.
Use the harness job registry and IM test adapter to expose the cross-chat reply routing on dev after PR Fei2411#1920.
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 calleddropOrigin(). That setmixed, 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 (includingREPLY_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 unknownim: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:
OWN_WORK_KINDSspecial case redundant. That code isn't included here. A test merge with 92ab554 merges the source automatically, with one textual conflict inds-bot/test/im.test.js. Any of its tests that expect a first non-IM message to block a later IM claim must follow the new rule.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(inds-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 --checknpm run lint(0 errors)dsh-v0.2.2-rc.1, mock model, all 56 steps passedThe leak scan also passes, with 0 must-fix findings. Not tested with a real IM account.
Checklist / 检查
src/client/changed →npm run buildran andclient.jsis committed. / 改了src/client/就已重新 build 并提交client.js。 (not changed)Co-authored-by. / 没有把 AI 工具写成作者或Co-authored-by。Agent: Devin (Cognition)
Implemented in session Fix IM replies dropped by dropOrigin
Review with Devin · Open in Devin Desktop