Skip to content

fix: close spark send hold gaps - #1411

Merged
ovitrif merged 7 commits into
masterfrom
fix/spark-hold-gaps
Nov 25, 2026
Merged

ovitrif merged 7 commits into
masterfrom
fix/spark-hold-gaps

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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:

  1. Fixes a retry that starts while Spark's list is read reading as the earlier attempt's failure
  2. Fixes an expired send whose hold ended on a sync from before its invoice expired
  3. Fixes releases after a listing dropping a send recorded meanwhile, on Spark and on the node
  4. Fixes a Spark send that never recorded its attempt releasing another send's hold, or taking one of its own

Description

  • A retry in flight while Spark's list is read, or that takes its hold or records its attempt meanwhile, now reads pending until a later list shows its result, also when it already ended. Before, Paykit read the earlier attempt's failure and could drop the proof of a payment the retry may still make or already made.
  • An expired send stays held until a sync after its invoice expired. A sync from before the expiry can predate the send's success, and settling on it marked a paid send failed.
  • The attempt releases after a listing skip a hash recorded or in flight since the listing's mark, on Spark and on the node, so a send admitted meanwhile keeps its record. The node side comes from the review of fix: close spark retry hold gaps #1406.
  • A Spark send refused before submission no longer ends another send's hold of the invoice or releases its attempt (bug: a refused spark send can let an invoice be paid twice #1407). A send that fails before recording its attempt no longer takes a hold either, as nothing of it reached Spark.
  • Adds tests for failing a pending Lightning send and for the Move to Spark check after a sheet is dismissed. The timestamped retry test now also retries once Spark's history can't be read, as @pwltr asked on fix: spark follow-ups #1355.

Out of Scope

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

  • added ChannelFreeRailTests.swift — a retry held while Spark's list is read reads pending
  • added ChannelFreeRailTests.swift — an expired send stays held until a sync after its expiry
  • added ChannelFreeRailTests.swift — a Spark send refused before submission keeps another send's attempt and hold
  • added ChannelFreeRailTests.swift — a retry that starts and ends while Spark's list is read reads pending
  • added ChannelFreeRailTests.swift — a retry in flight when Spark's list is read reads pending after it ends
  • added ChannelFreeRailTests.swift — a Spark send failing before it records its attempt takes no hold
  • added FailPendingLightningSendTests.swift — only a pending send is failed
  • added TimedSheetManagerTests.swift — dismissing a sheet checks only the Move to Spark intro
  • updated ChannelFreeRailTests.swift — the timestamped retry test also retries once Spark's history can't be read
  • updated ChannelFreeRailTests.swift — the expired-send retry test pins Spark's last sync between the expiry and the retry

Evidence

  • The full unit suite passes on an iOS 26 simulator at the fix commit, and ChannelFreeRailTests, TimedSheetManagerTests and FailPendingLightningSendTests pass at the head.
  • With each fix reverted, its new test fails: the read-during-list, expiry-sync, refused-before-submission, ended-during-list, in-flight-during-list and failed-before-recording tests.

Gaps

  • The release guards after a listing have no test: the window opens only to another send running at the same time, between two steps no test can pause.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: medium)
  • Implementation: claude-opus-5-5 (reasoning: medium)
  • Review: gemini-4-neon-high (reasoning: high)
  • Review rounds: 6

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.
@ovitrif ovitrif added this to the 3.2.0 milestone Nov 24, 2026
@ovitrif ovitrif self-assigned this Nov 24, 2026
@ovitrif
ovitrif requested review from jvsena42 and pwltr November 24, 2026 18:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T18:18:44.920084Z 5a2277c PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif ovitrif removed this from the 3.2.0 milestone Nov 24, 2026
@ovitrif

ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Moved the 3.2.0 milestone off this PR: #1407, which this PR closes, already carries it, and the release milestone tracks issues.

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • heldDuringRead making a just-finished send read pending in finishWatchSendIfRailAlreadySettled: that path ignores .pending and still waits on the payment event, so a synthetic pending row only delays the shortcut.
  • didRecordAttempt skipping markRailSendUncertain for a send that reached Spark: it is set in beforeSubmission right after recordRailAttempt, and markRailSendUncertain already returned early before then, since it requires an attempt recorded since the mark.
  • hasSynced(after: max(startedAt, expiresAt)) never settling: SparkManager.hasSynced compares against lastSyncedAt, 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 pwltr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

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.

Low candidate: The same pending row can outrank a bound Quick Pay failure during recovery.

Low: TimedSheetManagerTests.swift:39 writes the shared widget currency code and symbol during setup and leaves them changed after teardown.

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.

@ovitrif
ovitrif merged commit fac8292 into master Nov 25, 2026
20 checks passed
@ovitrif
ovitrif deleted the fix/spark-hold-gaps branch November 25, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: a refused spark send can let an invoice be paid twice

3 participants