Repository navigation
fix: close spark send hold gaps - #1411
Conversation
A retry that took its hold while Spark's list was read now reads pending, so Paykit no longer reads it as the earlier attempt's failure and drops a proof it may still need. An expired send stays held until a sync after its invoice expired, as a sync from before expiry can predate the send's success. The releases after a listing skip an attempt recorded or in flight since the listing's mark, on Spark and on the node, so a send admitted meanwhile keeps its record. A Spark send refused before submission recorded nothing, so it no longer releases another send's attempt and hold of the invoice. The timestamped retry test now also retries once Spark's history can't be read. Closes #1407 Verified: ChannelFreeRailTests and the full unit suite on an iOS 26 simulator; each new test fails with its fix reverted.
Verified: both tests pass in the full unit suite on an iOS 26 simulator.
Verified: one fragment for this change in changelog.d/next.
The holds are now read before Spark's unsettled sends are checked, so a retry that takes its hold during that check reads as taken during the read. A Spark send that fails before recording its attempt no longer takes a hold, as nothing of it reached Spark. The expired-send retry test pins Spark's last sync between the expiry and the retry, so it still exercises the retry's hold. The sheet test no longer fetches rates and clears every sheet it registered. Verified: ChannelFreeRailTests, TimedSheetManagerTests and FailPendingLightningSendTests on an iOS 26 simulator.
A retry that recorded its attempt while Spark's list was read, and whose success ended its hold before the read returned, read as the earlier attempt's failure when the list showed only that failure. It now reads pending until a later list shows its result. Tests cover that retry and a Spark send that fails before recording its attempt taking no hold. The sheet test polls for the Move to Spark intro instead of waiting a fixed time. Verified: full unit suite on an iOS 26 simulator; both new tests fail with the fix reverted.
The list read takes its attempt mark first and reads a Spark send in flight at the mark, or since, as pending too, so a retry that recorded its attempt just before the mark and ended during the read no longer reads as the earlier attempt's failure. The sheet test cancels the first check as a shown sheet does instead of waiting it out, and the failed-check test asserts the send reached Spark's send call. Verified: full unit suite on an iOS 26 simulator.
The sheet test drives the manager directly, so the sheet model's own calls into it can't race the test's. Verified: ChannelFreeRailTests and TimedSheetManagerTests on an iOS 26 simulator; the new test fails with the in-flight read reverted.
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. |
|
Moved the 3.2.0 milestone off this PR: #1407, which this PR closes, already carries it, and the release milestone tracks issues. |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Closes four Spark hold gaps in LightningService: a retry recorded or held while Spark's list is read now reads pending, an expired send stays held until a sync after its expiry, the post-listing releases on both rails skip a hash live since the mark, and a send that never recorded its attempt neither releases another send's hold nor takes one. Reviewed 5a2277c, full tier, static.
What I checked, and 3 candidates I ruled out
Read in full: LightningService.send (rail branch), releaseRailAttempt, releaseLdkAttempt, attemptsLive, admitSend, settledRecordedRailSend, markRailSendUncertain, settleListedRailSends, railSyncedSinceUncertainSend, channelFreeRailPayments, settledEarlierAttempt.
Callers traced: channelFreeRailPayments from PaykitPaymentProofService.railStatus, PrivatePaykitService+Invoices, QuickPayPaymentCoordinator.reconcileRows, WalletViewModel.finishWatchSendIfRailAlreadySettled.
Build: not built. iOS does not build on Linux, and an auto review on the Bitkit track never builds the branch, so this is reasoned from the code and from CI.
CI: SwiftFormat, validate and build-local green; unit tests, integration tests and e2e still running when this was posted.
Ruled out
heldDuringReadmaking a just-finished send read pending infinishWatchSendIfRailAlreadySettled: that path ignores.pendingand still waits on the payment event, so a synthetic pending row only delays the shortcut.didRecordAttemptskippingmarkRailSendUncertainfor a send that reached Spark: it is set inbeforeSubmissionright afterrecordRailAttempt, andmarkRailSendUncertainalready returned early before then, since it requires an attempt recorded since the mark.hasSynced(after: max(startedAt, expiresAt))never settling:SparkManager.hasSyncedcompares againstlastSyncedAt, which moves forward on every successful sync, so the first sync after expiry ends the hold.
Merge confidence: 4/5, the review is static and the unit and integration runs were still pending at this head.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not carry it)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 5a2277c. LightningService.swift:2571 can report a Spark send as pending after it has already been refused before submission. The history read remembers the in-flight hash even when the send recorded no attempt and took no hold.
Low: If a private Paykit lookup overlaps that refusal for the same invoice, it treats the invoice as attempted and removes it from the cache. When that invoice is the only accepted endpoint, the payment cannot open until a fresh resolution. See PrivatePaykitService+Invoices.swift:159 and PrivatePaykitService+Payments.swift:558.
Low candidate: The same pending row can outrank a bound Quick Pay failure during recovery. The coordinator then keeps the reservation and replays Pending on reopen. This requires a separate sender, such as an automatic Allowance, to reach Spark with the same invoice during recovery. See QuickPaySpendStore.swift:433 and QuickPayPaymentCoordinator.swift:428.
Low: TimedSheetManagerTests.swift:39 writes the shared widget currency code and symbol during setup and leaves them changed after teardown. Snapshot both keys before constructing CurrencyViewModel using the helper in AppStateIsolation.swift:69.
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
All three are tracked in #1420 under 3.3.0. The pending row lasts one read, and the fix is to count an in-flight hash only once its send recorded its attempt. Merging: approved on 5a2277c with CI green, and it has to land before the 3.2.0 cut. |
Fixes #1407
This PR closes Spark send hold gaps that could let one invoice be paid twice, found by a review of #1355 before its merge and by #1407:
Description
Out of Scope
Bitkit/Services/LightningService.swift: a retry held until expiry when the phone clock runs more than 10 s ahead of Spark: bug: spark retry stays held when the phone clock runs ahead #1408.Bitkit/Services/LightningService.swift: a retry Spark dates in the same second as the earlier failure stays pending until expiry; it needs a stable attempt id: bug: same-second spark retry stays pending until expiry #1409.Bitkit/ViewModels/SparkTransferFlow.swift: a deposit shows normal speed while the early-claim fee cap is still being removed: bug: deposit shows normal speed before the fee cap is removed #1410.BitkitTests/ChannelFreeRailTests.swift: the node in-flight count test from fix: close spark retry hold gaps #1406 stays with that PR, as it needs its in-flight count.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
N/A — no device testing required: the changes are in the send bookkeeping, covered by unit tests.
Journeys
N/A — no user-visible behaviour change.
Manual Tests
N/A
Automated Checks
ChannelFreeRailTests.swift— a retry held while Spark's list is read reads pendingChannelFreeRailTests.swift— an expired send stays held until a sync after its expiryChannelFreeRailTests.swift— a Spark send refused before submission keeps another send's attempt and holdChannelFreeRailTests.swift— a retry that starts and ends while Spark's list is read reads pendingChannelFreeRailTests.swift— a retry in flight when Spark's list is read reads pending after it endsChannelFreeRailTests.swift— a Spark send failing before it records its attempt takes no holdFailPendingLightningSendTests.swift— only a pending send is failedTimedSheetManagerTests.swift— dismissing a sheet checks only the Move to Spark introChannelFreeRailTests.swift— the timestamped retry test also retries once Spark's history can't be readChannelFreeRailTests.swift— the expired-send retry test pins Spark's last sync between the expiry and the retryEvidence
ChannelFreeRailTests,TimedSheetManagerTestsandFailPendingLightningSendTestspass at the head.Gaps
Models used
claude-opus-5-5(reasoning:medium)claude-opus-5-5(reasoning:medium)gemini-4-neon-high(reasoning:high)