Checkpoints, Retries, and Ambiguous Effects
Inject faults around intent, execution, acknowledgement and settlement; reconcile uncertain effects before completion.
A worker sends a request to an output service: append the processed records of file 4 to the archive. The request times out after thirty seconds. The worker’s retry policy says: on timeout, try again. The second request succeeds. The archive now holds file 4’s records twice, because the first request had succeeded too. Only its response was lost.
Nothing malfunctioned. The network delayed a reply, the timeout fired as configured, and the retry did what retries do. The defect is conceptual. The worker treated “I did not receive a confirmation” as “it did not happen.” Those are different statements, and the space between them is the ambiguous effect: an attempted operation whose actual outcome is not yet known. This chapter is about operating honestly inside that space. That means checkpoints that mean what they say, retries that cannot double an effect, and reconciliation that runs before anyone declares the work complete.
Evidence status. Draft manuscript. Project 04 (Crashproof Worker) has not started. The recovery design draws on the R04 dossier’s proposals (PROPOSED) and on documented behaviour of external systems it cites (DOCUMENTED; Established within those sources). Pi facts come from R02 source inspection (Established for the inspected 1.6.0 artifact; TEST NOT RUN). Project 01 code is cited by source inspection of the working-tree candidate independently re-reviewed with verdict REJECT (2026-11-23; not accepted). The educational demonstration D10-CRASH-01 (§10.7) is implemented and executed; the formal R04-E03 study of §10.8 is the remaining EXPERIMENT PENDING study.
10.1 Four outcomes, two of them indistinguishable
From the caller’s point of view, a dispatched operation ends in one of four ways:
- Confirmed success. A response says the effect happened.
- Confirmed failure. A response says it did not, for example a validation error before any change.
- No effect, no response. The request was lost before reaching the target, or the target failed before acting.
- Effect, no response. The target acted, and the response was lost, delayed past the timeout, or arrived after the caller crashed.
Cases 3 and 4 look identical to the caller: in both, nothing came back. No amount of waiting distinguishes them from the caller’s side alone, because a late response can always still be in transit. The only way to tell them apart is to ask the target what it did, using some identity for the operation that both sides recognize. That question is reconciliation. Every reliable recovery design in this chapter comes down to arranging that reconciliation is possible, and refusing to declare completion until it has been done or has explicitly failed.
R04’s failure model includes these cases among the conditions a harness
must survive: “lost acknowledgments”, “delayed responses”, “duplicate
delivery”, “cancellation races”. It states the consequence plainly: “No
response can accompany a completed effect. Trace labels must preserve both
possibilities” (R04-SECURITY-RECOVERY.md R04-P01; PROPOSED threat
model).
10.2 Where a crash can fall
Chapter 9’s journal records an operation’s progress as entries written around the dispatch boundary. R04 sets out the required recovery behaviour for each point at which a crash can occur (R04-P06; PROPOSED). It is reproduced here because the rest of the chapter elaborates it:
| Crash point | Required recovery behaviour (R04-P06) |
|---|---|
| Before committed intent | No dispatch is permitted. |
| After intent, before the dispatch boundary | Recover the intent; check authority and preconditions again. |
| During dispatch, or after the effect but before acknowledgment | Mark unresolved; query the target’s receipt or state, or retry the same key only under the target’s documented deduplication contract. |
| After acknowledgment, before durable settlement | Reconcile using operation identity and authoritative outcome; do not blindly issue another effect. |
| After settlement | Report the recorded confirmation; revalidate if the question concerns current state. |
Two features of the table matter. First, the third row is where ambiguity
lives. It is the only row whose required action depends on the target
offering something: a queryable receipt, a state that can be inspected,
or a deduplication contract. If the target offers none of these, the
harness cannot recover automatically from that row, and the honest outcome
is UNKNOWN (§10.5). Second, the second row requires rechecking
authority and preconditions. An intent recorded an hour ago, before a
crash, was authorized against the world as it was then. Chapter 6’s stale
base applies to authorization too.
10.3 Retries: safe only by contract
A retry re-sends an operation. Whether that is safe depends entirely on the target.
Idempotent operations have the same effect however many times they
are applied. “Set max_attempts to 7” is idempotent, while “append these
records” and “charge this card” are not. For idempotent operations,
retrying is safe as far as the effect is concerned, though it may still
cost money and time.
Deduplicated operations are non-idempotent operations that the target promises to apply at most once per idempotency key supplied by the caller. Retrying with the same key is safe within the target’s documented contract, and that contract has limits. R04 cites Stripe’s documentation as an illustration. Deduplication there has a provider-defined scope and retention, and keys may be pruned after at least 24 hours (R04-C10; DOCUMENTED for that provider; no Stripe workflow is proposed). A retry after the retention window can therefore duplicate an effect even with the right key. R04’s conclusion is that idempotency keys are “not universal exactly-once guarantees.”
Everything else must not be blindly retried. After an ambiguous dispatch, the harness reconciles first and retries only if reconciliation shows that the first attempt had no effect.
The book’s blueprint puts the general rule as a hard constraint: “Do not claim global exactly-once execution”. For irreversible effects, demand approval plus idempotency or reconciliation where possible (blueprint, “Effect broker”).
Retries also occur inside the runtime, and these must be accounted for
even when they have no external effect. R02 records that Pi 1.6.0 enables
session retry by default with a maximum of three, and that provider retry
is configured separately (R02-PI.md C13). A retried model request is not
usually a duplicate external effect, but it is a duplicate cost, and it
can change timing and therefore behaviour. Project 01 disables both and
asserts the effective settings before the first request (Chapter 3). The
corrective re-review observed the adapter recording session retry disabled
and provider retries zero (INDEPENDENT-REREVIEW.md; OBSERVED). A
harness that leaves them on must count every attempt, including failed
ones, against the budget, with unknown usage recorded as null (Chapter 3,
§3.6).
10.4 What a checkpoint means
A checkpoint is a durable assertion: every operation up to this
point is settled. “Settled” means CONFIRMED_SUCCEEDED,
CONFIRMED_FAILED, or explicitly abandoned as UNKNOWN with a recorded
decision. It is not a snapshot of the conversation, and it is not a marker
that “we got this far.”
The definition rules out a common mistake. A checkpoint written after dispatch but before confirmation claims something that is not yet known. If the process then crashes and recovery resumes from that checkpoint, the ambiguous operation is treated as settled, and its true outcome is never reconciled. In this sense a premature checkpoint is worse than none. Without a checkpoint, recovery at least re-examines everything. With a premature one, recovery skips the one operation that needed examining.
The definition also says what to checkpoint. It is task state, the journal position, and not the session. A checkpoint can still record a pointer to the session (a Pi session locator, or a hash of the history up to that point) so that a resumed conversation can be aligned with it (Chapter 9, §9.6). But the checkpoint’s meaning comes from the journal.
How often to checkpoint is a cost trade-off. Checkpointing after every confirmed operation makes recovery precise and adds a durable write per operation. Checkpointing every n operations batches the writes and leaves up to n operations to re-examine on recovery. Since re-examination is just reading journal entries and possibly querying the target, it is usually cheap. Checkpoints mainly let recovery skip work, not make it safe.
10.5 Reconciliation, and the right to say UNKNOWN
Reconciliation asks the authoritative source what happened to an
operation identified by its operation ID or idempotency key, and records
the answer as CONFIRMED_SUCCEEDED, CONFIRMED_FAILED or UNKNOWN.
R04-P06 adds three rules that this chapter adopts (PROPOSED):
- Inconclusive is a legitimate result. If the target cannot answer,
for example because it has no receipt API or the key has expired, the
operation stays
UNKNOWN. A human resolves it, or it is explicitly abandoned asUNKNOWN. The harness never speculates. - Compensation is a separate effect. Undoing a duplicate (refunding, deleting appended records) is a new operation with its own intent, authorization and possible failure. It is not a rollback of the original.
- Do not announce success before independent confirmation. This is Chapter 4’s rule, applied to effects.
The first rule is the most important and the least comfortable. A harness
that must always report success or failure will, under pressure, turn
UNKNOWN into one of them. Turning it into failure invites a retry that
may duplicate. Turning it into success hides a possible loss. The book’s
outcome vocabulary keeps UNKNOWN throughout, from Chapter 1’s verdicts
to Chapter 4’s trace verdict, precisely so that this case has a name.
The harness should verify its own effects in the same way. Project
01’s evidence bundle is an effect on the local filesystem. The candidate
writes bundle.json.partial, renames it into place, writes a digest
sidecar and then the receipt (supervisor.ts, writeBundle; source
inspection). Chapter 3 described how the first corrective freeze handled a
receipt-write failure by emitting two contradictory terminal events
(RER-04). That is a reconciliation failure inside the harness itself: an
effect (the receipt) whose outcome was declared before it was known. The
first freeze’s receipt-write failure (two contradictory terminal events,
RER-04 OBSERVED) is the harness-internal reconciliation failure this
section means. A second-freeze ordering correction was claimed in an
uncommitted comment; independent re-review returns RER-04 as PARTIAL
(returned channel coherent; on-disk stale success remains; REVIEW-02 §4),
so this section re-anchors to the first-freeze record.
10.6 Cancellation and timeouts do not roll back
When a run exceeds its budget or deadline, the harness stops it. Stopping is also an operation with uncertain completion.
At the runtime level, R02 records that Pi 1.6.0’s abort() requests
cancellation and awaits idle, and that dispose() returns void and
disconnects listeners after requesting aborts. R02’s limitation is that
“cooperative tool signals do not guarantee bounded physical termination or
rollback” (C11). At the operating-system level, R04 cites Microsoft’s
documentation that I/O cancellation is not guaranteed and requires
observing completion (R04-C08; DOCUMENTED). Neither layer offers
“cancel” as “undo.”
The consequences for recovery are direct. A cancelled run can have operations in any row of §10.2’s table. Cancellation therefore starts reconciliation; it does not replace it. R04-P06 describes cancellation as: stop admitting further work, request cooperative interruption, record the request, and reconcile anything already dispatched. A timeout or process kill “cannot certify rollback.”
Project 01’s supervisor shows the same discipline at the process level.
It allows bounded time for cooperative abort and drain, then attempts
termination of a hung child. If termination cannot be confirmed, the
inspected source records cleanup: "UNCONFIRMED" and sets the in-memory
contextDenied flag (supervisor.ts; source inspection). The offline
contract §4 requires retaining STOP_UNCONFIRMED; durable journaling of
that contract condition is a Project 04 requirement, not observed current
source behavior. Chapter 9’s caveat remains: the in-memory refusal does
not survive a restart.
10.7 Worked example: Crashproof Worker, crash by crash
This section is an executed educational demonstration, D10-CRASH-01
(examples/pi-harness-lab/src/checkpoint.ts;
examples/pi-harness-lab/test/checkpoint.test.ts; 11 tests pass offline).
It processes five input files and appends each file’s records to a fake
archive service with an independent effect log. The service supports lookup
by idempotency key. A second, “forgetful” variant prunes keys after a fixed
number of operations, modelling bounded deduplication (compare R04-C10).
Faults are injected around file 4. The blind-retry baseline (R0) re-sends
without asking; the treatment (R1) reconciles by key first and reports
UNKNOWN when the lookup is inconclusive. The table below is the measured
outcome of running both policies, not a prediction.
| Fault point (file 4) | Journal at restart | Blind retry (baseline) | Intent + reconciliation (treatment) |
|---|---|---|---|
Before INTENT |
Files 1–3 confirmed; nothing for file 4 | Processes file 4; correct | Processes file 4; correct |
After INTENT, before DISPATCHING |
Intent only | Re-sends; correct (first attempt never left) | Rechecks preconditions, dispatches; correct |
After DISPATCHING, effect not applied |
Dispatching, no observation | Re-sends; correct | Queries by key: not found → dispatch; correct |
After DISPATCHING, effect applied, response lost |
Dispatching, no observation | Re-sends → duplicate records | Queries by key: found → CONFIRMED_SUCCEEDED; no re-send; correct |
| After response, before confirmation entry | Observation recorded | Re-sends → duplicate | Reconciles the observation against the key: confirmed; correct |
| Same as row 4, “forgetful” service, key pruned | Dispatching, no observation | Duplicate | Query inconclusive → UNKNOWN, escalated; no re-send |
The last row is the one to remember. The treatment does not achieve a
correct archive there, because nothing can without more information. What
it achieves is an honest record: it reports UNKNOWN instead of a
duplicate silently labelled success. Under the scoring rules in §10.8, an
honest UNKNOWN is better than an undetected duplicate and worse than a
confirmed correct result. The baseline’s duplicates in rows 4, 5 and 6 are
all reported as successes, which is Chapter 4’s trace-versus-outcome
failure produced by a retry policy.
Reproduce it offline (Node ≥ 22, no network, no model calls):
npm --prefix examples/pi-harness-lab test
The D10 suites report the §10.7 table row by row, including the
premature-checkpoint refusal (PREMATURE_CHECKPOINT), the retention-window
UNKNOWN, and the journal invariants (every settlement has a preceding
intent; sequence numbers are monotonic). This demonstration validates the
teaching mechanism. It does not constitute formal Project 04 acceptance,
which requires the full 100-scenario R04-E03 schedule, process-kill fault
injection, and independent review (see §10.8).
10.8 Project 04 checkpoint: Crashproof Worker
Blueprint requirement: complete a long file-processing job. The new mechanisms are a durable event ledger, checkpoints, and recovery with reconciliation of ambiguous effects. The verification uses fault injection before and after intent, execution, acknowledgment and settlement, and never claims unverified success.
Status: formal study not started; educational demonstration D10-CRASH-01
executed (see §10.7). Prerequisites: an accepted Project 01 evidence
pipeline (re-review complete, REJECT — prerequisites unsatisfied pending
correction and re-review); a journal (Chapter 9, demonstrated in
checkpoint.ts); a fake effect service with an independent effect log;
and a deterministic fault injector (both demonstrated; process-kill
injection remains future work).
Proposed study. The design follows the R04 recovery simulator, R04-E03, which is PROPOSED; EXPERIMENT PENDING. It compares blind retry with intent plus reconciliation on identical scenario schedules, injects each crash point, duplicate dispatch and delayed or cancelled acknowledgment, and includes missing deduplication and expired retention. R04 proposes 100-scenario schedules, at most three attempts and 30 seconds per scenario as initial ceilings. These are proposed parameters, not measurements. The oracle checks three things: the actual fake effects (from the service’s independent log), ledger honesty, and unauthorized re-dispatch.
| Arm | Recovery policy |
|---|---|
| R0 | Blind retry on timeout or crash, up to the attempt limit |
| R1 | Intent journal + reconciliation by key; UNKNOWN when inconclusive |
| R1-ck | R1 with premature checkpoints (written after dispatch, before confirmation). Negative control |
| R1-nokey | R1 against a service with no deduplication or lookup. Shows the limits of reconciliation |
The endpoints are scored from the service’s independent effect log:
duplicated effects, lost effects, correct completions, honest UNKNOWNs,
and dishonest reports (the ledger says success but the log disagrees).
Each is counted per scenario and reported per crash point, together with
retries and elapsed time.
The registered predictions are:
- R0 duplicates on every “effect applied, response lost” scenario.
- R1 produces zero duplicates and zero dishonest reports on the
well-behaved service, and
UNKNOWNs exactly on the pruned-key scenarios. - R1-ck reproduces skipped reconciliation at the crash points after its premature checkpoint. This confirms that checkpoint timing, not merely the presence of a ledger, is part of the mechanism.
- R1-nokey yields
UNKNOWNrather than duplicates or false successes on ambiguous points.
Any dishonest report from R1 falsifies the mechanism, whatever its completion rate.
R04 attaches one more limitation, and the chapter keeps it. The simulator kills processes, and process-kill results cannot establish power-loss durability. That needs a separately designed storage study (R04-E03; Chapter 9, §9.4).
10.9 Failure modes
- No response treated as no effect. Blind retry after timeout. Defence: reconcile first; retry only under a documented deduplication contract.
- Idempotency key treated as a guarantee. Retry outside the target’s
retention or scope. Defence: record the contract’s limits with the key;
treat expiry as
UNKNOWN. - Premature checkpoint. The checkpoint is written before confirmation. Defence: checkpoint only settled operations; test with R1-ck.
- Cancellation treated as rollback. A timed-out run is reported as having done nothing. Defence: cancellation starts reconciliation.
- Forced verdict.
UNKNOWNis converted to success or failure for reporting convenience. Defence:UNKNOWNis a first-class outcome with an escalation path. - Compensation treated as undo. A reversal is applied without its own intent and authorization. Defence: compensation is a separate effect.
- Runtime retries uncounted. Session or provider retries consume
budget invisibly. Defence: disable them, or count every attempt with
nullfor unknown usage.
10.10 What you can build and test now
The D10 demonstration above already implements the core loop. Extend it in this order:
- Add R1-ck (premature checkpoints written after dispatch, before
confirmation) and confirm that it skips reconciliation at the crash points
after its checkpoint. This negative result is what the checkpoint-timing
claim depends on; the
checkpoint()refusal incheckpoint.tsis the enforcement point. - Add R1-nokey (a service with no deduplication or lookup) and confirm it
yields
UNKNOWNrather than duplicates or false successes on ambiguous points. - Replace simulated crashes with process-kill fault injection at each journal boundary, keeping the same oracle (independent effect log, ledger honesty, no unauthorized re-dispatch).
10.11 What remains unverified
- Formal Project 04 acceptance. The educational demonstration D10-CRASH-01 executes the §10.7 mechanism and its honesty property, but the registered R04-E03 schedule (100 scenarios, process-kill injection, independent review) has not run, and the Project 01 evidence-pipeline prerequisite remains REJECTED pending correction and re-review.
- Storage durability under power loss for any configuration on this book’s Windows environment (R04-C07, R04-E03).
- Pi 1.6.0’s abort and dispose behaviour under real hung tools, beyond the source-level documentation in R02 C11 (TEST NOT RUN).
- Reconciliation contracts of any real external service this book might use. The fake service is designed to have exactly the properties under test.
- Whether the Project 01 candidate’s process-level stop policy behaves as inspected: independent re-review is complete (REJECT), but the candidate is not accepted and further correction is required.
EXPERIMENT PENDING. The formal R04-E03 Project 04 study has not run; D10-CRASH-01 is an executed educational demonstration, not that study.
Part II has assumed throughout that the worker is allowed to perform the
effects it attempts. The journal records an AUTHORIZED entry, but nothing
so far has said who writes it, on what evidence, or what stops a worker
from skipping it. A capability to call a tool is not permission to cause
its effect. Chapter 11 separates the two.