Repository navigation
Conversation
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] The change is limited to Spark payment refusals and their retry path. The PR appears safe to merge, with a non-blocking gap in tests for failed cache writes. Findings
SummaryThis PR makes cleanup of an unsent Spark payment use one cache write and preserves the original refusal when that write fails.
Reviews (1) · Last reviewed commit: "fix: keep spark refusals when cleanup fa..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Makes the rollback of a Spark send refused before it went out a single CacheStore write (hold, attempt id, hash, expiry and, under a new key, the attempt), drops the in-memory hold only after that write lands, and makes the rollback best effort so the refusal reaches the caller. Reviewed 986fe08b, light tier on a payments path, files read whole.
Build skipped: Bitkit Android PR branches are not built here (Gradle would run the branch's code with a token in its environment), so this review is reasoned from the code and from CI. CI was still running at review time.
Merge confidence: 4/5, no findings, but CI had not finished and the change was not built or run here.
What I checked, and 4 candidates I ruled out
Read in full: SparkRepo.payInvoice through settleSentResult, bestEffort, sendHold; CacheStore Spark send writers (addSparkSendHash, removeSparkSendHash, addSparkUncertainSend, removeSparkUncertainSend, setSparkSendAttempt, dropSparkUnsentSend).
Call sites traced: dropUnsentSend (deadline/exit check inside spending, expired invoice, short balance); restoreSparkSendAttempt has no remaining callers in app/.
Ruled out
- Field parity with the old three writes:
dropSparkUnsentSendclearssparkUncertainSends,sparkSendAttemptIds,sparkSendHashesandsparkSendExpiries, the same fieldsremoveSparkUncertainSendandremoveSparkSendHashcleared; the attempt branch matches the oldrestoreSparkSendAttemptgate (!isReusedKey), andrestoresAttempt = falseleaves the map untouched. - Reordering the in-memory removal after the write: on a failed write the cache still holds the hold and attempt id written for this attempt, so keeping
uncertainSendsin step with it is consistent with the stated intent, not a leak. - Deadline path: a failing rollback inside
spending'sonFailureused to replacePaymentDeadlineExpiredwith the storage error; it is now logged and the deadline error is rethrown. - Cancellation swallowed by
bestEffort: it goes throughrunSuspendCatching, the same wrapper the settlement path already uses for these writes.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the runtime reports no named effort level for this run)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 986fe08.
Low: A failed rollback can still block retrying the same Lightning invoice. If Spark refuses a fresh send for insufficient funds and the cleanup write fails, SparkRepo.kt:663 preserves the refusal while leaving the saved hold in place. The Paykit send screen offers a retry. If storage recovers and channel liquidity is now sufficient, SparkRepo.kt:2037 still reports the invoice as pending with an empty Spark payment list, so LightningRepo.kt:1818 stops before sending. This can block the invoice until expiry despite the retry promise in changelog.d/next/2060.fixed.md:1. Extend the refusal test to fail the cleanup write against a real journal, restore writes, and retry the same invoice through the channel path.
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
@pwltr Changed the changelog in 5c7ba4c instead: when the drop itself fails, the journal on disk still holds the send, and a later reader can't tell it never left, so it stays held until its invoice expires, as any unknown outcome does. Freeing it there would risk paying twice. The entry now promises only that the refusal shows. 7811b5f also keeps a Spark withdrawal's refusal (short balance, fee rise, late deadline or exit) when closing its journal fails, with tests for the first two. |
A Spark send refused before anything went out now drops its journal in one atomic CacheStore write, so a failed write leaves the whole send held instead of a hash without its hold that blocks retries until the invoice expires. The cleanup is best effort, so the refusal (expired invoice, short balance, late deadline or exit) still reaches the caller. Verified: SparkRepoTest (new test fails on master), CacheStoreTest, QuickPayRepoTest, just lint
A store that fails its write leaves the whole held send in place, and a successful drop takes exactly one write. Verified: CacheStoreTest, just lint
A cleanup write that fails keeps the whole send held until its invoice expires, so the entry no longer promises an immediate retry. Verified: none (changelog text only)
A withdrawal Spark refuses before anything left (short balance, fee rise, late deadline or exit) now reaches the caller even when closing its journal fails, so the refused leg's proof and list are released. Verified: SparkRepoTest (short-balance test fails before the change), just lint
The late authorization refusal from #2053 now rolls back through dropSparkUnsentSend, which is already best effort. Verified: SparkRepoTest, CacheStoreTest, LightningRepoTest, just lint
7811b5f to
d7089a4
Compare
pwltr
left a comment
There was a problem hiding this comment.
Reviewed d7089a4. The rebase onto master brings #2053's late authorization refusal under the same atomic, best-effort rollback, and its tests now check that a failing write still returns the refusal. Nothing else changed. No issues found.
Review details
General review
Model: Claude Opus 5.5
Reasoning effort: high
Closes #2060
Description
CacheStorewrites (hold, hash, attempt); if a later one failed, the hash stayed without its hold, so every retry on Spark or the node saw a pending send and failed withPaymentPendingException.CacheStore.dropSparkUnsentSendnow drops the hold, the hash and, under a new key, the attempt in oneupdateDatawrite, replacingrestoreSparkSendAttempt. A failed write leaves the whole send held, as a send cut off mid-way is, and the in-memory hold is dropped only after the write succeeds.SparkRepo.payInvoice'sdropUnsentSendis now best effort, so every pre-send refusal (expired invoice, short balance, late deadline or exit) reaches the caller even when its cleanup write fails, and QuickPay falls back instead of treating it as an unknown outcome.SparkRepo.withdrawcloses its journal best effort on its refusals before sending (short balance, fee rise, late deadline or exit), so those refusals reach the caller too;clearJournalwas already one write.dropUnsentSend, so it is covered once both are on master.LightningService.swiftis threeUserDefaults.setcalls, which neither throw nor fail, and its expired-invoice, insufficient-funds and fee refusals throw before anything is recorded, so a cleanup failure can't replace them.Design
N/A — no UI changes.
Preview
N/A — no user-visible changes.
QA Notes
Setup
N/A — no device testing required: the bug needs a storage write to fail between two others, which unit tests reach and a device can't.
Journeys
N/A — no user-visible behaviour change.
Manual Tests
N/A
Automated Checks
SparkRepoTest.kt— a short-balance refusal stays a refusal when dropping the unsent send failsSparkRepoTest.kt— a withdrawal refused for its balance or a fee rise stays refused when closing its journal failsCacheStoreTest.kt— dropping an unsent send clears its hold and hash and keeps a reused attemptCacheStoreTest.kt— the drop is one store write, and a failed write leaves the whole held send in placeSparkRepoTest.ktandCacheStoreTest.kt— the rollback is checked throughdropSparkUnsentSendEvidence
removeSparkSendHashfailing), fails on master: theIOExceptionreplacesSparkError.SendRefused.SparkRepoTest,CacheStoreTest,QuickPayRepoTestandjust lint.Gaps
SparkRepoTestmocksCacheStore, so the held state it leaves is covered by theCacheStoreTestcase above instead.Models used
Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)