Skip to content

Fix #1024: bump CLI preflight timeout to 5s + add configurable override#1026

Merged
amrmelsayed merged 9 commits into
mainfrom
builder/bugfix-1024
Jun 10, 2026
Merged

Fix #1024: bump CLI preflight timeout to 5s + add configurable override#1026
amrmelsayed merged 9 commits into
mainfrom
builder/bugfix-1024

Conversation

@amrmelsayed

Copy link
Copy Markdown
Collaborator

Summary

The startup CLI preflight capped the codev --version probe at 400ms. On slow environments that probe legitimately exceeds 400ms, so preflight falsely decided the CLI was missing — opening the Get started with Codev walkthrough on every startup and no-op'ing every guarded command, even though codev --version succeeds from a terminal in the same window.

Fixes #1024

Root Cause

VERSION_TIMEOUT_MS = 400 in packages/vscode/src/preflight/preflight.ts was too tight against real latency sources: remote SSH / VSCode Server, WSL / VM-mediated shells, nvm/fnm/volta shim re-resolution on every spawn, AV / index scanning, and network filesystems. A timed-out probe returns "no version" → decidePreflight returns missing. The intent (kill a hung binary so it can't stall activation) was sound; the value left too little headroom over the ~80-100ms cold local baseline.

Fix

  • Bump the default 400ms → 5000ms (DEFAULT_VERSION_TIMEOUT_MS). Comfortable headroom against the realistic slow-env upper bound while staying well under "feels hung" — and the optimistic-pending path means commands fire normally during the probe window anyway.
  • Add codev.cliVersionTimeoutMs setting (number, default 5000, min 100, max 60000) so users on extra-slow infra can override without hand-patching dist/extension.js. The override survives extension upgrades.
  • Log a [Preflight] line to the OutputChannel on timeout, naming the timeout value and the recovery action, so a slow-env false-negative is diagnosable instead of silently reported as a missing CLI. runCodevVersion now returns a timedOut flag to distinguish the timeout case from a genuinely absent / broken binary.
  • Relocated the vscode-free runCodevVersion probe + a pure resolveVersionTimeout helper into preflight-core.ts so they are unit-testable under vitest without mocking the vscode module. The probe logic itself is unchanged (spawn path not rewritten), just moved.

Test Plan

  • Regression test added (preflight-version-timeout.test.ts): runCodevVersion honours an explicit timeoutMs (kills a hung probe, reports timedOut) and the OK/spawn-error paths; resolveVersionTimeout falls back to 5000 when the setting is unset and clamps out-of-range values.
  • Build passes (npm run build).
  • All tests pass (npm test; vscode package vitest: new + existing preflight suites green).

Notes

…verride

The 400ms cap on the `codev --version` startup probe was too tight against
legitimate latency sources (remote SSH, WSL, nvm/fnm/volta shim re-resolution,
AV scanning, network filesystems), producing a false `missing` status that
opened the 'Get started with Codev' walkthrough and no-op'd guarded commands
despite a healthy install.

- Default timeout bumped 400ms -> 5000ms (DEFAULT_VERSION_TIMEOUT_MS).
- New setting codev.cliVersionTimeoutMs (number, default 5000, min 100,
  max 60000) overrides it per-workspace, surviving extension upgrades.
- runCodevVersion now reports a timedOut flag; the OutputChannel logs a
  [Preflight] line naming the timeout value and recovery action when the cap
  fires, so a slow-env false-negative is diagnosable instead of silent.
- Relocated the vscode-free runCodevVersion probe + a pure resolveVersionTimeout
  helper into preflight-core.ts so they are unit-testable under vitest.
- Added unit tests covering the explicit-timeoutMs (positive) and
  setting-unset default (negative) cases.
codex + claude both noted comments still naming the old 400ms cap. Make them
version-agnostic: extension.ts now points at the codev.cliVersionTimeoutMs
budget; the #983 Tower-divergence comment drops the stale ~400ms figure.
Comment-only; no behavior change.
Per architect review at the pr gate: resolveVersionTimeout + MIN/MAX constants
were over-built for a constant bump. VSCode already returns the package.json
default for an unset setting and enforces minimum/maximum in its settings UI,
so the helper's unset-fallback branch was dead at runtime and only the marginal
clamp/non-number guard ran live.

- Read the setting with the codebase idiom:
  getConfiguration('codev').get<number>(KEY, DEFAULT_VERSION_TIMEOUT_MS),
  matching overviewRefreshSeconds et al.
- Delete resolveVersionTimeout, MIN_VERSION_TIMEOUT_MS, MAX_VERSION_TIMEOUT_MS;
  the 100/60000 bounds now live solely in package.json.
- Tests: drop the resolveVersionTimeout cases; runCodevVersion suite keeps the
  explicit-timeout (positive) + default-when-omitted (negative) + spawn-error +
  5000 regression-anchor coverage.

Trade-off: no runtime clamp of a hand-edited out-of-range settings.json value
(VSCode UI validation covers the realistic path).
@amrmelsayed amrmelsayed merged commit e80c5cf into main Jun 10, 2026
6 checks passed
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.

vscode: CLI preflight 400ms timeout triggers false "CLI missing" walkthrough on slow envs (remote SSH, WSL, nvm shims)

1 participant