Back to the curriculum

L3-M06 · Level 3 · ~15 h

Reliability, Recovery, Cost and Latency

What you build: Reliability report

lessons
5
lesson hours (estimate)
≈ 9.5 h
0/5 lessons marked done · Progress is saved in this browser only. No account, nothing is sent to a server.
In review. The curriculum, module overviews and Levels 1–3 lessons are drafts written with AI assistance and reviewed by AI. Human review is still pending. English translation: AI-assisted, not human-reviewed.

Levels 1–3 lessons, exercises and quizzes are published as drafts, in Vietnamese with an AI-assisted English translation. They may change after human review.

Module path

  1. Lesson 1 · L3-M06-L01≈ 2 h

    Failure injection for tools and models

    What you build: Fault-injection layer

    Needs: L3-M05-L04

    Key terms (7)
    • Fault injectionTiêm lỗi: cố ý làm hỏng một lời gọi đã chọn theo một cách đã chọn, trong sandbox
    • Fault plan / ruleKế hoạch lỗi / luật: loại, target, `on` hoặc `rate`, tham số
    • Partial writeGhi dở: máy chủ ghi tác động rồi mới báo lỗi
    • Rate limit (window)Giới hạn tốc độ (cửa sổ): bị giới hạn, và vẫn bị giới hạn cho tới hết `retry_after_ms`
    • Loud / silent failureThất bại trung thực (agent nói chưa xong) / thất bại im lặng (agent nói xong, trạng thái sai)
    • Not firedKhông kích hoạt: luật lỗi không chạm lời gọi nào; test đó không kiểm gì
    • Not observedKhông được thấy: lỗi đã kích hoạt nhưng phía gọi chỉ thấy `ok`; lần chạy không nói gì về hồi phục
  2. Lesson 2 · L3-M06-L02≈ 2 h

    Retries, timeouts and idempotency

    What you build: Duplicate-side-effect tests

    Needs: L3-M06-L01

    Key terms (7)
    • Retry policyChính sách thử lại: số lần thử, thời gian chờ, mã được thử lại, khóa
    • Capped exponential backoffBackoff mũ có trần: chờ gấp đôi sau mỗi lần, tối đa `cap_ms`
    • Full jitterJitter đầy đủ: thời gian chờ lấy đều trong [0, giá trị backoff]
    • Operation / attemptThao tác (một việc logic) / lần thử (một lần gửi thao tác đó)
    • Duplicate side effectTác động trùng: cùng một tác động nghiệp vụ được áp hơn một lần
    • Side-effect ledgerSổ tác động: các tác động đã áp, nhóm theo định danh nghiệp vụ; khác nhật ký tác động của L3-M02-L04
    • False failureThất bại giả: agent báo thất bại trong khi tác động đã xảy ra
  3. Lesson 3 · L3-M06-L03≈ 2 h

    Reliability over repeated trials (metric definitions verified at authoring)

    What you build: Success-rate curves over repeated trials

    Needs: L3-M06-L02

    Key terms (6)
    • Trial (of a task)Lần chạy: một lần chạy trọn một tác vụ từ môi trường sạch; khác lần thử (attempt) của một lời gọi tool ở L02
    • Unbiased estimatorƯớc lượng không chệch: kỳ vọng của nó bằng đúng đại lượng cần ước lượng
    • pass@k / pass^k (from n, c)1 − C(n−c,k)/C(n,k) / C(c,k)/C(n,k), trung bình theo tác vụ
    • Plug-in estimateƯớc lượng thay thế: đưa c/n vào công thức của p; bị chệch
    • Success-rate curveĐường tỷ lệ thành công: pass@k và pass^k theo k
    • Slip (lab)Lỗi nhầm: model mô phỏng dùng sai tham số ở một bước, với xác suất cho trước
  4. Lesson 4 · L3-M06-L04≈ 2 h

    Cost and latency budgets

    What you build: Budget assertions per task

    Needs: L3-M06-L03

    Key terms (5)
    • Task budgetNgân sách tác vụ: trần token và chi phí mỗi lần chạy, ngưỡng p50 và p95 độ trễ; ngưỡng của tester, khác ngân sách vòng lặp của L3-M01-L02
    • Hard cap / percentile thresholdTrần (một lần chạy vượt là vượt) / ngưỡng phân vị (trên các lần chạy)
    • Percentile method (nearest-rank / interpolated)Phương pháp phân vị (hạng gần nhất / nội suy kiểu NIST tại p(N+1))
    • Latency breakdownTách độ trễ: model, tool, timeout, backoff
    • HeadroomKhoảng chừa: phần ngân sách trên giá trị đo được, có ghi lý do
  5. Lesson 5 · L3-M06-L05≈ 2 h

    Writing a reliability report

    What you build: Report

    Needs: L3-M06-L04

    Key terms (5)
    • Reliability reportBáo cáo độ tin cậy: phạm vi, mục tiêu đặt trước, kết quả theo tác vụ, tiêm lỗi, ngân sách, giới hạn
    • Pre-registered targetMục tiêu đặt trước: thống nhất trước lần chạy, ghi trong báo cáo
    • Consistency checkKiểm nhất quán: số liệu của báo cáo khớp các lần chạy mà nó tóm tắt
    • Limits sectionMục giới hạn: điều báo cáo không cho thấy, cụ thể và không trùng lặp
    • HOLD / READY_FOR_REVIEWGiữ lại / sẵn sàng để người duyệt đọc; không phải phê duyệt

A. Module overview

Field Value
Module ID L3-M06
Level 3 - AI Agent Quality Engineer
Description Testing what an agent does when its tools and its model misbehave, and how consistently it manages, what it costs and how long it takes: a seeded fault-injection layer for tools and model text (tool errors, timeouts, rate limits, partial writes, malformed output) with a log that shows which faults really fired, and the seven outcomes of a run; a retry policy with timeouts, capped exponential backoff, full jitter and Retry-After on a simulated clock, idempotency keys and an effect ledger that finds duplicate effects by their business meaning; a repeated-trial runner with pass@k, pass^k (exact fractions) and the Wilson interval for each task; per-task budgets for tokens, cost and p50/p95 latency; and a reliability report with a gate that can only say HOLD or READY_FOR_REVIEW and fails closed on missing or broken data. The module's lab is the simulated agent of the fictional product ThuVien Mini (a school library helper) with four configurations that carry known faults, deterministic, offline: no model call, no real server, no API key; every effect lives inside one Python object. What is known about retries, idempotency, percentiles, rate limits and the metrics is cited from 16 sources read on 2026-11-05: two arXiv papers (Chen et al. on pass@k, read in the PDF; τ-bench on pass^k, read in the full HTML), Anthropic's article on agent evals, two pages of the NIST statistics handbook (confidence intervals, percentiles), three AWS articles (timeouts and backoff, idempotent APIs, jitter), three chapters of Google's SRE book (handling overload, cascading failures, SLOs), Stripe's idempotency documentation, the principles of chaos engineering, two pages of the Claude API documentation (errors, stop reasons) and RFC 6585. The depth of reading of each source is recorded in references.md and in §12 of each lesson.
Why this module matters An agent with side effects does not live in a world where every call succeeds: a tool returns a server error, takes too long, says "too many requests", the server writes and only then reports an error, the model returns a truncated string. The agent may then recover, fail honestly, lie ("Done" with no loan at all), or do the thing twice. One green run does not say how often it succeeds; a pooled rate hides a broken task; retries both hide errors and cost time and money. The module lays the ground for agent safety (L3-M07) and the capstone (L3-M08), where the reliability report is part of the testing framework.
Target professional competency Level 3: reliability testing of agents with side effects, including fault injection, retries and idempotency, measuring over many runs with sourced metric definitions, cost and latency budgets, and writing a report that a reader can check. The module does not measure real agents or models, does not state any provider's prices or speeds, and does not run chaos experiments on real systems.
Estimated time 5 lessons (110 + 120 + 120 + 110 + 110 minutes) = 9 hours 30 minutes, plus the quiz (~0.5 hours) and the module assignment (~5 hours) = ≈ 15 hours for someone who has finished L3-M05. An estimate, not measured with real learners.
Prerequisites L3-M05 (the first lesson needs L3-M05-L04). The module reuses, without repeating: the agent loop and stop reasons (L3-M01-L02), fake tools, the sandbox, the effect log and idempotency keys (L3-M02-L04), end state versus the message (L3-M03-L04), non-determinism, the Wilson interval and the rerun rule (L1-M06-L01, L1-M06-L02), paired comparison (L2-M07-L02), nearest-rank percentiles (L2-M07-L03), gates that fail closed on broken data (L2-M07-L04), reports traceable to data (L2-M07-L05), mutation testing (L3-M03-L03). No API key needed.
Module output (deliverable) Reliability report: an outcome table of twelve fault tests under four configurations, duplicate-effect and false-failure tests, the repeated-trial results of eight release candidates with per-task pass^3 and Wilson intervals, a budget table, one candidate's report printed with render, a scorecard that combines four layers with the lab's gate, and a golden table for mutation testing; plus each lesson's small output
Cost 0

What learners build. Step by step, in code-labs/l3-m06: (L01) fault plans, validate_plan, the seeded Injector with its log, fired, unfired_rules, the outcome table of classify, and the rule-matching part of an injector written by the learner; (L02) retry policies, validate_policy, backoff_ms, call, schedule, server-side idempotency keys, the effect ledger, duplicates, check_end_state; (L03) pass_at_k, pass_hat_k, the plug-in versions, wilson, curve, run_trials, and a curve function written by the learner; (L04) percentile (nearest rank and NIST), check_budget, breakdown; (L05) fault_row, build_report, validate_report, gate, render, and a report built from the learner's own runs. The lab does not import from earlier labs and needs only pytest.

What the module does not do. It does not measure real models or agents, does not state the price, speed or reliability of any model, agent or vendor, and does not rank or recommend any tool or provider: every number of the lab describes the simulation, and tokens, cu and milliseconds are the lab's numbers. The lab's agent follows a script per task; the variation between runs comes only from a seeded slip and seeded latency noise. The lab does not inject API errors of the model itself, a network cut halfway, a stopped agent or two nested faults, and there is no concurrent load. No shell command, network or file outside the Python process. Chaos engineering is borrowed only as the idea of an experiment; at Level 3 every fault is injected into fake tools in the sandbox. No automated workflow is created or changed in the repository. Every gate only labels, fails closed on missing or broken data and never uses the word "approve"; a person sets the targets before the run, chooses the budgets and decides every real-world effect.

Terms reused with another meaning (each lesson has a sentence separating them). An injected fault is what you cause at one call, unlike the outcome of the whole run; timeout is the caller's timeout, and the server may still be working (L01); an operation differs from each of its attempts (L02); a trial in L03 is one full run of a task, unlike the attempt of L02; a budget in L04 is a tester's threshold checked after the runs, unlike the budget the agent loop checks itself in L3-M01-L02; READY_FOR_REVIEW in L05 means "a person should read this report", not release.

B. Learning objectives

ID Objective
MO1 Design fault-injection tests for tools and the model, prove from the injector's log that every rule fired, and classify a run under faults by its end state, not by what the agent says.
MO2 Check a retry policy (which codes are retried, how long it waits, Retry-After, timeouts) and detect duplicate effects and false failures with the effect ledger, on data where business rules do not hide the bug.
MO3 Measure reliability over many independent runs with pass@k, pass^k and the Wilson interval for each task, and explain why a pooled rate and the plug-in values mislead.
MO4 Set token, cost and latency budgets for each task with a stated percentile method, and split a run's latency into model, tool, timeout and backoff.
MO5 Write a reliability report with targets set before the run, recomputable numbers and specific limits, use a gate that fails closed on broken data, and state which changes a READY_FOR_REVIEW survives and which it does not.

C. Lessons

ID Lesson Duration Prerequisite Concepts Practical output
L3-M06-L01 Fault injection for tools and the model 110' L3-M05-L04 five fault kinds and the real errors they stand for, seven outcomes (not_observed included), fault plans, the seeded injector, the rate-limit window, rules that never fire Fault-injection layer
L3-M06-L02 Retries, timeouts and idempotency 120' L01 the caller's timeout, capped exponential backoff, jitter, Retry-After, idempotency keys, the effect ledger, duplicates by meaning, false failures Duplicate-side-effect tests
L3-M06-L03 Reliability over repeated trials 120' L02 independent trials, pass@k and pass^k as estimators, the biased plug-in, the Wilson interval, per-task curves, pooling hides a broken task Success-rate curves over repeated trials
L3-M06-L04 Cost and latency budgets 110' L03 ceilings and percentiles, nearest rank and NIST, p95 of fewer than 20 runs, where time and cost go Budget assertions per task
L3-M06-L05 Writing a reliability report 110' L04 the six sections of the report, targets set before the run, recomputing from the runs, the HOLD / READY_FOR_REVIEW gate, limits and decision notes Reliability report

D. Practical work (module assignment)

Module assignment exercises.en.md: a reliability report for ThuVien Mini v2 on new data (seven broken plans, twelve new fault tests and a fault suite for the scorecard, the retry policy policy_v2 with six broken edits, the plan flaky_v2, seeds 13 and 31, v2 targets and budgets, eight release candidates): fault injection, retries and idempotency, repeated trials, budgets, report and scorecard, golden table and mutants, reproduction; a fixed interface, acceptance criteria AC1-AC7 and a 100-point rubric; plus a practical challenge on the lab's own data. The five standalone exercises of each lesson are in code-labs/l3-m06/exercises/ and in §9 of each lesson: outcomes under six plans, a plan that covers three fault kinds and the rule matching of an injector (L01), duplicate effects and a policy that recovers from every plan (L02), success counts, the curve and the missed targets (L03), p50/p95 under a fault and a budget set that flags the right tasks (L04), fixing a draft report with four errors, then building a report of your own (L05).

E. Module assessment

Module quiz quiz.en.md (12 questions, 20 points, pass mark 70%), the module assignment with acceptance criteria and rubric (exercises.en.md); the solutions and the instructor guide are for instructors only. Each lesson's practice set is practice-01.md to practice-05.md, public and with reference solutions. The instructor's solution set and tests are in code-labs/l3-m06/instructor/ and are for instructors only.

F. References

The shared list is in references.md (16 sources fetched on 2026-11-05, the access date and depth of reading of each source). Each lesson also has its own reference table in §12.

Objective ↔ assessment matrix

Objective Lesson Standalone exercise (§9) Quiz questions Module assignment criteria
MO1 L01 exercises/test_l01_faults.py Q1, Q6, Q11 AC1 (and AC6, AC7 for the whole module)
MO2 L02 exercises/test_l02_retries.py Q2, Q9 AC2 (and AC6, AC7 for the whole module)
MO3 L03 exercises/test_l03_trials.py Q3, Q7, Q10 AC3 (and AC6, AC7 for the whole module)
MO4 L04 exercises/test_l04_budgets.py Q4, Q8, Q11 AC4 (and AC6, AC7 for the whole module)
MO5 L05 exercises/test_l05_report.py Q5, Q12 AC5 (and AC6, AC7 for the whole module)