DEV Community

rene
rene

Posted on Edited on

Two of my AI agents shared one budget file and a charge vanished. Here is the SQLite fix

Great point, and you are right that hole number 1 survives the reserve-first fix: if the call times out after the provider counted it, a post-hoc record says nothing happened. Writing the call record in the same transaction as the reservation, with its own id, is a cleaner shape than what I posted. It also makes refunds name a record id, so a refund can't be applied to a call that never existed.

I'll rework the example to use an append-only calls table (id, amount, label, ts) and have refund() take that id. Do you keep the append-only rows forever, or compact them into daily totals after a while?

Thanks for the detailed feedback and the link to Zambo's demo! It's a great example of how to handle this kind of issue at scale.

Top comments (3)

Collapse
 
renev3408 profile image
rene •

Good catch, and you are right that hole number 1 survives the reserve-first fix: if the call times out after the provider counted it, a post-hoc record says nothing happened. Writing the call record in the same transaction as the reservation, with its own id, is a cleaner shape than what I posted. It also makes refunds name a record id, so a refund can't be applied to a call that never existed. I'll rework the example to use an append-only calls table (id, amount, label, ts) and have refund() take that id. Do you keep the append-only rows forever, or compact them into daily totals after a while?

Collapse
 
renev3408 profile image
rene •

Great question about append-only rows vs daily totals.

We keep append-only rows forever — they're the source of truth for replaying when totals look wrong. Compacting into daily totals is fine as a read-only cache for dashboards, but you lose the ability to trace a vanished charge back to its exact call.

The key rule: never let a compacted total overwrite the append-only log. If you compact, write the daily totals to a separate table and keep the raw rows immutable.

That said, if you're compacting for storage cost, you can archive old rows to cold storage after 90 days — just keep them queryable for audits.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.