Module: L3-M08 (capstone) · Duration: ~7 hours (estimate) · Previous: Milestone 3 · Next: end of Level 3
1. Introduction
A full run gives you a few hundred JSON files. The decision maker does not read a few hundred files; they read one report, and they need to trust that every number in it matches those files. The last milestone turns the results of milestone 3 into four things:
a trace-level report with a fail-closed gate, generated entirely from out/runs; a decision record signed by a person; a defence that answers hard questions about the framework's limits; and a self-assessment against the rubric,
with evidence. You finish by being able to say: can rc be released, based on which event of which trace, what is still unknown, and what would change the conclusion.
2. Objectives
- Generate
report.json,gate.jsonandreport.mdentirely from the run files: recount, do not copy numbers, and rebuild byte for byte. - Write each finding with trace-level evidence: the run file of the first failing seed, event indices, effect ids, the clause, the number of failed trials on both builds.
- Implement a gate that only says HOLD or READY_FOR_REVIEW, recomputes from the run files, re-runs the checks, HOLDs when data is broken, missing or inconsistent, and never raises.
- Write a decision record consistent with the gate, and defend it against questions about simulation, the number of seeds and the gate.
- Self-assess against
rubric.md, with evidence and one real weakness for each dimension.
3. Prerequisites
- Milestone 3 done:
tests/test_m3_checks.pyandtests/test_m3_run.pygreen on your scenario set. - Quick review: L3-M06-L05 (the reliability report,
validate_reportand a recomputing gate), L2-M07-L05 (the decision record), L3-M07-L05 (writing the findings of a red-team session). requirements.mdsection D3 (theout/outputs, one finding, the gate's reason codes, thereport.mdskeleton) andrubric.md(mandatory criteria, scale, self-score schema).- Disambiguation. A finding here is an entry
F01,F02, ... thatreport.findingsgenerates from the run files; it differs from the "candidate finding" of the triage table in L3-M08-L03 §6 (not yet backed by trace-level evidence) and from the finding of the red-team session in L3-M07-L05 (with a reproduction recipe). HOLD and READY_FOR_REVIEW are results of the gate (L3-M03-L03); the decision belongs to a person (L2-M08-L04 on gate overrides).
4. The parts of milestone 4
4.1 A report recomputed from the run files
report.build_report reads out/results.json and out/runs, but every number of the report is recomputed from the run records, not copied from results.json (R15). record_passed recomputes the verdict of one record
(clean lint, no product error, every fault fired, every check passed); recount counts per scenario (trials, passed, first, all, failed_checks), and a missing file is a failed trial; budget_from_runs recomputes the latency
and cost of each turn from the trace, without trusting the recorded latency_ms; coverage counts scenarios per suite and the number of adversarial scenarios. This is the rule of L3-M06-L05 §4.2: every number in the report must be recomputable from the runs.
report.md follows exactly the skeleton of requirements.md D3: a title containing MÔ PHỎNG (simulated); the sentence "Cổng chỉ báo HOLD hoặc READY_FOR_REVIEW; người quyết định" (the gate only reports HOLD or READY_FOR_REVIEW; a person decides) and the path deliverables/decision.md; seven sections ## 1. to ## 7.
(configuration; gate; per suite; per scenario; reliability, cost, latency; findings; limits). The tests read every table cell back and compare it with report.json, so a hand-typed cell is caught. Fractions are written as 3/4, percentages use a decimal comma (75,0%).
No timestamps, no machine paths: two builds of out/ are identical byte for byte (R20, AC5.4).
4.2 Findings and trace-level evidence
report.findings creates one finding for each check that fails in at least one trial of the candidate build, with the evidence of the first failing seed: {id, scenario, suite, claims, kind, check_index, seed, trials_failed, baseline_trials_failed, why, evidence {events, effects}, run_file}. It adds a kind: "harness" finding for a scenario with a record that fails lint, a product error or an unfired fault, and a suite: "budget" finding for each exceeded limit; these two kinds still have every key, with check_index, trials_failed, baseline_trials_failed set to null. The order is by suite
(end_state, trajectory, state, reliability, security), then scenario id, then check index; numbered F01, F02, ... The fixed order means the same run files give the same numbers, so the decision record can cite F03 without fear that its meaning changes.
A reminder about wording (L3-M08-L03 §3): trials_failed counts trials (one seed each), not the attempts of a tool call.
A good finding answers four questions for the reader: which clause is violated; where (run file, events, effects); how often (trials_failed out of k, and baseline_trials_failed of stable: it must be 0/5 to be evidence about rc);
why (the check's why, specific enough that nobody has to open the file to understand it). Only once you have those may you open the product's code to explain the cause in the report (the black-box rule). Anthropic's article on agent evaluation
reminds us that you will not know whether your graders work well unless you read the transcripts and grades of many trials [R1]: before signing, open at least one run file of each finding and check that the cited events show exactly what why says.
4.3 A fail-closed gate
report.gate(report, runs, policy, version, ctx) returns {"decision", "reasons"} for one build. It does not trust the report: it recomputes everything from runs and compares it with the report (R16). The groups of reason codes (requirements.md D3):
| Group | Codes | Meaning |
|---|---|---|
| Input | MALFORMED:<chỗ>, SCENARIO_ERRORS |
a malformed report, run file or policy; a spec was rejected |
| Coverage | TOO_FEW_SCENARIOS, SUITE_TOO_SMALL:<bộ>, TOO_FEW_ADVERSARIAL, MISMATCH:coverage |
the scenario set is below the policy's minimum, or the coverage in the report differs from the recomputed coverage |
| Run files | RUN_MISSING, RUN_EXTRA, RUN_IDENTITY, TRACE_INVALID, PRODUCT_ID |
missing, extra, wrong label, lint errors, a product_id that is not the product's |
| Tied to the scenario | SPEC_MISMATCH, INITIAL_MISMATCH, CHECKS_MISMATCH |
the spec in the record differs from the scenario's suite, clauses, adversarial flag or fault injection; the records of one scenario (every seed, every build) do not share one spec, or that spec differs from the report's spec_sha256; sessions are not the spec's sessions and turns; the initial snapshot differs from a fresh sandbox plus setup; a re-run check gives a different result |
| Trial | PRODUCT_ERROR, FAULT_NOT_FIRED, FAILED:<mã> |
the product raised, a fault did not fire, the scenario did not pass all k times |
| Aggregate | MISMATCH:versions, OVER_BUDGET:..., BUDGET_NO_DATA |
a build's numbers in the report differ from the recomputed ones; the budget is exceeded or has no data |
| Baseline | BASELINE_FAILS:<mã>, BASELINE_MISSING |
stable fails a scenario, or there are no stable runs |
spec_sha256 is the SHA-256 of the loaded spec (pipeline.run_all writes it into results.json): thanks to it, hand-editing the spec of a run file to drop a failing check no longer gets past the gate (AC4.6). The gate also never reads the name of a build: the same stable build under another name must get READY_FOR_REVIEW (AC4.15, builds.alias in product/README.md).
READY_FOR_REVIEW only when there is no reason at all. The whole body of the gate sits inside a block that catches every exception: an unexpected exception is MALFORMED:<loại>, never a traceback (mandatory criterion M3).
A limit to state plainly in the report and in the defence: the gate checks the consistency of the run files (lint, identity, spec, sessions, initial snapshot, re-run checks); it does not prove that the files were produced by the real product. Someone who edits the trace, the side-effect ledger,
the final snapshot and the check results together so that they agree will not be caught by the gate; that is why the grader re-runs the framework (L3-M06-L05 §5.1 names exactly this blind spot of validate_report).
4.4 The decision record
The decision belongs to a person (R17). deliverables/decision.md has three lines that the tests read: Quyết định: (KHÔNG PHÁT HÀNH, PHÁT HÀNH or PHÁT HÀNH CÓ ĐIỀU KIỆN: do not release, release, release with conditions), Người quyết định: (a person's name, not auto, gate, AI)
and Ngày: (ISO, not in the future); then the sections, including ## Giới hạn (limits) and ## Điều kiện để đổi quyết định (conditions to change the decision). The consistency rule (AC4.12): if the gate HOLDs rc and the decision is not KHÔNG PHÁT HÀNH, a Ghi đè cổng: line is needed
with a written reason (at least 40 characters). The record cites at least three real findings by id, from at least three suites (or budget), and says clearly that every number is simulated.
Two different vocabularies, do not mix them: HOLD and READY_FOR_REVIEW are results of the gate; KHÔNG PHÁT HÀNH, PHÁT HÀNH, PHÁT HÀNH CÓ ĐIỀU KIỆN are decisions of a person. READY_FOR_REVIEW is not PHÁT HÀNH either: it only says the evidence is consistent enough to read. "With conditions" only has value when the conditions remove exactly the violations seen from the release and can be checked by a re-run.
4.5 The defence
deliverables/defence.md has at least five questions as headings ### ...?, each answer at least 80 characters long and with evidence: a finding id, or a path under out/, scenarios/, agentqa/ (AC4.13). Prepare a 10-minute presentation and 10 minutes of questions.
Questions graders often ask:
- "Five seeds: does a problem that happens once in ten trials show up? What do you know about what does not show up?"
- "How could your gate be fooled? If I delete a run file, edit a check, or edit the trace and the snapshot together, what happens?"
- "Is finding F.. a problem of
rcor of the scenario? What doesstablegive on the same scenario?" - "What does the harness not simulate, and which conclusions do not carry over to an agent with a real model?"
- "If the product owner wants to change the p95 budget, what do you do, who signs, where is it recorded?"
- "Where did you use an AI assistant, and how did you verify it?"
4.6 Self-assessment
Score each dimension of rubric.md (design, harness, suites, findings, report_gate, defence, self_assessment) in deliverables/self-score.json with the schema agentqa-self-score/1: each dimension has level (an integer 0-3),
evidence (a list of existing paths, relative to starter/ or the project folder; the only folders allowed are scenarios, out, deliverables; at least one path must be something you wrote, otherwise NO_OWN_EVIDENCE) and weakness (at least 20 characters); plus must (M1-M7), total and passed. Check it with python -m agentqa.selfscore deliverables/self-score.json.
total is the sum of (level / 3 × weight), rounded to one decimal place; passed is true when the total is ≥ 70 and every must is true. Level 3 of self_assessment requires a real weakness: a limit that makes the conclusion less reliable than the reader thinks
(for example too few seeds for a small failure rate, a check with a blind spot), not "could add charts".
For findings, you do not know the grader's list: choose the level from the number of findings with evidence and the number of suites (the five suites of data/policy.json, plus budget) they belong to, and write in weakness that this is an estimate.
5. Hands-on: build the report, try to break the gate, self-score
A. The gate holds even stable when the evidence is not enough. At this milestone your scenarios/ already has many scenarios, so create a folder ex-only/ that contains only the three example scenarios, then run the gate for stable on that folder (reference solution):
mkdir -p ex-only && cp scenarios/ex-0*.json ex-only/
python -m agentqa --out out --scenarios ex-only --candidate stable
echo "exit=$?"
Output (copied from a real run, 2026-11-05, Python 3.14.6 and 3.12.3 on Linux; two builds of out/ identical byte for byte):
stable: HOLD (7 reasons)
report: out/report.md
exit=1
Section 2 of out/report.md:
| Phiên bản | Quyết định của cổng | Số lý do |
|---|---|---|
| stable | **HOLD** | 7 |
Lý do của `stable`:
- `SUITE_TOO_SMALL:end_state`
- `SUITE_TOO_SMALL:reliability`
- `SUITE_TOO_SMALL:security`
- `SUITE_TOO_SMALL:state`
- `SUITE_TOO_SMALL:trajectory`
- `TOO_FEW_ADVERSARIAL`
- `TOO_FEW_SCENARIOS`
All three scenarios pass 5/5 (section 4 of the report), pass@1 and pass^k are 1 (100,0%), the budget is đạt (met; p95 2057 ms, mean cost 1315,0), section 6 says "Không có phát hiện" (no findings). Still HOLD: three scenarios are not enough to say anything about five layers. No findings is not READY_FOR_REVIEW.
B. What a finding looks like. Make a copy of ex-only/ (the folder demo-scen/, command mkdir -p demo-scen && cp ex-only/*.json demo-scen/) and add to it the file demo-scen/demo-wrong-oracle.json: a scenario with a deliberately wrong oracle, one booking sentence but a check that requires "count": 2.
{
"id": "demo-wrong-oracle",
"title": "Kịch bản có oracle sai cố ý: đòi hai lịch hẹn cho một câu đặt lịch",
"suite": "end_state",
"claims": ["C1"],
"sessions": [{"patient": "P05", "turns": ["đặt lịch ngày 2026-12-01 buổi sáng"]}],
"checks": [
{"kind": "appointments", "patient": "P05", "date": "2026-12-01", "count": 2},
{"kind": "sms_count", "patient": "P05", "count": 1}
],
"notes": "Minh họa: stable fail vì kỳ vọng sai, không vì sản phẩm sai."
}
python -m agentqa --out out-demo --scenarios demo-scen --candidate stable (writing into out-demo/, so that the out/ of part A stays intact for part C) still prints stable: HOLD (7 reasons), but the first reason is now FAILED:demo-wrong-oracle (and SUITE_TOO_SMALL:end_state disappears because that suite now has 3 scenarios). Section 6 of the report ("Phát hiện ở stable (1)", findings on stable) has one finding, headed ### F01 · end_state · demo-wrong-oracle · appointments, with three lines:
- Fail 5/5 lần chạy ở `stable`; `stable` fail 5/5; điều khoản C1
- Lý do: 1 booked appointment(s) of P05 match, expected 2
- Bằng chứng: `out/runs/stable/demo-wrong-oracle/s1.json`, sự kiện 5; tác động E1
The evidence path in the report is always written from out/ (the skeleton of requirements.md D3); with --out out-demo, the actual file is out-demo/runs/stable/demo-wrong-oracle/s1.json. Open that file: event 5 is the book_appointment call, effect E1 is the appointment it created. Trace-level evidence exactly as the rubric defines it. And because the baseline also fails 5/5, this is a wrong scenario, not a problem of the product:
C1 says "book exactly one appointment". A finding about rc has value when its first line gives stable fail 0/5.
C. Try to break the gate. try_m4.py (root of starter/; it reads the out/ of part A) edits run files in memory and asks the gate again; it writes nothing to out/:
import copy
from agentqa import report
from agentqa.util import context, read_json
ctx = context()
rep = read_json("out/report.json")
runs = report.load_runs("out")
print("as built:", report.gate(rep, runs, ctx["policy"], "stable", ctx)["reasons"][-2:])
forged = copy.deepcopy(runs)
del forged["stable"]["ex-02-cancel-own"]["s3"]
print("one file missing:", [r for r in report.gate(rep, forged, ctx["policy"], "stable", ctx)["reasons"] if not r.startswith(("SUITE", "TOO"))])
forged = copy.deepcopy(runs)
rec = forged["stable"]["ex-01-book-morning"]["s2"]
rec["final"]["outbox"] = []
print("outbox emptied:", [r for r in report.gate(rep, forged, ctx["policy"], "stable", ctx)["reasons"] if not r.startswith(("SUITE", "TOO"))])
forged = copy.deepcopy(runs)
forged["stable"]["ex-03-search-unavailable"]["s1"]["trace"][4]["ms"] = 0
print("one wait set to 0 ms:", [r for r in report.gate(rep, forged, ctx["policy"], "stable", ctx)["reasons"] if not r.startswith(("SUITE", "TOO"))])
print("report is None:", report.gate(None, runs, ctx["policy"], "stable", ctx))
Output (same run, same two Python versions):
as built: ['TOO_FEW_ADVERSARIAL', 'TOO_FEW_SCENARIOS']
one file missing: ['FAILED:ex-02-cancel-own', 'MISMATCH:versions', 'RUN_MISSING:ex-02-cancel-own/s3']
outbox emptied: ['CHECKS_MISMATCH:ex-01-book-morning/s2']
one wait set to 0 ms: ['FAILED:ex-03-search-unavailable', 'MISMATCH:versions', 'TRACE_INVALID:ex-03-search-unavailable/s1']
report is None: {'decision': 'HOLD', 'reasons': ['MALFORMED:report']}
A missing file is a failed trial and makes the numbers in the report stop matching. Removing the message from the final snapshot makes sms_count give a different result from the recorded one when re-run. Setting one wait to 0 ms skews the trace's clock
(the next event starts at the old t): lint catches it, and that trial is recounted as a fail. A None report is HOLD, not a traceback.
D. Self-score. Copy the example from rubric.md into deliverables/self-score.json, change harness to level 3, change the evidence of design to deliverables/design-v2.md and that of defence to deliverables/defence-v2.md (two files that do not exist yet), change defence to "level": true with "weakness": "ngắn" (short), set total to 70.0 and passed to true, then run
python -m agentqa.selfscore deliverables/self-score.json (the out/ folder of part A exists):
INVALID:
- MISSING_EVIDENCE:design:deliverables/design-v2.md
- BAD_LEVEL:defence
- MISSING_EVIDENCE:defence:deliverables/defence-v2.md
- BAD_WEAKNESS:defence
Fix defence (level 2, a real weakness, the folder scenarios as evidence) and point the evidence of design back to deliverables/design.md (it exists since milestone 1; . or data would be BAD_EVIDENCE, README.md would be NO_OWN_EVIDENCE): one error remains, TOTAL, because six dimensions at level 2 and harness at level 3 give 2/3 × 80 + 20 = 73.3, not 70.0.
Change total to 73.3: OK: total 73.3, passed true. The checker only checks the shape and the arithmetic; the level you give yourself is still your own claim, and the grader reads the evidence.
E. The real run. When your scenario set is complete:
python -m agentqa --out out
echo "exit=$?"
python -m pytest
Exit code 1 means the gate HOLDs the rc build; that is the right result when your set has seen problems (mandatory criterion M4: stable READY_FOR_REVIEW, rc HOLD with findings that have trace-level evidence). With the reference solution and the reference scenario set,
python -m pytest gives 166 passed. This lesson does not print the rc report.
6. QA perspective
- What can go wrong: the report copies numbers from
results.jsoninstead of recounting; a table cell typed by hand; the gate reads the recordedpassedinstead of re-running the checks; the gate raises on a malformed file; a finding points at the last seed instead of the first failing seed; the decision record cites a finding id that does not exist; a tool's name as "the person who decides"; changing the budget or the number of seeds so thatrcgets READY_FOR_REVIEW; a level 3 self-score with the weakness "could add charts". - Read the report like the decision maker. Start with section 2 (the gate and its reasons), then section 6 (findings), then section 7 (limits). For each finding, ask: which clause, what does
stablegive, how many trials, which events. A finding that cannot answer those four questions is not ready for a decision. - What this framework does not know: what a real agent would do with real patients. The simulation shows you how to measure, not the numbers of a real product.
7. Milestone 4 deliverable
starter/agentqa/report.py
starter/out/report.md, report.json, gate.json, results.json, runs/ (tạo tự động; dựng lại giống từng byte)
starter/deliverables/decision.md (một người ký; nhất quán với cổng; trích ≥ 3 phát hiện ở ≥ 3 bộ)
starter/deliverables/defence.md (≥ 5 câu hỏi "### ...?" có câu trả lời và bằng chứng)
starter/deliverables/self-score.json (hợp lệ với python -m agentqa.selfscore)
starter/deliverables/design.md, explore-notes.md (mốc 1, cập nhật nếu thiết kế đã đổi)
Criteria: pass tests/test_m4_report.py (AC4.1-AC4.15) and tests/test_hygiene.py (AC5.1-AC5.4). AC4.12, and with it the mandatory criterion M6, requires decision.md to cite at least three real findings, from at least three suites (or budget): your scenario set must find problems in at least three suites for the capstone to pass. In addition, python -m pytest in starter/ is fully green, and every mandatory criterion M1-M7 of the rubric has evidence.
The grader also runs your scenario set on variants of the product (the findings dimension) and asks questions in the defence session (the defence dimension).
8. Self-check questions
0/12 done · Results are kept in this browser only.
P02 · True or false
P03 · Fill in the blank
P04 · Select all that apply
P05 · Match
P07 · Put in order
P08 · Recall
Lesson: L3-M06-L05P09 · True or false
P10 · Essay
Write the answer (6-10 sentences) to the defence question: "How could your gate be fooled, and why can the grader still trust the results?"
P12 · Multiple choice
9. Summary
- The report recounts everything from the run files; a missing file is a failed trial;
out/rebuilds byte for byte. - Each finding points at the run file of the first failing seed, the events, the effects, the clause, and the number of failed trials on both
rcandstable. - The gate recomputes, re-runs the checks, HOLDs when anything is broken, missing or inconsistent, and never raises; it checks consistency, it does not prove authenticity.
- The decision belongs to one person and is consistent with the gate; the defence answers hard questions with evidence; the self-score has real weaknesses.
- Completing the capstone means you have done the whole job of a Level 3 AI Agent Quality Engineer on a simulated product; it is not a promise about career outcomes.
10. References
See this module's references.md.