Skip to content

fix(remote): a reply that is already in the transcript, drawn once - #1008

Merged
huichen merged 6 commits into
mainfrom
fix/remote-live-dedup
Oct 13, 2026
Merged

huichen merged 6 commits into
mainfrom
fix/remote-live-dedup

Conversation

@huichen

@huichen huichen commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Opening a conversation whose newest exchange is still running drew the answer twice: the host's page already carries a partial copy of it (the agent writes each completed model call to its journal mid-run), and the pushed frames of that same run were then appended beside it. On screen that is the reply once frozen — and without the streaming mark — and once growing under it.

Reproduced from the real client before the fix, through the new harness scenario (remote-mid-flight, live state):

the running reply is not one row: copies=1 tails=1
  and it was drawn across 2 row(s) at its widest, running=false lastIsCopy=true

Neither copy can simply be dropped: the page's copy is the reply's beginning (the stream starts when this window subscribes) and the bubble is its end (it is written as the host writes it, which is why the reader opened the conversation). foldLiveReply draws them as the one reply they are — the record's segments, then the stream's, in the order they were produced — and the merged row keeps the record's identity (its entry id, its timestamp, the user entry a fork branches at) while taking the stream's liveness. So the row on screen is the one still being written, and the one that offers nothing to act on.

The two lanes stay disjoint by rule rather than by luck: a tail read restarts the live lane (RemoteRunStreams.restart), because the page it just read is the record of everything the pushes had built up to that point. The run's own clock survives that restart — a reconnect must not make the elapsed time of a reply being watched fall back to zero. A tool call or a compaction the record already carries is not drawn a second time either; text has no identity across the two lanes, and the boundary is what keeps it from repeating.

Verified

  • Unit: foldLiveReply (append when there is no copy, fold in place, keep the record's identity, no call or checkpoint twice, an earlier run untouched, a runless bubble never folded), RemoteRunStreams.restart (restarts the projection, keeps the clock), useRemoteTimeline (a catch-up read restarts the lane from the page it read).
  • View: RemoteConversationView — a reply the transcript already carries is one row carrying both halves, and it offers nothing to act on. Both new tests fail on the parent commit.
  • Harness: remote-mid-flight opens rs_forest — a fixture whose newest turn the host still reports as running — and continues that run on the push lane. It asserts the reply is one row carrying the page's beginning and the stream's tail, that the header reports the run while it is live, and that the settled transcript draws it once. It fails on the parent commit and passes here; remote-streaming and remote-lean-stream still pass against the reworked mock (which now shares one frame publisher).
  • tsc --noEmit, eslint, vitest run (293 files / 3912 tests), all green on this branch merged with origin/main.

The phone does not have this bug: it rebuilds the run from the host's replay (get_events_since) and strips the durable copy of it, which is the same rule this change expresses for a client that reads pages and pushes only.

Opening a conversation whose newest exchange is still running drew the
answer twice: the host's page already carries a partial copy of it — the
agent writes each completed model call to its journal mid-run — and the
pushed frames of that same run were then appended beside it. The reader saw
the reply once frozen (and without the streaming mark) and once growing
under it.

Neither copy can simply be dropped. The page's copy is the reply's
beginning (the stream starts when this window subscribes) and the bubble is
its end (it is written as the host writes it, which is why the reader opened
the conversation). `foldLiveReply` draws them as the one reply they are: the
record's segments, then the stream's, in the order they were produced. The
merged row keeps the record's identity — its entry id, its timestamp and the
user entry a fork branches at — and takes the stream's liveness, so the row
on screen is the one still being written, and the one that offers nothing to
act on.

The two lanes stay disjoint by rule rather than by luck: a tail read
restarts the live lane (`RemoteRunStreams.restart`), because the page it just
read is the record of everything the pushes had built up to that point. The
run's clock survives the restart — a reconnect must not make the elapsed time
of a reply being watched fall back to zero. A call or a compaction the record
already carries is not drawn twice either; text has no identity across the
lanes, and the boundary is what keeps it from repeating.

Verified: the view test (a reply the transcript already carries is one row,
carrying both halves), `foldLiveReply`'s own cases (append when there is no
copy, fold in place, keep the record's identity, no call or checkpoint twice),
the live lane's restart with its clock, and 491 remote-peer tests. The harness
gained `remote-mid-flight`, which opens `rs_forest` — a fixture whose newest
turn the host still reports as running — and continues that run on the push
lane: it asserts the reply is one row, carrying the page's beginning and the
stream's tail, that the header reports the run while it is live, and that the
settled transcript draws it once. It fails on the parent commit ("it was drawn
across 2 row(s) at its widest"), and `remote-streaming` and
`remote-lean-stream` still pass against the reworked mock.
…jector

CI caught what a same-millisecond local run hid: the elapsed-time anchor was
written whenever a projector was created, so rebuilding one (`restart`) reset
it — the assertion that a rebuilt reply keeps its clock passed here and failed
there, one millisecond apart. The anchor is now set only for a run this client
has not seen; an evicted or restarted run keeps the time a reader has been
watching.
@huichen
huichen merged commit 1886164 into main Oct 13, 2026
12 checks passed
@huichen
huichen deleted the fix/remote-live-dedup branch October 13, 2026 04:29
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