Repository navigation
fix: keep a stopped node's late writes off its rebuilt node - #2004
Conversation
Bumps ldk-node to 0.7.0-rc.82, which fences a replaced VSS store's writes. The release-gate kdocs now say the gate waits for free_node, not for the old node's detached work (#2003), and the background exit is named for the overlap it avoids. Verified: none (metadata and build run next)
Verified: ./gradlew --write-verification-metadata sha256 :app:assembleDevDebug
Verified: none (changelog text only)
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. |
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryUpdates
No actionable issues found. Builds and tests were not run during this review. Reviews (1) · Last reviewed commit: "chore: add ldk-node 0.7.0-rc.82 verifica..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Bumps ldk-node-android to 0.7.0-rc.82 for the VSS write fence, renames the background exit after the reason it stays, and corrects the release-gate kdocs. Reviewed 7f8ef77, light tier, static: Android branches are not built here, so this is reasoned from the code, the rc.81..rc.82 ldk-node diff and CI.
What I checked, and 4 candidates I ruled out
Read in full: the PR diff; LightningService.setup, build, stop, releaseHandle, awaitNodeRelease; LightningRepo.start, restartWithElectrumServer, restartWithRgsServer, restartWithPreviousConfig
ldk-node rc.81..rc.82: src/builder.rs, src/lib.rs (start, stop), the fence in src/io/vss_store.rs (STORE_FENCES, REPLACED_WRITES_TIMEOUT = 60 s, start_marked_live)
CI: build-and-test, lint, compose-ui, build-local still pending at review time
Ruled out
- FFI break from the bump:
bindings/ldk_node.udlis unchanged between rc.81 and rc.82, and the only new failure mode,BuildException.KvStoreSetupFailedafter the 60 s wait, is already mapped inErrors.ktand surfaces throughsetup's failure path, sorestartWith*falls intorestartWithPreviousConfigas the QA evidence shows. - The 60 s build wait outliving the release gate:
awaitNodeRelease(90 s) runs beforebuild, and the fence wait is insidebuildon the LDK queue withnode == null, so nothing that needs a live node is queued behind it. - Old node's
startracing the rebuilt one: rc.82 refusesstarton a node whose store was replaced (PersistenceFailed), and the app never restarts a released handle;setupalways builds a newNode. - The background exit becoming redundant: the fence state is process-wide (
STORE_FENCESstatic), so a process exit still resets it and the cold start path is unaffected; keeping the exit is consistent with the new kdoc.
Merge confidence: 4/5, CI was still running and the app's handling of the new build wait is covered by the manual test 1 evidence rather than a unit test.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the review session does not report it)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
A stopped node's VSS write can keep retrying for minutes, past one build's 60 s wait, so the single recovery start failed and Lightning stayed offline until the app restarted. Recovery now retries the start while the build fails on the busy store, up to five times. Verified: none (gate runs next)
Verified: none (gate runs next)
Verified: none (gate runs next)
Verified: none (gate runs next)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 6fc5bb2.
1 actionable finding — resolve or provide an evidence-backed rebuttal.
The ldk-node 0.7.0-rc.82 fence (1dd2f42e44561ee4005f109c0d2cb61e1de99123) waits up to 60s for a stopped node's in-flight VSS writes and fails the build without replacing the store. Recovery retries that KvStoreSetupFailed up to five times. A background stop requested before the first recovery start is still cleared by that start, so a later retry can run Lightning with background payments off. The resolved thread covers a stop requested during an in-flight recovery build; later retries now yield to that stop.
Device testing: not performed in this review. The author's manual tests 1 and 2 keep the app in the foreground. This review did not run the unit tests. The author reports just compile, just test, and just lint on 6fc5bb2.
Scoped comparison of bitkit-ios 2be17dd7919262391f996928744317d25f93ab07: LightningService.restartWithPreviousConfig does one setup and start. Only that recovery start was read.
Suggested additional test cases:
- Android, with Keep Bitkit active in background off. Block VSS, change the Electrum server, send the app to the background during the wait, then unblock VSS. Expected: Lightning stays stopped while the app is backgrounded, and returning to the app starts it.
- Unit: in
LightningRepoTest, callstopDebounced()from the failing new-serversetup, before recovery's firstsetup, and let a later previous-configsetupsucceed. Expected:nodeLifecycleStatestays offRunning.
Findings
- [MEDIUM] Yield to a background stop before the first recovery start — inline at
app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1301.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Verified: none (gate runs next)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 6fc5bb2, including the recovery start path those changes affect, at 35873ab. Baseline: previous review. Inherited coverage: the ldk-node 0.7.0-rc.82 VSS write fence and Gradle verification metadata, LightningService stop and background process exit, KvStoreSetupFailed classification, and the changelog fragment.
No new actionable code findings.
restartWithPreviousConfig checks the pending background stop before every recovery start, including the first, and calls startNode with shouldCancelPendingStop = false. A stop requested while the failed Electrum or RGS build is still running stays pending, so that recovery leaves the node stopped. Returning to the foreground still goes through WalletViewModel.start, which cancels the pending stop and starts the node. The recovery attempt cap remains 5. This is source analysis; the new unit test was inspected and not executed in this review.
Compared with bitkit-ios at 2be17dd for the Electrum change only: a failed connection reloads the stored server after lightningService.restart. That check did not cover the rest of the iOS app. iOS has no debounced background stop on this path.
Device testing: not performed in this review. Ready for device testing.
Suggested additional test cases
- Android, dev regtest, with VSS blocked as in manual test 1. Start an Electrum server change, send the app to the background before that build fails, and leave it there. Expected: Lightning stays down while the app is backgrounded, and the process is not aborted. Bring the app back to the foreground. Expected: the node starts on the previous Electrum server without restarting the app.
Earlier findings reconciled at this revision: 3 verified fixed.
Reviewer model: grok-4.7
Reasoning effort: xhigh
jvsena42
left a comment
There was a problem hiding this comment.
Code scan at 35873ab: no HIGH or MEDIUM. Two LOWs are inline, both about a stop losing to the new recovery path. I reviewed this as a funds/lifecycle change (ldk-node bump plus node start/stop).
What I checked and found clean:
- Two nodes on one store. Every build runs under
lifecycleMutexafterawaitNodeRelease. A failedsetupleavesnode == null, and the rc.82 fence refuses a build while a node is live. Retry attempts can't overlap each other or a foreground start. - Retry bound. At most 5 attempts, only on
KvStoreSetupFailed.WipeInProgressError,RecoveryModeErrorand start errors end the loop. A setup failure never takes theshouldRetrypath, so retries don't nest. - Error matching.
LightningService.buildthrowsLdkError(BuildException), and the cause-chain walk matches it bare or wrapped. - Wipe during retry.
WipeWalletUseCasesetsisWipingbefore itsstop(), so the next attempt exits withWipeInProgressError. - Cancellation. No
runCatchingaround suspend calls in the loop.startNoderethrowsCancellationException. - Upgrade. v3.1.1 ships rc.80. rc.81..rc.82 changes
builder.rs,vss_store.rs,lib.rsand tests. The fence is in-memory state, and the VSS schema version and key obfuscation are unchanged, so there is no persisted-format change. - Nit, not a finding: the
configChangeMutexkdoc says recovery is cheap to wait on. With rc.82 a recovery can take up to 5 × 60 s.
Performance-relevant: yes. The PR adds a retry loop and a wait of up to 60 s on the node start path. On a device I'll measure:
- foreground start time to
Node startedafter a >5 s background, against master; - spinner time and total recovery time for an Electrum change with VSS blocked.
Device gate (partial): 35873ab — not run yet; pending the start-time measurement against master and manual tests 1-2 (VSS blocked by iptables on a rootable emulator). The device result will follow in a second review.
Skipped — covered by CI at 35873ab: unit tests, lint, detekt, compose UI, local e2e (all green).
jvsena42
left a comment
There was a problem hiding this comment.
Approving at 35873ab. The code scan and the device gate found nothing above LOW. The two LOWs from my code scan are still open, each with a unit test that fails at this head. Fix them here or move them to a follow-up issue, whichever you prefer; please reply on each thread saying which.
Device gate: 35873ab vs merge base 1b3f373 (rc.81). Both are dev debug builds on a rootable Android 15 emulator against staging. VSS was blocked with iptables on tcp/443 to 34.65.252.32 only, since Electrum uses the same IP.
- perf: 3 runs per case.
- Foreground start,
ON_START→Node started: median 8.6 s (base 7.6 s). - Cold launch →
Node started: median 18.3 s (base 17.5 s). - The difference is about 0.8 s inside
start;buildtakes the same time on both. - Idle on Home for 2 min: 1.5 VSS puts/min (base 2.0). 0 put errors and 0 dropped writes on both, and the same single Firebase WARN on both.
- Foreground start,
- Manual test 1 ✅ Spinner 107.5 s. The rebuild fails with
still in flight, and the app logsFailed ldk-node config change, recovering in background….Dropped write of key //eventsfollows, thenNode started52.5 s after the unblock. Same pid throughout, no fatal signal. - Manual test 2 ✅ Retries reached
3/5: the old write drained only at 10:29:32 UTC, after the unblock, so a third build also timed out.Node startedcame 90.8 s after the unblock and syncs resumed. Same pid, no fatal signal. - LOW 1 on device: inconclusive. I tapped the notification's Stop at retry
2/5with keep-active on. The service'sonDestroyloggedSkipping node stop: activity is active. The process was then frozen as cached, so retry3/5never ran. On relaunch the loop loggedSkipped recovery start because a stop was requested, then started normally. The unit test on that thread still reproduces the gap with the process alive. - l10n: no UI text changed. Figma: no UI changes. iOS: no twin found.
Skipped — covered by CI at 35873ab: unit tests, lint, detekt, compose UI, local e2e (all green).
piotr-iohk
left a comment
There was a problem hiding this comment.
Approving at 35873ab4. I tested a locally built devDebug APK on an Android 15 ARM64 emulator with a fresh staging regtest wallet.
| Device check | Result |
|---|---|
| Background and reopen | Passed. After 12 seconds on Android Home, I reopened Bitkit. The logs showed the node stop, start again, and complete wallet sync in the same process (PID 4163). |
| Electrum settings restart | Passed. I changed the capitalization of the staging hostname, then restored the default. After each change, Settings showed Connected and the node completed wallet sync in PID 4163. |
| Late writes during rebuild and recovery after repeated waits | Both PR manual tests passed in jvsena42’s device run on this commit. My run covered the two normal restart paths above. |
| Stop while recovery is pending | Unverified on device. The stop in my background test occurred during normal operation. |
Two LOW findings remain open on whether recovery honors a stop request. Notification Stop · Graph reset during recovery
|
Merging: approved at 35873ab with CI green; the two recovery-stop Lows follow in their own PR. |
Closes #2003
Updates
ldk-node-androidto 0.7.0-rc.82, which carries synonymdev/ldk-node#140.Description
KVStoreSetupFailedand replaces nothing, and the existing recovery rebuilds the node.releaseHandleandawaitNodeRelease: the release gate waits untilfree_nodereturns, not for the old node's detached work, which can still run after a timed-out stop.exitBeforeRuntimeShutdowntoexitBeforeDetachedWorkOverlaps, after the reason it stays since rc.81.gradle/verification-metadata.xml.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
Dev (regtest) debug build on a rootable Android 15 emulator, with staging VSS (
34.65.252.32:443) blocked byiptables; Electrum on the same host stays reachable.Journeys
N/A — no user-visible behaviour change.
Manual Tests
Automated Checks
store_fences_testsand thevss_testcases in fix: fence a replaced vss store's writes ldk-node#140 and chore: release 0.7.0-rc.82 ldk-node#142 cover the fence.Evidence
Detaching background tasks after cancellation timed out.Deferring runtime shutdown until detached work still running at shutdown has ended.Writes of the current store to this VSS store are still in flight; the app loggedFailed ldk-node config change, recovering in background…and rebuilt the node on the previous server.Dropped write of key //events: another node was built on this VSS store, thenShut down the runtime after detached work ended.Node startedand a completed on-chain sync 6 s later; no SIGABRT or fatal signal in logcat, and the app process lived through the whole run.KV store setup failed, thenRetrying recovery start '2/5'; with VSS unblocked,Node startedandSuccessfully started node with previous configfollowed 11 s later and syncs resumed, with no fatal signal and the same app process throughout.just compile,just testandjust lintpass on 35873ab../gradlew :app:assembleDevDebugpasses against the publishedcom.synonym:ldk-node-android:0.7.0-rc.82.Gaps
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)