Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Failure windows and recovery invariants

Actual response loss/process exit,red-green acceptance repair and cross-ledger incident review.

Learning objectives: Reproduce unknown results,locate receipt/idempotency boundaries and write negative checks explaining recovery/effects.

Content checked: 2026-10-11 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Implementation · Build it. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Failure windows and recovery invariants
Recovery correctness is determined by the business facts before and after the failure. The test must cut off the window between "submission, receipt, and status advancement" to prove that replay will not break idempotency, permissions, and budget constraints.

How does the mechanism work?

Step-by-step explanation
  1. What is the difference between repeat requests and repeat effects?

    Recovery often relies on resending requests, so distinguish network attempts from actual business effects.

  2. Why is fixed model response still valuable for testing?

    Fault-injection experiments require repeatable control of variables, so explain the value and limits of test doubles.

  3. Does stopping at unknown when it cannot be verified count as a test failure?

    When the expected receipt is missing, specify exactly what the test requires.

Implementation · Build it

Implement the contract · Failure windows and recovery invariants

Objectives of this level: Inject fault,preserve red,repair acceptance and original-key recovery.

Visual guide · Commit can precede knowledge

Commit can precede knowledge

The local fault commits one merchant application before losing its response. A missing caller receipt does not establish zero effects. Select the figure to open it at full size.

Download and extract the complete project. All inputs and checker code follow.

Fresh isolated environment

Use a new ZIP extraction, Python 3.10+; this review used 3.12.14. Run beside lab.py with standard library, deterministic model and loopback merchant. fault-work must be fresh; do not delete business history. Carry main-return to proposal, read it, then approve. Approval lasts 300 seconds; restart the fresh route if expired.

python3 lab.py setup --workspace fault-work
python3 lab.py stage response --workspace fault-work
python3 lab.py stage prompt --workspace fault-work
python3 lab.py stage tool --workspace fault-work
python3 -m json.tool fault-work/main-proposal.json
python3 lab.py approve --workspace fault-work --proposal-file fault-work/main-proposal.json

Run the fault separately, expecting 75 and a terminated worker. Avoid a stop-on-error chain that prevents recovery.

python3 lab.py fault-main --workspace fault-work

Execute separately, expecting 0, and preserve both sides.

python3 lab.py inspect-main --workspace fault-work --out fault-work/before.json

Make the wrong assumption red

Save wrong_receipt_assert.py, run python3 wrong_receipt_assert.py. Expected exit 1 prints outcome_unknown, local_receipt=null, merchant_returns=1 before failing. This is the wrong recovery assumption, not a lost merchant effect.

import json
from pathlib import Path
d=json.loads(Path('fault-work/before.json').read_text());t=d['task']
n=sum(r['task_id']==t['id'] for r in d['merchant_audit']['returns'])
print(json.dumps({'status':t['status'],'local_receipt':t['receipt'],'merchant_returns':n},sort_keys=True))
assert n==0,'incorrect assumption: missing local receipt means no merchant commit'

For debugging, run the three probes at this fault scene before recovery. If already recovered, repeat the fault in another fresh extraction rather than mixing records.

Repair acceptance and recovery order

Preserve failure. Query the authoritative receipt under the original key, then verify task_id/proposal_hash/order_id/quantity. Without reliable evidence, do not guess success or change keys. Agent.execute already implements this path; calling it is not your newly developed module.

python3 lab.py recover-main --workspace fault-work

Repair your assertion to cross-ledger acceptance. Save correct_receipt_assert.py and run python3 correct_receipt_assert.py, expecting 0:completed, 1→1 effects, action_requests=1, reconciled=true. Agent events exclude direct debugging HTTP and are not all attempts.

import json
from pathlib import Path
b=json.loads(Path('fault-work/before.json').read_text());d=json.loads(Path('fault-work/recover-main.json').read_text());t=d['task']
bn=sum(r['task_id']==t['id'] for r in b['merchant_audit']['returns']);an=sum(r['task_id']==t['id'] for r in d['merchant_audit']['returns'])
requests=sum(e['kind']=='action_request' for e in t['events'])
reconciled=any(e['kind']=='business_receipt' and e['payload']['reconciled'] is True for e in t['events'])
result={'before_status':b['task']['status'],'after_status':t['status'],'merchant_before':bn,'merchant_after':an,'action_requests':requests,'reconciled':reconciled,'operation_key':t['operation_key']}
assert b['task']['receipt'] is None and t['receipt'] and bn==an==1 and requests==1 and reconciled
Path('fault-work/repair-verdict.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,sort_keys=True))

Submit your assertion diff, fault output, before.json, recover-main.json, repair-verdict.json. Calling supplied recovery is guided practice; also implement your own negative binding check in debugging to demonstrate coding.

code example

Evidence and interview explanation

Inject fault,preserve red,repair acceptance and original-key recovery.

Use the inputs,code,exits and ledgers above;submit your own diff,not copied green logs,and name unverified capabilities.

Acceptance task for this level

Inject fault,preserve red,repair acceptance and original-key recovery.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

Beyond exit0?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.