fix: make update check non-blocking by spawning detached child process#246
Draft
bukinoshita wants to merge 2 commits intomainfrom
Draft
fix: make update check non-blocking by spawning detached child process#246bukinoshita wants to merge 2 commits intomainfrom
bukinoshita wants to merge 2 commits intomainfrom
Conversation
When the update-state cache is stale or missing, the CLI now spawns a detached child process to refresh the cache in the background instead of awaiting a fetch() in the main process. This prevents commands from appearing to hang for up to 5 seconds on slow or offline networks. Key changes: - checkForUpdates() is now synchronous; it reads cached state, shows any stale notice, and kicks off a detached node process to refresh - buildRefreshScript() generates a self-contained Node script that fetches the latest version and writes update-state.json, writing the current version as fallback on any failure (prevents repeated retries on every command) - spawnBackgroundRefresh() spawns the script detached with stdio ignored and unrefs the child so the main process exits immediately - All functions converted to const arrow functions per coding standards - Removed JSDoc comments per coding standards Resolves BU-642 Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
Member
Author
|
@cubic-dev-ai can you review? |
Contributor
@bukinoshita I have started the AI code review. It will take a few minutes to complete. |
Contributor
There was a problem hiding this comment.
2 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/lib/update-check.ts">
<violation number="1" location="src/lib/update-check.ts:30">
P2: Falling back to `'node'` disables background update refresh for standalone binary installs that do not have Node in PATH.</violation>
</file>
<file name="src/cli.ts">
<violation number="1" location="src/cli.ts:189">
P2: Wrap `checkForUpdates()` in a local guard; it can still throw on malformed cached state and currently bubbles into the global error handler.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| if (/(?:^|[\\/])node(?:\.exe)?$/i.test(process.execPath)) { | ||
| return process.execPath; | ||
| } | ||
| return 'node'; |
Contributor
There was a problem hiding this comment.
P2: Falling back to 'node' disables background update refresh for standalone binary installs that do not have Node in PATH.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/update-check.ts, line 30:
<comment>Falling back to `'node'` disables background update refresh for standalone binary installs that do not have Node in PATH.</comment>
<file context>
@@ -1,38 +1,81 @@
+ if (/(?:^|[\\/])node(?:\.exe)?$/i.test(process.execPath)) {
+ return process.execPath;
+ }
+ return 'node';
+};
+
</file context>
| } | ||
|
|
||
| return checkForUpdates().catch(() => {}); | ||
| checkForUpdates(); |
Contributor
There was a problem hiding this comment.
P2: Wrap checkForUpdates() in a local guard; it can still throw on malformed cached state and currently bubbles into the global error handler.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/cli.ts, line 189:
<comment>Wrap `checkForUpdates()` in a local guard; it can still throw on malformed cached state and currently bubbles into the global error handler.</comment>
<file context>
@@ -186,7 +186,7 @@ program
}
- return checkForUpdates().catch(() => {});
+ checkForUpdates();
})
.catch((err) => {
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where the CLI update notifier blocks command exit for up to ~5 seconds on slow/offline networks (BU-642).
After every successful non-
updatecommand,checkForUpdates()was awaiting a live GitHubfetch()with a 5-secondAbortSignal.timeoutwhenever the cached update state was stale or missing. This kept the Node event loop alive and made fast commands appear to hang.Changes
src/lib/update-check.tscheckForUpdates()is now synchronous — it reads the cached state file, optionally prints a stale update notice, and when the cache is stale/missing, spawns a detached child process to refresh the cache in the backgroundspawnBackgroundRefresh()spawns a detachednode -echild process withstdio: 'ignore'and.unref()so the main CLI process exits immediatelybuildRefreshScript()generates a self-contained Node script that fetches the latest GitHub release and writesupdate-state.json, falling back to writing the current version on any failure (prevents repeated fetch retries on every subsequent command)resolveNodePath()determines the correct Node binary path for spawning the child processconstarrow functions per coding standardssrc/cli.ts.catch()wrapper sincecheckForUpdates()is no longer async and never throwstests/lib/update-check.test.tsvi.mock('node:child_process')to mock thespawncall in ESMbuildRefreshScript,resolveNodePath, andspawnBackgroundRefreshtest()toit()per coding standardsHow it works
Before:
cli.ts → checkForUpdates() → await fetchLatestVersion() → fetch(..., timeout: 5s)— blocks process exitAfter:
cli.ts → checkForUpdates() → spawnBackgroundRefresh()— spawns a detached child process that fetches and writes the state file independently; main process exits immediatelyThe cached notice path (fresh cache) remains in-process and is unaffected. On the next command after a background refresh, the updated cache will be read and any update notice displayed.
Linear Issue: BU-642
Summary by cubic
Make the CLI update check non‑blocking by moving the network fetch to a detached background process. Commands now exit immediately even on slow/offline networks, addressing BU-642.
checkForUpdates()is now synchronous; uses cached state, shows a stale notice if it indicates a newer version, and spawns a background refresh when the cache is stale/missing.spawnBackgroundRefresh()to runnode -edetached withstdio: 'ignore'and.unref(); spawn failures are ignored so the main process always exits.buildRefreshScript()fetches the latest GitHub release and writesupdate-state.json, writing the current version on any failure or invalid response to avoid repeated retries.resolveNodePath()selects the correct Node binary across platforms.src/cli.ts: callcheckForUpdates()without awaiting or catching.node:child_processspawn; add coverage for background refresh,buildRefreshScript,resolveNodePath, spawn failure handling, and stale notice behavior.Written for commit 53e8cc1. Summary will update on new commits.