Repository navigation
fix: spark exit alert and pending overlapping send - #1903
Conversation
A Redo exit that goes from NeedsFunding to Running on its held funding withdraws the funding notification. A Spark send refused for a competing send of its invoice returns that send's outcome instead of staying pending.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] This PR appears safe to merge; no actionable issues were found. SummaryFixes two Spark cases:
Adds tests for completed, failed, and pending sends, plus held-funding builds, failed-only builds, and a later build that needs more funding. Reviews (1) · Last reviewed commit: "fix: spark exit alert and pending overla..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27c2506c30
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
coreyphillips
left a comment
There was a problem hiding this comment.
Two independent reviews.
worth doing, does not block
- Same-tick Redo on held funding still leaves a non-unverified fee ask posted (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:400-402)
- Refused send can report a stale FAILED Spark row while another send is live (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1637-1644)
the reviewers disagree, your call
- A live overlapping retry can be reported as failed (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1637-1642)
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Withdraws the funding notification when a Redo exit moves from NeedsFunding to Running on the funding it already holds, and settles a Spark send refused for an overlapping send from that send's listed outcome instead of leaving it pending. Reviewed 27c2506, 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 4 candidates I ruled out
Read: the full diff, plus LightningRepo's Spark branch of payInvoice (authorizeSend, admitSend, the onFailure rail bookkeeping), SparkRepo.payInvoice / lightningSend / listedLightningSend / hasRecordedSendSince / uncertainSendHashes, SparkExitRepo's alert block and SparkExitDriver's Redo hold paths.
CI: build-and-test, build-local, compose-ui, detekt, lint and Greptile green; the e2e-tests-local shards were still running when I posted.
Ruled out
- A refused send reported as paid while the competing send is still in flight:
lightningSendreturnsFound(PENDING)for any hash in the uncertain set, and the competing send writesaddSparkUncertainSendbeforesparkService.send, so an unsettled overlap maps tonulland keeps the originalPaymentPendingException. - An earlier attempt's FAILED row taken as the competing send's outcome: a FAILED row is reported only when the hash is not uncertain; the competing send stays uncertain until its call returns, so FAILED here is that send's own result. The failure is a
SendRefused, which the service-leg path andQuickPayRepoalready treat as nothing sent, true in that case. - Notification withdrawn while new funding is still needed: the new term requires
record.funding == previous.fundingand the move to Running, so a top-up (which appends tofundinginSparkExitDriver) keeps the ask, as the newSparkExitAlertsTestcases pin. - Non-Redo ask withdrawn: gated on
previous.isRedoRebuild; the unverified-ask branch is unchanged.
Merge confidence: 4/5, no findings and each change 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)
… is live A Redo keeps a flag for its funding ask, so the notification is withdrawn on the Redo's own tick too. A refused overlapping send reads a failed Spark row as its outcome only when no send of the invoice is in flight or admitted on either rail and no node send was recorded since its checks.
|
Fixed all three points from the last review in 8bf1a0d: the Redo funding ask is now withdrawn on the Redo tick too, and a refused overlapping send trusts a failed Spark row only when no other send of the invoice is live. Re-review is needed only because of this push: https://github.com/synonymdev/bitkit-android/compare/27c2506c3..8bf1a0de3 |
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 1 new commit (8bf1a0d). 1 blocking finding the reviewers disagree about.
addressed
- Same-tick Redo on held funding still leaves a non-unverified fee ask posted (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:400-402). Fixed:
driveWhileFunding's Redo branch now setsisRedoAsk(SparkExitDriver.kt:556), andisFundingAskWithdrawnreads it on either record (SparkExitWorker.kt:401-405).adoptand theholdingRedocopy both keep the flag, so the Redo's own tick seesrecord.isRedoAsk. Every ask that reaches that branch is covered, fee-bump asks and asks that came back included. I traced this by reading the code. The new testa redo on a fee ask built from the held funding that tick withdraws the askstarts from a plain NeedsFunding record. I could not run it because the private packages don't resolve here.
still open
- Refused send can report a stale FAILED Spark row while another send is live (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1637-1644).
settledSparkSendOutcometakessparkRepo.lightningSend(hash)'s FAILED as the outcome of the invoice.lightningSenddoes not look atsendsInFlightor at node sends.earlierLightningSenddoes: it treats a send in flight or recorded since as pending even over a failed row (SparkRepo.kt:1399-1436). Two reachable cases: 1. Spark send B failed and was recorded after this call's mark, and a retry C over the node is now admitted. This send is refused because LDK holds the key inadmitSend.isOverlappedis true because of B, so it returnsSendRefused("Spark's earlier send of it failed")while C can still pay. 2. A Spark retry B is in flight over an older FAILED row. BetweensendRecordedAtbeing set (SparkRepo.kt:546) and theaddSparkUncertainSendwrite (550),lightningSendreturns FAILED, not PENDING. The window is two DataStore writes. Callers readSendRefusedas "nothing left the wallet": -failLightningPayment(hash, error)drops the Paykit proofs for the hash. - QuickPay classifies the send asPRE_DISPATCH_REJECTION. - The send screen shows payment failed. Before this change the refusal stayed pending, and the live send's event resolved it correctly. I found this by reading the code and did not reproduce it. Both cases need overlapping attempts, so it is unlikely in practice. A COMPLETED row is safe to return as is. A suggested guard for FAILED: trust it only when no send of the key is admitted on either rail (admittedSends[key] == null) and no node send was recorded since the checks (ldkSendRecordedAt[key] <= ldkRecordsBefore). Codex still sees it: LightningRepo.kt:1653-1655 checks current Spark activity only after reading the row, missing a retry that completes during that read. I paused a FAILED lookup, let the competing retry succeed and release admission, then resumed the lookup: the refused caller still received SendRefused. - A live overlapping retry can be reported as failed (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1637-1642). A stale failed attempt can produce a final failure while a competing retry is still live.
SparkRepo.payInvoicerecords the retry before its suspending journal writes, butlightningSendignoressendsInFlightand can still return the olderFAILEDrow. This branch converts that row intoSendRefused, so the caller shows failure even though the retry can pay. I confirmed this in a temporary coroutine reproduction using the unchanged methods: pause the competing retry ataddSparkSendHash, resume the overlapping call after its checks, then release the retry. The overlapping call returnedSendRefusedand the retry succeeded. The same interleaving before this commit returnedPaymentPendingException. Codex still sees it: The original journal-write pause now returns PaymentPendingException at LightningRepo.kt:1647. The reproduced variant where the retry completes during the lookup still reports failure for a paid invoice, leaving a narrower, non-blocking race.
new since the last review
worth doing, does not block
- A Redo rebuild's own short-build fee ask is no longer withdrawn (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:401-405)
- A competing Spark send that ends during the row read can still read as failed (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1643-1655)
- Later Redo funding asks no longer dismiss their notifications (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:401-404)
|
Pushed 3871825 for the re-review's three threads:
Re-review is needed only because of this push: 8bf1a0d...3871825 |
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 1 new commit (3871825). Nothing blocking remains.
addressed
- Refused send can report a stale FAILED Spark row while another send is live (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1637-1644). Fixed: Case 1:
isSendLive(LightningRepo.kt:1658-1660) checksadmittedSends[key]andldkSendRecordedAt[key] > ldkRecordsBefore, and now runs both before and after the read (1644, 1647). An admitted or recorded node retry therefore keeps the FAILED row pending. Case 2:sendsInFlight.putIfAbsent(SparkRepo.kt:542) runs beforesendRecordedAtis set (546), so a retry is already in flight during the DataStore window. I traced both cases; I could not run the tests because the private packages don't resolve offline. - A live overlapping retry can be reported as failed (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1637-1642). Fixed: A retry paused at
addSparkSendHash(SparkRepo.kt:547) is already insendsInFlight(542), soisSendLivereturns true.settledSparkSendOutcomethen returns null at LightningRepo.kt:1652, and the caller getsPaymentPendingExceptionagain. The in-flight test in LightningRepoTest covers this (isSendInFlightstubbed true over a FAILED row). Traced, not run. - A Redo rebuild's own short-build fee ask is no longer withdrawn (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:401-405). Fixed:
askForFundingnow setsisRedoAskfromrecord.isRedoRebuild(SparkExitDriver.kt:763-766), andisFundingAskWithdrawnhas theprevious.isRedoRebuildterm again (SparkExitWorker.kt:402). I traced the check path:rebuild(isRedoRebuild = true)(630), then a short build.tickkeeps the flag while NeedsFunding (139). The later build at 208 then runs Running on the same funding, so the predicate is true. The 1931 assertion is back. - Later Redo funding asks no longer dismiss their notifications (app/src/main/java/to/bitkit/repositories/SparkExitWorker.kt:401-404). Fixed:
holdingRedoreturns a hold only whileisRedoRebuildis true (SparkExitDriver.kt:387). A later short build in the hold therefore reachesaskForFundingwith that flag set, and the ask is marked as a Redo ask (765). The predicate also acceptsprevious.isRedoRebuild. The new test at SparkExitDriverTest.kt:1984-2011 takes the hold through a short build and then a build on the held funding, and asserts the withdrawal. Traced, not run.
still open
- A competing Spark send that ends during the row read can still read as failed (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1643-1655).
settledSparkSendOutcomechecksisSendLiveonly afterlightningSendreturns, so a competing send that finishes during that read is not seen as live. I did not confirm this; it depends on whether the Breez SDK lists a send's row while itssendcall is still running. The interleaving, for a refused call R and a Spark send B that is insparkService.send: 1. R'slistPaymentsstill shows an older FAILED row because B's row isn't listed yet. 2. B returns, which clearssendsInFlight(SparkRepo.kt:564) and the uncertain marker (584). 3. B'sLightningRepo.payInvoicecallsreleaseSend. 4. R then readsuncertainSendHashesandisSendLive(LightningRepo.kt:1653), and both now say nothing is live. R returnsSendRefusedwhile B paid the invoice. The window is narrower than the earlier points: B has to finish its send, a DataStore write and its release between R's list read and R's DataStore read. The author's reply covers a retry that starts during the read, not one that ends during it. Elsewhere this file reads liveness before the listing as well as after (inFlightBeforeinearlierNodeSendandkeepLdkSendHashes). Doing the same here would close the gap: takeisSendLiveand asendRecordMark()beforelightningSend, and treat a Spark send recorded since that mark as live. Codex still sees it: LightningRepo.kt:1644-1645 still samples liveness before taking the record mark. With an earlier overlap already recorded, an extracted-method reproduction started another retry between those reads and ended it during the row read: the current ordering returnedSendRefused, while taking the mark first kept it pending.
new since the last review
worth doing, does not block
- Liveness is read before the Spark record mark, leaving a cross-thread gap (app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1644-1645)
|
Merging: approved on this head, required checks green, all threads replied and resolved; the remaining non-blocking point is tracked in #1908. |
Description
Fixes the two Spark points deferred from #1898:
It also adds the #1898 hold tests @coreyphillips asked for: a prepare whose funding the held inputs pay, the failed-only branch, and a later short build asking again.
No changelog fragment, since this changes Spark behaviour that hasn't shipped in a release yet.
QA Notes
SparkExitAlertsTest: a Redo ask held through is withdrawn; a top-up and a non-Redo ask are notSparkExitDriverTest: the held-funding hold uses the held input, drops the ask and asks again on a later short build; the failed-only branch moves to RunningLightningRepoTest: a refused overlapping send returns the competing send's completed or failed outcome; still pending otherwisejust compile,just testandjust lint; all pass.