P1

Agent crashed on KeyError: 'change'

PD-7712 · stock-tool-agent · 2026-08-07 11:12:03 UTC

Traceaab13de33b9dbd4b
Tokens14.0K → 2.8KCost$0.0441
Post-mortemReplay with the fix
29 spansDurationTokensCost

Causal Copilot

I analyzed trace aab13de33b9dbd4b: stock-tool-agent, 29 spans over 55.2s, 16.8K tokens (~$0.0441).

Trace structure
  • 3 LLM calls, 7 tool calls, 8 failing spans
  • Entry point: stock-agent.run
  • First failure: format_quote at agents/stock/format.py:27
Why the tool failure detector fired

format_quote reads q['change'] by direct index. quotes-api v3 renamed the field to pct_change, so the first quote raised KeyError and aborted the run after 1 of 4 symbols.

Confidence 94% (judge: claude-haiku-5-5).

Root cause: 1 hop upstream

3f9a1c05 added format_quote(), which reads q['change'] by hard index at agents/stock/format.py:27. quotes-api v3 removed change on 2026-07-29 (pct_change replaced it, and the absolute delta is no longer returned), so the first v3 payload raised KeyError and aborted the run. The formatter's tests use a v2-shaped fixture, so CI stayed green. digest.py:112 and alerts/gap.py:44 share the same hard index.

Introduced in commit 3f9a1c05 (agents/stock/format.py:27).

Counterfactual: If format_quote had read v3's pct_change and rendered a missing value as n/a, the digest would have posted with explicit gaps instead of the run crashing on its first symbol.

The fix

quotes-api v3 dropped change for pct_change, and three call sites hard-index the old key: format.py:27, digest.py:112 and alerts/gap.py:44. Read pct_change at all three and render a missing or null field as n/a. Nothing is synthesized: previous_close is null before the session opens, so a derived delta would publish numbers the provider never sent, which is what the no_silent_defaults guardrail rejects.

→ PR #2044 (causal/fix-PD-7712), +15/−6, merged and shipped in market-2026.08.08.

TL;DR: Direct dict index on a provider field that was renamed. Fixing agents/stock/format.py removes this failure class entirely.

Demo: scripted from this incident's datalive: claude-sonnet-5-5