Repository navigation
fix: let a stop win over every recovery retry - #2012
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
In 3.2.0: it finishes the node stop and restart fixes of #2004, which ship in 3.2.0. |
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Makes a direct stop (notification Stop, onDestroy) end the recovery retry loop in restartWithPreviousConfig, and keeps a requested background stop across the graph-reset restart inside a recovery start. Reviewed 7509c529, full tier, statically.
What I checked, and 4 candidates I ruled out
Read in full: startNode, start, stop/stopLocked, stopDebounced/cancelPendingStop, restartWithPreviousConfig, restartWithElectrumServer, restartWithRgsServer, recoverOnCancellation, restartNode at the PR head.
Build: not built here. bitkit-android reviews are static on this side, so I relied on CI: build-and-test, lint and compose-ui / ui-tests are green at this head.
Ruled out
- The empty
lifecycleMutex.withLock { }might not let a queued stop run first: kotlinxMutexis fair (FIFO), so astop()that suspended on the lock while the failed build held it gets the lock before the recovery's re-acquire. The new test reproduces exactly that ordering. - A failed build could leave the state at
Stopped, which would end recovery with no stop requested: a failed setup or start undershouldRetry = falsesetsErrorStarting.stopLockedonly short-circuits onisStoppedOrStopping()with no node, so a real stop movesErrorStartingtoStopped, and only a stop does. The early returns (WipeInProgressError,RecoveryModeError) are not KV-store failures, so the loop has already exited before the check. - Attempt 0 sees the recovery's own
stop(): the check is gated onattempt > 0, so theStoppedthe recovery sets itself never trips it. - Graph-reset path changes for foreground callers:
start()uses the defaultshouldCancelPendingStop = true, so forwarding the caller's value changes nothing on that path. Only the recovery call (false) behaves differently, and that is the intent.restartNodestill cancels pending stops on graph reset, as the body says under Out of Scope.
Merge confidence: 5/5, CI green and both behaviours are exercised by the new LightningRepoTest.kt cases.
Reviewer model: Claude Opus 5.5
Reasoning effort: Unknown (not exposed in this run's metadata)
jvsena42
left a comment
There was a problem hiding this comment.
Code scan of 7509c52: no HIGH or MEDIUM. Both #2004 LOWs are addressed for the cases their tests cover. One LOW inline: the graph-reset path still restarts after a stop that has already run. Master does the same.
Also LOW, not inline: the new check at :1312-1318 takes and releases lifecycleMutex, reads the state outside the lock, and startNode takes the lock again at :416. A direct stop() that lands in that gap runs as a no-op on Stopped, and the retry then starts the node. The window is a dispatcher hop, so a unit test can't reach it. The stop counter from the inline fix would close it too: take the snapshot before the check and compare it inside startNode's lock.
Device gate:
Reviewer model: claude-fable-5-2 (primary), claude-opus-5-5 (verifier, coordinator)
Reasoning effort: Not exposed
Addressed in a304c94: that check is gone. Recovery snapshots the stop count after its own stop and passes it to |
jvsena42
left a comment
There was a problem hiding this comment.
Delta a304c94 (read, not built): the stop counter, checked inside lifecycleMutex in startNode, closes both LOWs from my last review. The recovery loop takes its snapshot after its own stop() and passes it to every attempt. The graph-reset restart carries the snapshot from the first leg. A stop that landed between the check and the lock now wins, as does one that ran as a no-op on Stopped. No new finding.
Device gate (ran at 7509c52, before a304c94):
| Case | Build | Result |
|---|---|---|
| 1. Keep-active on, VSS tcp/443 blocked, bad Electrum server, Stop from the notification while recovery retries | PR 7509c52 | ✅ Stop at 16:01 UTC after retry 2/5; log shows Skipped recovery start because the node was stopped; no retry, Building node or Node started for the next 8 min; no crash |
| 1. same | base 35873ab | ❌ reproduced: retries 3/5, 4/5 and 5/5 continue after the Stop |
Setup notes for case 1:
10.0.2.2:60009and a server with an untrusted certificate are rejected by the pre-restart probe, so recovery never starts.tcp://10.0.2.2:60001passes the probe and then fails onKvStoreSetupFailedwith VSS blocked.- Stop works only with the app in the background. In the foreground the log says
Skipping node stop: activity is active. - The first retry line comes about 3.5 min after recovery starts.
- Disable the cached-apps freezer, or a silent log can't be told apart from a frozen process.
Device gate: case 1 ✅ at 7509c52, master. perf: cold start to Node started, 3 runs each, median 9.97 s on the PR against 10.36 s on base; no regression.
Not approving while it conflicts. I'll re-run case 1 on the rebased head.
Reviewer model: claude-opus-5-5 (coordinator, delta read), claude-sonnet-5-5 (device driver)
Reasoning effort: Not exposed
|
@ovitrif this conflicts with |
A direct stop queued behind a failed recovery build now ends the retries, and the graph-reset restart inside a recovery start keeps a requested background stop. Verified: just compile, just test, just lint
Verified: none (changelog fragment only)
Stops are counted, and recovery and the graph-reset restart start only while no stop ran since they checked, compared inside the start's lock. Verified: just compile, just test, just lint
a304c94 to
49d45dd
Compare
jvsena42
left a comment
There was a problem hiding this comment.
Approving 49d45dd. Against its new base the rebase leaves the change identical to a304c94, which I reviewed last round. No HIGH, MEDIUM or open LOW. CI is green.
Device gate (49d45dd, Gate_Root_API35, VSS tcp/443 blocked, Electrum tcp://10.0.2.2:60001):
| Case | Run | Result |
|---|---|---|
| 1. Stop from the notification while recovery retries | 1 | ✅ Stop at 17:19:58 UTC during attempt 2; when that attempt failed at 17:22:27, Skipped start because a stop was requested; no build, start or retry for the next 9 min; same pid, no crash |
| 1. same | 2 | ✅ Stop at 17:35:57; skipped at 17:38:29; nothing for the next 9 min |
The base (35873ab) failure from the last round still stands: retries 3/5 to 5/5 continue after the Stop.
Nit: a stop that lands during an attempt still logs Retrying recovery start '3/5' right before the skip, because the warn at the top of the loop runs before startNode checks the counter inside the lock. No build follows it. Only the log reads as one more retry.
Device gate: case 1 ✅ ×2 at 49d45dd. perf: cold start to Node started, median of 3: 10.38 s, against 10.36 s on base; no regression.
Reviewer model: claude-opus-5-5 (coordinator), claude-sonnet-5-5 (device driver)
Reasoning effort: Not exposed
|
Merging: approved at 49d45dd with CI green and no open threads. |
Follow-up to #2004: the two Lows from its code scan (#2004 (comment), #2004 (comment)).
Description
LightningRepo.restartWithPreviousConfig: before each recovery retry, take and releaselifecycleMutexso a direct stop queued behind the failed build runs first, then stop retrying when the node isStopped. Only the debounced stop ended the retries before, so the notification's Stop action or the service'sonDestroycould be followed by another recovery start.LightningRepo.startNode: the graph-reset restart callsstartNodewith the caller'sshouldCancelPendingStopinstead of the publicstart(), so a recovery start that resets a stale graph keeps a requested background stop.configChangeMutexkdoc: a recovery can take up toRECOVERY_START_ATTEMPTSbuilds of up to 60 s each, so it is no longer cheap to wait on.Out of Scope
LightningRepo.restartNode: the same graph-reset path on master (noted as out of scope in the review).Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
Dev regtest build, VSS blocked as in #2004 manual test 1 (
iptableson a rootable emulator).Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
Automated Checks
LightningRepoTest.kt— recovery does not retry over a direct stopLightningRepoTest.kt— a recovery start's graph-reset restart keeps a requested stopEvidence
Both tests fail without the fix (the reviewer's reproduction) and pass with it;
just compile,just testandjust lintpass at f9a6c87.Gaps
Manual test 1 not run.
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)Claude Sonnet 5.5(reasoning:high)Closes #2013