feat(agent): a hand never reruns a killed call; outcomes per placement; KILL/MULTI/FAULT-HAND cases (S27a)
Summary
Part of #5482. Stacked on #5483 (base feat/s27a-remote-executor); retarget once it merges.
A hand now keeps a durable record of the calls it runs, on the execution ledger. A hand killed mid-call never runs that call again, and the session always gets an outcome instead of waiting forever.
packages/agent/src/execution/remote-hand-ledger.ts(new):createHandLedger(). Each invoke is admitted and walked todispatched(admit, prepare, effect, freeze, release, dispatch) BEFORE its handlers and tool run, and its result is recorded as the settlement. On restart,recover()runs the ledger's restart rule:preparinganddispatchedcalls endhand_restarted(uncertain once effects were possible) and are never rerun, whileprepared/releasedcalls survive and continue. The outcomes the session has not acknowledged are re-sent. A re-delivered invoke is answered from the record; a call whose admission never became durable is run (nothing of it ran).remote-executor.ts: optionalledger; a requiredonFaultreceives record failures (never swallowed); a restarted hand announces itself (hello) after re-sending outcomes.ExecutionLedger.scan()lists rows for that re-send.remote-tool-host.ts: a requiredplacement("split-local"|"cross-machine"), never inferred. Onhelloit re-sends every call still waiting. It acknowledges every outcome (ack). Aterminaloutcome becomes:- split-local (one machine): today's recovery. The interrupted call gets today's placeholder result (
TOOL_RESULT_PLACEHOLDER, "Tool output unavailable (context compacted)"), it is not rerun, and no uncertain outcome reaches the model (K3/X13). - cross-machine: the endpoint contract. An error result with
details: { outcome: "hand_restarted", uncertain, hooksRan }; the call is never rerun.
- split-local (one machine): today's recovery. The interrupted call gets today's placeholder result (
remote-protocol.ts:ack,terminalandhellomessages.
Inertness
Nothing in the product creates a remote ToolHost or a hand yet. The placement and onFault options are new requirements only for those new APIs.
KILL
Registered in packages/agent/src/conformance/registry.ts (intro #5482, adapters store+transport+executor):
KILL-HAND-NN-{B,D}-{SL,XM}(32 cases,execution/testing/kill-hand.ts). They kill the hand before and after each of the call's eight ledger commits (admit, prepare, effect, freeze, release, dispatch, settle, ack), on both placements, then restart it on the reopened store. Expected outcomes, from the last durable commit:- none: the call runs once, normal result;
- admit/prepare:
hand_restarted, not uncertain, never run; - effect:
hand_restarted, uncertain, never run; - freeze/release: survives the restart, runs once, normal result;
- dispatch:
hand_restarted, uncertain, the body runs at most once (it ran only if the kill came after dispatch was durable); - settle/ack: the recorded result.
On split-local everyhand_restartedis today's placeholder. Every case also ends with exactly one durable record, acknowledged.
MULTI-HAND-01(several scopes batch at once on one hand; each scope's calls start in lane order) andMULTI-KILL-01(killed with several scopes in flight; each endshand_restarted, uncertain, never rerun, one record each) inexecution/testing/multi-hand-cases.ts.FAULT-HAND-01..05(the five transport fault profiles: every call settles with its unfaulted result, each body runs once, per-scope order) andFAULT-HAND-MULTI-01(the hand is unreachable far past the resume window: dependent calls pause with no invented outcome, then each scope resumes once with its own result) inexecution/testing/fault-hand-cases.ts.
The Bun SQLite conformance host now provides executor and runs all of them. The DO host lives outside this repository; its run of these cases is still owed.
Mutations
Each mutation was applied to the head and test/execution/hand-conformance.test.ts (41 cases) was run against it:
| mutation | result |
|---|---|
redispatch-after-kill: the restarted hand skips recover() | killed: 17 failed |
uncertain-on-split-local: split-local reports the endpoint outcome | killed: 8 failed |
shared-scope-state: all scopes share one executor state | killed: 8 failed |
double-resume: the session's settle keeps the waiter | survived. A promise settles once, so the count it targeted could not fail. That assertion was removed; exactly-once resume is asserted as "each body ran once" and is fenced by the ledger's dispatch record (the redispatch-after-kill row) |
Tests
packages/agent/test/execution/hand-conformance.test.ts: every hand case on a memory store and the reference transport, plus the registry/implementation gap check (both placements, 32 KILL cases).packages/agent/test/execution/hand-win32-sim.test.ts(QX1.win): the KILL-HAND cases and MULTI-KILL-01 with the hand on a Windows named-pipe endpoint, killed signal-less (nothing of the dead hand becomes durable after the kill). It lives next to the cases inpackages/agentbecause the coding-agent tests cannot import the conformance cases. There is no hand-process spawn yet (a cross-process carrier does not exist), so the "every hand spawn passeswindowsHide" check has no site in this change.test/conformance/run-suite.test.ts: the export surface and the Bun host run include the new cases.- Exact-head gate rows: see the comment below.
Dead code
None made dead.
Summary by cubic
A hand now keeps a durable record of the calls it runs, so a hand killed mid-call never runs that call again and the session always receives an outcome instead of waiting forever.
createHandLedger()records each call as dispatched before its handlers and tool run, and records settlements; on restart, interrupted calls endhand_restartedand are never rerun, while surviving calls resume and unacknowledged outcomes are re-sent. A call whose scope cannot open leaves no record, a failed recovery reachesonFault, a frozen call resumes only with the arguments it was frozen with, and a record holding another writer's durableblockedoutcome (the brain executor's) is answered as refused (foreign_outcome), never as a terminal run.- New protocol messages
ack,terminal, andhello;placement(split-local|cross-machine) andonFaultare now required on the hand host and executor. Split-local recovery returns today's placeholder result; cross-machine returns an error withdetails: { outcome, uncertain, hooksRan }. - Nothing in the product creates a remote ToolHost or hand yet, so these new requirements only affect the new APIs.
Conformance tests
- Adds 32
KILL-HANDcases (kill before/after each of the eight ledger commits, both placements),MULTI-HAND-01andMULTI-KILL-01, andFAULT-HAND-01..05plusFAULT-HAND-MULTI-01, with a vacuity guard that fails the multi-fault case when the link never drops. - Runs them on the Bun SQLite host's new
executoradapter, and adds a win32-simulated run of the kill cases with signal-less termination.