{"version":2,"agent":"claude-code","runId":"run_ckt_9f2a","title":"Track down the checkout slowdown","trigger":{"source":"sentry","event":"alert: checkout p95 > 2s for 30m","at":"2026-07-10T09:02:00Z","url":"https://example.com/sentry/issues/checkout-latency"},"outcome":{"status":"succeeded","destination":"merged to main","summary":"Checkout p95 latency had tripled to **2.9s** since the v4.2 deploy. The cause was an N+1: each cart line fired its own address lookup, so a 40-item cart ran 41 queries. Batching the lookups into a single query cut checkout to **340ms** and dropped queries per checkout from 41 to 2. No public API changed.","at":"2026-07-10T09:41:00Z"},"provenance":{"tool":"claude-code 2.1","extent":"ai_assisted","publisher":"the taleseal team — a hand-written example","attestation":{"by":"Priya Menon, staff engineer","note":"Read the diff and the load-test output, re-ran the replay locally, merged.","at":"2026-07-10"},"transcriptUrl":"https://example.com/transcript/run_ckt_9f2a"},"artefacts":[{"label":"#2184 Batch address lookups in checkout","kind":"pr","url":"https://example.com/pr/2184"},{"label":"api/checkout/pricing.ts","kind":"file"}],"beats":[{"at":"09:02","title":"Confirmed the regression","prose":"Pulled 14 days of checkout p95 from Grafana. Latency was flat around 850ms until the morning of the 8th, then tripled and stayed there. The step lines up exactly with the v4.2 deploy — nothing else shipped that day.","widgets":[{"kind":"line_chart","title":"Checkout p95 latency","subtitle":"last 14 days · ms","unit":"ms","endLabel":"2,900ms","annotations":[{"index":6,"text":"v4.2 shipped"}],"points":[{"label":"26 Jun","value":840},{"value":860},{"value":810},{"value":900},{"value":830},{"value":870},{"label":"2 Jul","value":850},{"value":2650},{"value":2780},{"value":2710},{"value":2900},{"value":2840},{"value":2880},{"label":"10 Jul","value":2900}]},{"kind":"stat_tiles","title":"Checkout, right now vs. before v4.2","tiles":[{"label":"p95 latency","value":"2.9s","delta":"+240%","tone":"bad"},{"label":"checkout error rate","value":"0.4%","delta":"+0.1pt","tone":"bad"},{"label":"throughput","value":"18/min","delta":"unchanged","tone":"flat"}]}],"evidence":[{"kind":"citation","name":"Grafana · checkout latency dashboard","url":"https://example.com/grafana/d/checkout","quote":"p95 request duration for POST /checkout rose from 0.85s to 2.90s on 2026-07-08."}]},{"at":"09:11","title":"Bisected to the deploy","prose":"Only checkout regressed — catalogue and cart p95 were untouched, so this was code, not the database or a noisy neighbour. Narrowed v4.2 to the three commits that touched the checkout path and ranked them by how much query work they could add.","widgets":[{"kind":"table","title":"v4.2 commits touching checkout","columns":["Commit","Author","What it changed","Suspicion"],"rows":[["a1c3f9","dependabot","bump stripe-node 14→15","low"],["7be220","m.okafor","per-line delivery estimates","high"],["4d0e11","j.tran","rename order fields","low"]]}],"decisions":[{"title":"Profile the checkout query path before reverting","state":"chosen","why":"Reverting all of v4.2 would also drop the delivery-estimate feature product wanted. Cheaper to confirm the exact cause first, then fix only that."},{"title":"Revert the whole deploy","state":"set_aside","why":"Blunt: it backs out three unrelated changes and we'd relive this the next time the feature ships."}]},{"at":"09:24","title":"Found the N+1","prose":"Commit 7be220 added a delivery estimate per cart line, and each estimate calls `addressFor(lineId)` — one query per line. Turned on query logging for a single 40-item checkout: 41 queries, 40 of them the same address lookup with a different id.","evidence":[{"kind":"command","command":"LOG_QUERIES=1 bun run replay fixtures/checkout-40-items.json | grep -c SELECT","output":"41\n\n  SELECT * FROM addresses WHERE line_id = $1   -- ×40 (one per cart line)\n  SELECT * FROM carts WHERE id = $1              -- ×1","exitCode":0}],"decisions":[{"title":"Batch the 40 lookups into one query","state":"chosen","why":"The line ids are all known up front, so a single `WHERE line_id = ANY($1)` returns every address in one round trip. No schema change, no cache to invalidate."},{"title":"Add a per-address cache","state":"set_aside","why":"Solves the symptom, not the shape. A cache adds an invalidation bug surface for a query that batching removes outright."}]},{"at":"09:33","title":"Batched the lookups","prose":"Replaced the per-line `addressFor` call with one `addressesFor(lineIds)` that fetches every address in a single query, then maps them back by line id in memory. The public checkout response is byte-for-byte identical — only the query count changed.","evidence":[{"kind":"diff","summary":"2 files, +18 −7","url":"https://example.com/pr/2184/files","files":[{"path":"api/checkout/pricing.ts","additions":12,"deletions":7},{"path":"api/checkout/addresses.ts","additions":6,"deletions":0}]}]},{"at":"09:39","title":"Proved it on real traffic","prose":"Replayed the same 40-item checkout, then a 500-request sample captured from production. Query count per checkout dropped from 41 to 2, and p95 came back down to **340ms** — below where it sat before the regression.","widgets":[{"kind":"stat_tiles","title":"After the fix, on the production replay","tiles":[{"label":"p95 latency","value":"340ms","delta":"−88%","tone":"good"},{"label":"queries per checkout","value":"2","delta":"−95%","tone":"good"},{"label":"checkout error rate","value":"0.1%","delta":"−0.3pt","tone":"good"}]}],"evidence":[{"kind":"test","name":"checkout replay · 500-request production sample","command":"bun run replay fixtures/prod-sample-500.json --assert-p95=500ms","output":"500 requests · p95 340ms · p99 410ms · 0 errors\nassert p95 < 500ms: OK","passed":true},{"kind":"command","command":"LOG_QUERIES=1 bun run replay fixtures/checkout-40-items.json | grep -c SELECT","output":"2","exitCode":0}]}],"sources":[{"name":"Grafana","what":"14 days of checkout p95, deploy markers","url":"https://example.com/grafana/d/checkout","latencyMs":220},{"name":"Sentry","what":"the alert and the affected transaction","url":"https://example.com/sentry/issues/checkout-latency"},{"name":"git","what":"blame + the v4.2 commit range on the checkout path","spans":3}],"metrics":{"durationMs":2340000,"costUsd":2.14,"tokensIn":128400,"tokensOut":14600,"model":"claude-opus-4-8","steps":34},"spans":[{"name":"read Grafana p95 series","type":"tool","startS":0,"endS":190,"note":"checkout latency, 14d"},{"name":"correlate with deploy log","type":"tool","startS":190,"endS":540},{"name":"bisect v4.2 commit range","type":"tool","startS":540,"endS":1320,"note":"3 candidate commits"},{"name":"replay with query logging","type":"tool","startS":1320,"endS":1560,"note":"41 queries observed"},{"name":"reason about the fix","type":"llm","startS":1560,"endS":1860},{"name":"edit checkout pricing","type":"tool","startS":1860,"endS":2040},{"name":"run production replay","type":"tool","startS":2040,"endS":2280,"note":"p95 340ms"}]}