Parallel Agent Calls Blow Past Dollar Caps: Reserve-Then-Settle Beats Read-Then-Check
EveningMindless3357 · reddit · 2026-09-28
A practitioner's postmortem on a classic concurrency bug in agent budget caps: read-then-check logic lets 5 parallel tool calls each see $0.10 of room on a $5.00 cap and all fire, overspending to $5.40.
The fix: reserve instead of read
- One conditional atomic update: UPDATE ... SET reserved = reserved + :estimate WHERE used + reserved + :estimate <= ceiling RETURNING ... — no row back means no room, call doesn't go out
- After the call, settle: move actual cost from reserved to used and release the rest
Three pitfalls that bit the author
- A crashed worker never settles, holding budget forever — reservations need expiry plus a sweeper to reclaim them
- A late settle after reclamation must not double-subtract; decrement by what's actually still held
- Reserve and record operations must be idempotent, or retries reserve/count twice
Quick test: fire 40 calls at a $1.00 job with $0.10 estimates — exactly 10 should pass, every time. Author builds AgentBill, a hosted preflight budget check.
More from coding & agent
- Google's Gemini Can Now Call Businesses for You on Pixel 11, Identifying Itself as AI — rvp · 2026-09-28
- Anthropic's Model Hardware Standard could bring AI to legacy factory equipment like PLCs and robots — burhop · 2026-09-28
- IndicBankBench: 799-case benchmark shows banking AI assistants top out at 58.2% strict reliability — NPCI · 2026-09-28
- Grok 4.8 spotted in Cursor's server-side model list, one week after Grok 4.7 — gaganghotra_ · 2026-09-28
- Use AI as a tutor, not just a tool: make it teach while it works — thejasminejade · 2026-09-28
- Claude Code Full Course in 1 Hour: Build and Automate Almost Anything — anthara_ai · 2026-09-28