Skip to content

feat(remote): read the run's log on the desktop, so a reply is whole - #1020

Merged
huichen merged 9 commits into
mainfrom
feat/remote-run-replay
Oct 13, 2026
Merged

huichen merged 9 commits into
mainfrom
feat/remote-run-replay

Conversation

@huichen

@huichen huichen commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

A remote conversation is read from two lanes: the host's record (a page of its journal) and its stream (the events it pushes). Neither is the run. The page ends where the agent last saved each completed model call; the pushes begin where this window subscribed. So a reader who opens a conversation while the host is answering gets a fragment — and, since #1008 folded the two copies together on the assumption that the lanes do not overlap, occasionally the same words twice.

They can overlap. The run's own log is the third lane, and this makes the desktop read it the way the phone already does (get_events_since):

  • at an open — get_state names the run in flight before any frame happens to arrive (a long tool call pushes nothing for minutes);
  • when a link comes back — everything the host sent while it was down is gone, and the reply on screen is exactly what is stale;
  • when a push declares a gap the feed could see (a host that trims nothing sends one event per index, so a jump is loss).

A reply rebuilt from its log covers the run from its beginning, so the record's partial copy of that run is hidden and the reply is drawn once — carrying the run's own start time, which no push can supply, and continued in place by the frames that follow.

What moved into @future-os/thread-projection, because both clients read the same host:

  • runCursor — the per-run integrity cursor (high water + whether the beginning is provably present), previously the phone's.
  • replay — the page loop and its rules (readRunReplay, tailCoversRange, normalizeReplayEvent): snapshot bootstrap, pinned watermark, stalled cursor, trimmed-feed counting.
  • the projector now exposes the run's own startedAtMs (from agent_start) and durationMs (from agent_end), which is what makes the elapsed time on a joined reply the run's.

That deletes two duplicates: #1013's desktop port of the cursor (replayWindow) and the phone's private copy of the page loop, whose wire tests moved with it (36 cases, now covering both clients).

The fold is kept, but demoted. It is the answer for a run this client has not read the log of — an older host that answers Unsupported command (said once, then not asked again for the connection), or the first read still in flight. Two consequences fall out of that, and the harness caught one of them: a fragment built from pushes alone is dropped when the run ends (its beginning is only in the record, so keeping it drew the words twice — which is what remote-streaming reported), while a rebuilt reply is kept until the record is readable (the record trails the terminal frame, which is what used to make a settled reply blink).

Adjustments to the previous model, as I flagged they might be needed:

  • On this client's lane — the trimmed feed, which omits event families by design — "how much of the run do I hold" cannot be answered by counting what arrived, so a re-established run is read from its beginning rather than from the cursor. Bounded by the host's snapshot bootstrap, which folds a long run into one reply. A tail read is still used where the position is provably known and nothing has moved under it: a gap the feed can see.
  • get_state now also sets the streaming flag ("the host has a run in flight"), which is what a window that just opened has no other way of knowing — before this, the header said nothing was running until the first frame arrived.
  • The desktop view's live prop became liveReplies, because the two rules can briefly apply to two runs at once (a settled rebuilt reply waiting for its record, then the next run).

Verified

  • Desktop: tsc, eslint, vitest run — 302 files / 4017 tests.
  • Mobile: tsc, eslint, jest --runInBand — 153 suites / 3078 tests.
  • Shared package: 19 files / 595 tests (two of them were stale expectations about tool rows missing toolCallId/runId — verified identical on origin/main, fixed here because this suite is only run locally).
  • Harness: the mock host gained the two commands (get_state's activeRun, get_events_since), and remote-mid-flight asserts what only the log can give — one row, carrying the page's words and the run's, timed at the run's own eight minutes. Falsified: with the log read disabled the scenario fails with "the reply is timed from the reader's arrival, not from the run". remote-streaming and remote-lean-stream (the fold path) pass with a settled entry that carries run.status, as the real host's does.
  • docs/internals/desktop/CONNECTION.{md,zh-CN.md} updated: the paragraph docs(remote): the desktop client now shares the phone's catalog, replay and gaps #1019 wrote described the state perf(remote): incremental replay on remote timeline resume #1013 left, and the fallback it named is no longer "one whole-page read".

A remote conversation is read from two lanes: the host's *record* (a page of
its journal) and its *stream* (the events it pushes). Neither is the run: the
page ends where the agent last saved, and the pushes begin where this window
subscribed, so a reader who opens a conversation while the host is answering
sees a fragment — and used to see it twice, as the page's copy and the pushed
one were folded together on the assumption that the two lanes do not overlap.

They can. The run's own log is the third lane, and this makes the desktop read
it the way the phone already does (`get_events_since`): at an open (the state
read says which run is in flight, before any frame happens to arrive), when a
link comes back, and when a push declares a gap the feed could see. A reply
rebuilt from its log covers the run from its beginning, so the record's partial
copy of that run is hidden and the reply is drawn once — with the run's *own*
start time, which no push can carry, and continued in place by the frames that
follow.

What moved to `@future-os/thread-projection`, because both clients read the
same host: the run cursor (`runCursor`), the replay page loop and its integrity
rules (`replay`, `readRunReplay`), and the run's own start and duration in the
projector. The desktop's duplicate port of the cursor (replayWindow) is gone,
and so is the second copy of the page loop the phone kept for itself.

The fold is kept, but demoted: it is the answer for a run this client has *not*
read the log of — an older host that does not serve the command, or the first
read still in flight. A fragment built from pushes alone is dropped when the run
ends (its beginning is only in the record, so keeping it draws the words
twice), where a rebuilt reply is kept until the record is readable (the record
trails the terminal frame, which is what used to make a settled reply blink).

Verified: desktop 297 files / 3978 tests, mobile 153 suites / 3076 tests, the
shared package's 19 files / 595 tests, `tsc`, `eslint` on both clients. The
harness gained the two commands the desktop now reads and `remote-mid-flight`
asserts what only the log can give: one row, carrying the page's words and the
run's, timed at the run's own eight minutes. It fails without the read ("the
reply is timed from the reader's arrival"), and `remote-streaming` and
`remote-lean-stream` — which cover the fold path — still pass.
# Conflicts:
#	desktop/src/features/remote-peer/RemoteConversationView.tsx
The paragraph #1019 wrote described the state #1013 left: the desktop replayed
on resume and handed everything else to one whole-page read. Both clients now
read a run's log at the same three moments, the reply they draw comes from it,
and the page is kept for the part the log cannot answer. Says what the fallback
is when a host does not serve the command, which is no longer "one whole-page
read" but the fold.
@huichen
huichen enabled auto-merge (squash) October 13, 2026 06:26
The rewritten case exercises a path that arms the lane's retry timer, and it is
not a fake-timer test: leaving it armed kept the node process alive after the
suite finished. Locally that is a jest warning; in CI it is the mobile job stuck
`in_progress` (35 minutes and counting) on a step whose tests had all passed.
@huichen
huichen merged commit 32f4e98 into main Oct 13, 2026
12 checks passed
@huichen
huichen deleted the feat/remote-run-replay branch October 13, 2026 08:00
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.

1 participant