Skip to content

Preserve newer Stripe withdrawal state during submission - #957

Closed
Gajesh2007 wants to merge 2 commits into
masterfrom
fix/stripe-withdrawal-progress
Closed

Gajesh2007 wants to merge 2 commits into
masterfrom
fix/stripe-withdrawal-progress

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

A Stripe webhook can mark a withdrawal paid or refunded while its submission handler is waiting for payouts.create. The handler then writes its older transferred row, erasing the sweep ID, refund flags and terminal status. The new regression exercises the actual submission handler and a concurrent paid/reversal transition; both cases fail on master.

Submission now retains its last acknowledged mutable state and updates through CompareAndSwapStripeWithdrawal. Memory performs the comparison and index changes under one lock; PostgreSQL uses one conditional UPDATE. An exact desired state is successful retry after a lost database acknowledgement. A different current state is preserved, the handler stops subsequent submission steps, and the client receives 409 withdrawal_state_changed with instructions to check history. Immutable account, amount, method and creation fields stay unchanged.

The two legacy already-refunded status-only webhook updates use their lookup snapshot with the same comparison. Sweep-bounce and reversal transitions are addressed separately by #933 and #925; after those changes are composed, production no longer calls the unconditional legacy setter. This does not make Stripe calls and database transactions atomic or reconcile a previously unknown payout ID.

Before:

flowchart LR
  S[Submission reads pending or transferred] --> C[Stripe call]
  C --> W[Write old whole row]
  H[Concurrent paid or reversal webhook] --> T[New terminal state]
  T --> W
  W --> L[Terminal ownership and refund evidence lost]
Loading

After:

flowchart LR
  S[Submission retains acknowledged state] --> C[Stripe call]
  C --> CAS[Atomic mutable-state comparison]
  H[Concurrent webhook] --> CAS
  CAS -->|expected state| U[Update progress and indexes]
  CAS -->|exact desired state| R[Idempotent retry success]
  CAS -->|different state| P[Preserve newer row and return 409]
Loading

Validation:

  • Actual submission/webhook interleaving regression fails on master (both paid and refunded cases, 0.568s), passes with the change, and verifies 409 plus the complete unchanged terminal row.
  • Focused Stripe withdrawal/webhook race suite passes 3.772s; final regression with response assertions passes 3.949s.
  • Full store race suite passes against an owned isolated PostgreSQL 16 cluster (23.496s); cluster stopped afterward. Cross-store fixtures cover each of seven mutable fields, immutable-field preservation, index replacement, idempotent retry with unchanged timestamp, stale writes, missing/invalid identity and concurrent competing writers.
  • Existing injected update-error tests retain their fault behavior through a new guarded-update override.
  • Documentation lint passes 278 pages. Full GOTOOLCHAIN=go1.25.0 go test ./coordinator/... passes (API 193.782s).
  • Independent source review found no blocker. Automated Codex review was requested but rejected by the review usage limit; no automated approval is claimed.

@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 1:02am UTC
d-inference-console-ui-dev Ready Ready Preview Sep 12, 2026 1:02am UTC
d-inference-landing Ready Ready Preview Sep 12, 2026 1:02am UTC

Request Review

@Gajesh2007

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Gajesh2007
Gajesh2007 marked this pull request as ready for review September 12, 2026 01:04
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@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 (66fc5d28734439cad239037d8889c7704d08ce48), 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-console-ui-dev — 66fc5d28 Deployed Sep 12, 2026 by vercel[bot]
Preview – d-inference — 66fc5d28 Deployed Sep 12, 2026 by vercel[bot]
benchmarks — 66fc5d28 Deployed Sep 12, 2026 by Gajesh2007 via E2E Benchmarks #1047
Preview – d-inference-landing — 66fc5d28 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