Skip to content

fix(im): keep the reply origin when attached context joins the turn - #1842

Closed
super-new13 wants to merge 2 commits into
Fei2411:devfrom
super-new13:fix/1718-weixin-context-origin
Closed

super-new13 wants to merge 2 commits into
Fei2411:devfrom
super-new13:fix/1718-weixin-context-origin

Conversation

@super-new13

@super-new13 super-new13 commented Nov 19, 2026 •

Copy link
Copy Markdown

Issue

Fixes #1718 (weixin case); same root cause family as #1735. Independently reproduced on the weixin (iLink) platform.

What changed / ????

ds-bot/src/host/im/index.js: the session/event outbound classifier dropped a turn's IM origin whenever any user/message that is not the IM request joined the turn. On 0.3.8, a weixin direct chat message ("??") claimed the origin at seq 493, the DSH clock appended { kind: 'time-context', form: 'snapshot' } at seq 494, the classifier hit the catch-all else ? dropOrigin() + mixed, and the Bot's reply at seq 495 was silently dropped (no send attempt, no log - "the app has it, WeChat never gets it").

Attached context now neither claims nor withdraws the origin: isAttachedContextSource() recognizes DSH's attached ContextForm values (snapshot / catalog / instructions / recall) and the non-waking in-turn context kinds (runtime-context, time-context, skill-catalog, model-selection, compact-checkpoint, .). Waking triggers that share the notice/relay forms (tool-jobs, subagent-settled, webhook, peer relays) still fail closed, and a Web/peer/scheduled message still withdraws the origin.

This is the same direction as #1750 - if that one lands first, please close this and feel free to take just the tests.

Evidence (weixin, 0.3.8 desktop asar)

Transcript of the Bot's session, one turn:

  1. user/message source={kind:'user', rpcId:'im:weixin:38d6.'} - origin claimed
  2. user/message source={kind:'time-context', form:'snapshot'} - the clock; on 0.3.8 this alone kills the reply
  3. assistant/message - delivered in the app, never sent to WeChat

Hot-patched the shipped app.asar with this change and restarted: the same flow now delivers to WeChat. The 10-minute injection interval (refreshIntervalMs) is why it looked intermittent: the first message after a quiet period is dropped, follow-ups within the interval arrive.

How I checked it / ?????

  • node --check on the changed file
  • Reproduced before / verified after on the real 0.3.8 desktop app (weixin iLink direct chat)
  • New tests follow the existing reply origin suite helpers; not able to run the full npm test suite in this environment - please let CI cover it
  • 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.

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.

✅ Devin Review: No Issues Found

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

Devin Review

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: recommend closing in favour of #1750 (comment only, no changes requested).

The fix is correct for the WeChat case, and I confirmed it locally: merged onto current dev, test/im.test.js passes (61/61), build-client --check and lint are clean.

It is superseded, though:

  • #1750 fixes the same root cause for #1718 / #1735. It is the fix the maintainer review already picked as the preferred one for this issue family, and it is still open.
  • Both PRs rewrite the same block of session/event handling in src/host/im/index.js and edit test/im.test.js. They conflict, so only one of them can land.
  • This PR filters attached context with a hard-coded list of kind/form values. Any new context kind that is not added to ATTACHED_CONTEXT_KINDS brings the bug back. #1750 decides from the snapshot origin, so it does not need that list.

Your PR description already says to close this one if #1750 lands first, and I agree. The WeChat repro tests, a snapshot after the IM message and a snapshot before it, are still useful. If #1750 does not cover these orderings, please suggest them there as review comments or put them in a small follow-up PR on top of #1750.

Written by Devin

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still recommend consolidating this in #1750, but the comparison has changed since my earlier review. At the current heads, ds-bot/src/host/im/index.js:29–60,1487–1490 has the same attached-context classifier and early return in both PRs (the production-file diff is just a blank line). #1750 no longer avoids the kind/form lists; that is not a reason to prefer it. The two branches still conflict if combined. #1750 has broader tests for direct/group turns and a waking notice; this PR has the explicit Weixin clock test and the before-IM ordering in ds-bot/test/im.test.js. Please carry those regressions into #1750 rather than merging both implementations.

@Fei2411

Fei2411 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you for the investigation and clean tests! Since this overlaps with #1750, we'll consolidate the fix there and close this PR.

@Fei2411 Fei2411 closed this Nov 20, 2026
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.

2 participants