# Fixing "agent tax lookup timed out: invoices went out with zero tax lines"

## TL;DR

Fail closed on tax lookup failure: retry, and if it still fails, hold the invoice in draft instead of sending it with zero tax. Zero tax is a tax decision, and the agent is not allowed to make it by accident.

```text
agent tax lookup timed out: invoices went out with zero tax lines
```

## Steps

1. Wrap the tax lookup with retries and a timeout budget; on final failure, leave the invoice in draft and alert.
   Expected: No invoice finalizes without a successful tax computation or an explicit exemption.
2. Remove any code path that defaults tax to zero on error.
   Expected: A search for the zero-default finds nothing.
3. Add a pre-finalize check: every taxable invoice must have at least one tax line or a recorded exemption reason.
   Expected: Zero-tax invoices cannot slip through silently.
4. Sweep recent invoices for zero tax lines and cross-check each against exemption records.
   Expected: A list of invoices that need correction.

## Prevention

The silent zero-default is the whole bug. Tax failures must be loud and blocking: draft, alert, retry. If your volume demands it, cache tax rules per jurisdiction with a short TTL so a brief outage does not halt billing, but never cache a zero.

## Detection

Alert on any finalized invoice with zero tax lines and no exemption on file. Monitor tax service latency and error rates so timeouts are visible before invoices go out. Reconcile tax collected versus expected per jurisdiction.

## Recovery

For invoices that went out wrong: void and reissue with correct tax, or issue a debit note for the missing tax, following your jurisdiction's rules. Notify affected customers about the corrected invoice. Talk to your tax advisor about reporting obligations for the period.

## When this applies

- Invoices went out with no tax lines after a tax service timeout or outage
- The agent treats tax lookup failure as zero tax
- Tax collected drops to zero for a period without an exemption change

## When it doesn't

- The customer is genuinely tax-exempt with documentation on file
- The jurisdiction has no applicable tax for the product
- You use provider-native tax calculation that handles failures itself (verify its failure behavior)

## Compatibility

Stripe Tax, Adyen (tax handling on invoices), PayPal REST API v2 (tax line items), Avalara, TaxJar, and similar tax services. Any setup where tax is computed by an external call before finalizing.

### tax service timed out and invoice went out untaxed

### zero tax lines because the lookup failed silently

### invoices missing tax after a tax API outage

## Why it happens

Tax lookup is a network call in the middle of the invoice flow. When it times out, the agent needs a number to continue, and zero is the path of least resistance. Nobody notices because the invoice looks complete; the missing lines are invisible unless you look for them.

## Edge cases

- Mixed carts with exempt and taxable items: the check must be per line item, not per invoice
- Cached tax rules: refresh on jurisdiction rule changes, not just on TTL
- Reverse-charge and B2B exemptions: these are legitimate zero-tax cases and must carry an exemption reason so they pass the pre-finalize check

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_Zghi_j8mICekZutimT5WwA
