Skip to content

Keep an IM reply when the turn's own job or subagent reports mid-turn - #1917

Closed
Fei2411 wants to merge 1 commit into
devfrom
fix/im-own-work-mid-turn
Closed

Fei2411 wants to merge 1 commit into
devfrom
fix/im-own-work-mid-turn

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Issue

No issue yet. This change was split out of #1750 (originally commit 92ab554) so that #1750 only fixes #1735.

Not ready to merge. Devin Review found a cross-chat leak (below). Before this can merge, each background job and subagent has to be bound to the turn that started it.

What changed / 改了什么

DSH injects a background job's completion (tool-jobs) and a subagent's result (subagent-settled) into a busy owner's next step, inside the running turn. steer.js does the same for a call that a steer detached. The IM classifier in ds-bot/src/host/im/index.js treated these as a new asker and withdrew the chat's origin. So an IM turn that moved a slow command into the background lost its reply without any message.

Now the first classified message of a turn still decides who asked. After that, OWN_WORK_KINDS (tool-jobs, subagent-settled) leave the origin alone. As the first message of a turn (an idle Bot woken by followup) they still open a turn no IM chat asked for. Schedules, peer relays and Web messages that join a turn still withdraw the origin.

Open problem (Devin Review, security): two IM chats can share one Bot Session. A job started in chat A's turn can finish during chat B's turn, and the reply that uses A's result then goes to B; before this change, that reply was not sent at all. The exemption needs to check that the job or subagent was started by the current turn.

This PR is kept separate from the planned change that keeps the IM origin for the whole turn (#1869 / #1886).

Changelog

IM replies are no longer lost when a background job or subagent that the same turn started reports back mid-turn.

How I checked it / 怎么验证的

  • npm test (in ds-bot/): test/im.test.js passes 80/80 on this branch, including the new own-work tests (direct, group, idle wake) and the schedule / relay / Web withdraw tests
  • node scripts/build-client.mjs --check (no client change)
  • npm run lint
  • Smoke test: not run yet; run it once the cross-chat fix is in
  • Screenshot attached: no interface change

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. (not changed)
  • No keys, tokens or personal data, also in screenshots.
  • No AI tool as author or Co-authored-by.

Agent: Devin (moved Fei2411's commit; the original change was written with Claude Code)


Product Engineer opened this PR for Lulu
Implemented in session Fix Telegram replies dropped with time-context message
Review with Devin · Open in Devin Desktop


DSH injects a background job's completion (tool-jobs) and a subagent's
result (subagent-settled) into a busy owner's next step, inside the running
turn; steer.js does the same for a call a steer detached. The IM classifier
counted these like a new asker and withdrew the chat's origin, so an IM turn
that ran a slow command into the background lost its reply without a word.

A turn's first classified message still decides who asked. After it, these
two kinds are the result of the turn's own work and leave the origin alone.
As the first message of a turn (an idle Bot woken by followup) they still
open a turn no IM chat asked for, and schedules, peer relays and Web
messages joining a turn still withdraw it.

Moved from #1750 onto dev (originally 92ab554).
@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

@Fei2411 Fei2411 added the agent/devin Opened by Devin label Nov 21, 2026
@Fei2411 Fei2411 added this to the v0.3.9 milestone Nov 21, 2026

@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. It is left for you to triage below.

View findings in Devin Review · Follow Devin's work

Devin Review

Comment on lines +1704 to +1706
const midTurn = opened.has(session.id)
opened.add(session.id)
if (midTurn && OWN_WORK_KINDS.has(source?.kind)) return

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.

🟥 Background results leak across IM chats

When A's background work finishes during B's turn on the same Bot Session, OWN_WORK_KINDS preserves B's reply origin. Neither tool-jobs nor subagent-settled checks which turn started the work. Replies incorporating A's private results can reach B's chat.

Devin left this for you to triage: This is the known open problem this draft was split out of #1750 for: one chat's job result can reach another chat that shares the Bot Session. Do not merge until each tool-jobs/subagent-settled result is bound to the turn that started it; lulu's call is that this fix goes in this PR before it is ready.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@Fei2411

Fei2411 commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Closing in favor of #1953: keeping IM replies for background work started in the same turn isn't safe until completion notices say which turn launched it.

@Fei2411 Fei2411 closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/devin Opened by Devin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant