Skip to content

Keep IM replies when a context snapshot joins the turn - #1750

Closed
Fei2411 wants to merge 14 commits into
devfrom
fix/1735-im-context-snapshot
Closed

Fei2411 wants to merge 14 commits into
devfrom
fix/1735-im-context-snapshot

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Issue

Fixes #1735

What changed / 改了什么

Bug: replies to an IM chat (Telegram etc.) were silently dropped whenever a context message was appended to the turn. The DSH clock (kind: 'time-context'), DS Bot's own clock (ds-bot-time-context) and memory recall (ds-bot-memory-recall) all add a user/message with source.form === 'snapshot' after the chat's message. The session/event classifier in ds-bot/src/host/im/index.js sent it to the "any other source" branch, which called dropOrigin() and marked the turn mixed, so the assistant's reply had no origin and was not sent.

Now isAttachedContextSource() skips attached context before classification: the snapshot, catalog, instructions and recall forms, plus non-waking in-turn context kinds (runtime-context, working-directory, model-selection, plan-mode, compact-checkpoint, …, which also covers DSH releases before source.form). Such a message neither claims nor withdraws the origin, and does not consume a group's pending reset. Messages with an IM, RPC, user or DS Bot relay identity still go through normal classification, and the notice and relay forms (tool jobs, subagents, peer relays, schedules, goals) still fail closed. A turn that a Web/peer/scheduled message started still sends nothing to IM. The check sits next to #1908's guard for an already consumed IM request, and both are kept.

The job/subagent mid-turn exemption (92ab554) has been reverted here and moved to its own PR, #1917, because it still needs each job bound to the turn that started it (Devin Review found a cross-chat leak).

Changelog

IM replies are no longer lost when the current time, a memory recall or other context is added to the same turn.

How I checked it / 怎么验证的

  • npm test (in ds-bot/): new tests in test/im.test.js cover a snapshot before and after the chat's message in a direct and a group Session (all four fail on dev, pass with the fix), the other attached context forms and kinds, waking notices/relays that still drop the origin, and Web-turn guards for a direct and a group Session. Full run after merging dev with Keep IM replies when an IM message event is redelivered #1908: 3516 passed, 0 failed
  • node scripts/build-client.mjs --check
  • npm run lint
  • Smoke test, for changes to index.js or src/host/: against DSH dsh-v0.2.2-rc.1, all 56 steps passed after merging current dev
  • 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. (not changed)
  • No keys, tokens or personal data, also in screenshots.
  • No AI tool as author or Co-authored-by.

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


The clock and memory recall append a user/message with form 'snapshot'
after the chat's message. The outbound classifier treated it as another
source and withdrew the origin, so the reply to the IM chat was dropped
whenever a snapshot was injected (#1735).
@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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T11:35:26.524086Z
We couldn’t complete this review. Comment @codex review to try again.
714f3fa 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@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

@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: the fix looks correct and safe. No blocking issues.

Does what it says

  • The cause in #1735 is confirmed. @deepseek-ai/dsh-time-context, ds-bot-time-context (src/host/time-context.js) and the memory snapshots in src/host/memory.js (recall, group memory, memory update) all append a user/message with source.form === 'snapshot'. Before this PR, such a message went to the final else, which called dropOrigin().
  • Keying on form instead of a list of kinds is the right choice. snapshot is a variant of DSH's documented ContextFormed source type, so any future context plugin that uses it is covered.
  • The early return comes before pendingReset.delete(...). If a snapshot is the first message in a group Session's turn, it does not use up the pending reset; the next real message (or turn/end) still decides. The return also skips the send loop below, which is fine: a user/message produces no bot/view display items.

Tested

  • I ran this locally on the PR head. Without the im/index.js change, the new test "a context snapshot in the same turn keeps the IM origin" fails. With it, the test passes. im, time-context and text-annotation tests: 83/83 pass. lint exits 0 (only existing warnings). build-client --check is OK.
  • The second new test (a snapshot does not open a Web turn to IM) is a good guard. It also passes on dev, so it is a regression test, not a repro.

Findings (non-blocking)

  1. CI: ubuntu-latest · Node 24 · DSH 0.2.0-rc.2 is red. The failure is test/text-annotation.test.js:157 ("Ctrl+Enter sends the annotated quote to a group…", 0 !== 1). That is a client-side test this PR does not touch. The same job passed on dev at the same base (a95e3af), and the test passed 4 out of 4 runs locally. It looks like a flake. Please re-run the job and get it green before merging rather than merging on red.
  2. Smoke test not run. AGENTS.md asks for the smoke test on src/host/ changes. The PR says so and gives a reason, and the change is small and fully covered by unit tests, so I consider the risk low. Still, it is a skipped step in the checklist.
  3. Possible follow-up, not for this PR. DSH's ContextFormed also has instructions, catalog and notice forms. If any DSH plugin ever appends one of these as a mid-turn user/message, it would still withdraw the IM origin in the same way. I did not see one in the current harness, so this is only a note.

PR form: the branch name fix/1735-… into dev, Fixes #1735, the Changelog field and the commit author (no AI co-author) follow AGENTS.md and CONTRIBUTING.

Written by Devin

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

Verdict: APPROVE (posted as a comment because GitHub doesn't allow approving one's own PR) — the preferred fix of the three for #1735 (vs #1725, #1768).

  • The early return for source.form === 'snapshot' sits before pendingReset.delete, so a snapshot never claims, withdraws, or consumes the pending reset. In a group Session's late turn, the first real message still decides whether the origin is kept.
  • It covers every snapshot source on dev: DSH runtime-context/time-context and DS Bot's own ds-bot-time-context (time-context.js:42), ds-bot-memory-recall, group memory, and ds-bot-memory-update (memory.js:919/932/962). Non-snapshot unknown sources still drop the origin, so the rule stays fail-closed.
  • Verified: merges cleanly with dev a95e3af, npm test 2899 pass / 0 fail, npm run lint exits 0.

Non-blocking: #1768's matrix (before/after × direct/group) is worth porting here or as a follow-up, especially the group-Session case, which these two tests don't cover. Once this lands, #1768 and #1725 can be closed.

devin-ai-integration Bot and others added 5 commits November 17, 2026 18:16
Cover a snapshot arriving before and after the chat's message in both a
direct and a group Session, and a group turn taken over from the Web.
Skip all non-waking attached context forms (snapshot, catalog, instructions, recall) and in-turn context kinds (working-directory, model-selection, repeat-tool-reminder, ptc-mode, plan-mode, action-cards, tool-goal, user-approval, compact-checkpoint, and cleared runtime-context) in the IM origin classifier, while continuing to fail closed for waking notices and relays (tool-jobs, subagent-settled, agent-message, schedule, goal).

Fixes #1735.

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

Re-review of the commits since 714f3fa (comments only): nothing new to fix.

  • d6a33690 adds the missing group-Session tests: before/after × direct/group, with group-line delivery asserted. That closes the gap noted earlier.
  • b1cf3e09 replaces the snapshot-only check with isAttachedContextSource(). Explicit user, IM, relay and RPC identities still go through normal classification. notice and relay forms fail closed, so tool jobs, subagents, peer relays, schedules and goals never keep an IM origin. The early return still runs before pendingReset.delete().
  • At a615459 the branch merges cleanly with dev. npm test (3057 pass), build-client --check and lint pass. I did not rerun the bench smoke test.

One scope note, not a defect: a same-goal nudge (queueGoalRelay in goals.js, form: 'relay', role: 'goal') still withdraws the IM origin. #1768 proposed keeping it for a matching active goal. So landing this closes #1735 but not the scenario in #1767. Leave #1767 open, or link it to a follow-up.

Written by Devin

…apshot

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

# Conflicts:
#	ds-bot/src/host/im/index.js
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.
devin-ai-integration[bot]

This comment was marked as resolved.

The diagnostics log is written in the background. Two tests read it with no
wanted entry, so the first read could return before the MAX_TOKENS line
landed and fail with 0 !== 1 on a slow runner. Wait for that entry, as the
watched-turn test already does.
@Fei2411 Fei2411 added agent/devin Opened by Devin review/re-review New commits pushed after last review — needs re-review labels Nov 21, 2026
@Fei2411 Fei2411 added this to the v0.3.9 milestone Nov 21, 2026
Revert 92ab554. Keeping an IM origin when a background job or subagent
reports mid-turn can send one chat's job result to another chat that shares
the Bot's Session; it needs each job bound to the turn that started it, so it
goes on separately and this pull request stays on #1735.

@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

…apshot

# Conflicts:
#	ds-bot/src/host/im/index.js
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Closing: #1920 (IM origin kept for the whole turn) already fixes #1735 on dev; this PR's #1735 tests all pass on current dev without it.

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/re-review New commits pushed after last review — needs re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant