Skip to content

fix: spark follow-ups - #1355

Merged
ovitrif merged 64 commits into
masterfrom
fix/spark-follow-ups-2
Nov 24, 2026
Merged

ovitrif merged 64 commits into
masterfrom
fix/spark-follow-ups-2

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1236
Closes #1249
Closes #1264
Closes #1268
Closes #1270
Closes #1279
Closes #1321
Closes #1378
Closes #1374
Closes #1379

Twin: synonymdev/bitkit-android#1957

This PR fixes the Spark follow-ups from the 3.2.0 work: the Move to Spark sheet, payments and Activity row, the deposit claim poll, exit data backups, translations, Spark send retries and the Breez key check.

Description

  • Re-checks the Move to Spark sheet after another sheet closes on Home, so a sheet shown at cold start, before channels and Spark load, no longer keeps it from ever showing.
  • Keeps the move payment hashes across relaunches and in the metadata backup, so a move that settles after a relaunch, or a restore, is still known as one.
  • Shows a move to Spark in Activity as a "Move to Spark" transfer row, with the moved amount and the routing fee, its detail screen titled the same, listed under the Other tab instead of Sent. A move is known only by its payment hash, so an outside invoice carrying the same description stays a payment.
  • Makes the move quote testable and covers it with unit tests.
  • Stops the deposit claim poll from quoting and claiming again once a claim is waiting; later polls only check whether Spark has claimed the deposit. The early claim is capped at the fee the user approved, so Spark still claims a later offer within it; one above it ends as Unavailable and is claimed at maturity, and the cap is cleared once the poll gives up.
  • Sets exit data Spark can never import (or this app can't read) aside under a key derived from the data, so it stays recoverable, no longer blocks exit data backups, and copies from different devices never overwrite each other, and when another device has replaced the remote backup, the restored data itself is kept and the other device's backup is restored before anything replaces it.
  • Translates every Spark string into all locales and drops the unused lightning__spending_confirm__up_to.
  • Never sends a Lightning invoice through Spark again while an earlier Spark attempt on it is unresolved: the payment shows as pending until Spark settles or fails that attempt. A failure Spark dates no more than 10 seconds before the send's start is the send's own and ends it at once, shown failed, with a retry allowed; an older failure is an earlier attempt's and is ignored, so its row stays pending. A send's start is saved at least 11 seconds after the latest failure Spark dated for the invoice so far, so a known earlier failure never reads as a retry's own. A Spark send is refused while Spark's list can't be read, unless after a restore Spark's operators show no send of the invoice, and a listing settles only the sends held before it was read; a held send stays pending unless that list shows its success or its own failure, so a retry's success never reads as an earlier attempt's failure. At startup, a held send ends from the own failure or success Spark lists. A send Spark never settles ends once its invoice expired and a sync since the send reached Spark, and its Activity row is written from Spark's attempt or failed in place. Of two failed attempts, the later one's amount, fee and time stay in Activity. This replaces the retry hold and its saved journal from earlier pushes.
  • Opens the Spark connection detail from App Status's Spark row also offline, once Spark has read its state.
  • Keeps exit data and move metadata intact: set-aside exit data carries Spark's network name, and a move marks the metadata backup as its hash is saved. During an exit, a send's hold still ends at its invoice's expiry through Spark's history.
  • Fails a Release build at the start when the Breez API key is blank in both the build setting and the keychain, a locked or blank keychain item included, without printing the key.

Out of Scope

Design

N/A — no design available. The row reuses the existing transfer row (icon, colour and layout).

Preview

Activity on a regtest simulator with seeded moves (succeeded, pending, failed), an outside payment with the same description, a sent and a received payment.

Activity and tabs Move detail
case1-activity2x.mp4
case2-detail2x.mp4

QA Notes

Setup

Regtest build of this branch with an LDK channel that can send at least 1,000 sats and Spark connected (as for the move-to-spark.xml journey).

Journeys

  • J1: updated move-to-spark.xml — after the move, Activity lists a "Move to Spark" transfer row with the amount and routing fee, its detail is titled "Move to Spark", and the Spending button is gone

Manual Tests

N/A

Automated Checks

  • added MoveToSparkQuoteTests.swift — the quote grows to fit the fee, keeps a smaller target, falls back to the last fitting amount, and reports too large, nothing to move and Spark unavailable; move hashes survive a relaunch, back up sorted, restore and wipe
  • updated SparkTransferFlowTests.swift — a waiting claim is not quoted or claimed again, its cap is the approved fee and is cleared when the poll gives up, and the deposit counts as added once Spark claims it
  • updated SparkExitBackupTests.swift — unreadable or rejected exit data is set aside and backups go on; different rejected copies never overwrite each other; rejected data another device replaced remotely is kept from the restored copy and the other device's backup is restored, not overwritten; a backup written while an unreadable one is set aside is restored first; discarding rejected staged data keeps newer data staged meanwhile
  • updated AppStatusHelperTests.swift — the Spark row opens the detail offline once Spark has read its state, and not before
  • updated SparkRelaunchActivityTests.swift — an older Spark attempt's failure keeps the later failed attempt's row, and a later one's replaces it
  • updated ChannelFreeRailTests.swift — a retry stays held while Spark lists only an earlier attempt's failure and ends at its own; a late failure event dated before the send keeps it held, one dated at the send ends it; an earlier failure while a retry is in Spark's call before submission stays off its screen; a retry that takes the invoice while an expired send settles stays held; a failure of an attempt 5 seconds before a retry keeps it held and off its screen, and at expiry fails the retry's own row; a launch that reads a send's own failure lets the node retry while Spark can't list; a Spark send is refused while Spark can't list, and a pre-restore invoice the operators show failed as unverified; a send held while Spark's list is read is not settled from it; a retry whose hold ends during the read without its result listed stays pending; a retry Spark never lists ends at its invoice's expiry; any pending attempt refuses a retry

Evidence

  • Unit suite (the selection in unit-tests.yml) on an iPhone 17 Pro simulator, iOS 26.5, at 98d8e2b: all pass but one exit backup test, fixed after; the touched suites (exit backup, move quote and hashes, channel-free rail, transfer flow, wallet activity, exit funding index) pass at 971cd37, and the exit backup suites at f39522a; the Spark suites (channel-free rail, move to Spark, exit backup, Spark send, payment safety, relaunch and transfer activity, transfer flow, claim offer and fee, funding recovery) at 82a5411; the exit backup and rail suites at 5f603e4; the Spark suites again at e114c01; the Spark suites again at 8d0436f; the App Status suites at 859dee8; the rail and payment safety suites at f811fea; the Spark suites again at ed84ea9; the unit suite at d330aa5, f9aeb92, fab6210, 4542de2, 26545fc, 9d4b7e0, 061e5ec, fbc4a64, 3264677, 8497853, 946713c, 7d07dac, 3e655ff, 45d1c14, c02b4b0 and 7b428de; the Spark activity and rail suites at a873836, 1f7698a, c177de8, fa92ad3, 809c8a3, b401fa4, a528bf0, 6e58693, c9937ed and 1ef7403.
  • Activity rows and detail at bc8caab (iPhone 17 Pro simulator, iOS 26.5, regtest), with seeded moves (succeeded, pending, failed), an outside payment with the same description, a sent and a received payment: the three moves show as "Move to Spark" transfers under Other and not Sent; the outside payment stays a Sent row; the detail shows Payment 48,210 and Fee 7.
  • Release key check run against a stubbed keychain: a missing, blank or locked item fails the build, a set item or build setting passes, Debug is unaffected.

Gaps

  • J1 was not driven end to end with a real channel move; the rows were checked with seeded activities.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium), Claude Sonnet 5.5 (reasoning: high)
  • Review: Claude Opus 5.5 (reasoning: medium)

@ovitrif ovitrif added this to the 3.2.0 milestone Nov 17, 2026
@ovitrif ovitrif self-assigned this Nov 17, 2026
@ovitrif
ovitrif requested review from a team, ben-kaufman and pwltr and removed request for a team November 17, 2026 14:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T14:32:12.679323Z 971cd37 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.

@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR reaches several Spark wallet workflows and the Release build setup.

Preserve the actual rejected exit data before merging; the current path can delete it after saving a different remote copy.

Findings

  1. P1 Rejected exit data is lost ▶

Summary

This PR fixes Spark follow-ups across moves, Activity, deposit claims, exit backups and Release builds.

  • Move to Spark payments keep their identity and appear as transfers.
  • Waiting Spark deposit claims are checked without submitting another claim.
  • Spark exit data the app cannot use stays in a separate backup copy.
  • Earlier Spark failures no longer end a retry that is still in doubt.
  • The Move to Spark sheet is checked again after another sheet closes.
  • Move quote services can be swapped out for focused tests.
  • Release builds stop early when the Breez key is blank or unavailable.
  • Spark text now has updated translations across the app's locales.

Acknowledged scope from ovitrif:

  • Reading saved SPARK_EXIT_REJECTED copies back is intentionally out of scope.
  • A late failure releasing a submitted retry that is not in doubt is explicitly deferred.

Verification was limited to source review. Native iOS tests and UI capture were not run in the Linux environment.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Download exit backup] --> B[Stage exit state locally]
  B --> C[Try Spark import]
  C -->|Temporary failure| D[Keep staged data and retry]
  C -->|Rejected| E[Download remote backup again]
  E --> F[Save downloaded copy separately]
  F --> G[Delete staged exit state]
  G --> H[Allow fresh exit backups]
  E -. Remote copy may have changed .-> G
Loading

Reviews (1) · Last reviewed commit: "fix: spark exit data kept on every rejec..." · Reviewed by Greptile

Comment thread Bitkit/Services/BackupService.swift Resolved
@ovitrif ovitrif removed this from the 3.2.0 milestone Nov 17, 2026

@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. Follows up the Spark 3.2.0 work: move-to-Spark hashes are now persisted and backed up, and moves show as transfer rows in Activity. Also covers the waiting-claim poll, setting aside exit data Spark rejects, the late-failure retry hold, the Move to Spark sheet re-check and the Release key check. Reviewed 971cd37, full tier, static: iOS does not build on this reviewer's Linux host, so this is reasoned from the code and from CI.

What I checked, and 9 candidates I ruled out

Read in full: MoveToSparkManager.swift, BackupService.swift (exit backup and metadata paths), SparkManager.swift (exit import, deposit claim), SparkTransferFlow.swift (pollDeposit, waitForConfirmations), LightningService.swift (rail uncertainty helpers, emitChannelFreeRailEvent), TimedSheetManager.swift, the four Activity files, the new and changed tests.
Cross-checked against: breez spark-sdk decode_exit_state / import_unilateral_exit_state and the Payment.timestamp adaptors; bitkit-android#1957's BackupJson.kt.
Localization: 61 changed keys across every locale, checked mechanically for placeholder parity with en (0 mismatches); the translations themselves were not read.
CI: SwiftFormat, validate and build-local green; Run Tests, Run Integration Tests and e2e still running when this was posted.

Ruled out

  • .rejected set too wide: every SdkError.InvalidInput from the import is a property of the payload (unsupported version, wrong network, unparseable JSON, or ServiceError::InvalidInput mapped through From<SparkWalletError>). Operator and storage failures map to SparkError/Generic, so they stay .pending.
  • Setting aside the wrong remote copy: uploads are blocked while restored data is staged, so the SPARK_EXIT copy fetched on .rejected is still the one the staged file came from.
  • Stale started timestamps: every path that clears channelFreeRailUncertainSendFailedAt (endRailSendUncertainty, forgetRailAttempts) clears the started key too. An entry written before this change has no started value, and isEarlierThanUncertainRailSend returns false for it, which is the old behaviour.
  • Retry overwriting started: markRailSendUncertain writes started only when no uncertainty exists, and the second call from the catch path keeps the submission time.
  • Spark clock behind by more than 10 s: the send's own failure would be ignored, but the hold still ends through railSyncedSinceUncertainSend once the invoice expires. It is bounded, not stuck.
  • Waiting-claim poll never surfacing an outcome: a deposit Spark claims at maturity also leaves listUnclaimedDeposits, so it reads .added. The window still ends in .unavailable because offers[txid] is set, and waitForConfirmations still cancels the watch and releases the cap.
  • Restore re-triggering a metadata backup: MoveToSparkPayments.restore saves without sending on savedPublisher, so only insert marks metadata required.
  • Sheet re-check clobbering a pending full check: onSheetDismissed schedules the move-only check only when no timer is valid, and a later reevaluate() replaces it with a full check.
  • Android twin reading the new moveToSparkPaymentHashes key: Android's backupJson is built from json with ignoreUnknownKeys = true, so an iOS envelope carrying it still decodes there.

Merge confidence: 4/5. CI's unit and integration runs had not finished, iOS could not be built here, and the real channel move (J1) has only been checked with seeded activities.

@ben-kaufman ben-kaufman 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.

Rejected exit data can still be lost when two devices archive at once.

Reviewer model: gpt-6.1-sol
Reasoning effort: xhigh

Comment thread Bitkit/Services/BackupService.swift Resolved
@ovitrif
ovitrif requested a review from ben-kaufman November 17, 2026 15:18
@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 4ac88c9: a Spark failure event now checks whether it belongs to an earlier attempt and ends the hold under one lock. Before, the check and the release were two separate steps, so a retry recorded between them could lose its hold. ChannelFreeRailTests pass on this head.

pwltr
pwltr previously requested changes Nov 17, 2026

@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 4ac88c9.

High: An older Spark failure within ten seconds of an uncertain retry still releases that retry's hold (Bitkit/Services/LightningService.swift:1664). For example, an attempt created at 995 is treated as the retry submitted at 1000. If its delayed failure arrives after the retry returns an unknown error, settlement deletes the retry's uncertainty and recorded attempt. With only the older failed row listed, another send is then allowed while Spark may still complete the retry, risking duplicate payment. The shared predicate also permits the older failure to replace pending Activity. Keep ambiguous failures from releasing the hold, or correlate them with an actual attempt identity. Cover delivery of the close-timestamp event; the current test checks its classification but only delivers the much older event.

Review details

Quick review
Model: Claude Opus 5.5
Reasoning effort: high

General review
Model: GPT-6.1 Sol
Reasoning effort: high

Combined review
Model: GPT-6.1 Sol
Reasoning effort: high

@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

High: An older Spark failure within ten seconds of an uncertain retry still releases that retry's hold

@pwltr Addressed in 219a499. Before a retry goes out, the send now records Spark's ids of the invoice's earlier attempts, taken from the listing it already reads. A late failure releases the hold, and replaces pending Activity, only when its Spark payment id is not one of those. Where ids are missing, the check fails safe: a failure created before the send or within ten seconds after it keeps the hold. testALateFailureOfAnEarlierAttemptKeepsARetryInDoubtHeld now delivers the earlier attempt's failure at 995 and an id-less failure at 1000; both are refused, and the retry's own failure releases the hold. testAFailureWithoutSparkIdsKeepsTheHoldUntilPastTheClockMargin covers the timestamp fallback.

@ovitrif
ovitrif requested a review from pwltr November 17, 2026 17:57
@ovitrif ovitrif modified the milestone: 3.2.0 Nov 17, 2026
@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

b0bfc73: a Spark send's Activity row no longer stays Pending after its retry hold ends at the invoice's expiry. The hold keeps the row pending against an earlier attempt's failure; ending it now writes Spark's latest send of the invoice, or marks the stored pending send failed when Spark lists none. Spark syncs also end holds whose invoice expired, so this no longer waits for a new send of the invoice. The same gap was raised on the twin in synonymdev/bitkit-android#1957 (review).

@ben-kaufman ben-kaufman 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.

Expiry reconciliation can lose a failed Activity update and overwrite a concurrent row change.

Reviewer model: gpt-6.1-sol
Reasoning effort: xhigh

Comment thread Bitkit/Managers/SparkManager.swift Resolved
Comment thread Bitkit/Services/CoreService.swift Resolved
@ovitrif
ovitrif requested a review from ben-kaufman November 17, 2026 21:38
@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

82a5411: an Instant early claim that Spark defers is now capped at the fee the user approved, not the first quote's fee, so Spark still claims a later offer the approved fee covers. After a waiting claim the poll still sends no new quote, as before. An offer above the approved fee ends as Unavailable and is claimed at maturity. This matches the twin's change for synonymdev/bitkit-android#1957 (review).

pwltr
pwltr previously requested changes Nov 17, 2026

@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.

Please consider splitting the Spark exit-backup recovery and payment retry changes so each can be reworked around the state it must preserve.

Reviewed 82a5411.

Both exit backup paths can reach the canonical write at Bitkit/Services/BackupService.swift:476 without a version tied to the snapshot they archived.

High: If another device has already replaced the staged snapshot in SPARK_EXIT, Bitkit/Services/BackupService.swift:466 and Bitkit/Services/BackupService.swift:1539 archive the staged snapshot and upload the local export over the other device’s backup. Recovery data held only in that other snapshot disappears from normal restore. BitkitTests/SparkExitBackupTests.swift:243 expects the overwrite.

Medium candidate: The same overwrite may occur if another device writes a fresh backup while Bitkit/Services/BackupService.swift:1519 is archiving an undecodable one. The restore gate clears after that archive write, and the fresh backup can reach the canonical write without ever being read.

High: A Spark retry hold saved before upgrade has neither the attempt IDs nor the start time required by Bitkit/Services/LightningService.swift:1701. A late failure for the first attempt can clear the unresolved retry’s hold and allow another send while Spark may still complete the retry. The same missing upgrade fallback lets history sync mark the retry’s pending Activity row failed through Bitkit/Services/CoreService.swift:1009, even while the hold is still active.

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 17, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Please consider splitting the Spark exit-backup recovery and payment retry changes

We keep them in this PR, matching the twin synonymdev/bitkit-android#1957, so both platforms land the same Spark follow-ups together. Both are reworked below around the state they must keep.

High: If another device has already replaced the staged snapshot in SPARK_EXIT [...] upload the local export over the other device's backup.

Addressed in 5f603e4. When Spark rejects the staged data and SPARK_EXIT now holds another device's exit data, the staged copy is set aside and the remote one is restored instead of being replaced. The next backup imports it. If Spark rejects that one too, the remote then matches the staged copy, so it is set aside and replaced as before. testRejectedDataAnotherDeviceReplacedRemotelyIsSetAsideFromTheStagedCopy now expects the other device's backup to stay and be restored.

Medium candidate: The same overwrite may occur if another device writes a fresh backup while [...] archiving an undecodable one.

Addressed in 5f603e4. After setting an unreadable backup aside, the restore reads SPARK_EXIT again and stays pending if it changed, so the new backup is restored before anything replaces it (testABackupAnotherDeviceWritesWhileAnUnreadableOneIsSetAsideIsRestoredFirst). The VSS client's store call takes no expected version, so a write landing between that read and our upload can't be detected; that window is now one read and one write.

High: A Spark retry hold saved before upgrade has neither the attempt IDs nor the start time

Addressed in 5f603e4. A send in doubt with no recorded start counts any failure as an earlier attempt's. It stays held, and its Activity row stays pending, until its invoice expires. The expiry step (from b0bfc73 and 24e6da9) then writes the row from Spark's latest send, retrying until the write is saved (testASendInDoubtSavedBeforeTheUpgradeStaysHeldAgainstAnyFailure).

@ovitrif
ovitrif requested a review from pwltr November 17, 2026 22:36
pwltr
pwltr previously requested changes Nov 17, 2026

@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.

Please rework the Spark exit backup and payment retry paths around the recovery data and attempt identity they need to preserve.

Reviewed 5f603e4.

High: Both rejection paths read SPARK_EXIT separately from the unconditional replacement at Bitkit/Services/BackupService.swift:486. A second device can upload a usable backup after the staged-data comparison at Bitkit/Services/BackupService.swift:469 or after the post-archive read at Bitkit/Services/BackupService.swift:1534. The fresh export can then erase exit data this device never read or preserved.

High: Bitkit/Services/BackupService.swift:473 deletes the rejected staged file before line 477 records that a newer remote backup needs restoring. If the app stops between those operations, the next launch can overwrite the other device’s backup without reading it.

High: Bitkit/Services/BackupService.swift:1569 can leave the only usable recovery copy under SPARK_EXIT_REJECTED_*, while normal restore at Bitkit/Services/BackupService.swift:1525 reads only SPARK_EXIT. A compatible app can miss the archived exit data it needs when Spark operators are unavailable.

Medium candidate: Bitkit/Managers/SparkManager.swift:1469 treats a failed read of an existing staged file as an absent file. If the staged read fails while Spark can still export, Bitkit/Services/BackupService.swift:481 allows the fresh export to replace the remote copy.

Both payment effects below follow from Bitkit/Services/LightningService.swift:1135 clearing attempt identity as soon as submission returns, while the retry can still be pending.

High: An older Spark failure can pass Bitkit/Services/LightningService.swift:1754, report the retry as failed, and remove its duplicate-payment guard. If Spark history then becomes unavailable, the app can send the same invoice over a channel while the Spark retry is still settling.

Medium: The same failure can pass Bitkit/Services/CoreService.swift:1003 and replace the newer attempt’s Pending Activity row with Failed.

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

A send's read of Spark's list can miss an earlier attempt, which a later send
then keeps after a newer one, so the kept order may be wrong. Spark's dates
decide between two kept attempts again; the kept order only breaks a
same-second tie.

Verified: swiftformat lint; BitkitTests on the iPhone 17 Pro 2x simulator, new SparkRelaunchActivityTests case fails without the fix
A failure Spark reported while a send's call ran was dropped, so a call that
returned the same payment pending left it held with no failure reported. The
failure is now kept during the call and replayed once when the call returns
that payment failed or pending; a succeeded result drops it. A wipe clears it.

Verified: swiftformat lint; BitkitTests on the iPhone 17 Pro 2x simulator, new ChannelFreeRailTests cases included
A failure held during a send call that then threw was dropped; it is now
replayed with Spark's date, so the rules of a send in doubt settle it. Whether
the call's result fails the send is decided with the call's end, before the
send is taken, so the taken-send expiry sweep never reports it too.

Verified: swiftformat lint; BitkitTests on the iPhone 17 Pro 2x simulator, new ChannelFreeRailTests case included
A Lightning invoice is never sent through Spark again while an earlier
Spark attempt on it is unresolved; the payment shows as pending until
Spark settles or fails it. The send's start, kept in the existing
uncertain-send record, decides: a failure Spark dates no more than 10
seconds before it is the send's own and ends it at once; an older one is
an earlier attempt's and is ignored. A send Spark never settles ends at
its invoice's expiry once a sync since the send reached Spark.

Removes the retry hold layer and its saved journal from earlier pushes:
attempt ids, taken and kept attempts, row writers, the in-call failure
buffer and the 10-minute grace.

Verified: unit suite (BitkitTests selection) passes on an iPhone 17 Pro simulator, iOS 26.5.
Spark dates each attempt at its start, so of two failed attempts of one
invoice the later one's amount, fee and time now stay in Activity: an
older attempt's failure no longer replaces them, and a later attempt's
failure replaces an older one's also when the fees match.

Verified: Spark relaunch activity, channel-free rail, payment safety and wallet activity suites pass on an iPhone 17 Pro simulator, iOS 26.5.
A retry in Spark's send call that wasn't submitted yet has nothing at
Spark, so a failure arriving then is an earlier attempt's: it no longer
reaches the retry's screen or releases its attempt.

Verified: Spark relaunch activity, channel-free rail, payment safety and wallet activity suites pass on an iPhone 17 Pro simulator, iOS 26.5.
A failure event, a listing or an expired invoice ended whatever hold the
invoice had once checked. If the send ended and a retry took a new hold
in between, the retry lost it and could be sent again while unresolved.
Each now ends only the hold it read, by its start.

Verified: ChannelFreeRailTests, SparkRelaunchActivityTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro
simulator, iOS 26.5; the new test fails without the fix
A Spark failure event checked the invoice's hold and ended it in separate
steps, so a retry that took the hold in between could still get the
earlier send's failure on its screen. The check and the end are now one
step under the lock, judged by whichever send holds the invoice then.

Verified: ChannelFreeRailTests, SparkRelaunchActivityTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro
simulator, iOS 26.5
A failed attempt Spark dated within the clock margin before a retry read
as the retry's own: it could end the retry's hold, fail its screen,
replace its Activity row and, at expiry, copy its details into the
retry's row. A send's saved start is now at least the margin plus one
second after the latest failure Spark dated for the invoice, from its
list or its events, so a known earlier failure never reads as the
retry's. Nothing new is saved.

Startup also ends a held send from the own failure or success it reads,
before releasing it, so a channel retry no longer waits on a later read
of Spark's history.

Verified: ChannelFreeRailTests, SparkRelaunchActivityTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro
simulator, iOS 26.5; the two new retry tests fail without the floor
A retry sent while Spark's list can't be read knows no earlier failure
after a relaunch, so one Spark dated within the clock margin before it
could still read as its own. Its start is now saved past the margin
after now, as Spark may have dated a failure of the invoice up to then.

Verified: ChannelFreeRailTests, SparkRelaunchActivityTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro
simulator, iOS 26.5; the new test fails without the change
A Spark send whose list can't be read saved its start past now, so its
own failure read as an earlier attempt's and kept it held until its
invoice expired. Such a send is now refused before anything goes out,
unless Spark's operators show no send of the invoice at all after a
restore. A listing also settles only the holds taken before it was read,
so a send that starts meanwhile is never settled from the older list.

Verified: ChannelFreeRailTests, SparkRelaunchActivityTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro
simulator, iOS 26.5; both new tests fail without their change
After a restore, an unsynced Spark whose operators show a pre-restore
invoice's sends all failed can't date a new send after them, so it was
refused with the generic payment failure. It now gets the restored
invoice refusal, as on Android.

Verified: ChannelFreeRailTests, SparkRelaunchActivityTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro
simulator, iOS 26.5
A retry's success event could end its hold while Spark's list was read, with the list holding only the first
attempt's failure, so the invoice read as failed until the next read and Paykit could drop the paid request's
proof. The list is now read again when a hold ends during the read, and a hold still ending on the last of three
reads stays pending.

Verified: SwiftFormat lint on the changed files; SparkRelaunchActivityTests, ChannelFreeRailTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the new test fails
with the LightningService change reverted.
A retry's success event could end its hold just after c9937ed's re-read check, or before Spark listed the
success, so the retry still read as the earlier attempt's failure and Paykit could drop the paid request's proof.
A held send now keeps its pending row unless the same list shows its result: a success, or a failure dated as its
own. The re-read loop is gone.

Verified: SwiftFormat lint on the changed files; SparkRelaunchActivityTests, ChannelFreeRailTests,
SparkPaymentSafetyTests and WalletActivityTests pass on an iPhone 17 Pro simulator, iOS 26.5; the new test fails
on 6e58693's code.
@ovitrif
ovitrif force-pushed the fix/spark-follow-ups-2 branch from 1ef7403 to 41ed0d3 Compare November 24, 2026 14:19
@ovitrif

ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto master (31451c75c) to clear the conflict from #1357. The new head is 41ed0d36c.

Only the locale files and journeys/transfer/move-to-spark.xml conflicted:

  • Locales: kept the copy from feat: spark transfer to spending design #1357. This PR's translations stay only for keys that en still has, so node scripts/validate-translations.js passes.
  • Journey: kept the new Lightning Connections check from master, followed by this PR's check of the "Move to Spark" Activity row.

The Spark and Paykit code is unchanged from 1ef7403.

The rebase onto master left three spark exit keys twice in every
locale, the extra copy with older wording. Keep master's line.

Verified: no duplicate keys in any Localizable.strings; node scripts/validate-translations.js passes.
@ovitrif

ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

befad53 removes three spark exit keys that the rebase left twice in every locale (lightning__spark_exit__earlier_addresses, _earlier_addresses_text and _note_notifications_button). Each locale now keeps master's line. The extra copies had older wording.

@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 befad53.

Low: Both Spark history retry tests use an already-expired invoice and a failure row with timestamp zero (BitkitTests/ChannelFreeRailTests.swift:1018, BitkitTests/ChannelFreeRailTests.swift:1052). The expiry sweep can release the hold before Spark's listing is read, so both tests can pass without showing that the listed failure released it. Extend the existing timestamped case at BitkitTests/ChannelFreeRailTests.swift:855 to retry again after history becomes unavailable. That covers both assertions with the clock pinned before expiry and a failure dated to the held send.

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 24, 2026

Copy link
Copy Markdown
Collaborator Author

Low: Both Spark history retry tests use an already-expired invoice and a failure row with timestamp zero (BitkitTests/ChannelFreeRailTests.swift:1018, BitkitTests/ChannelFreeRailTests.swift:1052).

@pwltr thanks. The timestamped case now also retries once Spark's history can't be read, with the clock pinned before expiry and the failure dated to the held send. That lands in the follow-up PR, together with three fixes from a pre-merge review of befad53 and the fix for #1407.

Merged: approved by @pwltr on befad53, checks green, no open threads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants