Skip to content

fix(coordinator): commit invite redemption and credit atomically - #948

Closed
Gajesh2007 wants to merge 2 commits into
masterfrom
fix/invite-redemption-credit
Closed

Gajesh2007 wants to merge 2 commits into
masterfrom
fix/invite-redemption-credit

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Invite redemption currently commits the claim and use count before crediting the account. If the separate balance write fails, the consumer gets 500 with no balance, but the code is already consumed and a retry is rejected.

RedeemInviteCode now commits the claim, use count, non-withdrawable balance and ledger entry together: one memory lock or the existing PostgreSQL transaction. The API no longer performs a second credit. The existing credit-failure 500 response is retained through ErrInviteCredit; eligibility and duplicate failures retain their current responses.

flowchart LR
  subgraph Before
    A[handleRedeemInviteCode] --> B[RedeemInviteCode commits claim and use count]
    B --> C[Separate Store.Credit]
    C -->|Failure| D[500, no credit, code consumed]
    C -->|Success| E[200 with balance]
  end
  subgraph After
    F[handleRedeemInviteCode] --> G[RedeemInviteCode locks and validates code]
    G --> H[Claim, count, creditBalance or creditLocked, ledger]
    H -->|Commit| I[200 with balance]
    H -->|Credit failure| J[Rollback claim and balance, 500, retry allowed]
  end
Loading

Validation:

  • HTTP regression fails on baseline with claimed=true, balance 0 and 500. It passes after the change and confirms there is no standalone credit call, duplicate redemption remains rejected and invite credit is not withdrawable.
  • Focused invite race tests pass (API 1.907s/store 1.274s).
  • Full store race suite passes against isolated PostgreSQL16 and memory (22.153s). New fixtures race two accounts for one use and inject an actual PostgreSQL ledger-trigger failure, verifying claim/count/balance rollback followed by a successful retry and exactly one ledger credit. The database is stopped.
  • Docs lint passes (278 pages); full coordinator Go suite passes (API 194.493s).

The transaction prevents new partial redemptions. It does not retroactively repair previously consumed codes whose old credit failed.

@vercel

vercel Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
d-inference Ready Ready Preview Sep 12, 2026 12:41am UTC
d-inference-console-ui-dev Ready Ready Preview Sep 12, 2026 12:41am UTC
d-inference-landing Ready Ready Preview Sep 12, 2026 12:41am UTC

Request Review

@Gajesh2007

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-12T00:48:49.720779Z 865bd10 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Gajesh2007

Copy link
Copy Markdown
Member Author

Consolidated into #1056 for review and merge after #1094, #1095 and #1096. #1056 contains this branch's exact head (865bd102c5f8a5c4b26498ea1bb18cd1deab35ae), including its reviewed fixes, with implementations and regressions reconciled into the coordinator subsystem owners. Closing the component PR to collapse the stack; its branch, commits and review history are retained. Follow #1056 for combined validation and merge status.

@Gajesh2007 Gajesh2007 closed this Sep 16, 2026

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference — 865bd102 Deployed Sep 12, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 865bd102 Deployed Sep 12, 2026 by vercel[bot]
benchmarks — 865bd102 Deployed Sep 12, 2026 by Gajesh2007 via E2E Benchmarks #1028
Preview – d-inference-landing — 865bd102 Deployed Sep 12, 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