P3

Invoice sent to the wrong customer

PD-6510 · billing-agent · 2026-08-11 11:07:41 UTC

Trace21b93b4c3f7abe0c
Tokens11.1K → 2.2KCost$0.0410
Post-mortemReplay with the fix
32 spansDurationTokensCost

Causal Copilot

I analyzed trace 21b93b4c3f7abe0c: billing-agent, 32 spans over 1m 20s, 13.3K tokens (~$0.0410).

Trace structure
  • 4 LLM calls, 9 tool calls, 4 failing spans
  • Entry point: billing-agent.run
  • First failure: db.lookup_customer at agents/billing/lookup.py:33
Why the tool failure detector fired

customer_for() indexes the region-filtered customer list by order.index, which is not the customer's row after filtering. The invoice was addressed to cust_5522 instead of cust_5521.

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

Root cause: 1 hop upstream

5e2b7d18 resolves the billing customer with customers[order.index] at agents/billing/lookup.py:33, a position in a region-filtered, name-sorted listing rather than a key. For order #55210, position 1 was Norrland Tooling AB (cust_5522), not the order's own customer_ref cust_5521 (Northwind Traders LLC). The recipient check that should have caught it has run after the send since e91c33b7 moved dispatch onto the async mail queue, so nothing stopped delivery.

Introduced in commit 5e2b7d18 (agents/billing/lookup.py:33).

Counterfactual: If the lookup had keyed on order.customer_ref, or the recipient assertion had run before the send, the $4,200.00 invoice would never have reached Norrland Tooling AB.

The fix

Resolve the customer by order.customer_ref instead of a position in the region-filtered listing, and move assert_recipient_matches_order in front of the mail queue, so a mismatch stops the send instead of being reported after it.

→ PR #1990 (causal/fix-PD-6510), +6/−6, merged and shipped in billing-2026.08.12.

TL;DR: Positional index used as a customer key. Fixing agents/billing/lookup.py removes this failure class entirely.

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