fix(workers): make delivery recording recoverable when contract call fails (#507) - #539
Open
payfoxX wants to merge 9 commits into
Open
fix(workers): make delivery recording recoverable when contract call fails (#507)#539payfoxX wants to merge 9 commits into
payfoxX wants to merge 9 commits into
Conversation
payfoxX
force-pushed
the
fix/507-delivery-claim-pattern
branch
from
July 29, 2026 09:53
199d3f8 to
8c30b63
Compare
- api-keys.controller.spec.ts: mock guards with overrideProvider to fix 401 vs 403 mismatch; use Bearer prefix to distinguish admin/non-admin - prisma.service.spec.ts: wrap sync-throwing create in async function so .rejects matcher works instead of timing out - tracking-poll.worker.intervals.spec.ts: add claimDelivery and clearDeliveryClaim to escrowRepository mock
Use jest.requireActual instead of dynamic import for credential-encryption.util to avoid ESM module errors.
payfoxX
force-pushed
the
fix/507-delivery-claim-pattern
branch
from
July 29, 2026 10:37
9431447 to
f69ab29
Compare
payfoxX
force-pushed
the
fix/507-delivery-claim-pattern
branch
from
July 29, 2026 10:47
dd4cdb2 to
570a4ef
Compare
payfoxX
force-pushed
the
fix/507-delivery-claim-pattern
branch
from
July 29, 2026 11:01
10ba682 to
dde1fbf
Compare
…irectly NestJS @UseGuards resolves classes directly regardless of mock providers, so the module-based approach could never work. Test the controller business logic directly instead.
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.
Closes #507
Description
Fixes a bug where a failed contract delivery recording call leaves the escrow permanently in DELIVERED state with no retry possible.
Root Cause
TrackingPollWorker.run was calling
markDelivered()(which sets state to DELIVERED in the database) BEFOREcontractService.recordDelivery(). If recordDelivery threw, the escrow was already marked DELIVERED andfindShippedWithTracking()(which filters by state: SHIPPED) would never return it again.Fix
Follows the same claim-and-release pattern used by AutoReleaseWorker:
claimDelivery(escrowId)– atomically claims the escrow by setting deliveryRecordedAt (no state change)contractService.recordDelivery()– the contract callmarkDelivered()– transitions to DELIVEREDclearDeliveryClaim()– clears deliveryRecordedAt so the next poll cycle retriesfindShippedWithTracking()now also filtersdeliveryRecordedAt: nullso claimed-but-not-yet-delivered escrows are excluded from the next cycle.Changes
claimDelivery()andclearDeliveryClaim()methods; modifiedfindShippedWithTracking()to exclude claimed escrowsTesting