Skip to content

Fix/1763 settlement scheduler persist retry count - #1780

Merged
Olowodarey merged 3 commits into
Arena1X:mainfrom
strngecloud:fix/1763-settlement-scheduler-persist-retry-count
Aug 29, 2026
Merged

Fix/1763 settlement scheduler persist retry count#1780
Olowodarey merged 3 commits into
Arena1X:mainfrom
strngecloud:fix/1763-settlement-scheduler-persist-retry-count

Conversation

@strngecloud

Copy link
Copy Markdown
Contributor

Idempotent settlement scheduler: persist retry attempt count

The advisory-lock idempotency, DB-transactional claim/finalize, and
exponential backoff for market-settlement.scheduler.ts already existed on
main. This PR closes the remaining gap: the retry attempt counter lived
only in an in-memory Map, so a process restart silently reset a market's
retry budget to zero and a queued retry (settleMarketWithRetry) bypassed
the DB transaction entirely.

Changes

  • Add settlement_attempt_count column to Market (+ migration).
  • claimMarketForSettlement increments the persisted counter on every claim
    and refuses to reclaim a market once it hits MAX_RETRY_ATTEMPTS, so the
    budget holds across restarts.
  • settleMarketWithRetry now goes through the same transactional
    settleMarket path as a fresh sweep instead of calling SorobanService
    directly.
  • Unit tests for the persisted counter and unified retry path.

Testing

  • pnpm test — 1491/1491 passing
  • pnpm run lint — 0 errors
  • pnpm run build — clean
  • pnpm run migration:check-timestamps — passed

Closes #1763

Adds settlement_attempt_count column so the settlement scheduler's
retry budget survives a process restart instead of resetting to zero
along with the in-memory dead-letter queue.
- claimMarketForSettlement now increments settlement_attempt_count
  each claim and refuses to reclaim a market once the persisted count
  hits MAX_RETRY_ATTEMPTS, so the budget holds across restarts.
- settleMarketWithRetry now calls the transactional settleMarket path
  (advisory lock + settlement-attempt row + DB transaction) instead of
  calling SorobanService directly, so a queued retry is no longer an
  untracked second code path around the DB.
- Add settlement_attempt_count to existing market fixtures.
- New specs: attempt counter increments on every claim, a market that
  already exhausted its persisted budget is never reclaimed (even
  without an in-memory queue entry), and a manual retry goes through
  the same claim/finalize transaction as a fresh sweep.
@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
insight-arena-4rll Ready Ready Preview Aug 29, 2026 3:26pm

@Olowodarey
Olowodarey merged commit 58b08d6 into Arena1X:main Aug 29, 2026
5 checks passed
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.

[Backend] markets: Idempotent settlement scheduler with retry + backoff

2 participants