Interactive engineering lab

Shared agent budget: check-then-act, central counter or escrow

Shared agent budget: check-then-act, central counter or escrow. Compare overspend, false rejections and shared-counter load as eight workers grant credit.

By Sandeep Belgavi · Published 2026-12-04 · Prepared 2026-12-03

Synthetic fixtures computed locally. No model, database or production service is contacted.

Experiment workspace

Decision trace

    The question this experiment answers

    Several agent workers grant goodwill credit from one daily budget. Where should the budget be enforced so that it is never overspent, without every grant touching one shared counter? Set the number of requests, the budget, the number of workers, the mean request size, the mean gap between requests and the read-to-write gap, then choose a strategy: check-then-act, a central conditional decrement, escrow allocations, or escrow with reclaim. The model counts approvals, points granted, overspend, rejections, rejections while budget remained elsewhere, shared-counter operations, the busiest second and points left stranded with workers.

    Change one assumption at a time

    Start from the check-then-act preset and set the read-to-write gap to 0: overspend disappears, which shows the race is the time between reading the balance and recording the grant. Switch to the central counter to see overspend stay at zero at any gap. Switch to escrow and watch shared-counter operations fall while rejections with budget remaining rise. Raise the share pre-allocated to workers to 100% in the full split preset, then switch on reclaim. Finally shorten the mean gap to 20 ms in the busy preset.

    Expected outcomes

    With 400 requests, a 6,000-point budget, 8 workers, mean amount 20, mean gap 200 ms, a 1,500 ms read-to-write gap, 50% pre-allocated and refills of 200: check-then-act approves 298 for 6,131 points, an overspend of 131. The central counter approves 296 for exactly 6,000 with 400 shared operations. Escrow approves 305 for 5,984 with 110 shared operations but 79 rejections while budget remained elsewhere and 16 points stranded. Escrow with reclaim approves 296 for 6,000 with 213 shared operations and a peak of 18 in one second. Full split: 106 rejections, all with budget elsewhere, 92 stranded. Busy check-then-act: 7,494 points granted, overspend 1,494.

    Read the metrics and the table

    Approved plus rejected always equals the number of requests. Overspend is points granted beyond the budget and can only be non-zero for check-then-act. Rejected while budget remained elsewhere counts refusals that happened although the pool and other workers together still held enough points; it measures the cost of splitting the budget. Shared-counter operations and the busiest second show the load on the single place every worker must agree on. Stranded is what was left in worker allocations at the end of the day. Each table row is one request: its time, worker, amount, outcome and the reason.

    What to take back to a real system

    Give the agent one reservation tool that grants or refuses atomically and is idempotent on the case id, and do not show it a balance to reason about. Start with a central conditional decrement; it is rarely a bottleneck because agent decisions are slow. Introduce escrow only when the shared counter is a measured limit, and add reclaim or allocation expiry at the same time. Track rejections while budget remained elsewhere as a separate metric, and reconcile grants against the budget daily.

    Limits of this model

    Requests are handled one at a time in arrival order; real workers interleave and retry. Amounts, arrivals and worker assignment are synthetic and generated by a fixed seeded generator, so the same inputs always give the same result. A reclaim is modeled as instantaneous, while in a real system it is a coordinated transfer that can fail. No database, queue or model is contacted.

    Views are my own and do not represent any employer, past or present.