Repository navigation
fix(payouts): claim-based batch execution, conditional transitions and retry repair - #1634
Open
comandanto wants to merge 1 commit into
Open
comandanto wants to merge 1 commit into
comandanto wants to merge 1 commit into
Conversation
…d retry repair - Fix ReferenceError on retryHashs typo in getRetryableItems - Implement claimForPayout with single-statement conditional write in SettlementsRepository - Prevent settled rows from being downgraded to pending on batch resubmission - Implement conditional transitionStatus for pending -> settled and pending -> failed - Decode and repair batchPayoutProcessor.test.ts (mockResolved -> mockResolvedValue) - Add comprehensive unit tests for claim, skip and transition semantics (34/34 passing) - Extend batchPayoutAtomicity integration test to verify status stays settled after retry Closes CredenceOrg#1609
Author
|
hey, friendly ping: is there anything I should change to get this reviewed or merged? happy to rebase or adjust. thx |
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
Closes #1609
This PR resolves the duplicate-retry and status-corruption defects in
BatchPayoutProcessorby replacing blind upserts with atomic, conditional claims and forward-only state transitions.Root Cause Analysis
The blind upsert (
INSERT ... ON CONFLICT (transaction_hash) DO UPDATE SET status = EXCLUDED.status) previously used to record payout items defeated retries and corrupted settled ledger entries:faileditem was retried, the upsert flippedstatusback topending. Because a conflict occurred, PostgreSQL reportedxmax > 0, markingisDuplicate = true. The processor logged "Skipping duplicate" and returned immediately without executing, leaving the item trapped inpendingforever.settledbatch unconditionally downgradedstatus = 'settled'to'pending'before reporting duplicate.getRetryableItems()referencedretryHashsinstead ofretryHashes, crashing withReferenceError.src/jobs/batchPayoutProcessor.test.tswas committed base64-encoded and usedmockResolvedinstead of Vitest'smockResolvedValue.Design & Changes
claimForPayout):SettlementsRepositoryusing a single-statement conditional write:failedstate. Items inpendingorsettledare untouched and return 0 rows.settledor in-flight/orphaned.transitionStatus):WHERE transaction_hash = $1 AND status = $fromto enforce forward-only progression (pending -> settled,pending -> failed).retryHashs->retryHashesingetRetryableItems().src/jobs/batchPayoutProcessor.test.tsand corrected mock APIs (mockResolvedValue,mockRejectedValue).tests/integration/batchPayoutAtomicity.integration.test.tsduplicate-retry test to assert settled rows remain intact.Test Verification
TypeScript check (
npx tsc --noEmit) passes with 0 errors insrc/jobs/batchPayoutProcessor*.ts.