Skip to content

feat(remote-peer): branch a remote conversation, and stop a compaction from looking like a run - #959

Merged
huichen merged 2 commits into
mainfrom
feat/remote-conversation-tools
Oct 10, 2026
Merged

huichen merged 2 commits into
mainfrom
feat/remote-conversation-tools

Conversation

@huichen

@huichen huichen commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

What this does

Two gaps in the desktop's client role, both about a conversation on a host.

Branch a remote conversation at a settled turn. The phone could fork a conversation on the desktop it pairs with; a desktop acting as a client could not fork one on a paired host at all. The host's route and the desktop's own Fork button already existed — this is the missing client half.

Fix: a compaction is not a run. streaming was derived with !isTerminal(type), which counts every type this client does not recognize as "a run just started". A compaction event therefore left the conversation looking busy, and the composer offering Stop, for a run that did not exist — and the state only cleared when an unrelated run's terminal frame happened to arrive.

The fork's substance is which id it sends

The host resolves the fork point against its store, and the two ids a client sees are not the same id:

  • a history read carries the persisted entry id — what the host can resolve;
  • a live push carries a run-scoped event id (s:r:1:idx) — a frame on the wire that names nothing in the store.

So the timeline now tracks which ids came from history, the fork point is the preceding user entry (a reply is not itself a stored turn, and this mirrors the desktop's own Fork button), and a turn that has not been persisted yet is reported instead of sent. The host's own refusal for the wrong id is "Fork source thread could not be loaded", which describes a bug rather than the situation the user is in — the message here says the turn is not saved yet and to reopen the conversation.

The child is opened from the ids in the host's answer, never from a guess, and the host is re-read first because the child is a new row in its catalogue. A failed fork does not navigate.

Tests

29 new tests; 3412 desktop tests pass. tsc --noEmit, full eslint (0 errors), stylelint, and the shared shell-projection test all pass — the same scope CI runs. 0 uncovered lines added by this branch (repo's documented v8 method, intersected with the branch's own diff).

Where the assertions sit:

  • Which id, and on which lane. A fork sends the parent's session id and the preceding user entry's id, routed on the parent's lane — asserted per call, because an id the host cannot resolve is accepted by the transport and refused by the store.
  • Event ids are not persisted ids. A live push (s_1:r_1:1:7) is asserted to land outside persistedEntryIds, and an older page's ids are added without dropping the newest page's.
  • Ids are per conversation: opening a second conversation must not keep trusting the first one's ids, or a fork could address an entry the host stores under a different session.
  • The fork point skips intervening rows to reach the turn's prompt, returns null when there is no preceding prompt, and no control is offered on a user entry or while a run is in flight (the turn has not settled).
  • The failure is reported, not sent: an unstored turn raises a message and sends no fork_session (asserted specifically — opening a conversation also talks to the host via its history read, so a bare "nothing was sent" would assert the wrong thing).
  • The classification fix in both directions: a compaction does not start a run, and a compaction mid-run does not end one.

Two tests that could not fail

Both were found by the failures they produced, and both are worth naming because they are the kind of test that quietly proves nothing:

  1. My first event helper omitted sessionId. The timeline ignores another session's events, so the events never reached the reducer — and the "another family of event is not a run" test was passing vacuously. Fixed, and then verified by mutation: flipping the classification back to !RUN_SETTLED.has(type) makes that test fail.
  2. expect(invoke).not.toHaveBeenCalled() on the unstored-turn path was wrong for the same family of reason: opening the conversation legitimately calls the host for history. The assertion now filters for the fork_session command.

The hover handlers were also uncovered until a test dispatched mouseover/mouseout — asserting both that the control fades in and that it stays mounted, since a control removed on mouse-out is unreachable by keyboard.

Not in this PR

Compact context and remote file browsing/download are still missing. I did not fold them in: compaction completion has to be recognised from the host's own events (the command only acknowledges), and file transfer is a separate surface with its own list/download flow. Both are real work rather than a few lines, and half-doing either would put a control on screen that appears to work.

Related

Follows #955 (client role + merged lists), #956 (client runtime + multi-host e2e), #957 (a prompt names a conversation), #958 (manage/start a remote conversation). Mobile already implements remote fork; the semantics here match it, including the "not persisted yet" case.

`streaming` was derived with `!isTerminal(type)`, which counts *every* type
this client does not recognize as "a run just started". A compaction event
therefore left the conversation looking busy and the composer offering Stop
for a run that did not exist, and the state only cleared when an unrelated
run's terminal frame happened to arrive.

Enumerate the activity and settling types instead. A type from another family
now leaves the run state exactly as it was, in both directions: a compaction
does not start a run, and a compaction mid-run does not end one.
The phone could fork a conversation on the desktop it is paired with; the
desktop acting as a client could not fork one on a paired host at all. The
host's route and the desktop's own Fork button were already there, so this is
the missing client half.

What makes it more than a command wrapper is which id it sends. The host
resolves the fork point against its *store*, and the two ids a client sees are
not the same id: a history read carries the persisted entry id, while a live
push carries a run-scoped event id (`s:r:1:idx`) that names a frame on the
wire and nothing in the store. The timeline now tracks which ids came from
history, the fork point is the preceding *user* entry (a reply is not itself a
stored turn), and a turn that has not been persisted yet is reported instead
of sent — the host's own refusal ("Fork source thread could not be loaded")
describes a bug rather than the situation the user is in.

The child is opened from the ids in the host's answer, never from a guess, and
the host is re-read first because the child is a new row in its catalogue.
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