Repository navigation
Qualify existing reservation adapters for current wallet composition - #1249
Conversation
Paid AI work needs a before-call hold and an exactly-once settlement on the existing wallet (app#2105 milestone 1, reused by Context accounting app#2123). The current preflight only reads the balance, so concurrent requests can each pass it. reserveCreditsOnce, settleCreditReservation and releaseCreditReservation wrap the new database functions. Inputs are validated before the wallet is touched; insufficient capacity is a definite receipt so a caller can return a machine-readable 402. Lost replies and invalid receipts raise reconciliation errors that keep the operation key; settlement reuses the charge receipt identity and its CreditChargeNeedsReconciliation. No caller, price, ceiling, auto-top-up or provider call is added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up for the credit reservation adapters. A returned database error with SQLSTATE 22023 is raised inside the RPC transaction, which rolls back, so the call wrote nothing. The adapters now throw CreditReservationRejected with the fixed database reason in that case, so a future caller can return a definite 402/409 instead of replaying an identical call forever. Every other error, lost reply or invalid receipt still raises the reconciliation error. The README now says a held receipt is not an execution lease (duplicate deliveries must be deduplicated by the caller's attempt identity) and that connecting any caller requires database#101, api#1009 and database#88. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Source contribution delivered through #1257 at 5a4ce3b. Verified all adapter, validator and test files are preserved byte-for-byte; the README retains the contribution with the reviewed correction for current reused-hold status and independent dispatch ownership. GitHub already reports this ancestor PR as merged; no separate close or branch deletion was needed. Original branch/history retained. This is source-only supersession: no database apply, activation or deployed settlement acceptance is claimed. |
This successor integrates the existing API #1026 reservation adapters unchanged onto current main and corrects their wallet-composition documentation. Shared holds remain claims against the balance; pack holds are already deducted. Current refill, top-up and deduction writers are already atomic, so the old prerequisite text was stale.
Depends on recoupable/database#134, which retains Database #115 and adds protection against legacy/pack debits consuming held funds, including a reproduced repeatable-read race. Original API #1026 and its branch remain untouched. No new HTTP/MCP operation or caller is enabled; adapter inputs, receipts and uncertainty classes remain byte-identical. Context's disabled request/pilot/module consumer is separate work under recoupable/app#2123; common accounting is #2105 milestone1, independent of hosting prices.
Validation: 696 focused API tests across122 files, production TypeScript, full lint and adapter formatting pass. Independent composition review passed; 11 original adapter/validation/test files verified byte-identical to #1026. Companion disposable SQL tests pass36 cases on PostgreSQL15/17 plus11 existing pack cases on17, with17 new composition tests independently rerun.
No production migration, grants, financial data, provider call, spending or pricing change. One-wallet enforcement and legacy pre-dispatch authorization remain prerequisites for live activation. Root retains review/merge/release authority; this draft is source preparation only.
Summary by cubic
Adds opt-in credit reservation adapters so paid AI work can hold credits before dispatch and settle exactly-once on the existing wallet, closing the race where concurrent requests all pass the balance preflight.
reserveCreditsOnce,settleCreditReservation, andreleaseCreditReservationwrap the new database RPCs with validated inputs and typed receipts; no production caller is enabled.CreditReservationRejectedwith the fixed reason, so callers can return a definite 402/409; lost replies and invalid receipts raise reconciliation errors that retain the same operation key.Activation requires the database reservation migration and wallet composition guard; this is source preparation only, with no spending, pricing, or financial data changes.
Written for commit cdbd817. Summary will update on new commits.