Skip to content

fix(api): only expire a pending intent when the network answers NOT_FOUND (#37) - #1107

Merged
DevTobis merged 2 commits into
DevTobis:mainfrom
Anambraboi-1:fix/sweep-expiry-only-on-not-found
Oct 23, 2026
Merged

DevTobis merged 2 commits into
DevTobis:mainfrom
Anambraboi-1:fix/sweep-expiry-only-on-not-found

Conversation

@Anambraboi-1

Copy link
Copy Markdown
Contributor

closes #37

Summary of Changes

  • In sweepPendingIntents (services/api/src/intents.ts), only expire a stale pending intent when the network answered NOT_FOUND for it on this pass. If the outcome lookup throws (RPC outage) or the book update fails after the claim, the intent stays pending, however old, and is retried on the next sweep.
  • settleIntent now delegates to an internal settle() that also reports whether the lookup returned NOT_FOUND. The public SettleResult shape returned by the /v1/tx routes is unchanged. A plain pending result wasn't enough to go on: a caller that loses the claim race re-reads a row that can still be pending when the winner's book update failed.
  • NOT_FOUND also covers transactions older than the RPC's retention window (see getTxOutcome), so an old intent with that answer is still expired. This is noted in a comment at the expiry check.
  • Tests in intents.test.ts: rewrote the RPC-error test so it asserts the intent stays pending (no expiry, line not marked failed), and added a test where the book update fails on a stale intent. That intent isn't expired, and the next sweep settles it. The existing NOT_FOUND expiry test is unchanged. Both new tests fail against the old sweep.

…OUND (DevTobis#37)

The sweep expired any stale intent whose settleIntent threw, so an RPC
outage or a failed book update after a successful transaction wrote the
transaction off and flagged its line or pledge failed. Expiry now needs a
NOT_FOUND answer on the same pass; throws leave the intent pending for
the next sweep.
@DevTobis
DevTobis merged commit 33a5aa3 into DevTobis:main Oct 23, 2026
4 checks passed
DevTobis added a commit to manchesternews98-jpg/ballast that referenced this pull request Oct 23, 2026
The sweep claimed the intent as expired and then applied the failure outside a
transaction, so a crash in between left it expired with its line or pledge still
pending and no later sweep revisited it (same class as DevTobis#36). Do both in one
transaction, as settle does, and count a rolled-back expiry as an error so the
next sweep retries it.

Drops the rest of this branch: the settle path is already atomic on main (DevTobis#1074)
and expiry on NOT_FOUND only is covered by DevTobis#1107.
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.

Sweep writes off a transaction that succeeded when the RPC errors or bookkeeping fails

2 participants