Repository navigation
fix: keep spark settlement going on cache errors - #2015
Conversation
Verified: SparkRepoTest, LightningRepoTest and BackupRepoTest pass; each new test fails without its fix.
Verified: just compile, just test and just lint pass.
Verified: LightningRepoTest and detekt pass; the new test fails without the trim guard.
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 fragment only).
|
Linked #2016 as the 3.2.0 tracking issue for this PR and moved the milestone from this PR to that issue, since the release milestone tracks issues. |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Follow-up to #2014: makes the Spark own-failure marker writes best-effort, reads Spark's listing readiness after the listing and re-reads an unreadable list before sending, keeps a node send recorded during a Spark check or the listing trim by re-checking inside the cache write, and drops attempt ids from the restore log. Reviewed eb022e3, full tier, static: per the Bitkit track rule this branch was not built here, so the review rests on the code and CI.
What I checked, and 5 candidates I ruled out
Read in full: SparkRepo.payInvoice, lightningSend, listedLightningSend, canListPayments, refuseUnverifiedRestoredInvoice, isUnsentPerOperators, recordActivity, the sync refresh around markUnsavedOwnFailure; LightningRepo.earlierNodeSend, listPaymentsKeepingSendHashes, keepLdkSendHashes, payInvoiceWithLdk's record/add order; CacheStore.trimLdkSendHashes, removeLdkSendHash, addLdkSendHash; runSuspendCatching (rethrows CancellationException).
Ruled out
canListread after the listing lets an unsynced list pass: whenlightningSendreturnedUnavailablebefore the first sync and the sync lands beforecanListis read, theUnavailablebranch now re-readslistPayments(), which is the synced list at that point, so aCOMPLETED/PENDINGrow still skips or refuses. A sync landing aftercanListonly makesrefuseUnverifiedRestoredInvoicestricter.- Unavailable branch now sends after a synced list failed once: intended per the body; the re-read must succeed and its
latestSendis checked beforeonBeforeSend, and a second failure still throwsSendRefused. removeLdkSendHashdrops a hash recorded right after its transform:payInvoiceWithLdksetsldkSendRecordedAtbeforeaddLdkSendHash, and DataStore serialises transforms, so either the transform sees the record and keeps the hash, or the add lands after the removal; the secondisRetried()then returnsPending.- Swallowed marker write loses an own failure in-process:
unsavedPaymentsstill carries the id, so the next refresh retries the row; only the cross-restart detail is lost, as the KDoc states. A failed remove leaves a stale id whose replay hits theSUCCEEDEDguard or re-saves the same failed row. ldkSendRecordedAtkept for failed hashes: only entries newer thanrecordsBeforesurvive, i.e. sends recorded during the trim, which must keep it.
CI: build-and-test, build-local, lint and ui-tests still pending at review time.
Merge confidence: 4/5, no findings, but CI had not finished and the branch was not built here.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
jvsena42
left a comment
There was a problem hiding this comment.
Approving eb022e3. Code scan: no HIGH, MEDIUM or LOW. CI is green.
- No ordering of a node send against the Spark check or the listing trim drops a hash while that node send is in flight or newly recorded.
- The own-failure marker writes are now best-effort and use
runSuspendCatching, and no hold or send decision reads the marker. - The second listing read before a send still refuses when it fails again.
Device gate: the PR's cases are unit-tested races and storage failures, so I ran ordinary Spark sends on the PR build as a regression check (local bitkit-docker spark stack, Gate_Throwaway).
| Case | Result |
|---|---|
| R1. Send that succeeds, ×3 | ✅ one Sent Spark payment, one PaymentSuccessful, Sent sheet, no PaymentFailed |
| R2. Send that fails right away (receiver offline) | ✅ one Failed sheet, one PaymentFailed, row Failed |
| R3. Hold invoice settled while open / failed while open | ✅ / ✅, one event each, rows Sent / Failed |
R4. Send right after a cold start, and from a lightning: URI after a cold start |
✅ both paid. Spark's first sync lands about 2 s after launch, before Confirm can be reached, so the "before the first sync" branch can't be driven from the UI. |
Device gate: R1–R4 ✅ at eb022e3. perf: swipe to SSP "payment initiated" median 1.34 s (3 samples), within the 1.3–2.7 s range measured on #2007 for base and PR; not performance-relevant otherwise.
Reviewer model: claude-fable-5-2 (primary review), claude-opus-5-5 (coordinator), claude-sonnet-5-5 (device driver)
Reasoning effort: Not exposed
|
Two items that predate this PR, for a follow-up. Neither blocks it.
|
@jvsena42 thanks, both are tracked for 3.2.0:
|
Closes #2016
Refs: #2014
Description
Follow-up to the review on #2014: #2014 (review)
payInvoicereads it once, after the listing, as before fix: close spark retry hold gaps #2014. A listing that couldn't be read is read again before the send, so a synced list that failed once no longer refuses outright, and a first sync landing after the listing doesn't either.sparkUnsavedOwnFailuresandsparkSendAttemptIds.earlierNodeSendand the listing trim released it from a snapshot taken before the write. Both now check in-flight and newly recorded node sends inside the cache write, andearlierNodeSendagain after it.Out of Scope
Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
N/A — no device testing required: each fix is a race or storage-failure path covered by unit tests.
Journeys
N/A — no user-visible behaviour change.
Manual Tests
N/A
Automated Checks
SparkRepoTest.kt— a pre-restore retry is sent when Spark's first sync lands during its listing and the operators show it failedSparkRepoTest.kt— a send that returns failed still reports it when the cache can't keep its unsaved failureSparkRepoTest.kt— a sync whose own-failure cleanup fails still ends a paid holdLightningRepoTest.kt— a node send recorded while a Spark check releases the invoice keeps its hashLightningRepoTest.kt— a node send recorded while the listing trims its failed attempt keeps its hashCacheStoreTest.kt— a node send listed failed stays kept when recorded again before the trim writesEvidence
just compile,just testandjust lintpass; the last commit, which only adds a test, ranLightningRepoTest.ktand detekt.SparkRepoTest.ktandLightningRepoTest.kttest fails with its fix reverted.Gaps
None.
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)gemini-4-neon-high(reasoning:Not exposed)The review runner records only the model id, whose
highsuffix names its tier; it exposes no separate reasoning setting.