Repository navigation
fix: spark retry follow-ups - #2007
Conversation
Each Spark send passes a fresh idempotency key, which Spark keeps as the attempt's payment id, so only that attempt's outcome ends its hold. Verified: SparkRepoTest and CacheStoreTest pass
Also splits the listed-send report out of the settle step and drops comments that still described dating failures. Verified: just compile, just test and just lint pass
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. |
Verified: none (changelog text only)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af7fa265c2
ℹ️ 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). |
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 627b6d5.
Medium candidate: A history read failure can let Spark receive a second submission for an invoice already paid by the same wallet. This can happen when another device paid the still-valid invoice and the retrying device has no local hold. SparkRepo.kt:561 can continue to SparkRepo.kt:605 with a fresh key. Please verify whether Spark SDK 0.28.3 rejects the same invoice under two distinct keys on both the direct Spark and SSP routes. The second submission is reachable, and whether it can debit the wallet again depends on the SDK.
Startup recovery uses the saved hold as a proxy for whether someone needs the outcome.
Low: If the app is interrupted before Spark records a send, reopening the same invoice can leave its pending screen stuck. The caller starts tracking it again, but SparkRepo.kt:711 suppresses the expiry failure. An automatic allowance payment can also remain open because its recovery lookup finds no terminal status for the released hash.
Low candidate: Startup can announce a historical payment if the SDK emits its terminal callback after reconnect. SparkRepo.kt:2084 discards the marker before emitting when the callback comes first, and SparkRepo.kt:746 leaves the payment ID unclaimed when listing comes first. Verify whether the pinned SDK can deliver that callback after reconnect.
Activity needs attempt ownership through the write and any retry of the write.
Low: SparkRepo.kt:743 can write an earlier failure over a newer retry's pending Activity row if the retry enters during the history reread. The event guard runs after the write. Assert the row stays pending in the existing retry interleaving fixture.
Low: If saving a retry's own failure hits a transient Activity storage error, the retry queue at SparkRepo.kt:2119 and SparkRepo.kt:2168 keeps the payment ID but loses its ownership for the refresh at SparkRepo.kt:1462. An older failed row can then keep its original fee and timestamp after storage recovers.
Low: Two existing tests can pass without exercising attempt-ID settlement. Use the submitted key in SparkRepoTest.kt:4167 and assert the poll releases the hold before the success callback. In SparkRepoTest.kt:4734, use an unexpired invoice and give the late failure at SparkRepoTest.kt:4746 the submitted key so expiry cannot satisfy the assertion.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Binds each Spark send hold to the idempotency key it passed, so only that attempt's own outcome ends the hold early, and stops reporting outcomes at launch for sends that settled while the app was closed. Reviewed 627b6d5, full tier, static.
What I checked, and 5 candidates I ruled out
Build: not built here. The PR-run gate could not confirm the author's permission and failed closed, so this review is reasoned from the code, the Spark SDK source and CI.
Read: the whole diff of SparkRepo.kt and CacheStore.kt, plus payInvoice, settleUncertainSend, trySettleUncertainSend, takeUncertainSend, restoreUncertainSends, onPayment, recordActivity and SparkService.send around it; the new and changed tests in SparkRepoTest.kt.
SDK contract: checked against breez/spark-sdk at 0.28.3, the version pinned in libs.versions.toml. On the SSP route pay_and_persist_lightning_invoice passes the key as the transfer id and Payment::from_lightning sets Payment.id to it. On the Spark route the same id goes to transfer(...), and the payment is built from that transfer. TransferId::from_str takes a UUID, which UUID.randomUUID() gives.
CI: unit tests, compose UI tests, lint and detekt green. Five e2e shards still running.
Ruled out
- A start in the middle of the process marks a live hold as restored and mutes its outcome:
restoreUncertainSends(atStart = true)marks a hash only whenputIfAbsentadded it. An in-process hold is already inuncertainSends, and one inside the send call is skipped throughsendsInFlight. - A retry starts while an earlier attempt's hold is still in memory, so the earlier hold outlives the cache entry:
payInvoicethrowsPaymentPendingExceptionwhilelightningSendreads the hash as held, so a retry only starts after the hold has ended. - A hold saved by an older build, with no attempt id, is released by any failure:
hasOwnFailurereturns false on a null id, andisHeldFromtreats a null id as different from every failure id. It waits for a paid listing or expiry, as the description says. - Own failure reported twice, by the event inside the send call and by the call's result: the event takes the
isHeldFrombranch while the send is in flight and returns before it reports anything. The result then reports once throughreportedSendIds. wipeleaves restored-at-start state for the next wallet:restoredAtStart.clear()is inwipe.
Merge confidence: 4/5, no findings but not built here, the e2e shards are still running, and the process-kill cases are only covered by unit tests.
jvsena42
left a comment
There was a problem hiding this comment.
Code scan at 627b6d5: no HIGH or MEDIUM. One LOW is inline. I reviewed this as a funds change.
What I checked and found clean:
- Idempotency key in the SDK (breez spark-sdk 0.28.3, pinned at
libs.versions.toml:27).- The key becomes the transfer id on both the Spark and SSP routes (
bolt11.rs:76-80,wallet.rs:688-709). Payment.idis that transfer id on both routes. The SDK'sidempotency_tests.rsassertspayment.id == idempotency_key.- A send that threw is resumed under the same id, and the in-call leaf retry reuses it.
- A reused key would return the stored payment, but
:587makes a new UUID per attempt.
- The key becomes the transfer id on both the Spark and SSP routes (
- No double pay. Only a FAILED payment carrying the hold's own attempt id ends the hold early (
:1575-1586). While a hold exists,lightningSendreads NotFound, Unavailable and FAILED as PENDING, so no retry starts on either rail. - The id is saved with the hold before the send call (
:594before:605), in oneupdateData. Process death on either side of the call keeps the hold bound to its id. - Upgrade. v3.1.1's
CacheStore.kthas no Spark fields, so released builds have no id-less holds.sparkSendAttemptIdsdefaults to an empty map, so old JSON deserialises. - Authorization. Between
onBeforeSend()andsparkService.send, the history read is gone and nothing replaced it. The amount is fixed inpreparedbefore the check. - Reporting. A FAILED return reports once (
reportedSendIds). The late SDK event stops at:2092. QuickPay attributes the failure because the op is already dispatched. - Cancellation. No new swallowed
CancellationException. TherunCatchingat:597wraps only non-suspending checks. - Nit, not a finding: the
payInvoiceKDoc at:526-527still lists "could not … list its payments" as aSendRefusedcause. This PR removed that refusal.
Performance-relevant: yes. The poll at :666 now skips syncWallet() once the hold has ended, and the pre-send listPayments() is gone. On device I'll measure:
syncWallet/Syncedcount for 60 s after a send that settles within 10 s (manual test 3; expect 1, not 2);- tap-to-dispatch time against master.
CI: e2e-tests-local - lightning_security and lnurl_transfer are red. They fail the same way on the unrelated feat/nfc-payments run 45390985877: the home chrome (TotalBalance) is not found after the SpendingBalanceReadyToast drag. That points to master, not this PR. They need a re-run before merge.
Device gate (partial): 627b6d5 — not run yet; pending manual tests 1-3 on the local Spark stack (hold invoice, force-stop mid-send) and the sync-count measurement. The device result will follow in a second review.
Skipped — covered by CI at 627b6d5: unit tests, lint, detekt, compose UI (green).
Also reports a send Spark never recorded at its expiry after a restart, keeps a newer retry's row from an old failure, keeps a failure's ownership through a failed activity write, and keeps Spark's callback for a hold settled while closed quiet. Verified: just compile, just test and just lint; SparkRepoTest and lint again after the last one-line change
Verified: just compile, just test and just lint pass
Addressed in fa7c56b: a send is refused while Spark's synced list can't be read, as before this PR, now ahead of the final permission check. A restored wallet still gets its own refusal first. The fix doesn't rely on how the SDK treats one invoice under two keys.
Addressed in fa7c56b: a send Spark never recorded reports its failure at expiry also after a restart, so the pending screen and an automatic allowance payment both get it. A caller asking for the invoice again also clears the launch mute.
Addressed in fa7c56b: a muted outcome claims its payment id, and a callback for a hold taken back at start claims it too, so neither order reports it. The launch test now sends the callback after the listing.
Addressed in fa7c56b: the failure counts as the attempt's own only while no newer attempt holds the invoice.
Addressed in fa7c56b: a failed write keeps the attempt's ownership until the row saves. Added a test with a failing first write.
Addressed in fa7c56b: both use the submitted key, the first asserts the poll releases the hold before the success callback, and the second uses an unexpired invoice. |
fa7c56b restores that refusal (a send is refused while Spark's synced list can't be read), so the KDoc is accurate again.
I'll re-run them on the current head before merging. |
|
In 3.2.0: it fixes Spark retry settlement from the review of #1957, which ships in 3.2.0. |
Re-ran on 2d68d2f: all e2e shards pass. The failures came from the update spending balance modal, which synonymdev/bitkit-e2e-tests#316 now dismisses; the first run had checked out e2e main before it merged. |
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 2d68d2f.
Startup recovery uses the restored-hold marker to suppress the same event that send screens and Paykit use to settle.
Low: Reopen a still-pending Spark invoice after relaunch when channels now have enough capacity. The LDK path returns the existing Spark send as pending without clearing the marker. If the send settles after the screen's one-time lookup, either the SDK callback or the synced list can suppress the completion and leave the screen pending. An automatic allowance attempt can also stay open until a later recovery pass if its startup reads see pending. See LightningRepo.kt:1726 and SparkRepo.kt:727, :765, and :2103.
Low: A matching callback can announce an old failure during startup if it arrives after the list removes the marker and before the Activity write returns. Register suppression before the write can suspend. See SparkRepo.kt:727, :761, :765, and :2103.
Low candidate: Before the first sync, the app can hand a still-valid invoice to the SDK even if the old history read would have failed. This requires an invoice already paid elsewhere, no local hold or applicable restore guard, and a pre-sync storage failure. The base used the read to date failures and could also submit when the read succeeded. Whether this newly admitted submission can debit again depends on Breez SDK 0.28.3 handling on the direct Spark and SSP routes. See SparkRepo.kt:592 and :1680.
Low: If the retry's Activity write fails and the process exits before another refresh, the earlier failed row keeps its fee and timestamp because the hold is cleared and the retry's ownership survives only in memory. The recovery test also counts the failed upsert as satisfying the assertion. Extend it to check the successfully saved row after Synced. See SparkRepo.kt:647, :2156, and :2182, and SparkRepoTest.kt:5140.
Low: The foreground restart test goes through expiry for an unlisted send, which always emits failure. It would pass if every start marked restored holds for suppression. Use a listed terminal outcome or a matching SDK callback to exercise the first-start guard. See SparkRepoTest.kt:5167 and SparkRepo.kt:730.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
|
Thanks. All five go into one follow-up PR, so this approved head stays as is:
Follow-up: the LDK path's pending answer will clear the restored-hold marker as
Follow-up: the muted outcome's id will be claimed before the write.
The refusal applies once the synced list is readable; before the first sync, master also sends without a list. The follow-up will check how 0.28.3 treats a paid invoice under a new key on both routes and refuse there too if it can debit again.
Follow-up: ownership will persist with the hold until the row saves, and the test will check the saved row after
Follow-up: the test will use a listed outcome so it exercises the first-start guard. |
|
Merging: approved on 2d68d2f and CI is green. pwltr's five Lows go to a follow-up PR; device tests 1–3 results will follow here. |
Device tests 1–3Tested 2d68d2f (the merged head), dev debug build against a local Spark stack, Android 16 emulator. Amounts are exact leaf sums, since leaf swaps fail on the local stack; no "calculated R point" error appeared.
Recordings at 2x. |
|
Post-merge notes on 2d68d2f, for the follow-up PR. Device results (emulator, local bitkit-docker
Delta review of fa7c56b and 2d68d2f: no HIGH or MEDIUM. The restart fix is complete, including Out of scope, not introduced here: the node rail has no equivalent of the new refusal. |
|
@pwltr all five Lows from #2007 (review) are fixed in #2014. For the pre-sync case, spark-sdk 0.28.3 pays an invoice again under a new key on the Spark route, so a send before the first sync is refused when the list can't be read and uses the local list's answer when it can. |
Refs: #1957
Description
Payment.idon both the Spark and SSP routes. Only a failure with that id ends the hold early; any other failure, from an earlier attempt or another device, leaves the retry pending until a paid listing or the invoice's expiry. The phone clock plays no part, so a phone clock ahead of Spark's no longer holds a send's own failure until expiry. Raised in fix: spark follow-ups #1957 (review) and fix: spark follow-ups #1957 (comment).Same-invoice Spark retries stay.
Out of Scope
CacheStore: re-recording an unchanged Spark send row wroteapp_cache.jsontwice (fix: spark follow-ups #1957 (comment)). master no longer has the row-writer fields after the retry redesign, so nothing is left to fix.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
Local Spark stack (bitkit-docker
sparkprofile) with a dev debug build using the local-stack build settings, as in #1957's device gate.Journeys
N/A — no user-visible behaviour change beyond the cases below, which need a hold invoice and process kills.
Manual Tests
Automated Checks
SparkRepoTest.kt— a send's own failure ends its hold with the phone clock 30 s ahead of Spark'sSparkRepoTest.kt— a send settled before its poll starts forces no extra wallet syncSparkRepoTest.kt— a hold that failed while the app was closed updates its row without reporting at launchSparkRepoTest.kt— a send whose call returns failed reports its failure onceSparkRepoTest.kt— a retry's own failure takes its details over an earlier attempt's failed rowSparkRepoTest.kt— a hold from an older build stays held past a listed failure until its invoice expiresSparkRepoTest.kt— a retry Spark took stays held past another attempt's failure dated 5 s before it, listed and as an event; the send's own outcomes are listed under the key it passedSparkRepoTest.kt— the send is refused while Spark's synced list can't be readSparkRepoTest.kt— a send Spark never recorded reports its failure at expiry after a restartSparkRepoTest.kt— a retry's own failure keeps its details through a failed Activity writeSparkRepoTest.kt— a cancelled send restored by a foreground restart reports at expirySparkRepoTest.kt— the launch test sends Spark's callback after the listing; a retry entering during the reread writes no failed row; the poll releases the hold before the success callbackLightningRepoTest.kt— the node test checks the Spark send with its keyEvidence
just compile,just testandjust linton 2d68d2f: all pass.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)Claude Sonnet 5.5(reasoning:high)Closes #2010