By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
On a Tuesday at 09:12, an engineer releases prompt v7 and a new refund adapter for the Helio Assist refund agent. The adapter change looks like plumbing: it maps the refund tool's response into the agent's own fields. The release skips the canary, which is the release that goes to a small share of traffic first.
At 09:05 that morning the refund tool's vendor renamed one response field from refund_amount to amount. The adapter reads refund_amount and falls back to 0.0 when the field is missing. Nothing raises an error. From 09:26 the agent writes refunds of $0.00 and tells each customer the money is on its way.
Every dashboard stays green for the next hour. The error rate is 0.0%, p95 first-token latency is 1.5 s against a 2.5 s target, and the weekly graded set still passes at 0.91. The first customer report lands at 09:46. An engineer starts investigating at 10:18 and rolls back at 10:41, after 219 refunds were written at the wrong amount.
A trace is the record of one request. It holds a span per model call and per tool call, and a span is one unit of work inside that request: a name, a status, a duration and the identifiers you chose to keep.
The two numbers that would have found this both existed that morning. The refund ledger held the amount written, and the order system held the amount owed. Nobody joined them into one panel with an owner, so nothing watched the difference. This is the common shape of an observability gap: not a missing collector, a missing join.
Save this as lab2_incident.py. It uses the standard library only and needs no key. TRAFFIC is the fixture: ten model spans and a few refund calls per five-minute bucket, shaped like the spans this agent emits.
"""Lab 2. Reconstruct an incident from simulated traces.
Standard library only. TRAFFIC is fixture telemetry shaped like the spans a
Claude system emits: one model call per row with a first-token latency, and one
tool call per refund with the amount written and the amount the order expected.
"""
from math import ceil
TRAFFIC = {
"09:12": {"latency": [1180, 1205, 1240, 1260, 1290, 1310, 1330, 1360, 1420, 1510],
"refunds": [(420.0, 420.0), (89.0, 89.0)]},
"09:16": {"latency": [1170, 1210, 1230, 1250, 1280, 1300, 1320, 1350, 1390, 1470],
"refunds": [(240.0, 240.0)]},
"09:21": {"latency": [1190, 1220, 1250, 1270, 1300, 1330, 1350, 1380, 1440, 1530],
"refunds": [(1120.0, 1120.0), (56.0, 56.0)]},
"09:26": {"latency": [1180, 1230, 1260, 1280, 1310, 1340, 1360, 1390, 1450, 1560],
"refunds": [(0.0, 310.0)]},
"09:31": {"latency": [1200, 1240, 1270, 1290, 1320, 1350, 1370, 1400, 1460, 1580],
"refunds": [(0.0, 128.0), (0.0, 74.0)]},
"09:36": {"latency": [1195, 1225, 1255, 1285, 1315, 1345, 1365, 1395, 1445, 1545],
"refunds": [(0.0, 950.0)]},
"09:41": {"latency": [1185, 1215, 1245, 1275, 1305, 1335, 1355, 1385, 1435, 1525],
"refunds": [(0.0, 62.0), (0.0, 240.0)]},
"09:46": {"latency": [1190, 1220, 1250, 1280, 1310, 1340, 1360, 1390, 1440, 1530],
"refunds": [(0.0, 189.0)]},
}
EVENTS = [
("09:12", "Prompt v7 and adapter v3 released to 100 percent, no canary"),
("09:46", "First customer report: refund promised, no money received"),
("10:18", "Engineer finds the tool payload has no refund_amount key"),
("10:41", "Adapter v2 restored; 219 refunds replayed"),
]
def build_spans(traffic):
spans = []
for minute, bucket in traffic.items():
stamp = minute.replace(":", "")
for index, ms in enumerate(bucket["latency"], start=1):
spans.append({"minute": minute, "span": "t-%s-m%d" % (stamp, index),
"kind": "model", "name": "messages",
"status": "ok", "ms": ms, "paid": None, "owed": None})
for index, (paid, owed) in enumerate(bucket["refunds"], start=1):
spans.append({"minute": minute, "span": "t-%s-r%d" % (stamp, index),
"kind": "tool", "name": "issue_refund",
"status": "ok", "ms": 260, "paid": paid, "owed": owed})
return spans
def p95(values):
"""Nearest-rank 95th percentile. With ten samples this is the slowest call."""
ordered = sorted(values)
return ordered[max(0, ceil(0.95 * len(ordered)) - 1)]
def per_minute(spans):
rows = []
for minute in sorted({span["minute"] for span in spans}):
bucket = [span for span in spans if span["minute"] == minute]
latencies = [span["ms"] for span in bucket if span["kind"] == "model"]
failed = [span for span in bucket if span["status"] != "ok"]
refunds = [span for span in bucket if span["name"] == "issue_refund"]
rows.append({
"minute": minute,
"p95": p95(latencies),
"error_rate": len(failed) / len(bucket),
"refunds": len(refunds),
"mismatch": sum(1 for span in refunds if span["paid"] != span["owed"]),
})
return rows
def first_alert(rows, threshold=2, buckets=3):
"""Earliest minute where the trailing window holds enough mismatches."""
for index, _ in enumerate(rows):
window = rows[max(0, index - buckets + 1): index + 1]
if sum(row["mismatch"] for row in window) >= threshold:
return rows[index]["minute"]
return None
def minutes_between(earlier, later):
def to_minutes(stamp):
hours, minutes = stamp.split(":")
return int(hours) * 60 + int(minutes)
return to_minutes(later) - to_minutes(earlier)
def main():
spans = build_spans(TRAFFIC)
rows = per_minute(spans)
print("%-6s %8s %11s %8s %11s" % ("minute", "p95_ms", "error_rate", "refunds", "mismatches"))
for row in rows:
print("%-6s %8d %10.1f%% %8d %11d"
% (row["minute"], row["p95"], row["error_rate"] * 100, row["refunds"], row["mismatch"]))
ok = sum(span["status"] == "ok" for span in spans) / len(spans)
first_bad = next(row["minute"] for row in rows if row["mismatch"])
alert = first_alert(rows)
reported = next(stamp for stamp, text in EVENTS if "First customer report" in text)
print()
print("spans reporting ok %.1f%%" % (ok * 100))
print("first amount mismatch %s" % first_bad)
print("integrity alert fires %s (2 mismatches in 15 minutes)" % alert)
print("first customer report %s" % reported)
print("caught earlier by %d minutes" % minutes_between(alert, reported))
if __name__ == "__main__":
main()Read the report in three steps.
error_rate is 0.0% in every bucket and p95_ms never passes 1.6 s. The system you are reviewing was healthy by every measure it kept.python lab2_incident.pyspans reporting ok 100.0% is the line to keep. A health signal that reads 100% during an incident is not lying. It answers a different question from the one that decides the outcome.
A dashboard is a set of questions with owners, not a wall of charts. Six panels cover this agent, and each one names the question it answers, the source that can answer it, and the person who acts when the line moves.
| Panel | Question | Source | Owner |
|---|---|---|---|
| Volume and p95 latency | Is the assistant fast enough? | Model spans, first-token duration | Platform |
| Error rate by span kind | Is anything failing loudly? | Span status | Platform |
| Refund integrity | Does the amount written match the amount owed? | Refund ledger joined to order totals | Payments |
| Tool contract violations | Did a tool response change shape? | Adapter validation events | Integrations |
| Graded set by slice | Did quality move, and in which slice? | Offline run on every release | Evaluation |
| Escalation and complaint rate | Are customers finding us in the wrong channel? | Support queue tags | Support |
Only the third panel could have shown this incident, and it did not exist. A dashboard built from errors and latency will always look healthy during a silent data fault, because a wrong number is not an error.
A threshold nobody can act on is a chart with ambition. Set three levels per signal: warn, page, and an automatic action. Write the owner beside every page.
| Signal | Warn | Page | Automatic action | Owner |
|---|---|---|---|---|
| Refund integrity | 1 mismatch in 15 minutes | 2 mismatches in 15 minutes | Pause refund writes and queue them for replay | Payments |
| Tool contract violation | 1 validation failure in 5 minutes | 3 failures in 5 minutes | Route the tool to its last known contract | Integrations |
| p95 first-token latency | 2.0 s for 10 minutes | 2.5 s for 10 minutes | Stop the canary ramp | Platform |
| Error rate | 1% for 10 minutes | 3% for 10 minutes | Roll back the adapter | Platform |
The refund integrity row is the one this incident needed. Notice what it measures: a business invariant, not a code exception. Silent faults raise no exception, so an exception-based alert cannot see them.
Here is the timeline you can rebuild from the fixtures and the human actions.
| Time | Event | Where it is visible |
|---|---|---|
| 09:12 | Prompt v7 and adapter v3 go to 100% of traffic | Deploy log |
| 09:26 | First refund written at 0.00 against an order of 310.00 | Refund ledger |
| 09:31 | Two mismatches sit in the 15-minute window | The panel that did not exist |
| 09:36 | One more mismatch, still silent | Refund ledger |
| 09:41 | Two more mismatches, still no page | Refund ledger |
| 09:46 | First customer report: refund promised, no money received | Support queue |
| 10:18 | Engineer finds no refund_amount key in the payload | Adapter log |
| 10:41 | Adapter v2 restored, 219 refunds replayed | Deploy log |
The first bad refund lands at 09:26. A joined panel would have flagged it at 09:31, five minutes later and 15 minutes before the first customer complaint. The gap between a fault and a page is a design choice, not bad luck.
A postmortem explains how the system allowed the failure. It is not a search for the person who typed the change. The engineer did what the runbook said, and the runbook had no step for a vendor renaming a field.
| Contributing factor | Why it was reasonable | Control |
|---|---|---|
| The adapter defaulted a missing field to 0.0 | The field had been present for two years | Fail closed on a required field and raise a validation error |
| The release skipped the canary | It was described as plumbing, not a prompt change | Canary every change that touches a tool contract |
| No panel compared the two amounts | The team tracked errors, which had found every earlier fault | Alert on the business invariant, with a named owner |
| The trace kept status but not amounts | Full payloads were removed for privacy | Keep two redacted numbers on the span, not the payload |
| The graded set checked eligibility only | The labels came from the support rubric | Add an amount slice to the graded set |
Four controls came out of the review. Rank them by the moment they fire, not by how thorough they feel.
| Control | Fires at | Catches | Misses |
|---|---|---|---|
| Tool contract test in CI | Before the deploy | A renamed or retyped field | A field that only changes shape in one live tenant |
| Canary at 5% for 30 minutes | Within 30 minutes of the deploy | Anything that fails on real traffic | A fault that only appears at full volume |
| Refund integrity alert | 09:31 in this incident | Any cause of a wrong amount | A wrong decision that still writes the right number |
| Amount fields on the span | At the same moment as the alert, if something reads them | Diagnosis after the alert | Detection, unless a panel watches them |
The contract test is the cheapest and the earliest. It is also the narrowest, because it assumes the next failure keeps the shape of a schema change. The integrity alert is the one that generalises: it watches the outcome the business cares about, so it catches a renamed field, a rounding bug, a currency mistake or a wrong order join.
Fund the alert first when you can fund only one. Add the contract test in the same sprint when continuous integration (CI) already replays a recorded tool response, because the marginal cost is then one fixture and one assertion.
You have one sprint and one engineer. Choose one control: the contract test, the integrity alert, the canary, or the amount fields on the span.
A strong answer picks the integrity alert, because it is independent of the cause and it names an owner. A weaker answer funds the contract test alone, because the next incident need not be a schema change.
Your lab is done when every row in this table is true.
| Check | Evidence |
|---|---|
| The script runs on the standard library alone | A clean machine runs it with no pip install |
| The metrics table prints eight buckets | Rows from 09:12 to 09:46, with a mismatch count per row |
| The error rate stays at 0.0% while mismatches rise | The two columns contradict each other on purpose |
| The alert minute and the gap are stated | integrity alert fires 09:31 and caught earlier by 15 minutes |
| You can name the join that was missing | One sentence: refund ledger amount against order total |
| You can name the control you would fund first, and its blind spot | Two sentences in your decision log |
Run the verification command from the folder that holds the script.
python lab2_incident.py| Trap | What it looks like | Control |
|---|---|---|
| A fixture that only reproduces the incident you already know | Every run passes and production still surprises you | Add a second failure shape and one quiet bucket to the fixture |
| A p95 computed from a handful of samples | A percentile that is really the maximum | Report the sample count beside the percentile, and pick nearest-rank on purpose |
| An alert that pages on every anomaly | The on-call engineer mutes the channel inside a month | Require a sustained breach, cap the page volume, attach a first action |
| A postmortem that stops at the trigger | A fix for this rename and nothing for the next | Write one factor per layer, with an owner for each control |
Stretch. Add a second incident to the fixture: a currency bug that writes the right number in the wrong currency, with no schema change. Show whether the integrity alert catches it, then design the one panel that catches both incidents. State what the extra panel costs you in false pages per week.
Key takeaways
Silent data faults leave every exception-based signal green, so alert on the business invariant.
An observability gap is often a missing join between two systems you already own.
Fifteen minutes of the incident were recoverable with one panel and one owner.
Rank controls by when they fire; the cheapest one is usually the narrowest.
A postmortem lists contributing factors with a control for each, never a culprit.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.