Skip to content

fix: keep the spark exit transfer until cooperative steps land - #1885

Merged
ovitrif merged 2 commits into
masterfrom
fix/spark-exit-transfer-pending-cooperative
Nov 12, 2026
Merged

ovitrif merged 2 commits into
masterfrom
fix/spark-exit-transfer-pending-cooperative

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Description

  • An emergency exit's transfer to savings now stays active while any cooperative step of its recovery is still unconfirmed. Before, it settled as soon as the sweep's activity was in the wallet and no failed or waiting leaves were left. In a mixed recovery, the value of a cooperative step still on its way then dropped out of the in-transfer balance before it reached Savings. The driver kept broadcasting, so only the displayed balance was affected.
  • Follow-up to feat: spark emergency exit #1782 for @pwltr's candidate in the review at d0f2a45 (comment).

Out of Scope

None.

Design

N/A — no UI changes.

Preview

N/A — the in-transfer amount stays until the cooperative step confirms.

QA Notes

Automated Checks

  • SparkExitRepoTest: a landed sweep keeps the transfer while a cooperative step is still on its way. The transfer stays while the cooperative step is Ready and settles once it confirms.
  • Not run locally (the paykit dependency doesn't resolve here), so this PR's CI is the first run.

Not tested

  • No device run: a recovery that mixes a sweep with a cooperative step isn't something regtest can stage on demand.

@ovitrif ovitrif self-assigned this Nov 12, 2026
@ovitrif
ovitrif requested a review from pwltr November 12, 2026 11:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T11:24:18.050154Z 780bcbb 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 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Keeps a Spark exit transfer active while any cooperative step in its current recovery remains unconfirmed.

  • A pending cooperative step keeps the Spark exit transfer active after the sweep lands.

Reviews (1) · Last reviewed commit: "fix: keep the exit transfer while a coop..." · Reviewed by Greptile

@ovitrif ovitrif added this to the 3.2.0 milestone Nov 12, 2026
@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Triage: milestone 3.2.0. This PR fixes the Spark emergency exit (#1782), which is 3.2.0 work, and closes no issue, so it carries the milestone itself.

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

1 finding (1 P1). Keeps a Spark exit's transfer unsettled while a cooperative step of the recovery is unconfirmed, so its value stays in the in-transfer balance until it lands. Reviewed 780bcbb, full tier, static: Bitkit Android PRs are not built here, so this is reasoned from the code and from CI.

What I checked, and 4 candidates I ruled out

Read in full: settleIfFinished, afterTick and load in SparkExitRepo.kt; isActive, hasLeavesOutstanding, adopt in SparkExitRecord.kt; broadcastReady, broadcastWithoutSdk and the all-confirmed end in SparkExitDriver.kt; confirmedReceived/paidTo in SparkExitFunding.kt; SparkExitState.inTransferSats; the new test.
Call sites traced: settleIfFinished (from afterTick and load), inTransferSats (DeriveBalanceStateUseCase, WalletRepo)
CI: lint red on this diff (detekt ImportOrdering, inline); build-local green; build-and-test still running when this was posted.

Ruled out

  • Transfer stuck forever on a cooperative step that never confirms (an Unverified one nodes refuse): the !record.isActive arm still settles it once the exit ends, whichever way it ends, so the new condition cannot hold the transfer past the exit.
  • Balance double counted after the step confirms: inTransferSats subtracts confirmedReceived, which includes confirmed COOPERATIVE outputs, and the same tick settles the transfer, so the value moves from in-transfer to Savings once.
  • Recovery without a sweep: sweepActivity is null, so that arm never fired before either; behaviour unchanged.
  • Test passing for the wrong reason: the second load() runs on a fresh SUT (isLoaded is per instance), and the record differs only in the cooperative step's status, so markSettled is reached through the new condition and nothing else.

Merge confidence: 1/5, CI fails on the change itself (the import order), though the fix is a one-line move.

Reviewer model: claude-opus-5-5
Reasoning effort: Unknown (not recorded in the run metadata available to this reviewer)

@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed the import order that failed lint (detekt ImportOrdering).

Re-review is needed only because of this push: 780bcbb...b03ecad

@github-actions

Copy link
Copy Markdown
Contributor

Regtest APK

Built from b03ecad (run).

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

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

No findings at b03ecad. The import is now in order. The transfer change, which keeps the exit's transfer until every cooperative step confirms, is unchanged and looks right.

Review details

General review
Model: Claude Opus 5.5
Reasoning effort: high

@ovitrif

ovitrif commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Merging into master: approved by @pwltr on b03ecad, required checks green, no open review threads.

@ovitrif
ovitrif merged commit 2eb505a into master Nov 12, 2026
23 checks passed
@ovitrif
ovitrif deleted the fix/spark-exit-transfer-pending-cooperative branch November 12, 2026 12:03

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

No findings. The transfer stays active while a cooperative step is pending, and !record.isActive still settles it whenever the exit ends; settleOrphanedTransfers is unchanged. Confirmed cooperative outputs count in confirmedReceived, so the same tick settles the transfer, and a rebuild carries earlier confirmed value in earlierReceivedSats. Cooperative-only exits behave as before. The driver is untouched, so nothing new is broadcast or paid.

Device gate: no device check needed: a mixed recovery can't be staged, as the description says, and the change is in-transfer accounting covered by the new test. perf: not relevant.

Reviewer model: Claude Fable 5.2 (claude-fable-5-2), Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed

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.

4 participants