api: add durable idempotent batch receipts - #625
Open
ajroetker wants to merge 34 commits into
Open
Conversation
ajroetker
force-pushed
the
codex/durable-idempotent-batches
branch
from
September 2, 2026 21:27
c7ae95a to
6799888
Compare
ajroetker
force-pushed
the
codex/durable-idempotent-batches
branch
from
September 2, 2026 21:37
6799888 to
8d49eae
Compare
…g-409 # Conflicts: # go/pkg/sdk/oapi/client.gen.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Idempotency-Keywhile preserving the header-free fast pathDecisionConflictis no longer treated as proof of abortidempotency_receipt_pendingwhen initial receipt publication is ambiguousDurable execution model
The stable boundary is receipt-first and execution-second. Receipt lookup, comparison, forwarding, adoption, and replay do not consume execution capacity. Only the bounded backend job may atomically mark a receipt started and enter retained 2PC.
Before execution starts, deterministic validation failures can safely become terminal
not_applied. After execution starts, only an explicit typed coordinator outcome can prove commit or abort. Thrown errors remainunknown, preserve the pending receipt, and are reconciled by recovery without repeating execution.Terminal state is one atomic durable value: broad outcome plus exact error code, message, and retryability. That prevents restart replay from degrading a specific error such as
table_not_foundortransaction_conflictinto a generic response.Ownership and restart recovery
Every durable store receives lease defaults. Owner incarnation and lease CAS fencing apply equally to cluster-shared and node-local stores, including standalone node zero. Foreground execution and recovery share one deadline-aware heartbeat: transient store failures are retried while the last confirmed lease remains valid, and only explicit fencing loss or deadline exhaustion marks ownership uncertain.
Global renewal has its own durable-job owner and in-flight state, so slow recovery cannot suppress a due renewal pass. Renewal scans an in-memory set maintained atomically with session publication, containing only locally owned mutable sessions and terminal sessions with live recovery debt. Immutable retained receipts therefore create no periodic lease-write amplification. Large active sets are advanced in bounded fair batches.
Configured renewal intervals are clamped to one third of the lease TTL. Foreground work uses a conservative deadline captured before its durable execution marker; if that write consumes the safety window, it must establish a fresh fenced lease before invoking externally visible transaction work.
After a crash and lease expiry, a successor may atomically adopt the pending receipt and continue recovery without requiring the client to replay the request. Scope still controls whether a local miss is authoritative; it no longer disables ownership fencing or takeover for an atomic local durable store.
Compatibility
Requests without
Idempotency-Keyretain the existing fast path and response shape. Persisted schema changes are additive. Older receipt records that contain only the broad terminal outcome remain readable and replay with the legacy generic fallback, while newly completed receipts retain the exact response envelope.Pre-feature binaries do not scan the versioned receipt namespaces. New binaries continue to scan both interactive-session and receipt namespaces with fair recovery, cleanup, renewal, retention, and shared capacity accounting.
Long-term regressions
DecisionConflictand proves the receipt stays pendingValidation
make generatemake zig-generated-checkmake zig-buildzig build api-http-runtime-test --summary all— 71 passedzig build api-transactions-docid-test --summary all— 17 passedzig build lib-api-session-maintenance-test --summary all— 41 passedgit diff --check