FlockTab
Back to all articles

Why concurrent requests need reservations

Prevent several requests from each spending the same apparent remainder of a tab.

FlockTabBudget controls3 min read

A budget check that reads a balance and then sends a request looks correct in a single-threaded demonstration. Under concurrency, several requests can all read the same remaining amount before any one of them has finished.

The missing concept is money already promised to work in progress. That needs to be visible to the next admission decision.

Walk through the race

An illustrative tab has $1 remaining. Two simultaneous requests each need an estimated 75 cents. If both read the remainder before either records its commitment, both can pass. The system has admitted $1.50 of estimated work against $1 of room.

Recording the cost only after the provider responds cannot repair that admission error. The second request needs to see the first request's hold while the first is still running. Available room should account for settled usage and outstanding reservations.

Make admission atomic

PostgreSQL row locks can serialize conflicting changes to the same row. In FlockTab's ledger, the tab is locked while the admission check and reservation update are made together. The next transaction sees the updated reserved amount before deciding whether its request fits.

Keep the provider call outside that transaction. A slow network response should not hold the tab's database lock for the entire inference. The transaction establishes the reservation; later settlement replaces the hold with the accounted usage or releases it under the appropriate failure rule.

Know which requests share a boundary

Several keys or concurrent sessions for the same Agent need to meet at the same tab balance. Otherwise minting another key or opening another terminal could accidentally create additional spending room.

Different Agents can have separate tabs. A project report that adds their usage does not automatically become one enforced project-wide cap. If a team needs a shared project ceiling, it must verify that such a control exists at admission time rather than inferring it from a grouped chart. FlockTab's named Agent tab is the relevant budget unit described here.

Test concurrency, not just the happy path

Create a test upstream that counts received requests. Send two simultaneous requests whose combined estimates exceed the available room, and verify that only the admissible request reaches it. Check the outstanding balance while the accepted request is still pending.

Then exercise duplicate settlement and a provider failure. The hold should resolve once, and repeated finalization should not spend or release the same amount twice. These tests establish the financial invariant behind the interface: every admitted request has a place in the ledger before the provider begins its work.

Sources checked 23 September 2026. Numerical scenarios are illustrative unless explicitly identified as provider data. Vendor limits and interfaces can change; consult the linked documentation for current details.