Skip to content

fix: release savings payments a force transfer no longer needs - #2142

Merged
ovitrif merged 8 commits into
masterfrom
fix/spark-exit-release-unneeded-funding
Nov 27, 2026
Merged

ovitrif merged 8 commits into
masterfrom
fix/spark-exit-release-unneeded-funding

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2136
Twin: synonymdev/bitkit-ios#1518

Description

  • Fixes a savings payment to a force transfer's funding address blocking every new on-chain send once the exit no longer needs it. The payment had no answer from the node, so it stayed unresolved, and Payment Pending could only pay it again, to an address the exit no longer watches.
  • Payment Pending now tells such a payment apart by its address (the exit's, or an earlier exit's) and offers to cancel it once the exit no longer needs it: the exit ended or was cancelled, or another wallet funded it and none of this payment's transactions landed or are still awaited. The cancel goes through the existing release (it first checks the payment never reached the network, then spends its coins back to the wallet), with its own note.
  • While the exit still needs the payment, Payment Pending keeps Retry. Like Progress' Pay from savings, the retry reads the funding address right before sending and refuses when the exit no longer asks for the funding (another wallet's funding covered it), the exit or address can't be read, or its cancel was approved. A partial payment from another wallet still leaves the ask, so Retry stays: what savings pays beyond it comes back as leftover.
  • An approved cancel is finished from Payment Pending even after the exit's record is gone.

Out of Scope

Tracked in #2157:

  • An ended exit's address is not kept when a new exit replaces its record, so a payment to it is treated as an ordinary send. This predates this PR.
  • Progress' Pay from savings refused because funding arrived does not update the funding shown until the next refresh.

Design

N/A — no design available. One new note in the cancel confirmation, translated into every locale.

Preview

N/A — a savings payment the exit no longer needs, with no answer from the node, hasn't been reproduced on a device yet.

QA Notes

Journeys

N/A

Manual Tests

  • 1. start a force transfer paying from savings while its savings send has no answer, then fund the exit from another wallet → Payment Pending offers to cancel the savings payment, and new on-chain sends work after it
  • 2. same, but the exit still asks for the funding → Payment Pending offers Retry, which pays it once

Automated Checks

  • updated PaykitPaymentProofRepoTest.kt, SparkExitRepoTest.kt, SendPendingViewModelTest.kt and AppViewModelSendFlowTest.kt
  • ran ./gradlew testDevDebugUnitTest for those
  • ran ./gradlew detekt

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: Gemini 4 Neon (reasoning: high)
  • Review rounds: 6

A savings send to a Spark exit's funding address, told apart by that
address (the current record's or an earlier exit's), is released through
the existing release path once the exit no longer needs it: the exit was
cancelled or ended, or it holds all its funding and none of it is the
send's. One the exit adopted, or still waits for, is never released.

Payment Pending never offers "Retry original payment" for an exit's
funding, which Progress owns, and offers the release with its own note
once the exit no longer needs it. Progress' Pay from savings retry and
Payment Pending's retry read the exit again right before dispatch and
refuse once it is funded.

Verified: testDevDebugUnitTest (full suite; the new
PaykitPaymentProofRepoTest release and pay-again tests fail with the gate
stubbed out), detekt, lintDevDebug
A savings send's txid stayed on the exit record after another wallet funded it, so the send was never released. Only a payment the exit still waits for keeps it now. A release already approved also stops for a send that landed as leftover, and paying again refuses once another wallet's funding reached the address. Adds tests for the retry's funding check and Send Pending's exit-funding guard.

Verified: gradlew testDevDebugUnitTest PaykitPaymentProofRepoTest, SparkExitRepoTest, AppViewModelSendFlowTest (before the isAdopted line wrap); detekt
Once a release of a savings send to a force transfer's funding address is approved, Send Pending finishes it even after the exit's record is gone, instead of offering Retry. Paying again now ignores the exit's own adopted outputs and their change when it looks for other funding.

Verified: gradlew testDevDebugUnitTest PaykitPaymentProofRepoTest, SparkExitRepoTest, AppViewModelSendFlowTest; detekt
Send Pending hid Retry for every savings send to a force transfer's funding address, so an unresolved one Progress could not pay again stayed stuck and blocked new on-chain sends. It offers Retry again unless the release is offered, and the retry checks right before dispatch that the exit still asks for the funding and nothing else reached the address, the same check Progress uses. A send whose release was approved is never paid again.

Verified: gradlew testDevDebugUnitTest PaykitPaymentProofRepoTest, SparkExitRepoTest, AppViewModelSendFlowTest, SendPendingViewModelTest; detekt
A savings send whose cancel was approved is refused before the exit-funding check, so it stays refused once the exit's record is gone, and Send Pending hides Retry for it.

Verified: gradlew testDevDebugUnitTest PaykitPaymentProofRepoTest, SparkExitRepoTest, AppViewModelSendFlowTest, SendPendingViewModelTest; detekt
@ovitrif ovitrif self-assigned this Nov 26, 2026
@ovitrif
ovitrif requested review from jvsena42 and pwltr November 26, 2026 20:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 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-26T20:03:55.561411Z 2afb912 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 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking issue where Payment Pending can keep Retry hidden after the exit needs funding again.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect recovery for a bounded set of on-chain savings payments tied to Spark exits.

The PR appears safe to merge, with a non-blocking issue where Payment Pending can keep Retry hidden after the exit needs funding again.

Findings

  1. P2 Retry stays hidden ▶

Summary

Lets Payment Pending cancel unresolved savings payments that a force transfer no longer needs.

  • Payment Pending offers to release Spark exit payments the exit no longer needs.

Explicitly deferred by ovitrif: keeping an ended exit's address when a new record replaces it; updating Progress immediately when savings payment is refused because funding arrived.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Unresolved savings payment] --> B{Matches an exit address?}
  B -->|No| C[Keep ordinary Retry]
  B -->|Yes| D{Exit still needs payment?}
  D -->|Yes| E[Retry checks exit and address again]
  D -->|No| F[Offer cancellation]
  F --> G[Check that no candidate reached the network]
  G --> H[Approve and save release]
  H --> I[Spend coins back to wallet]
Loading

Reviews (1) · Last reviewed commit: "fix: never pay an approved exit funding ..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 378c2e2 (run).

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

@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 new findings. Lets Send Pending release an unresolved savings send to a Spark exit's funding address once the exit no longer needs it, and makes Retry check the exit again right before dispatch. Reviewed 2afb912, full tier, static.

What I checked, and 5 candidates I ruled out

Read in full: SparkExitFundingRelease.kt, and the changed parts of OnchainSendAttemptStore.kt, PaykitPaymentProofRepo.kt, SparkExitRepo.kt, SendPendingViewModel.kt, SendPendingScreen.kt, AppViewModel.kt
Call sites traced: canBeAbandoned (store approveRelease, recordRelease, abandonUnbroadcast), onchainRequestHasEnded, abandonUnbroadcastOnchainPayment, finishRelease, retryOriginalOnchainSend's authorize callback, SparkExitMath.fundingState / newFunding, the cancel path that moves a forgotten exit's address into SparkExitEarlierAddressStore
Build: not built here. The sandboxed runner refused the build, so CI is the gate (build-and-test, lint, compose-ui / ui-tests, all still pending at review time)

Ruled out

  • Every ordinary send now passes canBeAbandoned, so the store no longer refuses releasing one: the only path to approveRelease / abandonUnbroadcast is abandonUnbroadcastOnchainPayment, which first needs onchainRequestHasEnded. For mayFundSparkExit that is exitNoLongerNeeds, which is true only when the address matches the stored record's funding address or an earlier exit's. An unreadable exit returns false.
  • Retry pays an address that already got funding from another wallet: authorizePayAgain reads the address's UTXOs inside the authorize callback before dispatch, and mayPayAgain allows only Ask with nothing received, or Paid where every new UTXO is one of this attempt's candidates. A failed read refuses.
  • Release of a payment that landed: isAdopted / exitNoLongerNeeds check every candidate against funding, leftover and the awaited fundingPaymentTxid, and onchainCandidatesNeverReachedNetwork still runs before approval.
  • Stale record read off disk while the repo writes it: SparkExitStore.save and the earlier-address store write a temp file and ATOMIC_MOVE it into place, so storedExit sees the old file or the new one, never a partial one.
  • Retry hidden after the exit asks for funding again: this is the open Greptile thread on SendPendingViewModel.kt:364. I did not repeat it.

Merge confidence: 4/5. No findings, but CI was still running at review time and this was not built here.

Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: Not exposed (this runtime does not report it)

…ase-unneeded-funding

# Conflicts:
#	app/src/main/java/to/bitkit/repositories/SparkExitRepo.kt
@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 40d4816, resolving a conflict in SparkExitRepo.retrySavingsPayment: it keeps master's pending-error handling, which keeps the txid and notes the send after success or failure, and runs this PR's authorize check before dispatch.

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

One MEDIUM and one LOW, inline.

LOW (PR body, no line to anchor): manual test 1 cannot be performed as written. While the savings send has no answer, noteSavingsSend sets isSavingsSendUnresolved, so canCancel is false (SparkExitRepo.kt:1238-1248), Progress hides Cancel (SparkExitProgressScreen.kt:158) and cancel() throws "The Spark exit can no longer be cancelled". An Unknown outcome also sets fundingPaymentTxid, which fails canCancel too. Please rewrite case 1 to a reachable route: exit funded by another wallet (as in #2136), or exit ended (Done/Failed).

Checked and clean:

  • Paid twice: retry re-signs the attempt's originalInputs (retainPreparedReceipt requires the same input set and amount), so at most one candidate confirms.
  • Release and retry both going out: approveRelease, recordRelease and abandonUnbroadcast compare the whole stored attempt to the expected one, so a retry that changed the attempt makes a release started earlier stop. releaseApproved survives retainPreparedReceipt and discardUnsubmittedRetryCandidate, so authorizePayAgain refuses a retry after an approved release. The two buttons disable each other.
  • Release while the broadcast is unresolved still needs a fresh sync showing no candidate, and releaseOutbids still needs an original coin and a higher fee than any candidate.
  • Ordinary sends reach approveRelease only through onchainRequestHasEnded, which needs an address match against the exit record or an earlier exit.
  • Authorization: retry keeps the fee dialog, sanity warnings and PIN/biometrics before anything is retained; the exit check runs after approval and right before dispatch. Release keeps its note, fee and PIN steps.
  • Lifecycle: killed after approveRelease, reopening offers only the cancel and finishes it; killed after the release broadcast, the saved releaseTxid is found on the next cancel. Attempts from the published release without originalInputs cannot be abandoned, as before.
  • Persisting releaseApproved before the fee prompt follows the existing Shop-payment pattern, and Send Pending still offers to finish the release afterwards.
  • Back/cancel on Send Pending: closing before approveRelease persists nothing. Fee-rate, fee-approval and PIN cancels on Retry retain no candidate.
  • wallet__send_pending__abandon_exit_note is in all 16 locales. The longest (it 217, nl/el/ca 213, de 212 characters) are in the range of the existing wallet__send_pending__abandon_note in the same AppAlertDialog.

perf: not relevant.

Device gate: not run; held until the MEDIUM is resolved.

Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating and verifying; Fable 5.2 (claude-fable-5-2) primary review
Reasoning effort: Not exposed

Pay again while the exit still asks, waits for this payment or holds its
own coin: a retry re-signs the same inputs, and what savings pays beyond
the ask comes back as leftover. An unreadable list of earlier exit
addresses reads as empty, so it never refuses an ordinary send's Retry.

Verified: gradlew testDevDebugUnitTest SparkExitRepoTest, PaykitPaymentProofRepoTest, SendPendingViewModelTest (pass; the partial-payment and unreadable-list tests fail on 40d4816 per the reviewer's repro), gradlew detekt
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

LOW (PR body, no line to anchor): manual test 1 cannot be performed as written.

@jvsena42 Fixed in the PR body. Case 1 now funds the exit from another wallet, then cancels the savings payment. The two inline points are addressed in 378c2e2.

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

Low: Declining the exact cancellation fee can disable Retry for the original savings payment. PaykitPaymentProofRepo.kt:770 saves releaseApproved before the fee dialog. Dismissing it exits at SendPendingViewModel.kt:277 before a release transaction is recorded. If the externally funded exit later asks for a top-up, Retry stays unavailable even after reopening Payment Pending. Keep the original retry available when the user declines the fee, while preserving recovery for an authorized release.

Low: Payment Pending and Force Transfer Progress use different eligibility checks from retry dispatch. When an unconfirmed payment from another wallet already covers the funding request, SparkExitFundingRelease.kt:66 refuses retry. SendPendingViewModel.kt:364 still offers Retry and takes the user through fee approval, and SparkExitViewModel.kt:508 still offers Pay from Savings even after Progress shows the funding as seen. Use the funding eligibility to decide when to offer both actions and recheck it before dispatch.

Review details

Quick review: Claude Opus 5.5, high reasoning effort
General review: GPT-6.2 Sol, high reasoning effort
Verification: GPT-6.2 Sol, high reasoning effort

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

QA for 378c2e2:

Tested on Pixel 10 Pro XL (Android 16 emulator), local regtest. A local debug-only change marked the force transfer's first savings payment as sent, then gave it no answer and never broadcast it, so it stayed unresolved.

🟢 1. Another wallet funds the exit fully
1. Another wallet funds the exit fully

Another wallet paid the full 7 623 sats and the exit moved on. A new on-chain send opened Payment Pending, which offered only Cancel expired payment, with the note that the force transfer no longer needs this payment. The cancel sent the coins back to the wallet (network fee 703 sats), and the next on-chain send (1 000 sats) went through.

case1-cancel2x.mp4

🟢 2. Another wallet pays part of the funding
2. Another wallet pays part of the funding

Another wallet paid 3 000 of the 7 623 sats and the exit kept asking. Payment Pending offered only Retry original payment. After the fee approval it paid once: the funding address got that one savings payment (7 623 sats) besides the partial one, and one block later the exit broadcast its next step.

case2-retry2x.mp4

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

Re-review at 378c2e2: both of my findings are fixed, and the delta adds nothing new.

  • MEDIUM (partial funding from another wallet left no way out): fixed. mayPayAgain now allows a retry in Ask whatever receivedSats is (SparkExitFundingRelease.kt:69). It allows one in Paid only for this payment's own txid (:71), and in Seen only while this payment's own coin is unconfirmed, so the retry just bumps it (:73-75). It refuses once other wallets' coins alone cover the funding (:63-66). Covered by an unresolved savings payment keeps a way out once another wallet paid part of the funding and the extended Spark exit funding is paid again only while the exit asks or waits for this payment.
  • LOW (unreadable earlier-addresses file): fixed. storedExit reads that file with its own getOrDefault(emptyList()) (:84-86). Covered by an ordinary savings send is paid again when the earlier exit addresses cannot be read.

Checked in the delta:

  • Every allowed retry is still the same attempt over the same inputs and amount. retryOriginal needs originalInputs, and retainPreparedReceipt compares the input set and amount, so it conflicts with every earlier candidate and cannot add a second payment.
  • If the own coin confirms before dispatch, the replacement is rejected for spent inputs and nothing else leaves.
  • A payment with another txid stays refused.
  • utxos == null and a funded exit both refuse.
  • Progress "Pay from savings" and Send Pending Retry still go through the same mayPayAgain.
  • In every newly allowed state the record is active with a shortfall, so release and retry are never both offered.
  • The 9 000 → 21 000 test changes keep the covered-funding refusal under test, and no assertion was weakened.

perf: not relevant.

Device gate (partial): 378c2e2 — not run yet; Retry after a partial payment from another wallet, and the release once another wallet covers the funding, on the local Spark stack. Result to follow.

Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating and verifying; Fable 5.2 (claude-fable-5-2) delta review
Reasoning effort: Not exposed

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved on 378c2e2, device run on this head posted above, all checks green.

@ovitrif
ovitrif merged commit fe5a4f3 into master Nov 27, 2026
23 checks passed
@ovitrif
ovitrif deleted the fix/spark-exit-release-unneeded-funding branch November 27, 2026 13:55
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low: Declining the exact cancellation fee can disable Retry for the original savings payment.
Low: Payment Pending and Force Transfer Progress use different eligibility checks from retry dispatch.

Both are valid. They're tracked in #2157, which gets fixed in a follow-up PR for 3.2.0, together with the iOS twin (synonymdev/bitkit-ios#1528).

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: an unresolved savings send keeps blocking sends after another wallet funds the force transfer

4 participants