DEV Community

Dakota Liu
Dakota Liu

Posted on

An Idempotency Ledger for Model-Driven Tool Calls

An operation ledger becomes useful on the morning after a worker crashed. Which rows can resume locally, which ones require a lookup, and which receipts can be returned to the caller? Give each state an evidence requirement so that a sweeper cannot turn an old row into a second write.

A ledger an operator can interpret

State Evidence to keep What the operator can conclude
Accepted Durable operation ID, tenant and approved effect parameters Intent exists. Only the dispatcher elected by an atomic claim may initiate the effect.
Dispatch started Owner/version and time recorded before the outbound write The call might have reached the provider, even if no receipt is local.
Confirmed Provider resource or transaction ID with the expected outcome Return the recorded receipt to later callers.
Unresolved Timeout, lost reply or expired dispatch lease Reconcile before any new attempt that could duplicate the effect.

An atomic compare-and-set has an outcome. A worker that loses the state transition must stop before sending. Bind subsequent updates to the owner/version and require the expected number of changed rows. Otherwise an old worker can overwrite a more recent decision. Store late receipts as evidence and reconcile their identity and status instead of discarding them or marking the operation completed unconditionally.

Test two clocks

The local lease controls worker ownership. The provider's idempotency window controls the meaning of a repeated request there. Expiring the first has no power over the second. Set a fixture's worker lease to expire while its stub provider is still processing. Reclaim responsibility for investigating the item, not permission for an unconditional second write. Check both the remote resource count and the local state.

Authoritative evidence might be a receipt lookup with the same tenant, operation reference and effect. A similar title or an empty eventually consistent listing is weaker. Preserve unresolved records for the period in which delayed clients can resume, consistent with the retention policy. Report their owner and age so uncertainty is visible.

PostgreSQL INSERT ยท Stripe API idempotency

This article was created with AI assistance.

Top comments (0)