Repository navigation
fix(payment-service): recover payments stuck in PROCESSING (#18) - #195
Merged
Merged
Conversation
Claims stamp processingClaimedAt and a processingToken. A claim older than PAYMENT_PROCESSING_TIMEOUT_MS (or with no claim time) is taken over atomically by the next retry; only the token holder can settle, so a taken-over request writes nothing. The payment sweep settles payments abandoned for PAYMENT_PROCESSING_ABANDON_MS as FAILED, not charged (simulated gateway). Rows stuck before this deploy are recoverable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Payments can no longer get stuck in
PROCESSING(#18).Closes #18.
Changes
PENDING → PROCESSING) stampsprocessingClaimedAt(database clock) and a freshprocessingToken. Migration 004 adds both columns as nullable.PAYMENT_PROCESSING_TIMEOUT_MS(default 60 s) gets409, as before.UPDATE … WHERE "processingClaimedAt" < now() - timeoutand settles the payment. Of many concurrent takeovers exactly one wins.WHERE "processingToken" = <own>). A request whose claim was taken over writes nothing and returns what the new holder settled, so a payment is settled exactly once.PROCESSINGafterPAYMENT_PROCESSING_ABANDON_MS(default 15 min) asFAILED: "Payment processing was interrupted, so you were not charged." Thenpayment.failedis published, the order moves toFAILEDand the customer is notified.Docs:
docs/services/payment-service.md("Stuck PROCESSING recovery"),.project-context/04-database-design.mdand.project-context/05-event-driven-design.md.Lease ownership for side effects is the next issue, #19.
Test plan
PAYMENT_TEST_DATABASE_URL), 21 tests, including:PROCESSINGrow is listed as abandoned and reclaimable;processingClaimedAt timestamptzandprocessingToken uuid.tsc; lint shows 0 errors.🤖 Generated with Claude Code