# Durability verification index

The rule anchors in [durability.md](/internals/durability/) are stable. This index names
each implemented rule’s tests by repository directory and Go function, with a
subtest name where needed. The index does not replace those tests’ assertions.
`core/driver/TestM1FaultMatrix` enumerates every actual append in twelve scenarios and
runs eight boundary outcomes, followed by repeated crashes during
recovery. `core/testkit/crashtest` validates attempt closure, settlement arithmetic,
observation groups, and atomic timer registration without importing the reducer.

Run `make check` for the full gate across the root, examples, and eval modules.
Real process and filesystem tests additionally run under `-tags=integration`.

| Rules | Named verification |
|---|---|
| [E1](/internals/durability/#e1) | `core/loop/TestEffectID`; replay and state restoration in `core/loop/FuzzFold` |
| [E2](/internals/durability/#e2), [E3](/internals/durability/#e3), [E4](/internals/durability/#e4) | `core/loop/TestE2AttemptMustCloseBeforeRestart`, `core/loop/TestB4AttemptLedger`, `core/loop/TestE4ClosedAttemptCannotCarryAnotherCharge`, `core/testkit/crashtest/TestIndependentChecker`, `core/driver/TestM1FaultMatrix` |
| [E5](/internals/durability/#e5) | `core/driver/TestRunRecordsFailedModelCalls`, `core/driver/TestRunRecordsFailedToolCalls` |
| [E6](/internals/durability/#e6) | `core/driver/TestR4ToolRecoveryTable`, `examples/external-driver/TestExternalDriverKillAndRecover` |
| [E7](/internals/durability/#e7) | `core/loop/TestE7LateCompletionDoesNotSettle`, `core/driver/TestRunWaitsForItsTools` |
| [B1](/internals/durability/#b1), [B4](/internals/durability/#b4), [B6](/internals/durability/#b6) | `core/loop/TestB4AttemptLedger`, `core/provider/openaicompat/TestB4IncompleteUsage`, `core/driver/TestM1FaultMatrix`, `core/TestX1X3ResultRecovery` |
| [B2](/internals/durability/#b2) | `core/provider/TestB2Reservation`, `core/loop/TestB2MissingReservationRefused`, `core/TestB2HardBudgetRequiresBounds`, `core/provider/openaicompat/TestB2ReservationMatchesWire`, `core/TestB2RenderedReservationFitsHardLimit`, `core/TestB2RenderedReservationRefusalIsReplayable` |
| [B3](/internals/durability/#b3), [B5](/internals/durability/#b5) | `core/TestB5Budgets`, `core/loop/TestB5ReservationCannotOverflowLimit`, `core/driver/TestM1FaultMatrix` |
| [B7](/internals/durability/#b7) | `core/loop/TestSubagentLinks`, `core/TestSubagentCannotStartSubagents` |
| [C1](/internals/durability/#c1), [C2](/internals/durability/#c2) | `core/TestSessionIsExclusive`, `core/driver/TestRunAdoptsBeforeFolding`, `core/driver/TestM1FaultMatrix` |
| [C3](/internals/durability/#c3) | `core/driver/TestRunRecordsIntentBeforeAction`, `core/driver/TestStartAfterTerminationDoesNotAppend`, `core/driver/TestM1FaultMatrix`, `examples/external-driver/TestExternalDriverKillAndRecover` |
| [C4](/internals/durability/#c4), [O1](/internals/durability/#o1) | `core/driver/TestRunFaultsAtEverySplitAppend`, `core/testkit/crashtest/TestIndependentAtomicGroups`, `core/driver/TestM1FaultMatrix` |
| [C5](/internals/durability/#c5) | `core/driver/TestBeginFaults`, `core/driver/TestRunFaultsAtEveryAppend`, `core/driver/TestL4LeaseLossCancelsAmbiguousRead`, `core/driver/TestM1FaultMatrix` |
| [C6](/internals/durability/#c6) | `core/driver/TestRecordsAfterCancelAreBounded`, `core/driver/TestRunWaitsForItsTools`, `core/driver/TestS1StopPreservesCompletedResponseWithoutFinishingRun`, `core/driver/TestS1StopPreservesCompletedFailures` |
| [C7](/internals/durability/#c7), [O2](/internals/durability/#o2), [O3](/internals/durability/#o3) | `core/driver/TestR4ToolRecoveryTable`, `core/driver/TestM1FaultMatrix`, `core/loop/FuzzFold` |
| [C8](/internals/durability/#c8) | `examples/external-driver/TestOwnExecutor`, `examples/external-driver/TestExternalDriverKillAndRecover`; separate-module `examples/apicheck/TestUse` |
| [L1](/internals/durability/#l1), [L2](/internals/durability/#l2), [L7](/internals/durability/#l7), [L12](/internals/durability/#l12) | `core/lease/TestLocalConformance`, `core/lease/file/TestConformanceOnFakeFS`, `core/lease/file/TestConformanceOnRealFS`, `core/lease/file/TestLeaseAcrossProcesses`; the wall-clock stepping assumption remains explicit in L7 |
| [L3](/internals/durability/#l3), [L4](/internals/durability/#l4), [L5](/internals/durability/#l5) | `core/driver/TestAcquireRefusesALateGrant`, `core/driver/TestAuthorityWatchdog`, `core/driver/TestLateRenewalDoesNotRevive`, `core/driver/TestRunStopsWhenAuthorityEnds`, `core/driver/TestL4LeaseLossCancelsAmbiguousRead`, `core/TestL4LeaseLossDuringConfiguration`, `core/driver/TestM1FaultMatrix` |
| [L6](/internals/durability/#l6) | `core/driver/TestAuthorityRelease`, `core/driver/TestReleaseCancelsARenewal`, `core/TestReleaseFailuresAreReported`, `core/TestCleanupIsBounded` |
| [L8](/internals/durability/#l8), [L9](/internals/durability/#l9), [L10](/internals/durability/#l10) | `core/store/file/TestConformanceOnFakeFS/FenceSurvivesCrash`, `core/store/file/TestFailedFencePersistBreaksTheSession`, `core/store/file/TestWriterLockIsPerAppend`, `core/store/file/TestHandoffWhileTheOldWriterLives`, `examples/external-driver/TestExternalDriverKillAndRecover` |
| [L11](/internals/durability/#l11) | `core/store/file/TestAdoptMakesTheTailDurable`, `core/driver/TestRunAdoptsBeforeFolding`, `core/driver/TestRunStopsWhenAdoptionFails` |
| [R1](/internals/durability/#r1), [R3](/internals/durability/#r3) | `core/loop/TestR3TerminationWinsOverRetry`, `core/driver/TestR3RecoveryHonorsInterrupt`, `examples/external-driver/TestStartCommandPrecedesRecovery`, `core/loop/TestR3InterruptWinsOverFailedCompletion`, `core/driver/TestT7OverdueRecovery`, `core/driver/TestM1FaultMatrix` |
| [R2](/internals/durability/#r2) | `core/driver/TestRunRefuses`, `core/driver/TestRunRefusesAMissingTool`, `core/driver/TestRunRefusesAChangedTool`, `core/driver/TestR2SchemaComparisonPreservesIntegers` |
| [R4](/internals/durability/#r4), [R6](/internals/durability/#r6) | `core/driver/TestR4ToolRecoveryTable`, `core/driver/TestM1FaultMatrix` (`overflow`: compaction calls recovered at every boundary, applied once); uncertain calls reconcile as unknown |
| [R5](/internals/durability/#r5) | `core/driver/TestR5RecoveryBatches`, `core/driver/TestM1FaultMatrix` |
| [S1](/internals/durability/#s1), [X2](/internals/durability/#x2) | `core/TestCancel`, `core/TestAgentClose`, `core/TestStartContextOwnsTheExecution`, `core/driver/TestS1StopWhileInterruptJoins`, `core/driver/TestS1StopPreservesCompletedResponseWithoutFinishingRun`, `core/driver/TestS1StopPreservesCompletedFailures` |
| [S2](/internals/durability/#s2) | `core/TestS2InterruptInFlight`, `core/driver/TestR3RecoveryHonorsInterrupt`, `cmd/zelk/TestFirstCtrlCInterrupts` |
| [S3](/internals/durability/#s3) | `core/TestSubscribeDetach`, `core/TestSubscribeCancelled` |
| [S4](/internals/durability/#s4) | `core/driver/TestRunRetriesModelCalls`, `core/driver/TestRunRetryBackoffIsCapped`, `core/driver/TestRunStopsWaitingWhenCancelled`, `core/driver/TestM1FaultMatrix` |
| [K1](/internals/durability/#k1), [K2](/internals/durability/#k2) | `core/TestK1SendValidatesBeforeAdmission`, `core/driver/TestRunRefuses`, `core/driver/TestM1FaultMatrix` |
| [K3](/internals/durability/#k3), [K4](/internals/durability/#k4) | `core/TestK3CommandDeduplication`, `core/loop/TestK3DuplicateAcceptanceIsInconsistent`, `core/driver/TestK5QueueAndDuplicateAcks`, `core/driver/TestM1FaultMatrix` |
| [K7](/internals/durability/#k7) | `core/loop/TestPlanModeCeiling`, `core/loop/TestModeChangeBoundaries`, `core/loop/TestModeChangeAtIdleAndRejections`, `core/loop/TestRecordedPolicyIsChecked`, `core/driver/TestUnauthorizedModeIsNotAccepted`, `core/driver/TestModeChangeSurvivesReopen`, `core/TestPlanModeSession`, `core/driver/TestM1FaultMatrix` (`plan`, `mode_switch`) |
| [K5](/internals/durability/#k5), [K6](/internals/durability/#k6) | `core/driver/TestK5QueueAndDuplicateAcks`, `core/TestK5AckCancellationDoesNotWithdrawCommand`, `core/driver/TestK5SendRacesWithClosure`, `core/TestS2InterruptInFlight` |
| [T1](/internals/durability/#t1), [T2](/internals/durability/#t2), [T3](/internals/durability/#t3) | `core/loop/TestT2TimerSurvivesMissingSet`, `core/loop/TestT3RefusedRunDropsTimerEffect`, `core/testkit/crashtest/TestIndependentAtomicGroups`, `core/driver/TestM1FaultMatrix` |
| [T4](/internals/durability/#t4), [T5](/internals/durability/#t5), [T6](/internals/durability/#t6), [T7](/internals/durability/#t7) | `core/TestT4WallTimer`, `core/loop/TestT5StaleTimer`, `core/driver/TestT7OverdueRecovery`, `core/driver/TestM1FaultMatrix` |
| [T8](/internals/durability/#t8), [T9](/internals/durability/#t9) | `core/TestT8ProviderDeadline`, `core/TestT8ToolDeadlineAndNextWake`, `core/driver/TestT8DeadlineUsesIntentTimestamp`, `core/TestT4WallTimer`, `core/driver/TestM1FaultMatrix` |
| [X1](/internals/durability/#x1), [X3](/internals/durability/#x3) | `core/TestX1X3ResultRecovery`, `core/TestX3UsageAfterCommandAppendFailure`, `core/TestX3UsageAfterTimerAppendFailure`, `core/TestResultTextIsTheRunsOwn`, `core/TestResultTextIgnoresCutOffText` |
| [O4](/internals/durability/#o4) | `core/driver/TestRunToolCallSeesAndRecordsSessionState`, `core/internal/builtin/files/TestInstructionDiscovery`, `core/internal/builtin/files/TestInstructionsAreRecordedOnce`, `core/loop/TestInstructionsReachTheModel`, `core/TestProjectInstructions`, `core/loop/TestBadObservationsAreInconsistent`, `core/loop/TestTodosFold`, `core/driver/TestM1FaultMatrix` |

Compaction (trap 5) is covered by `core/loop/TestMicrocompaction`, `core/loop/TestFullCompaction`,
`core/loop/TestReactiveCompaction`, `core/loop/TestCompactionFailures`, `core/loop/TestNativeWindow`,
`core/loop/TestNoCompactionWithoutConfig`, `core/driver/TestNativeCompaction`,
`core/driver/TestOverflowIsClassified`, `core/TestContextOverflowCompacts` and
`core/loop/TestCacheStablePrefix`.

[Q1](/internals/durability/#q1), [P1](/internals/durability/#p1) and [P2](/internals/durability/#p2) for
questions and plan exit are covered by `core/TestSuspendForAnswer`, `core/TestInputCallback`,
`core/TestInputDenied`, `core/TestEnterPlanMode`, `core/TestExitPlanMode`, `core/TestInputExpiry`,
`core/loop/TestSuspendedTimeIsExcluded` and `core/driver/TestM1FaultMatrix` (`question`: a request
answered exactly once across a crash at every boundary). The integration test
`core/TestSuspensionEndsOnlyTheRunsProcesses` checks the recorded states and live
PIDs of execution-owned and conversation-owned processes at suspension.
[P3](/internals/durability/#p3)
for trees is covered by `core/TestTreeSuspension`: a child's question comes up
through its parent's report and the parent's own request suspends the root, and
the answer goes back down through `TaskOutput`, marked as relayed, exactly
once. The rule's depth-1 tree rests on the child's tool set, which never
includes the `Task` tools (`core/TestSubagentCannotStartSubagents`).

Plan-mode entry also has reducer coverage in `core/loop/TestEnterPlanModeDeniesLaterCall`,
`core/loop/TestEnterPlanModeQueuedState` (JSON checkpoint while a tool holds the mode
change), and `core/loop/TestEnterPlanModeInvalidatesApproval`.

The external-driver integration test is the kill-and-recover process proof.
The CLI integration test exercises a real shell under first-interrupt semantics;
the second-stop join race uses the deterministic driver harness. No paid provider
evaluation is part of these checks.

Worktree host lifecycle boundaries are covered separately from the session log:
`cmd/zelk/internal/host/TestWorktreeFaults` interrupts creation after its intent, checkout and include
copy; `cmd/zelk/internal/host/TestWorktreeRemovalFaults` interrupts removal before and after the
`removing` record, after git removes the checkout and after branch deletion.
Each attempts a reopen or second exit, asserting reconciliation or an explicit
refusal with recovery instructions, never silent recreation or loss of ownership.
These tests use real temporary repositories under `-tags=integration` and make
no provider calls. Sweeping unused worktrees is covered by `cmd/zelk/internal/host/TestSweepWorktrees`
and `cmd/zelk/internal/host/TestSweepKeepsWhatIsntZelks`.


Completion decision coverage includes `core/loop/TestDecisionRecords`,
`core/TestCompletionDecisionRecords`, `core/loop/TestTaskAttributionSnapshot`,
`core/loop/TestTaskAttemptsAcrossDifferentActions`, `core/loop/TestTimerRecordsAfterStateRoundTrip`
and `core/loop/FuzzDecisionRecords`. `core/driver/TestM1FaultMatrix` includes `completion`, `report`
and `task_attempt` groups, exercising explicit completion/continuation records,
shortcut flags and task attempts through repeated crash recovery.
Context stress includes `core/loop/TestLongRunningCompaction`, `core/loop/TestLongNativeCompaction`
and integration `core/loop/TestLongCompactionFileReopen` (200 cycles each), plus native
protected-handoff and irreducible-overflow regression tests.

Hook and approval coverage exercises [H1](/internals/durability/#h1) (hooks) and
approvals under [Q1](/internals/durability/#q1). `core/driver/TestM1FaultMatrix` adds three groups:
`hook` (each invocation decided exactly once across a crash at every
boundary, run only after its intent is durable, and re-run only as a new
attempt with the same invocation ID), `approval` (each approval answered
exactly once) and `classify` (each action's verdict recorded exactly once,
with attempt settlement checked by `crashtest`). [K7](/internals/durability/#k7)
decisions from the folded log alone are covered by `core/loop/TestDecisionsInTheReducer`, `core/loop/TestApprovalResponses`,
`core/loop/TestSessionGrant`, `core/loop/TestApprovalBinding` and
`core/loop/TestApprovalDoesNotSurviveAPolicyChange`. Replay without re-running hooks is
covered by `core/TestPreToolUseDeny` and `core/TestDeferredApprovalResumes`, and
integration `core/TestDeferredApprovalNewProcess` proves a deferred approval
answered by a second process: the action runs exactly once and the hook isn't
run again. The persisted circuit breaker is covered by `core/TestAutoModeBreaker`.

The `output` group of `core/driver/TestM1FaultMatrix` checks that a
rejected and an accepted `StructuredOutput` call, faulted at every append
boundary, leave exactly one recorded verdict each, and the folded output is
the accepted value. Validators run only after the call's intent is durable.
The reducer's own checks are `core/loop/TestStructuredOutputLifecycle`,
`core/loop/TestStructuredOutputInvalidated`, `core/loop/TestStructuredOutputPerRun` and
`core/loop/TestStructuredOutputInconsistent`.

The `records` fault-matrix group submits a
rejected call and two accepted records in one model response. Every append
boundary and a second crash during recovery must leave exactly records 1 and
2 with their corresponding values, with no duplicate numbering or gap.
`core/loop/TestOutputRecordWaves` checks serialization of calls whose numbers depend on
earlier verdicts.
