Skip to content

feat(backend): add retry queue for failed recordPaymentOnChain calls#197

Open
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:feat/payment-retry-queue
Open

feat(backend): add retry queue for failed recordPaymentOnChain calls#197
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:feat/payment-retry-queue

Conversation

@leocagli

Copy link
Copy Markdown
Contributor

Closes #129

Summary

recordPaymentOnChain in both weather and search handlers was called fire-and-forget with .catch(warn) — a transient RPC failure silently dropped agent score updates, causing score drift between on-chain state and reality with no recovery path.

  • backend/src/lib/paymentRetryQueue.js (new): in-memory queue with exponential backoff (5s → 10s → 20s → 40s → 80s, max 5 attempts). A 5s setInterval worker (unref'd so it does not block process exit) processes due entries.
  • services.js: weather and search handlers now call enqueuePaymentRecord(agentAddress, fn) in their catch block instead of silently discarding the failure.
  • After MAX_ATTEMPTS, the entry is dropped and logged at error level with full context for operator alerting.

The queue is in-process only — lost on restart. This handles the common transient failure case (RPC hiccup, network timeout) without SQLite/file persistence complexity.

Test plan

  • Mock recordPaymentOnChain to fail 3 times then succeed — verify the retry queue succeeds on the 4th attempt
  • Mock it to always fail — verify it is dropped after 5 attempts with an error log
  • Normal operation: successful first call is not enqueued

Closes Stellar-Ecosystem#129

recordPaymentOnChain was called fire-and-forget with .catch(warn) —
transient RPC failures silently dropped agent score updates, causing
score drift between on-chain state and reality with no recovery path.

Changes:
- Added backend/src/lib/paymentRetryQueue.js: an in-memory queue with
  exponential backoff (5s → 80s, max 5 attempts) driven by a 5s interval
  (unref'd so it does not block process exit)
- services.js weather handler: on first failure, logs a warning and
  enqueues via enqueuePaymentRecord() for automatic retry
- services.js search handler: same pattern

The queue is in-process only (lost on restart). This handles the common
transient failure case (RPC hiccup, timeout) without the complexity of
SQLite/file persistence. Permanent failures after MAX_ATTEMPTS are logged
at error level with full context for operator alerting.
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@leocagli, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aaed909b-904f-4739-81b0-5402eafa8a81

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb6da9 and 8311b11.

📒 Files selected for processing (2)
  • backend/src/lib/paymentRetryQueue.js
  • backend/src/routes/services.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant