Skip to content

fix: keep a stop requested during a server change's build - #1529

Merged
piotr-iohk merged 3 commits into
masterfrom
fix/stop-during-config-build
Nov 28, 2026
Merged

piotr-iohk merged 3 commits into
masterfrom
fix/stop-during-config-build

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1527
Companion: synonymdev/bitkit-android#2148

Keeps a stop requested while an Electrum or RGS change is building the node, matching synonymdev/bitkit-android#2148.

Description

  • A stop requested while a config change or its recovery builds the node finds no node yet, so it stops nothing, and the change then started the node on the new server. The change now checks for a stop again after setup and releases the node its own setup built instead of starting it, never a node another start built since.
  • The restart reads the stop count when it is queued instead of after its own stop, so a stop requested while it waits behind another restart or stops the old node wins too. A restart or recovery that finds such a stop leaves the current node alone, since another start (such as the routing-cache reset after a failed payment) may have built it after that stop.
  • A config change ended by a stop no longer runs its recovery, which could stop a newer node.

Out of Scope

Design

N/A — no UI changes.

Preview

N/A

QA Notes

Setup

N/A — no device testing required: the stop has to land inside the build, which cannot be timed from the app.

Journeys

N/A — no user-visible behaviour change.

Manual Tests

N/A

Automated Checks

  • added LightningServiceTests.swift — a built node is released instead of started after a stop during setup, and starts without one; a queued restart leaves the current node alone after a stop while it waited; a config change ended by a stop does not recover.

Evidence

  • Unit suite (CI test selection) on an iPhone 17 Pro simulator, iOS 26.5, at 7f490ab: passed.

Gaps

  • A stop landing inside the build cannot be timed in the app, so the release is covered by the unit tests only.

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: 1

A stop requested while a config change or its recovery builds the node finds no node to stop. The change now checks again after setup and releases the built node instead of starting it, and reads the stop count before its own stop.

Verified: CI unit-test selection on an iPhone 17 Pro simulator (iOS 26.5) before the stop-count move, LightningServiceTests after it, swiftformat --lint on the changed files.
The restart reads the stop count when it is queued, so a stop requested while it waits behind another restart wins, and a config change ended by a stop no longer runs its recovery.

Verified: CI unit-test selection on an iPhone 17 Pro simulator (iOS 26.5), swiftformat --lint on the changed files.
@ovitrif ovitrif added this to the 3.2.0 milestone Nov 27, 2026
@ovitrif ovitrif self-assigned this Nov 27, 2026
@ovitrif
ovitrif requested review from a team, ben-kaufman and piotr-iohk and removed request for a team November 27, 2026 13:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 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-27T13:46:53.433018Z 4a90137 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 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking gap in tests for queued restarts.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects Lightning restart and recovery flows across server settings and other restart callers.

The PR appears safe to merge, with a non-blocking gap in tests for queued restarts.

Findings

  1. P2 Stop timing remains untested ▶

Summary

This PR keeps stop requests from being overtaken by an Electrum or RGS server change.

  • Lightning restarts leave a built node stopped when a stop arrives.
  • A stop now ends a failed server change without restoring the old settings.

Scope acknowledged by ovitrif: a stop between the node lookup and native start() remains out of scope because the race affects every start path.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Queue restart and capture stop count] --> B[Wait for previous restart]
  B --> C[Stop old node]
  C --> D{Stop requested?}
  D -->|Yes| E[Throw without recovery]
  D -->|No| F[Build node]
  F --> G{Stop requested?}
  G -->|Yes| H[Release built node]
  H --> E
  G -->|No| I[Start node]
Loading

Reviews (1) · Last reviewed commit: "fix: let a stop win over a queued restar..." · Reviewed by Greptile

Comment thread BitkitTests/LightningServiceTests.swift Resolved

@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. Rechecks for a stop after setup in the config change and its recovery and releases the built node instead of starting it, reads the stop count when the restart is queued, and skips the recovery when a stop ended the change. Reviewed 4a90137f4, full tier, static: iOS does not build on Linux, so I did not build or run it.

What I checked, and 3 candidates I ruled out

Read in full: restart, restartNode, applyConfigChange, restartWithPreviousConfig, startRetryingBusyStore, startUnlessStopRequested, stop/stopNode, stopReleasingFinishedNode, setup in LightningService.swift; the new and existing tests in LightningServiceTests.swift.
Call sites traced: restart(electrumServerUrl:rgsServerUrl:) from SettingsViewModel+Electrum.swift:27, SettingsViewModel+Rgs.swift:22, LdkDebugScreen.swift:111, AppViewModel.swift:1956; stop() from WalletViewModel.stopNodeLocked (reached by NodeRestarter's recovery stop, resetNetworkGraph, stopForWipe).
Twin: compared with synonymdev/bitkit-android#2148, which also releases the built node when the stop count moved during setup.

Ruled out

  • Release of a built, never-started node fails: stopNode runs node.stop() through stopReleasingFinishedNode, which swallows NotRunning, the error ldk-node gives for a node that never started, then releases it and the lightning lock.
  • The release error is retried as a busy store: startUnlessStopRequested throws nodeNotSetup, which isKvStoreSetupFailure rejects, so startRetryingBusyStore does not start again.
  • Moving the capture to queue time cancels a restart over an unrelated stop: a stop counted while the restart waits is exactly the case the PR wants to win; stop() is only reached from the recovery, graph reset and wipe paths, and none of them wants the restart to bring the node back.

The queued-capture timing has no test; Greptile already raised that, so I did not repeat it.

CI: SwiftFormat, validate and Greptile passed; Run Tests, Run Integration Tests and build-local were still pending when I read them.

Merge confidence: 4/5, no findings, but the unit tests have not reported on this head and the review is static.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not report an effort setting)

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

QA review

Scope: full PR diff against its merge base, at 4a90137f.

No new actionable code findings.

No actionable code findings. A stop counted while an Electrum or RGS restart is queued, waiting, stopping the old node, or building the new one releases that built node and skips recovery, matching #1527. stopNode still treats ldk-node's NotRunning as the release of a built node that never started, so the node and the lightning lock are dropped. The race inside LightningService.start(), between the node lookup and native node.start(), remains the case the PR leaves out of scope; this change does not widen it.

Compared only the stop-during-build contract with bitkit-android#2148 at abd015b07. Both sides release the built node and skip recovery when a stop is counted during setup. Android also releases a node left behind by a failed or cancelled change, and it debounces a background stop. On iOS a failed change with no stop still runs recovery.

Device testing: not performed in this review. A journey cannot time a stop into the build, which is why the PR marks device testing N/A. The new tests in LightningServiceTests.swift cover releasing instead of starting and skipping recovery. They do not run restart(), so they would still pass if the stop count were read again after the queue wait. That gap is already in Greptile's comment. This review did not run the unit suite. On this head, GitHub's Run Tests and Run Integration Tests were still in progress; SwiftFormat and validate had passed. The author reports the unit suite passed locally at this revision.

Existing concern, unchanged from the merge base: recovery still calls setup with nil server URLs, and setup resolves nil to Env's network default rather than the saved Electrum or RGS server. A failed change that recovers would bring the node up on that default for the rest of the session.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Existing concern, unchanged from the merge base: recovery still calls setup with nil server URLs, and setup resolves nil to Env's network default rather than the saved Electrum or RGS server.

@piotr-iohk Confirmed: a normal start passes the saved servers, recovery passes nil. Out of scope here, since it predates this PR: tracked in #1530 under 3.2.0.

@ovitrif
ovitrif requested review from pwltr and removed request for ben-kaufman November 27, 2026 16:24
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Requested review from @pwltr instead of @ben-kaufman, who is away for a few 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.

Reviewed 4a90137. The earlier stop snapshot extends cancellation to the queue wait and old-node teardown.

Low — A canceled restart can stop the wallet’s replacement node. Bitkit/Services/LightningService.swift:448 looks up and stops the current node before checking whether the queued restart is still valid. If a routing-cache retry stops the node and finishes starting a replacement while that restart is queued, the restart can tear down the replacement and then exit, leaving Lightning offline while the wallet still reports it as running. Check for cancellation before touching the current node.

Low — An interrupted RGS change can report failure and still become the saved setting. Bitkit/ViewModels/Extensions/SettingsViewModel+Rgs.swift:71 saves the URL before the restart. If a separate node stop interrupts teardown, Connect or Reset shows a failure, and the next wallet start still uses the newly saved URL. Save the URL after the restart succeeds.

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

A restart and its recovery read the current node before checking for a stop, and stop only that node; a restart that yields to a stop after setup releases only the node its own setup built. Another start (such as the routing-cache reset after a failed payment) may have built the current node after that stop.

Verified: swiftformat lint, unit suite (CI selection) on an iOS simulator
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@pwltr

Low — A canceled restart can stop the wallet’s replacement node.

Fixed in 7f490ab: a restart, and its recovery, read the current node before checking for a stop that came while they waited, and stop only that node. A restart that yields to a stop after setup now releases only the node its own setup built.

Low — An interrupted RGS change can report failure and still become the saved setting.

Out of scope: tracked in #1535, because the URL is saved before the restart on master too; this PR doesn't change that path.

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

QA review

Scope: changes since 4a90137f, including affected code paths and prior findings, at 7f490ab8. Baseline: QA review.

No new actionable code findings.

No new actionable code findings in the follow-up. A queued restart and its recovery snapshot the current node, then yield when a stop was requested while they waited, and a stop during setup releases only the node that setup built. A node another start built after that stop, including the routing-cache retry, stays up. That closes the replacement-node stop described in pwltr's review.

Existing concerns, still present and already tracked: recovery still passes nil server URLs, so a failed change comes back on the network default for the rest of the session (#1530). An RGS change still saves the URL before restart, so a failed change can remain the saved setting (#1535). Both remain in the current tree.

Compared the stop-during-setup contract with bitkit-android#2148 at a45ca2ae. Android's yield stops the current service node. This change releases only the node its own setup built.

Device testing: not performed in this review. Run Tests, Run Integration Tests, and SwiftFormat succeeded on this head. The new unit tests cover the static yield guard. A stop inside a real build remains outside what those tests and a journey can time. The Greptile thread on that test gap is resolved.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@piotr-iohk
piotr-iohk merged commit 7c65088 into master Nov 28, 2026
21 of 22 checks passed
@piotr-iohk
piotr-iohk deleted the fix/stop-during-config-build branch November 28, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: a stop during a server change's build is lost

4 participants