Repository navigation
feat(agent-link): keep a handed-over turn running across a restart in the reference client - #1043
Merged
Merged
Conversation
lavaman131
force-pushed
the
feat/turn-handover-client
branch
from
November 30, 2026 23:53
ddceaf5 to
8f8fd3d
Compare
lavaman131
marked this pull request as ready for review
November 30, 2026 23:54
lavaman131
added a commit
that referenced
this pull request
Dec 1, 2026
The coarse-pointer fix (0b678f8) moved one test off a loop of calls per element; the same loops kept others near their minute in CI. "A copied element is as many pixels as its Tailwind classes say" checked 128 elements with five or six traced calls each, and timed out on main at 1041785 (run 46540012615) and on #1043 (run 46540622380). In CI it took 42 to 60s, and the message box took 47 to 49s, re-reading every control's visibility for each control in turn. The icon family test took 39 to 46s. Each such loop now reads all its elements in one evaluateAll and asserts on the result, with the same assertions and the same messages: the element's label, index or classes, and the property. - assistant-ui-geometry: expectClassGeometry checks every element a locator finds in two calls and returns how many it checked; the handoff pills and subagent cards, the message actions, toolbar and reaction pills, the gallery tiles, the message box's controls and icons, and the staged chips are read the same way. - fixture: shown, Playwright's isVisible for an element that is not display: contents, to ask of every element in one call. - emoji (the icon family), touch-targets (rows, their targets and where a finger lands between them), connecting-indicator (the dots) and chat-media (toolbar buttons and the file icons' inks) likewise. Assistant-model: Claude Opus 5.5 Assistant-verification: bun run design:behavior on origin/main and on this change, both in full: 123 passed, 3 skipped; locally the Tailwind classes test went from 21.6s to 11.1s (wide) and 21.6s to 9.6s (narrow), the message box from 20.3s to 4.8s and 20.0s to 4.3s, the icon family from 19.6s to 5.0s and 18.4s to 5.0s, the media colours from 8.9-10.1s to 6.0-6.3s, the message actions from 7.1s to 5.0s and 6.4s to 4.8s; an injected 3px border on a gallery tile fails with its label, classes and "border widths"; bun run fix (its oxlint autofixes to two unrelated connector files reverted), ci and types
… the reference client
The reference client now asks for turn-handover beside resumable-sessions.
On a link that accepted it, every tools, part, host-tool-call and turn-end
frame of a turn carries seq from 1, numbered as it is sent (a frame too
large to send uses no number) and kept until a server gives a cursor.
On turn-handover the client stops sending that turn's frames to the old
process, and when the link closes it keeps the turn running, its host calls
open (no LINK_CLOSED, no abort) and new frames, host calls included,
queued. The resumption carries the turn; the next link names it in resume.
A resumed that lists it resends every kept frame after the server's cursor,
in order, then goes on live; one that leaves it out aborts it locally and
sends nothing. A turn not taken back within withinMs of the close is
aborted; if a resume had already named it and resumed lists it, the client
sends one turn-end {status: aborted, seq: after + 1} and nothing else. A
handover is used once: the next close without a new one ends the turn. An
abort, destroy or detach, a refused resume, or a server without the feature
gives it up.
An ended turn keeps its frames, its turn-end included, until its session's
next turn, an abort or destroy, or the close, so a handover that arrives
before the server read the end can still pass it on. A server without the
feature sees exactly what it saw before: no seq, and a close ends the turn.
Assistant-model: Claude Opus 5.5
Assistant-verification: bun test packages/agent-link (82 pass; 26 single-line mutations of the new client code each fail a test); bun test of apps/server harness/remote, testing, chat/remote-planner, chat/threads, mcp link tests (452 pass); bun run fix, ci and types; oxlint --no-ignore on the changed files
A turn kept every frame since the last cursor a server gave, without bound. It now counts the UTF-8 bytes of the frames it keeps. A turn-handover, like a resumed, drops the frames through its cursor and counts only the rest. Once the kept frames pass 32 MiB the turn can no longer be handed over: its frames are dropped and it is left out of the next resume. On an open link it ends at the close as before the feature, with its pending host calls failing with "The agent connection closed." and the turn aborted, and a turn-handover for it is ignored. On a link that has already closed it ends that way at once; if a resume already named it, the resumed that lists it gets the one aborted turn-end at its cursor. Frames are still numbered past the cap, because the server requires seq on every frame. Assistant-model: Claude Opus 5.5 Assistant-verification: bun test packages/agent-link (85 pass, 5 runs); 40 single-line mutations of the client's handover code each fail a test; bun test of apps/server harness/remote, testing, chat/remote-planner, chat/threads, mcp link tests (452 pass); bun run fix, ci and types; oxlint --no-ignore on the changed files
The turn-handover tests drove the server with raw frames; this one runs a real connectAgent client against it. Its turn writes "Writing", has edit_plan applied by the first process, and is still running when that process hands it over and closes. The client keeps it in its resumption, connects to the next process with resume, and finishes the reply there. The edit is applied once, the reply reads "Writing more." exactly once, and Chat says nothing of a restart. It fails with a client that ends its turns when the link closes. takeOver now takes just the linked document, so the test needs no Deployed of the raw-frame helper. Assistant-model: Claude Opus 5.5 Assistant-verification: bun test apps/server/src/chat/turn-handover.test.ts -t "reference client" (3 runs, 1 pass each; fails with the client's close-keeps-handover branch removed); bun test packages/agent-link (85 pass); apps/server harness/remote, testing, chat/remote-planner, chat/turn-handover, chat/threads, mcp link tests (475 pass); bun run fix, ci and types
lavaman131
force-pushed
the
feat/turn-handover-client
branch
from
December 1, 2026 00:55
8f8fd3d to
f5c63ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Client half of
turn-handover: the reference agent-link client (packages/agent-link/src/client.ts) keeps a running Planner turn alive across a server restart, so the next process can take it over instead of the turn being cut.Pairs with the server side, #1044, now on main; this branch is rebased onto it.
What the client does
turn-handovertogether withresumable-sessions(the default). With a server that does not list it, nothing changes: no frame carriesseq, and a close ends the turn as before.tools,part,host-tool-callandturn-endcarryseqfrom 1 per turn, numbered as they are sent. A frame too large to send uses no number. Each frame is kept until a server gives a cursor.turn-handover, the client stops sending that turn's frames to the old process. When the link closes, the turn keeps running: its pending host calls stay open (they are not failed with "The agent connection closed."), and new frames, host calls included, are queued. Theresumptioncarries the turn.resumenames the turn inturns. Ifresumedlists it withafter, the client resends every kept frame withseq > after, in order, from the server's cursor and never from what it last sent. It then goes on live on the new link. Ifresumedleaves the turn out, the client aborts it locally and sends nothing.withinMsstarts at the close. If no link takes the turn back in that time, the turn is aborted. If aresumehad already named it andresumedstill lists it, the client sends exactly oneturn-end {status: "aborted", seq: after + 1}and none of the kept frames.resumedtakes the turn back, a later close without a new handover ends it. A second handover sends only what follows its own cursor.turn-endincluded, until its session's nextturn, anabortordestroyof it, or the close. A handover that arrives before the server read the end can still pass the end on.turn-handoverorresumeddrops the frames through its cursor, so only the rest count. A turn past the cap is no longer handed over: its frames are dropped and it is left out of the nextresume. On an open link it ends at the close as before the feature: pending host calls fail with "The agent connection closed." and the turn is aborted. If its link has already closed, it ends that way at once. Frames are still numbered past the cap.Tests
client.test.tsadds 14 tests in "Agent connection client handing a turn over". They cover numbering with and without the feature, a turn surviving the close with its calls open and its frames held, resending from the server's cursor, single use, a second handover, an ended turn's frames, the next turn dropping them, thewithinMstimer from the close, the aborted end atafter + 1, a turn the server does not list, rollback, refusal, abort, destroy and detach, and the cap: crossed before a handover, after it on the open link, after the close, and after theresumenamed the turn, with only frames after the cursor counted.Each line of the new client logic was removed or altered in turn (40 mutations), and every one makes at least one test fail.
apps/server/src/chat/turn-handover.test.tsadds "the reference client across a deploy". A realconnectAgentturn hasedit_planapplied by the first process and is still running when that process hands it over and closes. The client reconnects to the next process withresumeand finishes the reply there. The test checks that the edit was applied once, that the reply reads "Writing more." exactly once, and that Chat says nothing of a restart. It fails with a client that ends its turns when the link closes.Verification on
8f8fd3d4(main10417854+ 3 commits):bun test packages/agent-link: 85 passbun testof the server's remote-link, testing, remote-planner, turn-handover, threads and MCP link tests: 475 passbun run fix,bun run ciandbun run typespass, andoxlint --no-ignorereports nothing on the changed filesNot run: E2E.