Skip to content

fix(mobile): replay in-flight reply streams when the phone link reconnects - #3257

Draft
Fei2411 wants to merge 3 commits into
devfrom
fix/3108-stream-reconnect
Draft

Fei2411 wants to merge 3 commits into
devfrom
fix/3108-stream-reconnect

Conversation

@Fei2411

@Fei2411 Fei2411 commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

Issue

Refs #3108 (partial: the ordering/visual-position half is a product decision and is not done here, see "Remaining" below)

Agent

Agent: DS Bot (SWE-2.1)

What changed / 改了什么

Root cause / 根因: during a long turn the reply text exists only as transient stream feed events. The phone link forwarded only live events with no replay, so a phone that lost its link mid-turn — the app drops the link in the background — received nothing at all until the turn committed. The whole reply then appeared at once, and to a user who had sent another message meanwhile the conversation read as out of order. The same applied when the user left the chat screen mid-turn: Streaming accumulated text in component state, so the remount started over from whatever delta arrived next.

  • ds-bot/src/host/feed.js: expose rt.replayFeed, the same feed opening subscribeFeed listeners already get (hello + accumulated reply text per in-flight attempt).
  • ds-bot/src/host/phone.js: forward feed events through a shared helper; when a device's ready count increases, invite the replay so a reconnecting phone catches up with the reply streamed so far. Devices already tracking the stream rebuild identical text, so replaying to all connected devices is safe.
  • mobile/src/screens/Chat.tsx: accumulate stream attempts in module-level state keyed by session id instead of component state, so leaving and re-entering a chat mid-turn keeps the text received so far; empty sessions are released when attempts end. Subscription happens before the mount-time snapshot so no delta is lost in between.
  • Regression test: ds-bot/test/phone.test.js — a phone connected mid-stream disconnects, misses further streamed text, reconnects, and must receive the replayed baseline (红 → 绿 verified).

Ordering note / 排序说明: the seq-based order of committed messages is unchanged and intentionally so. A queued user message commits only when the next turn consumes it, so the committed order answer → queued message is causally correct; reordering by insertion time would break pagination cursors and read watermarks that share the seq domain. Whether the chat should visually pin a user message at its insertion position (its agent/inbox/spliced event) is a product decision — left out here because splices can sit on an earlier page than the commit, which the paging architecture cannot reposition across.

Remaining / 剩余: the ordering half — showing a queued user message at its insertion position instead of after the committed answer — is not done and is not possible without changing the seq/paging domain; it needs a product decision (and its own issue/PR if wanted). This PR fixes only "in-turn reply is invisible until the turn lands".

Changelog

When the phone app returns from the background or reopens a chat while the Bot is still answering, the reply being typed now reappears and keeps streaming instead of showing nothing until the turn ends.

How I checked it / 怎么验证的

已验证(在 Mac 上验证):

  • npm test (in ds-bot/) — npm run test:windows full suite: 8616 tests, 8609 pass, 0 fail, 0 cancelled (7 skipped). Regression test red before the fix ("the link must invite a feed replay when a device connects"), green after; re-confirmed red by stashing the fix.
  • node scripts/build-client.mjs --check
  • npm run lint — 0 errors (warnings unchanged, pre-existing)
  • Mobile: npm run typecheck clean; npm test 286/286 pass (including the updated streaming.test.ts remount case)
  • Desensitization scan: must fix: 0
  • Targeted host suites: test/phone.test.js + test/feed.test.js + test/mobile.test.js + test/remote.test.js + test/phone-push.test.js + test/phone-browser.test.js — 118/118 pass
  • Smoke test, for changes to index.js or src/host/ — not runnable on this machine (no deepseek-harness source); see below
  • Screenshot attached, for interface changes / 界面改动已附截图 — mobile only, no device preview available here

未验证:

  • Smoke test of src/host/ changes against a live DSH session (no deepseek-harness source on this machine, per the squad README).
  • Real device behavior of the reconnect replay (relay timing, overlapping tunnels); verified against the in-process relay server in tests only.
  • Mobile web preview was not started; the change is RN component logic covered by unit tests.
  • Known limitation, unchanged by this PR: if the host itself restarts mid-turn, the accumulated stream text for the in-flight attempt is lost (same as before — SSE clients had the replay, but the host never rebuilt the accumulator after restart).

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 不适用 — no src/client/ changes.
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息,截图里也没有。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。
  • Substantive external issue/idea credited with Co-authored-by — N/A.

…nects

A phone drops its link when the app goes to the background or loses the
network mid-turn. The phone link forwarded only live feed events, so a
phone that reconnected during a long turn received no streamed text at
all until the turn committed its message; the whole reply then appeared
at once, which reads as if it landed after any message the user sent
meanwhile.

The feed already replays its accumulated reply text to SSE clients and
remote subscribers when they connect. Reuse the same replay for the
phone link: when a device joins, forward the feed opening to every
connected device so the newcomer catches up and the ones already
tracking the stream rebuild identical text.

Streaming accumulated its attempts in component state, so leaving the
chat screen mid-turn and coming back discarded the text received so far.
Keep the accumulation in module-level state keyed by session id; the
feed keeps flowing while the screen is away, and the remount reads the
current text instead of starting over.

Refs #3108
A delta arriving between the snapshot read and the feed subscription
would never reach the screen again. Subscribe first, then sync.
@github-actions github-actions Bot added the agent/dsbot Opened by a DS Bot team Bot label Dec 5, 2026
@Fei2411 Fei2411 added model/swe-2-1 Written by a Bot on Devin SWE 2.1 needs-product-ok Waiting for maintainer product/UI approval before merging to dev review/re-review New commits pushed after last review — needs re-review labels Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/dsbot Opened by a DS Bot team Bot model/swe-2-1 Written by a Bot on Devin SWE 2.1 needs-product-ok Waiting for maintainer product/UI approval before merging to dev 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