Skip to content

fix: cancel hold invoice when expiring ACTIVE orders#837

Open
grunch wants to merge 2 commits into
mainfrom
fix/cancel-orders-expired-holdinvoice
Open

fix: cancel hold invoice when expiring ACTIVE orders#837
grunch wants to merge 2 commits into
mainfrom
fix/cancel-orders-expired-holdinvoice

Conversation

@grunch

@grunch grunch commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

Ensures that when the cancel-orders job expires an ACTIVE order, the associated Lightning hold invoice is canceled so the seller's locked funds are refunded promptly, instead of being orphaned until the on-chain CLTV timeout. The expiry transition is also serialized under the per-order mutex with a state re-check to avoid racing concurrent flows.

Previously, the job marked expired orders as EXPIRED without canceling the hold invoice. Because the expired-hold-invoice check ignores EXPIRED orders, the seller's funds remained locked until the on-chain timeout.

Changes

  • jobs/cancel_orders.ts — Run the expiry transition inside PerOrderIdMutex.instance.runExclusive(orderId, ...) and re-read the order under the lock so the job does not stomp an order that advanced concurrently (e.g. a release/payout in flight under the same lock). Only ACTIVE and FIAT_SENT orders are expired:
    • ACTIVE — the buyer never signalled fiat-sent, so cancel the hold invoice (refund the seller) before marking the order EXPIRED.
    • FIAT_SENT — the buyer claims to have paid; the hold invoice is left open and the case is logged for the dispute/admin flow rather than auto-refunded.

Testing

  • npx tsc --noEmit passes.
  • prettier --check and eslint pass.

When the cancel-orders job expires an order, run the transition under
the per-order mutex and re-read the order so it does not stomp an order
that advanced concurrently (e.g. a release/payout in flight under the
same lock).

For ACTIVE orders the buyer never signalled fiat-sent, so cancel the
hold invoice and refund the seller instead of orphaning the payment
hash. Previously the order was marked EXPIRED without canceling the
hold invoice, and since the expired-hold-invoice check ignores EXPIRED
orders, the seller's funds stayed locked until the on-chain CLTV
timeout.

FIAT_SENT orders are not auto-refunded here (the buyer claims to have
paid) and are left for the dispute/admin flow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

More reviews will be available in 8 minutes and 28 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ 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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cec57eb4-2db1-4565-a0a8-94231f3d6257

📥 Commits

Reviewing files that changed from the base of the PR and between 056284a and 96593e4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • jobs/cancel_orders.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cancel-orders-expired-holdinvoice

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

package.json was bumped to 0.15.2 (commit 056284a) but package-lock.json
still declared 0.15.1. The CI 'Run prettier' step runs 'npm install'
followed by 'git diff --exit-code', and npm rewrites the lockfile
version to match package.json, producing an uncommitted diff that fails
the check. Sync the lockfile version so the working tree stays clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@grunch

grunch commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@grunch grunch requested a review from knocte June 13, 2026 11:51
@grunch

grunch commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

@codex review

@grunch grunch requested review from Luquitasjeffrey and removed request for knocte June 13, 2026 11:54
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.

1 participant