Skip to content

Recover pending token settlements after database failures - #159

Draft
mrmps wants to merge 2 commits into
mainfrom
codex/classifier-billing-recovery
Draft

mrmps wants to merge 2 commits into
mainfrom
codex/classifier-billing-recovery

Conversation

@mrmps

@mrmps mrmps commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Reproduced: after successful paid inference, three database settlement failures leave customer funds pending with no automatic retry path.

Persist the numeric settlement decision in Postgres before applying it, then atomically settle and remove the queued record. The existing scheduled worker retries up to 100 queued settlements per run without double charging or refunding unknown outcomes.

  • Add a preview-only reconciliation command: bun scripts/reconcile-token-reservations.ts. An explicit --refund REQUEST_ID releases an unjournaled, unreviewed token hold older than 24 hours; this intentionally waives any unknown charge for that request.
  • Existing holds are not automatically released. If all journal writes fail, or execution ends before the intent is saved, manual reconciliation is still required.
  • Migration 0018_token_settlement_recovery.sql must run before the Worker, as the deployment workflow already does. No production balances were changed.

Visual evidence is not applicable: backend settlement and operator CLI only.

@coderabbitai

coderabbitai Bot commented Oct 27, 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

Comment @coderabbitai help to get the list of available commands.

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