Skip to content

fix: spark follow-ups - #1957

Open
ovitrif wants to merge 100 commits into
masterfrom
fix/spark-follow-ups
Open

ovitrif wants to merge 100 commits into
masterfrom
fix/spark-follow-ups

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1802
Closes #1819
Closes #1840
Closes #1848
Closes #1919
Closes #1976
Closes #1983
Closes #1982
Closes #1984
Closes #1986
Twin: synonymdev/bitkit-ios#1355

This PR closes the remaining Spark follow-ups from bitkit-android#1946. It also carries the Android side of three iOS issues:

Description

  • Move to Spark keeps running after its screen closes. A new app-scoped MoveToSparkManager holds the move and its outcome. Pressing Back during a move no longer cancels the wait. Opening the screen again shows the same move. When a closed screen's cleanup runs late, it leaves a reopened screen's quote alone. A wallet wipe drops the move, so the next wallet starts on a new quote. A move waiting on its payment reads the node's stored payment again while it waits, so a missed outcome still ends it. Spending and Lightning Connections keep offering Move to Spark while a move is kept for its result, also once too little is left to move again.
  • A move's payment hash is persisted and backed up. It is stored in CacheStore, so after a restart the move is still recognised: no received notice, and it stays a Move to Spark row. The metadata backup carries the hashes as moveToSparkPaymentHashes, as bitkit-ios does: lowercase hex, sorted, left out when there are none, and read as none when the value is not a list of strings. A restore adds them to the device's own.
  • Tests for MoveToSparkRepo.move(). They cover:
    • the fee cap passed to payInvoiceOverLdk and the fee reported back
    • a failure matched by payment id
    • a payment with no outcome before the timeout
    • the hash surviving a restart
  • A move to Spark shows in Activity as "Move to Spark". The row and the detail screen reuse the transfer row's icon and layout. They show it as outgoing, with the moved amount plus the routing fee. A pending or failed move keeps the row, with Pending or Failed as its subtitle and the usual pending or failed icon. Moves list under Other, with transfers, and not under Sent. Both apps build it the same way; a later design can restyle it.
  • A Lightning invoice is not sent again through Spark while an earlier Spark attempt on it is unresolved. An attempt is unresolved while it is in Spark's send call, and after it until Spark settles it or its invoice expires, also when Spark took it but its list doesn't show it yet. Until Spark settles or fails it, the payment shows as pending: a retry is refused as pending on both rails. A failure Spark dates no more than 10 s before the send's start, the room left for Spark's clock to differ from the phone's, is the send's own: it ends the send at once, marks its row failed, tells the send screen and allows a retry. The start is the time already saved just before the send, and it is saved at least 11 s past every failure Spark dated for the invoice that the app knows from Spark's list, its events or a send's result, so an earlier attempt's failure never reads as a retry's own; nothing new is stored. A send is refused before anything goes out when Spark's list can't be read to date it. After a restore, before Spark syncs, a Spark send of a pre-restore invoice the Spark operators show failed is refused until Spark syncs, as nothing can date that failure yet. A failure Spark dates earlier is an earlier attempt's, and it changes nothing: the settled-send lookup reads no failure and the Activity row stays pending, so an earlier attempt's late failure leaves the send held; at the invoice's expiry it fails the send's row in place, which keeps its own amount and fee (bitkit-android#1848). The same holds for any failure while the send is still in Spark's send call, which its result settles, and for another attempt's failure while Spark lists the retry it took as pending or paid. Otherwise a send in doubt ends on its success, or once its invoice expired and Spark synced, or reported a failure, since; that also marks its row failed and tells the send screen. When Spark lists several attempts on one invoice, only the one that decides it writes the row: a success over a pending one over a failure, the latest on a tie. This matches bitkit-ios. A send that returns pending reads a settled outcome again once the send screen tracks it, so an outcome handled between the two still resolves it, and the pending screen then shows Sent; only that send's own contact is attached, so a payment the send screen moved on to keeps its contact.
  • The claim poll stops quoting once Spark says the early claim is waiting. It then watches for the deposit to leave the unclaimed list and shows Adding. The early claim is capped at the fee the user approved, never above the one the swiped quote showed, also when a max transfer's swipe prices it again, so Spark claims any later offer within it by itself, and one above it waits for the claim at maturity. This is the Android side of bitkit-ios#1264.
  • Unimportable stored exit data no longer blocks exit backups. This covers stored data that doesn't decode, and data that Spark rejects as invalid input. That data is kept unchanged under SPARK_EXIT_REJECTED_ plus the first 16 hex digits of its SHA-256, as bitkit-ios does in the same VSS store, and the fresh export is uploaded. Each copy has its own key, so none replaces another, and a copy already kept is not uploaded again. A staged restore is dropped only when it holds that same data. Restored data that Spark rejects as invalid input is set aside the same way before the upload: the stored backup when it still holds that data, otherwise a new backup envelope around it. Then it is dropped instead of being retried on every start, and the stored backup is merged into Spark before the upload, so exit data another device stored is never replaced. Dropping a rejected staged copy asks for the stored backup to be merged again, and every upload merges it until one merge succeeds, also after a failed attempt. Stored data Spark can't import is replaced only when it is still the stored one after it was set aside. A staged restore is compared and dropped under the same lock that stages and imports it, so a restore retried meanwhile keeps its new copy. A restore that finds stored exit data it can't read sets it aside the same way and reports the exit data as not restored. Any other error still blocks the upload. The restore's cache log leaves out the move hashes. This is the Android side of bitkit-ios#1268.
  • The Spark strings are translated in every locale. This adds the missing keys and refreshes the ones whose English changed. lightning__setting_up__step_seen, lightning__setting_up__step_sent and lightning__spending_confirm__up_to are not in English, so they are not added.
  • The liveness comment in LightningRepo.kt is reworded (bitkit-android#1919).
  • bitkit-ios#1321 needs no Android change. release.yml already fails early on a blank key, and release-internal.yml leaves the key optional on purpose.
  • A restore reports exit data Spark rejects as not restored (bitkit-android#1976, from bitkit-android#1979). The restore connects Spark itself and imports the staged exit data at once, so onboarding lists it as not restored when Spark rejects it. Spark's events are collected before the restore connects it, and staging and importing share one lock.
  • The earlier retry hold and its saved journal are removed (bitkit-android#1983). The rule above makes the per-attempt ids, taken retries, clock-skew windows and row-writer journal unnecessary, so a retry Spark took can no longer stay held past its invoice's expiry.

Out of Scope

  • A restore that can't connect Spark still reports staged exit data as restored, as the import then waits for Spark's start.
  • A write from another device between the exit backup's read of the stored backup and its upload can still be replaced, as VSS has no write conditional on the version read: vss-rust-client-ffi#38.
  • bitkit-android#1814
  • Rechecking the send authorization after the last storage write before a Spark send: bitkit-android#1962, from this review.

Design

N/A — no design available. The row reuses the existing Lightning-era Transfer activity row (component, icon, layout), titled "Move to Spark"; a later design can restyle it.

Preview

Activity shows a move as one outgoing Move to Spark row, and its detail shows the moved amount, the routing fee and the transfer icon:

row2x.mp4

QA Notes

Setup

  • Journey J1: the local Spark regtest from bitkit-android#1774's QA Notes. That is the spark profile of bitkit-docker, plus a dev build pointed at it, with one channel to the SSP.
  • Preview:
    • A dev build of this PR, on a fresh regtest wallet with dev mode on.
    • The build carried a local-only hook that is not in this PR. After Dev Settings → Generate Test Activities, it marks one generated Lightning send as a move.

Journeys

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

Manual Tests

N/A

Automated Checks

  • added MoveToSparkRepoTest.kt — the move pays capped at the quoted fee and reports the fee paid, matches a failure by payment id, reports a payment with no outcome in time as in flight, and keeps a move's hash after a restart, and a move whose outcome was missed while the node was down reads it once the node is back
  • added MoveToSparkViewModelTest.kt cases — leaving during a move keeps it and shows it again, leaving while it's in flight keeps waiting, leaving after it settled quotes anew, a closed screen's late cleanup leaves a reopened screen's quote, wiping the wallet drops an in-flight move and quotes anew
  • added AppViewModelSendFlowTest.kt cases: a pending Spark send whose success was handled before it was tracked resolves as sent, and leaves the next send's contact alone
  • added a SparkFundingViewModelTest.kt case: a max transfer's swipe approves no higher Instant claim fee than the one shown
  • added SparkRepoTest.kt cases — the claim poll stops quoting once Spark waits for the early claim and shows Adding once it claims; a failure listed or reported while a send is in doubt or in Spark's send call is no settled send event, and an earlier attempt's late failure event leaves a send in doubt pending, refused and with no failed row, also when Spark took the retry; a retry Spark took stays held while Spark lists only an earlier attempt's failure; a send whose caller was cancelled inside Spark's send call ends at its invoice's expiry without a restart; an older attempt's failure event leaves the row of a later failed attempt; a send Spark refuses for its balance stays in flight until its hold is cleared; a sync while the poll settles a send in doubt reports its failure once; a send's own failure the poll settled first is reported once when Spark's event follows; a retry Spark never lists reports its failure at expiry past an earlier failure already reported; a retry read as pending while the poll settles a send keeps its own success event; a retry that enters Spark's send call as the poll settles a send never shows the earlier send's failure and keeps its saved expiry; a retry that enters Spark's send call while a failure event is handled keeps its hold and saved send, and never shows the earlier failure; a send in doubt ends at once on its own failure, and a retry then sends again; a send in doubt fails its row and reports its failure once its invoice expires with only an earlier failure listed; a send that failed lets a retry of its invoice send again; a retry's success decides its Activity row over an earlier attempt's failure; an uncertain retry's row stays pending after a restart while Spark lists only its older failure; a held send whose own failure the launch sync lists frees its invoice even when the next read of Spark's list fails; a retry started 5 s after an earlier attempt's failure stays held while Spark lists only that failure, and at expiry fails its own row in place, also through the next start's sync; a send is refused before it goes out while Spark can't list its payments; a send held while a sync writes its list is not settled from that list; an unsynced Spark refuses a pre-restore invoice the operators show failed and sends one they show no send of; dropping rejected staged exit data asks for the stored backup to be merged again; staged exit data Spark rejects reads as rejected while other import failures stay pending
  • added BackupRepoTest.kt cases — stored exit data that Spark can't import, or that doesn't parse, is kept apart and the upload goes through; each copy goes under its own digest key and never the plain key, and a copy already kept is not uploaded again; a restore sets aside exit data it can't read and reports it not restored; a rejected staged copy merges a stored backup another device replaced before the upload, also on the next upload after a failed merge, and stored data replaced while unreadable data was set aside is merged first; staged exit data Spark rejects is set aside as the stored backup that holds it, or on its own once the stored one moved on, and dropped; other merge errors still block it; the metadata backup carries the move hashes lowercase and sorted, leaves them out with none, and a restore adds them to the device's
  • added BackupJsonTest.kt case — move hashes read from a list of strings, and any other value reads as none
  • added ActivityListViewModelTest.kt case — a move, failed too, lists under Other and not under Sent
  • added LightningConnectionsViewModelTest.kt case — a move kept for its result keeps Move to Spark offered once nothing is left to move
  • updated WipeWalletUseCaseTest.kt — a wipe resets the Move to Spark manager
  • updated NotifyPaymentReceivedHandlerTest.kt and AppViewModelSendFlowTest.kt — the move check is now a suspend call

Evidence

  • Preview: tested on an Android emulator (Pixel profile, 896 × 1994, 320 dpi) at 001af49fc, with the local hook.
    • All Activity showed the marked send as Move to Spark, outgoing, at 733,712, which is 733,585 plus a 127 sat fee. It had the purple transfer icon.
    • Its detail was titled Move to Spark and showed fee 127.
    • 114f3a88c adds the pending and failed move rows and lists moves under Other. Unit tests cover those; the Preview doesn't show them.
  • Checks: just compile, just test, detekt and lintDevDebug pass.

Gaps

  • J1 on the local Spark stack was not run for this PR: a real move, Back during a move, and the row after a real move. The unit tests above cover Back during a move. The Preview shows the row on generated data.

Models used

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

A late failure event of an earlier attempt no longer ends the hold of an uncertain retry of the same invoice. After a waiting early claim, the Instant claim poll stops quoting and only watches for the claim. Also rewords the spark send liveness comment.
Stub the now-suspending move check in the send flow tests, drop translations
of two keys English marks untranslatable, wrap long lines, and add the
Activity row to the move-to-spark journey.

Verified: detekt, lintDevDebug, MoveToSparkRepoTest, BackupRepoTest, AppViewModelSendFlowTest, MoveToSparkViewModelTest
A closed Move to Spark screen's late cleanup no longer clears the quote of a
screen opened after it. Skipping unimportable stored exit data drops a staged
restore only when it holds that same data.

Verified: detekt, BackupRepoTest, MoveToSparkViewModelTest, SparkRepoTest, MoveToSparkRepoTest
@ovitrif ovitrif added this to the 3.2.0 milestone Nov 17, 2026
@ovitrif ovitrif self-assigned this Nov 17, 2026
@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:36:35.051920Z 8b6dfd7 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 requested review from a team, ben-kaufman and pwltr and removed request for a team November 17, 2026 14:34
@ovitrif ovitrif removed this from the 3.2.0 milestone Nov 17, 2026
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The PR reaches payment tracking, wallet activity, Spark claiming, and exit-backup workflows.

Clear the move manager during wallet wipe before merging.

Findings

  1. P1 Old move survives wallet wipe ▶
  2. P2 Portuguese messages contain broken words ▶

Summary

This PR keeps Move to Spark running after its screen closes and remembers move hashes across restarts.

  • A Move to Spark payment keeps running after its screen closes.
  • Move to Spark payments appear as one outgoing Activity entry.
  • Spark claim polling waits for an early claim instead of asking for more quotes.
  • An earlier Spark payment failure no longer ends a retry’s hold.
  • Unimportable Spark exit data no longer blocks a fresh backup upload.
  • Spark screens and wallet notices have translated text across the app’s locales.
  • The Lightning liveness note and move-payment tests are updated.

Acknowledged behavior: ovitrif explicitly describes the missing restored send time and the decision to let failure events end that hold after restart.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Screen[Move screen] --> Manager[App-scoped move manager]
  Manager --> Repo[Move repository]
  Repo --> Cache[Persist move hash]
  Repo --> LDK[Send over Lightning]
  LDK --> Outcome[Wait for payment outcome]
  Outcome --> Manager
  Cache --> Activity[Move title and icon in Activity]
  Wipe[Wallet wipe] --> Stores[Clear wallet stores and node]
  Wipe -. Missing reset .-> Manager
Loading

Reviews (1) · Last reviewed commit: "fix: keep staged exit data and a reopene..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from ff2687e (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

Back up move to Spark hashes in the metadata envelope as bitkit-ios does
(lowercase, sorted, left out when empty, read leniently) and merge them on
restore. Set unimportable exit data aside under SPARK_EXIT_REJECTED, keeping
the first copy and a different one under its digest. List moves under Other,
not Sent, and keep a pending or failed move's row with its status.

Verified: just test, just lint
@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 114f3a88c to match bitkit-ios on three points:

  • Move hashes in the metadata backup: they ride as moveToSparkPaymentHashes (lowercase, sorted, left out when empty, read as none when unreadable), and a restore adds them to the device's own.
  • Exit set-aside key: unimportable exit data now goes under SPARK_EXIT_REJECTED, the key bitkit-ios uses in the same store. A copy already kept is never replaced; a different one goes under the key plus the first 16 hex digits of its SHA-256.
  • Move rows: moves list under Other and not Sent, and a pending or failed move keeps its row with Pending or Failed as its subtitle.

An earlier attempt's late failure now returns before it is recorded, so the
uncertain retry's Activity row stays pending, as on bitkit-ios. The
move-to-spark journey takes the iOS wording for its last steps.

Verified: just test, just lint
@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 97b31e1c6. A late failure from an earlier attempt now returns before it is recorded, so a retry still in doubt keeps its Activity row pending, as on bitkit-ios. The move-to-spark journey also takes the iOS wording for its last two steps.

@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 in the paths I read. Spark follow-ups: moves to Spark are kept in the cache and backup so Activity shows each as one move, the move screen's state now lives in a singleton MoveToSparkManager, unimportable Spark exit backups are set aside, an older failure no longer settles an uncertain retry, and QuickPay re-checks its limits at dispatch. Reviewed 114f3a8, static: per the Bitkit track rules this branch was not built here.

What I checked, and 4 candidates I ruled out

Read: MoveToSparkRepo, MoveToSparkManager, MoveToSparkViewModel, CacheStore.addMoveToSparkHash, BackupPayloads (LenientStringListSerializer), the BackupRepo exit-backup and restore hunks, the SparkRepo hunks (uncertain sends, early claim wait, mergeRemoteExitBackup), ActivityListViewModel, ActivityRow / ActivityIcon / ActivityDetailScreen.
Not read in full: the middle of the QuickPayRepo diff (LNURL admission and the dispatch path), and the tests.

Ruled out

  • Hash case mismatch: every write and read of moveToSparkHashes lowercases, including restore merge and isMoveToSpark.
  • A move lost on process death before payment: the hash is persisted before payAndWait, so a restart still hides both legs.
  • Rejected exit backup overwritten: setAsideRejectedExitBackup never replaces an existing copy and suffixes a different one with its SHA-256 prefix.
  • Screen reset cancelling a running move: reset returns while isMoveInFlight, and a newer screen token blocks an older screen's reset.

Merge confidence: 3/5, part of the diff (QuickPay dispatch, tests) was not read, so this is the ceiling whatever the reviewed paths showed.

Verified: just compile, just test, just lint
@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed f7184ed: three changes, each to match synonymdev/bitkit-ios#1355.

  • Retry hold allows for clock skew. A late Spark failure counts as an earlier attempt's only when it is dated more than 10 s before the retry started. A failure within that window is the retry's own and ends its hold.
  • Restored exit data that Spark rejects is set aside. Before each exit backup upload, Spark tries the staged restore again. When it rejects the data as invalid input, the stored backup is set aside if it still holds that data. Otherwise the staged data is set aside in a new backup envelope. Then the staged file is dropped and the fresh export uploads.
  • Each rejected copy has its own key. Rejected copies go under SPARK_EXIT_REJECTED_ plus the first 16 hex digits of their SHA-256, and the plain key is never written.

New cases in SparkRepoTest.kt and BackupRepoTest.kt cover all three. The clock-skew case fails without the margin.

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code scan at f7184ed: no findings.

f7184ed already closes the one candidate that survived verification, the late-failure compare with no clock-skew margin. isEarlierFailureOfUncertainSend now allows RAIL_CLOCK_SKEW_SECONDS = 10 (SparkRepo.kt:1787), as iOS does. I reproduced the old behaviour with a unit test before the push: a phone clock 3 s ahead of Spark dropped the send's own PaymentFailed, leaving the send screen pending and the invoice refused until it expired. The 10 s margin makes it pass, and the older-failure cases still hold.

What I checked:

  • Double pay. reset() is skipped while isMoveInFlight, and start() doesn't quote while it keeps an outcome. Done(InFlight) offers only OK, so no path from the UI quotes over a running move. A restart mid-move re-quotes with a new invoice, and the pending HTLC lowers movableSats. The fee cap is still feeCapMsat(quote.feeSats), now tested.
  • Backup. Spark and Move to Spark aren't in v3.1.1, so there's no installed format. The new field is read as null from old envelopes and ignored by old apps (ignoreUnknownKeys). LenientStringListSerializer returns empty for malformed values. Restore takes the union of lowercased hashes. Wipe resets CacheStore (WipeWalletUseCase.kt:122).
  • Exit set-aside (f7184ed). Rejected staged exit data is copied aside under a digest-keyed SPARK_EXIT_REJECTED_* key before discardStagedExitState deletes it. The delete happens only when the file still holds the same data, so a failed set-aside keeps the staged file for the next upload. A transient import failure stays Pending.
  • Cancellation. It propagates through the move and the exit paths. quoteJob is touched only from the main thread, and generation checks guard the state writes.
  • iOS twin. synonymdev/bitkit-ios#1355 already had the skew margin and a synchronous move-hash read.

perf: mildly relevant. After Spark reports Waiting, the claim poll does one listUnclaimedDeposits per 5 s tick instead of a list plus a quote. Each Activity row now runs its own moveToSparkHashes collector.

Device gate (partial): f7184ed — not run yet; pending: transfer/move-to-spark.xml with Back during a move and reopen, Activity rows and details for a done, pending and failed move, and Activity scroll frame timing with 100+ rows. Device results and the final review type follow in a second review.

@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed ab895d2: two changes, each to match synonymdev/bitkit-ios#1355.

  • A retry's send time survives a restart. It is stored with the in-doubt send, so after a restart a late failure from an earlier attempt still can't end the retry's hold or mark its row failed. Sends kept before this change have no send time, and their own failure still ends the hold.
  • A restore sets aside exit data it can't read. The data goes under its digest key, and the restore completes instead of reporting the exit category as failed.

New cases in SparkRepoTest.kt and BackupRepoTest.kt cover both. The restart case fails without the stored send time.

A sync that runs as a send returns no longer takes back its saved hold
before the result clears it, as when Spark refuses it for its balance.

Verified: just format, just compile, just test, just lint
A sync takes back saved holds under the same lock a send leaves flight
with, so it never restores a hold a refused send just cleared.

Verified: just format, just compile, just test, just lint
Settling a send takes its hold and clears the saved copy under the
lock a sync restores holds with, so its failure is reported once.

Verified: just format, just compile, just test, just lint
The poll and Spark payment event claim the payment id before reporting,
so a failure the poll settled first is not reported again.

Verified: just format, just compile, just test, just lint
The poll builds the event from the payment it read and claims its id
only for the send own final outcome, so a retry read as pending keeps
its success and an expiry past an earlier failure is still reported.

Verified: just format, just compile, just test, just lint
Verified: just format, just compile, just test, just lint
Verified: just format, just compile, just test, just lint
Verified: just format, just compile, just test, just lint
@ovitrif

ovitrif commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

cc0cc6c: a failure event no longer drops a retry's hold. The event checked the hold, then read Spark's list and wrote the row before ending the hold and the saved send for the invoice, so a retry that entered Spark's send call in between lost both. The event now checks again under the restore lock right before ending them, as the poll does since 5f79ba2.

Verified: just format, just compile, just test, just lint
The sync that records Spark's list now settles each held send from that
same list, so a send whose own failure Spark lists frees its invoice at
launch even when the next read of Spark's list fails.

Verified: just format, just compile, just test, just lint
pwltr
pwltr previously requested changes Nov 21, 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 d20d1c7. Spark's ten-second clock allowance in SparkRepo.kt:1535 can match a previous attempt's failure to a different attempt on the same invoice. For example, the first attempt fails, the user retries five seconds later, and the retry loses its response while history still shows only the first failure.

Medium: The poll and the delayed failure callback can both release the live retry's hold and saved send (SparkRepo.kt:688, SparkRepo.kt:741, SparkRepo.kt:1990, SparkRepo.kt:2009). That allows another submission, including over a Lightning channel, while Spark may still finish the retry.

Medium: The pending-screen lookup can independently use that first failure before the hold is cleared (SparkRepo.kt:1518, AppViewModel.kt:7991, AppViewModel.kt:8022). It reports the retry as failed, clears its pending contact context and stops tracking it on the Pending screen. Bind failure to the attempt before releasing the invoice or resolving the screen.

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 retry's saved start is floored 11 s past every failure Spark dated for
its invoice, or past now when Spark's list can't be read, so an earlier
attempt's failure inside the clock margin never reads as the retry's own.
A failure only fails an existing send row in place, so at expiry the
retry's row keeps its own amount and fee.

Verified: just format, just compile, just test, just lint
@ovitrif

ovitrif commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr the clock-margin case from your review of synonymdev/bitkit-ios#1355 applies here too, as this PR uses the same date rule. Fixed in 8573baf:

  • A retry's saved start is now at least 11 s past every failure Spark dated for its invoice that the app knows, from Spark's list, its payment events or the send's own result. In your case (A starts at 995 and fails, B starts at 1000), B's start is saved past A's failure, so A's failure no longer ends B's hold or replaces B's amount and fee.
  • At expiry, with only A's failure listed, B's row fails in place and keeps its own details, also when a later sync lists A's failure again.
  • The floor is still only the saved start, so nothing new is persisted, and a restart reads it back.

The remaining gap is a retry starting before the app knows the earlier attempt's failure. It can't happen:

  • An attempt whose outcome is unknown keeps its hold until Spark lists or settles it, so a retry can't start before. Only errors that guarantee nothing reached Spark clear the hold: an expired invoice, a short balance, and the deadline and exit checks before the call.
  • A failure learned in an earlier run is read from Spark's list at the retry. When that list can't be read, the start is saved past now, so any failure Spark could already have dated falls before it.

Also in 2372752: the launch sync now settles a held send from the list it just read, so a send whose own failure Spark lists frees its invoice even when the next read of the list fails.

Covered by new cases in SparkRepoTest.kt.

@ovitrif

ovitrif commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

The poll and the delayed failure callback can both release the live retry's hold and saved send

The pending-screen lookup can independently use that first failure before the hold is cleared

@pwltr addressed in 8573baf, which this comment explains. A retry's saved start is now at least 11 s past the earlier attempt's failure, so in your five-second case that failure reads as the earlier attempt's on every path that reads it: the poll, the failure event, and the pending-screen lookup. The retry stays held and pending until its own outcome or its invoice's expiry.

The sync settles only the holds taken before it read Spark's list, so a
send held while it writes activity is never settled from that older list.
A send whose start can't be dated because Spark can't list its payments
is refused before anything goes out, instead of saving a start past now
that made its own failure read as an earlier attempt's.

Verified: just format, just compile, just test, just lint
After a restore, before Spark syncs, its list can't date an earlier
attempt the operators show failed, and a send must start past that
failure, so a Spark send of such an invoice is refused until Spark syncs.
An invoice the operators show no send of still sends.

Verified: just format, just compile, just test, just lint
@ovitrif

ovitrif commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed ff2687e: after a restore, before Spark syncs, a Spark send of a pre-restore invoice that the Spark operators show failed is now refused until Spark syncs. Spark's list can't yet date that earlier failure, and a send must start past it so the failure never reads as its own. An invoice the operators show no send of still sends, and the node's rail is unchanged. This matches bitkit-ios.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

5 participants