Repository navigation
fix(store): refund rejected Stripe withdrawals when the coordinator clock is ahead - #1352
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Postgres refund check summed ledger rows with created_at >= the withdrawal created_at. The withdrawal uses the coordinator clock and the ledger rows use the database clock. When the coordinator clock is ahead, the check misses the debit and refuses every refund with ErrPayoutConflict, so rejected Stripe transfers are never refunded. Remove the time bound. The memory store already has no bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Deployment failed for project d-inference with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
Threat model review — advisoryReviewed head Review not completed for this head. Previous findings are superseded, not confirmed resolved. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Coverage: 0/0 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. |
|
@codex review this |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca51fbe08f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployment failed for project darkbloom-status with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Brings in master through #1328 (goose migrations, store in store/postgres/), #1344, #1351, #1352 and others. Conflicts: - ci.yml (Report coverage): master inlined the empty-profile, coordinator-row and statement-format checks (#1252). This PR moved the same checks into scripts/coordinator-statement-coverage.sh, which ci.yml and integration.yml both call. Keep the script call. - docs/developer/test.md (coverage command): keep the script call. - docs/developer/test.md (CI workflow map): keep master's ci.yml row (adds the provider coverage table) and this PR's integration.yml row (adds the e2e coverage row and artifact). The #1284 store contract tests and coverage tests build and vet against master's store layout with no change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fix rejected Stripe withdrawal recovery when the coordinator clock is ahead of PostgreSQL. The previous ledger timestamp bound could hide the original debit and permanently return
ErrPayoutConflict.stripe_withdraw:<id>reference, independent of clocks.idx_ledger_stripe_refund(account_id, reference)index concurrently forrefundandstripe_payoutrows. This addresses the review finding that removing the time bound alone would scan a busy provider's lifetime ledger.Before
After
flowchart TD M["migrate: ensureConcurrentIndex"] --> I["Valid partial account/reference index before readiness"] A["Recovery or payout-audit"] --> B["RefundRejectedStripeWithdrawal: same row and advisory locks"] I --> C["Indexed ledger SUM: account + reference; no clock bound"] B --> C C --> D{"Exact debit and valid refund evidence?"} D -- "No" --> E["ErrPayoutConflict; no balance mutation"] D -- "No prior refund" --> F["Commit credit + ledger row + refunded flag atomically"] D -- "Already refunded in ledger" --> G["Repair flag without another credit"] F --> H["Subsequent recovery is a no-op"] G --> H classDef process fill:#dbeafe,stroke:#2563eb,color:#172554 classDef success fill:#dcfce7,stroke:#16a34a,color:#052e16 classDef failure fill:#fee2e2,stroke:#dc2626,color:#450a0a class M,I,A,B,C,D process class F,G,H success class E failureValidation
Validated locally against isolated PostgreSQL, never production:
go test -count=1 ./coordinator/tests/store/... ./coordinator/tests/cmd/...: all 10 packages pass with localDATABASE_URL.make coordinator-test: complete suite and runner guards pass with localDATABASE_URL.make coordinator-build: passes.golangci-lint run ./coordinator/...: 0 issues.make docs-impact-check BASE=origin/masterandmake docs-check: pass.The original PR's failed coordinator run was
e2e/testbed/profile.TestProfilerDiff(negative timing delta), unrelated to refund correctness. The full local suite passes; latest remote checks are tracked separately.Refactor Pass
A dedicated, fresh-context, read-only refactor reviewer assessed the final scoped code, tests, and docs after focused validation. No cleanup was warranted; the existing transaction structure and shared concurrent-index helper remain intact. Full tests/build/lint and documentation checks were run on the final version.
Migration And Operations
No API or protocol changes. Startup builds the new index concurrently, preserving live writes; an invalid/interrupted index build fails readiness and requires operator repair. Initial construction still consumes database IO and may extend startup.
After a separately approved deployment, existing confirmed-rejected withdrawals are retried by the recovery loop. A read-only
payout-auditcan identify affected withdrawals first. This PR review did not deploy, mutate production, or execute refunds.