Repository navigation
handoff HO4: source agent (write turn, marker, cap, joined check) - #824
Conversation
The old session gets one normal turn on its own thread with the setting's instructions; its reply is part 2 of the handoff when the turn completed, no other message joined it, the reply starts with the marker line and is within the command source's 32 KB cap. A reply that does not count falls back like the command source (size: parts 1, 3, 4; idle: nothing). A stopped, failed, joined or timed-out write turn means no handoff: the old session carries on. Fixed ids per source run, so a run never writes or hands off twice; the write run is no turn end and stays out of the transcript. Default stays off; no migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lens AVerdict: SAFE. Reviewed at head dbba7f5. No path sends a handoff twice, hands off mid-task or leaves the thread stuck. Every failure I found means a handoff that does not happen: the old session carries on with its full context. Major 1 drops part 2 without a word, and major 2 leaves a steered exchange out of later handoffs. Both should be fixed. The changed test files pass when run one by one: handoffAgent 4, HandoffService 63, handoffBusyCheck 15, handoffFacts 15, handoffAlert 15. BlockingNone. Major
Minor
Checked and fine
|
Lens BVerdict: SAFE to merge (head dbba7f5). The default stays off. Every failure ends in "no handoff, the old session carries on", or in the documented fallback (parts 1, 3, 4). Nothing is sent twice, and no failure loses the old session. The three majors below should be fixed before anyone turns BlockingNone. Major (non-blocking; fix in this PR or file follow-ups)
Minor
Checked, no finding
Tests run (own worktree, one file at a time)
|
… quiet - A late update of the source run, or a restart, no longer drops part 2: any loop that finds a write turn as the latest run carries it on to its handoff (fixed ids, so at most once). - A message steered into a write turn stays in later handoffs' part 3; only the write turn's prompt and marked reply are left out. - A failed or timed-out write turn at the size backstop sends parts 1, 3 and 4 (idle: nothing), as the command source does. - Notes lines that could pass for the message's own lines are quoted. - T3 stops a write turn at its timeout (run.interrupt, its own reason); after one such stop the next size handoff uses the fallback at once. - A completed write turn is marked quiet, as the handoff run is. - New source `none` is the default, so a saved handoff setting keeps its old behaviour; `agent` only when set. - The last reply that starts with the marker is used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A missing program under `timeout` can exit before the empty stdin is written, so the reason sometimes read as an output error. The case now uses a spawn that fails (its project folder is gone); exit codes 126 and 127 stay covered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lens round 2Verdict: SAFE to merge at head d7785af. All six round-1 majors are fixed or, where the PR says so, fixed in part. The rule "handoff mode without a source keeps today's behaviour" holds. There is one new major, N1: a server restart in the middle of a write turn. It still sends exactly one handoff and loses nothing. But it costs a second write turn and puts the old notes into part 3. Like the leftovers, it is not a blocker while 1. Round-1 majors
2. New problems from the fix roundN1 (major, not blocking): a restart mid write turn does not happen the way the test models it.
T3's own stop vs a person's: sound.
Slot-wait and timeout loops: bounded and correct.
Double dispatch: never two; zero only in documented cases.
State question.
3. The "Left" items
4. d7785af (handoffCommand.test.ts)
Tests run (own worktree, one file at a time, each after a capacity check)
|
What and why
Handoff source
agent, the last part-2 source. When a handoff is due and the setting's source isagent, the old session gets one normal turn, the write turn: on its own thread, with its own model and no fresh context, so its cache is still warm. The text is the setting'sinstructions(or a default), plus "start with the marker line" and the 32 KB cap. The handoff then goes out with that reply as part 2.Built on HO1–HO3 rather than beside them:
handoffDispatchDropped)HANDOFF_COMMAND_MAX_BYTES)HANDOFF_IDLE_LEAD_MS.agent, 4 min)How the reply is judged (pure,
handoffAgent.ts):[T3 handoff notes], or only the marker: the reply does not count, and the fallback above applies.The ids are fixed per source run (
handoff-write:<thread>:<run>), so the same run never writes or hands off twice, including after a restart. The write run is not a turn end: no timer, and the pure decision skips it aslast-run-handoff. It is also kept out of the part-3 transcript. Default staysoff; no migration; no upstream file touched, so no seam lines.Tests
apps/server/src/fork/handoff(11 files) plus the slot/start-path tests: 222 passed. Typecheck,vp fmt,vp lintand knip are clean.Cases covered:
instructionstext, nomodelSelection/freshContext; the transcript leaves the write turn out.handoffBusyCheck)instructionsuses the defaultOn the old code: 7 tests fail, and 2 files do not load (
handoffAgent.tsis missing).Red checks. Each guard was removed and the test that then fails was named:
handoffAgent"a write turn that was stopped, failed or joined…" and service "a write turn where another message joined it…"handoffAgent"a write turn that was stopped, failed or joined…"noHandoff→ returnhandoffDispatchDropped)Seen once under load: HO3's
handoffCommandtest "a program that cannot start…" got "its output could not be read" instead of "could not start". It passed 3 runs in a row on its own, and this PR does not touch that file; it looks like a timing race in that test.Follow-up (not in this PR)
See "After the fix round" below: a completed write turn is now quiet; a failed one still alerts (upstream code).
Size
846 changed lines, over the 400 guide: about 280 source, 510 tests and 40 docs. The source is the write turn, the pure judge and the facts ids; most of the rest is the tests the brief asks for. Adding a default source also needed the existing harness and alert/busy-check tests to model a write turn.
General vs project
All general: a setting any T3 user can turn on. There are no project facts, paths or ids; the marker and default instructions are generic.
Upstream fit: a fork-only add-on in
apps/server/src/fork/handoff. It uses upstream's normal message dispatch, run and turn-item projections and the slot gate, and touches no upstream file.Handoff design row HO4
After the fix round (lenses A+B)
One fix round on both lens reviews. The tables above describe the first version; this section is current.
Major findings
finishWrite), with the same fixed ids, so at most once. A late update during the write turn or during the slot wait after it, and a restart mid write turn, all still send.commandsource does; at idle nothing. A person's Stop or a joined message is still no handoff.[T3 handoff,Recent conversation:, the rules line) are quoted with>(neutraliseNotes, also forcommand).run.interruptwith its own reason, so it reads differently from a person's Stop) and waits up to one more minute. After a write turn T3 had to stop, the next size handoff skips the write turn and sends parts 1, 3 and 4 at once. A write turn that ignores the stop sends its handoff when it ends.:loudsuffix, through the existing seam lines; no new upstream line). A T3-stopped write turn is an interrupted run, which upstream does not alert for. Left: a failed write turn still alerts as "failed": that alert is in upstream's awareness code, which is not a fork seam.Minor findings
noneis the default; a savedmode: handoffwithout a source keeps parts 1, 3 and 4.agentonly when set.runIds).Red checks (each fix removed, the named test fails; put back after):
nonedefaultState questions in tests: restart mid write turn; restart after a write turn that ended long before (nothing sent, no new write turn); timeout then the next turn (bounded); a steered message then a second handoff.
The flaky HO3 test ("a program that cannot start…") failed once in this round. Cause: on Linux the program runs under
timeout, which exits 127 at once for a missing program, sometimes before the process runner has written and closed the empty stdin. That write then fails (EPIPE), and the reason reads "its output could not be read" instead of "could not start" (35 of 200 in a direct Node run). The handoff is still a failure either way; only the reason text differs. Test-only fix: the "could not start" case now uses a spawn that fails (its project folder is gone), with no race; the 126/127 exit codes, which are how a missing program reads on Linux, stay covered. 8 runs in a row green. Left: the race itself is in the upstream process runner (apps/server/src/processRunner.ts, a seam file); fixing it (ignore a stdin EPIPE once the program has exited) needs a seam line, so it is a follow-up.Size of this round: about 620 source lines, 690 test lines and 60 docs lines.
🤖 Generated with Claude Code