Skip to content

Qualify existing reservation adapters for current wallet composition - #1249

Merged
sidneyswift merged 4 commits into
mainfrom
codex/shared-reservation-composition
Nov 17, 2026
Merged

sidneyswift merged 4 commits into
mainfrom
codex/shared-reservation-composition

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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, and releaseCreditReservation wrap the new database RPCs with validated inputs and typed receipts; no production caller is enabled.
  • Rolled-back database rejections (SQLSTATE 22023) throw CreditReservationRejected with 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.
  • Documents that shared holds are claims against the balance while pack holds are already deducted, so refill and top-up never see holds as consumption.

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.

View guided diff Turn on auto-fix

sidneyswift and others added 4 commits October 10, 2026 16:44
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>
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Nov 17, 2026 7:15pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@sidneyswift

Copy link
Copy Markdown
Contributor Author

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 branch was successfully deployed

1 active deployment
Preview — cdbd8179 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant