Skip to content

fix: spark send and exit follow-ups - #1898

Merged
ovitrif merged 1 commit into
masterfrom
fix/spark-send-and-exit-follow-ups
Nov 12, 2026
Merged

ovitrif merged 1 commit into
masterfrom
fix/spark-send-and-exit-follow-ups

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes three Spark points deferred from #1892 and #1893:

  • Stale fee ask during a Redo hold (fixes bug: spark exit fee ask stays up during a redo hold the held funding paid #1894). A Redo rebuild that the held funding paid for now moves the exit to Running and drops the fee ask, whatever the old shortfall said. A later build that comes up short asks again.
  • Overlapping Spark sends of one invoice (fixes bug: overlapping spark sends of one invoice both go out #1895). A second Spark send of a hash Spark already holds is refused at admission, and so is one Spark recorded since the send's checks. Spark doesn't refuse a repeat; the node rail still counts its own sends, since LDK refuses repeats.
  • Failed send locks out a pre-restore invoice (fixes bug: a failed send locks out a pre-restore invoice #1896). When the operators show a FAILED Lightning send, the invoice now counts as unsent: the SDK reports FAILED only once every attempt at the hash was returned. A retry after the app's own failed attempt pays instead of being refused until expiry. The seedRestoredSendHashes KDoc and the new log line are updated to match.

No changelog fragment: these change Spark behaviour that hasn't shipped in a release yet.

QA Notes

  • New unit tests, each failing without its fix:
    • SparkExitDriverTest: a redo hold built from the held funding drops the fee ask the top-up was for
    • LightningRepoTest: of two overlapping spark sends of one invoice only one reaches spark; a spark send of an invoice spark recorded since its checks is refused at submission
    • SparkRepoTest: a pre-restore invoice retries on both rails after its spark send failed (replaces the test that expected a refusal)
  • Ran detekt, the compile and the unit tests of the three touched classes; all pass.
  • No UI change, so no media.

A Redo hold whose build the held funding paid drops the fee ask. A second overlapping Spark send of one invoice is refused at admission. A failed operator status no longer locks out a pre-restore invoice.
@ovitrif ovitrif self-assigned this Nov 12, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T17:26:54.737320Z 8ee7828 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge, with no actionable issues found.

Summary

This PR fixes three Spark send and exit follow-ups:

  • Only one overlapping Spark send of an invoice gets submitted.
  • A failed Spark send no longer blocks a pre-restore invoice retry.
  • A built Redo hold clears its outdated fee request.

No actionable issues were found. The added tests cover the changed decisions. No tests were run during this review.

Reviews (1) · Last reviewed commit: "fix: spark send and exit follow-ups" · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 8ee7828 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Closes the three Spark follow-ups: a Redo hold that the held funding built goes back to Running with no fee ask, a second Spark send of one invoice is refused at admission, and an operator FAILED status lets a pre-restore invoice retry. Reviewed 8ee7828, full tier, static: per this repo's rule for auto reviews the branch was not built here, so this rests on the code and CI.

What I checked, and 5 candidates I ruled out

Read: the full diff, plus LightningRepo.payInvoice / payInvoiceWithLdk / admitSend / releaseSend, SparkRepo.payInvoice / lightningSend / refuseUnverifiedRestoredInvoice / isUnsentPerOperators / hasRecordedSendSince, SparkExitDriver.tick / buildOnceFunded / build / holdingRedo / askForFunding, and SparkExitRecord.fundingShortfallSats.
Upstream checked: fetch_lightning_send_status in breez/spark-sdk at 0.28.3 (the version libs.versions.toml pins) returns Failed only when the preimage requests are non-empty, none has a preimage or PreimageShared, none is WaitingForPreimage, and none is Unknown (that one is an error, which isUnsentPerOperators treats as "can't be asked"). So FAILED really does mean every attempt at the hash was Returned, which is what the new KDoc says.
CI: build-and-test, build-local, lint and Greptile green; the e2e-tests-local shards and compose-ui were still running when I posted.

Ruled out

  • Spark refusal leaves the rail record wrong: the throw happens inside authorizeSend with isRefused = true and isAdmitted = false, so onFailure leaves sendRails alone and the finally does not release a hold it never took.
  • A sequential retry after a failed Spark send is now refused: sparkRecordsBefore is read at the start of the retry, after the first attempt was recorded, so hasRecordedSendSince stays false; only a send recorded after the checks refuses it.
  • Overlap already covered by sendsInFlight: that guard closes only while sparkService.send runs. A second send whose checks passed before the first was recorded and whose submission comes after the first returned slips past it; the new hasRecordedSendSince term in the Spark admission closes that window, and the held-by-Spark term closes the window before putIfAbsent.
  • Held Redo build stuck in Running: isRebuilding stays true and lastBuildAt is set, so the next tick takes the Running if record.isRebuilding branch and rebuilds at REBUILD_INTERVAL; a later build that comes up short goes through askForFunding and shows NeedsFunding again.
  • FAILED opening a Spark-address invoice: with prefersSpark on, an invoice carrying the Spark address hint is still refused after FAILED, since a direct transfer is invisible to the operators. That is narrower than the description's wording, but it is the safe side.

Merge confidence: 4/5, no findings and each fix has a test, but the e2e shards were still running and the branch was reviewed without a local build.

Reviewer model: claude-opus-5-5
Reasoning effort: 15 (runtime setting of this run)

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two independent reviews, nothing blocking a merge.

worth doing, does not block

  • Funding notification outlives a Redo hold that turns Running on a later tick (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:397-399). The PR drops the fee ask on screen and in App Status, but on some paths the posted SparkExitAlert.Funding notification stays up after the exit moves to Running. The notification is only withdrawn in SparkExitRepo.updateAlerts, through SparkExitAlerts.isFundingAskWithdrawn (SparkExitWorker.kt:397-399). That check needs previous.isUnverifiedAsk. driveWhileFunding clears isUnverifiedAsk on the Redo tick (SparkExitDriver.kt:551), so the withdrawal fires only when the held build runs in that same tick (buildOnceFunded reaches build when isRebuildDue). The new isBuilt hold can instead move the exit to Running on a later tick. That happens in three cases: - the Redo tick finds the rebuild not due, within REBUILD_INTERVAL of the last build; - the Redo tick's prepare is empty, so the hold keeps NeedsFunding; - the Redo tick's first build comes up short. Then previous.isUnverifiedAsk is already false, and a notification asking for the top-up stays in the shade while the screen shows Running. This predates the branch: the old hold-end adoption made the same NeedsFunding to Running move. The PR improves the common same-tick case. I found this by reading the code; I did not reproduce it in a test. A small fix would treat previous.phase is NeedsFunding && previous.isRedoRebuild && record.phase == Running with no new funding as a withdrawn ask. Another would keep a flag for the ask through the Redo.
  • Settled competing sends can leave the refused caller pending (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1538-1543)

nits

  • New redo-hold test never passes held funding to recover (app/src/test/java/to/bitkit/repositories/SparkExitDriverTest.kt:1906-1925)

@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: CI is green, @coreyphillips approved this head and every thread is answered. His non-blocking points go in a follow-up PR: #1899 (the funding notification after a Redo turns Running, plus the hold tests) and #1900 (a refused overlapping send stays pending).

@ovitrif
ovitrif merged commit db3b1b2 into master Nov 12, 2026
24 checks passed
@ovitrif
ovitrif deleted the fix/spark-send-and-exit-follow-ups branch November 12, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants