packages/agent/docs/runtime-simplification.md
Rework the real implementation under packages/agent/src/harness/runtime/ and the canonical durable types in packages/agent/src/harness/session/types.ts. This is not the isolated scratch spike.
The execution graph is total and public drive is enabled. Format 4 is still work in progress, so the durable type replacement required no migration or compatibility representation.
Pre-M6 completion measurements:
eb1185d93: 5,358 TypeScript lines;417905647: 4,667 lines;0e77e57d9: 4,654 lines;Implemented by the simplification pass:
ContinueOperationResult<T> with cancel_requested instead of implicit undefined;publishResponse for common assistant/deferred durable publication and publishConfigurationFailure for their identical pre-intent failure transition;runtime/drive/tool-placement.ts;toolOperation() casts, and their result unions removed; genuine sibling/progress/memo checks retained;runtime/transcript.ts;LanePatch, no redundant Drive promise-settlement flag, and no unused operation reject arm.At simplification completion, the largest files were runtime/lane.ts (~996), runtime/drive/tools.ts (~663), runtime/drive/checkpoint.ts (~452), and runtime/drive/response.ts (~417).
M6 established structural execution on the simplified substrate. Its first coherent slice added:
at leaf in runtime/drive/structural.ts;R1a, R2, and R3 then moved queued input to the lane, replaced hydrated family outcomes with immutable operation records, and collapsed the family cross-product to 13 neutral leaves. R1b replaced transitional checkpoint drains and marker fields with one shared atomic boundary planner, a transcript-derived threshold guard, and off-line finish-hook replanning. M7 removed drained control, added atomic drain-and-return cancellation, reconciled all 13 leaves, and installed the total direct dispatcher.
M8 added primitive/convenience lane surfaces, one ordered tagged inbox, idle ownership, snapshot/event replication, reduceLaneSnapshot, and remote resnapshot. M9 reconciled the normative specification. M10 forwards exactly one stable ordinary-provider identity derived from Session metadata id plus lane name; structural summaries keep fresh request identities. At M10 completion the runtime is 7,410 lines, runtime/drive is 4,147, lane.ts is 1,992, structural.ts is 1,221, and the new normative reducer is 193 lines. Relative to the reviewed M7 checkpoint, the public/replication surface added 1,130 runtime lines; the durable 13-leaf procedure model stayed unchanged.
Keep the visible durable procedure order:
prepare → publish intent → perform effect → publish outcome.
Do not introduce a generic Procedure interface, runner, scheduler, graph, callback plan, or dependency facade. Historical work-package documents remain unchanged.
A Lane is one process-local actor over one durable lane projection.
Lane.state is authoritative for tip, configuration, current operation, control, inbox IDs, and the latest operation ID.Lane.state before releasing it.requestAbort is the only durable operation cancellation.Lane.state; they never rediscover control state.OperationState has one discriminator, at, with 13 direct leaves:
startingcheckpointassistant.readyassistant.effect_pendingassistant.retry_waittoolsdeferred.suspendeddeferred.effect_pendingsummary.decidingsummary.readysummary.effect_pendingsummary.retry_waitnavigation.ready_to_commitEvery leaf carries one uniform OperationScope. The summary quadruple carries one SummaryTask; its closed ResultBoundary selects in-run checkpoint resumption, standalone finish, or navigation commit. The summary algorithm is derived from that boundary rather than duplicated in state. Control remains orthogonal. ToolBatch remains a child state machine because parallel tool children genuinely mutate sibling call statuses concurrently.
Procedures never read these addresses to decide execution:
laneStateoperationMetaoperationStatebranchTiplaneConfigoperationResultThey use the current Lane.state supplied by the mutation line.
Storage reads remain only for content and cleanup:
pendingEntry payloads;While a Drive procedure is alive, no supported concurrent actor can change or remove its operation state:
requestAbort changes only control;Consequently, ordinary procedure transitions do not recheck operation existence, operation ID, operation kind, at, attempt identity, or nested status. Those are procedure preconditions established by dispatch, not supported races.
The remaining real races are:
Cancellation is checked in three places only:
control and commits the appropriate cancelled result.An ordinary transition helper may centrally decline progress when current control is cancel_requested. Procedures do not repeat that branch manually.
Closing the harness:
Close performs no durable write, installs no replacement Drive, and creates no ownership-loss state. A late effect may return, but its mutation is rejected with HarnessClosed.
Whether close also signals process-local provider/tool work is a resource-cleanup policy, not durable state-machine behavior. Do not couple it to Drive replacement or recovery.
Replace repeated LaneCommand ceremony in procedures with two concrete Lane operations. They are not a scheduler, graph, or action interpreter.
continueOperationUsed for ordinary non-terminal progress.
cancel_requested without invoking the semantic planner; callers cannot confuse cancellation with a planner value.OperationState, materialization, and events.operationState write and publishes the matching process-local operation projection.at value.settleOperationUsed after an admitted provider/tool/structural effect and for genuine parallel child transitions.
operationResult, idle laneState with lastOperationId, and the idle process-local projection.The caller supplies the typed outcome, cleanup/publication writes, last result, and event. Terminal business decisions remain visible in the owning procedure.
Effectful procedures expose four concrete phases:
prepare immutable inputs
→ publish durable effect intent
→ perform the external effect
→ publish one durable outcome
The intent phase must remain visible and precede the external effect. Otherwise a crash after the effect but before its intent would leave no recoverable unknown-outcome marker. Each procedure uses concrete functions such as prepareGeneration, publishGenerationIntent, performGeneration, and publishResponse; there is no generic Procedure abstraction.
Delete the installer-owned model.
installerSignal.DriveAbandoned.LostOwnership and lost_ownership from procedure results.commandDriveOwned.finalizedOutcome and planned external-finalization owner retention unless the Flue investigation establishes a concrete requirement.activeDrive only as the lane's install/join slot.requestAbort retains the two-part gate ordering:
beginAbort before cancellation mutation
commit cancel_requested
signalAbort after commit
This prevents a new effect from entering while the durable marker is being committed.
Do not remove validation of external or referenced content:
These validate data or genuine child concurrency. They are not defensive revalidation of the operation state machine.
Files:
src/harness/session/types.tssrc/harness/runtime/, restore, conformance helpers, and focused testsdocs/harness.mddocs/work-packages/05-direct-durable-drive.mdActions:
at union.Exit: npm run check; existing focused runtime tests pass; no phase.kind, generation status, deferred status, or structural decision status remains in canonical operation state.
Files:
src/harness/runtime/lane.tssrc/harness/runtime/types.tsActions:
continueOperation and settleOperation, including the terminal-decision suffix.Exit: focused tests prove durable state and Lane.state remain identical after every helper commit.
Files:
runtime/drive/checkpoint.tsruntime/drive/generation.tsruntime/drive/recovery.tsruntime/progress.tsActions:
same* predicates.continueOperation.settleOperation.Exit: no control-state storage reads; no repeated assistant state verification; focused generation tests pass.
Files:
runtime/drive/deferred.tsruntime/drive/tools.tsruntime/progress.tsActions:
Exit: tool status checks exist only for genuine sibling concurrency; focused deferred/tool/progress tests pass.
Files:
runtime/types.tsruntime/lane.tsexecution/effect-gate.tsruntime/drive/*.tsActions:
LostOwnership, commandDriveOwned, exact Drive checks, installerSignal, DriveAbandoned, and finalizedOutcome.activeDrive only for install/join arbitration.Exit: grep finds no ownership-loss or installer-abandonment vocabulary in production runtime.
Files:
runtime/harness.tsruntime/lane.tsActions:
Exit: close and process loss leave the same durable restart point; no close path writes cancellation or synthetic settlement.
Files:
runtime/drive/structural.tsruntime/drive/reconcile.tsruntime/drive.tsruntime/lane.ts public surfacesActions:
state.at switch.External finalization is excluded unless the Flue investigation identifies a concrete, current caller that cannot be expressed through close, explicit abort, recovery, or offline administration.
After every code stage:
npm run check
Run each modified focused test file from the package root. Do not run the full Vitest suite directly. Public drive was enabled only after the final stage made every leaf total.
Final audit:
rg 'lost_ownership|LostOwnership|DriveAbandoned|commandDriveOwned|installerSignal|finalizedOutcome' packages/agent/src/harness
rg 'operationState\(|laneState\(|branchTip\(|laneConfig\(' packages/agent/src/harness/runtime/drive
The second audit may match write constructors, but no reader call may use those control addresses.