Skip to content

fix(launcher): Windows MCP connect timeout — route ensure-bun.ps1 bun probe through cmd /c - #6

Merged
zaynram merged 3 commits into
mainfrom
fix/windows-connect-timeout
Jun 16, 2026
Merged

zaynram merged 3 commits into
mainfrom
fix/windows-connect-timeout

Conversation

@zaynram

@zaynram zaynram commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Primary fix — Windows MCP connect timeout

On Windows, plugin:scholar:scholar failed with connection timed out after 30000ms. Root cause: bin/ensure-bun.ps1's version probe used the PowerShell call operator & $BunBin --version. Under launch.mjs's detached/no-console spawn (stdio:["ignore",2,2], windowsHide:true) PowerShell refuses to activate a native .exe in the pipeline (CantActivateDocumentInPipeline) and the probe returns empty — so Test-Ok reported "not provisioned" even for a valid pinned bun.exe, re-downloading ~110 MB on every launch and blowing the 30 s connect budget.

Fix: route the version probe and the post-provision success-log through cmd /c "<bun>" --version, which invokes the exe via the command interpreter (no activation restriction). The --provision-only SessionStart pre-warm shares the same script and is fixed by the same change. POSIX ensure-bun.sh uses $(...) capture and was never affected (Windows-only bug).

Verification (bounded)

  • Source + form — tests/ensure-bun.test.ts static guard (runs on every host incl. Linux CI): asserts the defect form & $BunBin is absent from executable code and every --version read routes through cmd /c.
  • Shipped artifact — extracted bin/ensure-bun.ps1 from inside both built archives (out/scholar.plugin win32 + out/scholar.mcpb Desktop): identical 3190 bytes, cmd /c probe present at both call sites, zero bare & $BunBin in code. The fix reaches the real shipped bundles, not just source.
  • Launcher entry path — bun bin/launch.mjs run as a process entry on Linux fires main() (dies CLAUDE_PLUGIN_ROOT is unset, exit 1 — not a silent exit 0), proving the post-refactor import.meta.main guard is intact. Same launch.mjs ships to all three targets.
  • UNPROVEN LEG (Windows hardware): the cmd /c behavioral efficacy — that the probe now returns the version under the host's detached spawn — is guarded by a test.skipIf(process.platform !== "win32") test that is skipped on this Linux host. The actual end-to-end timeout resolution rests on Windows-hardware validation of that test.

Regression guards

  • 3b — source-sync launchable (Windows): launch.mjs refactored to a pure, exported resolveEntry(root) (prefers dist/server.js, else src/server/index.ts) gated behind import.meta.main; tests/launch.test.ts pins both branches. Behaviour-preserving relocation — provision/resolve/spawn logic byte-identical. bin/launch.d.mts types the import under moduleResolution:"bundler".
  • 1 (UI extension capability + view-opener _meta) and 2 (persisted-corpus rehydrate on server start) were already covered — registry.test.ts (UI extension gating + _meta.ui.resourceUri wire serialization) and cli.test.ts / reopenPersistedCorpus (rehydrate across CLI + stdio restart). No new code needed; cited here for traceability.

Known-open disposition (all pulled into scope)

  • (a) pdf-child koffi + pinned-bun SIGILL — SURFACED, not fixed. Both are Windows-native and cannot be validated off the target (per fix-or-surface-defects):
    • koffi Cannot find native Koffi module — the predicted slim-bundle require("koffi") failure, now field-confirmed 2026-06-10. Already best-effort try/catch off-by-default (Job-Object pdf-child reaping); doc flipped from "predicted" to "observed", no behaviour change required.
    • pinned-bun Illegal instruction (SIGILL) on pdf-child spawn — new, intermittent (single occurrence). Added as a tracked open item with mechanism hypotheses (AVX2-baseline mismatch vs. download corruption) and remediation hypotheses (-baseline bun build vs. ensure-bun integrity probe), all marked unvalidated pending a Windows repro that distinguishes them.
  • (b) digest scope_key "section:<x>" cache poisoning — ALREADY FIXED + GUARDED. digest.ts resolves rows + effectiveScopeKey per scope and persists under it, failing closed on unsupported scopes. Pinned by src/server/tools/digest.test.ts:174 (section:<label> filters to that section and persists under it).
  • (c) scholar.pdf.refresh-extraction ingesting the viewer error sentinel — ALREADY FIXED + GUARDED. parseGetTextResult throws PDF_GET_TEXT_FAILED on the MCP isError envelope rather than ingesting it. Pinned by src/server/tools/pdf.test.ts:337 (caller-propagation with a real isError envelope).

Descoped

  • IWR-no-timeout (no -TimeoutSec on Invoke-WebRequest): not addressed. After the probe fix, provisioning only runs on first install — where the SessionStart pre-warm absorbs it — and PS 5.1 -TimeoutSec bounds per-operation, not total download, so it isn't a clean fix anyway.

Test status

bun test src tests → 389 pass / 5 skip / 1 todo / 0 fail. bunx tsc --noEmit → clean. Both built artifacts rebuilt and inspected.

🤖 Generated with Claude Code

zaynram and others added 3 commits June 10, 2026 21:55
…ws connect timeout)

On Windows the MCP server fails to connect ("connection timed out after
30000ms") because ensure-bun.ps1's version probe used the PowerShell call
operator `& $BunBin --version`. Under launch.mjs's detached/no-console spawn
(spawnSync powershell, stdio:["ignore",2,2], windowsHide) PowerShell refuses to
activate a native .exe in the pipeline (CantActivateDocumentInPipeline) and
`& $BunBin` yields EMPTY. So Test-Ok reported "not provisioned" even for a VALID
pinned bun.exe, and EVERY launch re-downloaded ~110 MB — overrunning the 30 s
connect budget on every start, not just the first. The --provision-only
SessionStart pre-warm shares the script and is fixed by the same change.

Route the version probe AND the post-provision success-log through `cmd /c`,
which invokes the exe via the command interpreter (no activation restriction).
POSIX ensure-bun.sh uses $(...) capture and is unaffected (Windows-only bug).

Regression guard (tests/ensure-bun.test.ts):
- Static (runs on every host incl. Linux CI): asserts no `& $BunBin` invocation
  survives in code and every --version read routes through `cmd /c`.
- Behavioral (win32-only, skipped on Linux): mirrors launch.mjs's exact detached
  spawn — with a valid pinned bun present, asserts exit 0 in <2s and no
  "provisioning bun" on stderr. UNEXECUTED on the Linux dev host.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…fallback)

Guard 3b. The committed manifest runs `bun ${ROOT}/bin/launch.mjs` on every OS;
a source-sync install ships NO dist/, so the launcher must fall through to the TS
entrypoint (src/server/index.ts) and let bun boot from source. If that fallback
regressed to a hard-coded dist/server.js, a no-dist install would never boot —
the "source-sync launchable on Windows" property had no test.

Extract the inline entry ternary as a pure exported `resolveEntry(root)` and gate
the side-effectful launch sequence behind `import.meta.main`, so the test can
import resolveEntry without triggering the provisioner or a server spawn. The
provision/env/spawn/signal logic is byte-identical to before — a pure relocation
into main() (verified by diff). bin/launch.d.mts types the .mjs public surface so
the .mjs import typechecks under moduleResolution:"bundler" with no allowJs.

Verified: resolveEntry returns dist/server.js when present else src/server/index.ts
(tests/launch.test.ts); `bun bin/launch.mjs` run-as-main still fires main() (dies
on unset CLAUDE_PLUGIN_ROOT), proving the import.meta.main guard didn't disable the
real entry path. tsc clean; full suite 389 pass / 0 fail.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…IGILL field findings

The win32 behavioral guard in tests/ensure-bun.test.ts bounded a no-op
re-launch at 2s. On Windows CI a cold process spawn + AV scan + slower FS
can exceed 2s without re-downloading, so widen to 5s — still far below a
real ~110 MB re-provision and well under the 30s MCP connect budget the
fix protects. Title + comment updated to match.

Docs (surface-only, no code change):
- slim-plugin-pivot.md: flip the koffi.node win32 reaper item from
  "predicted" to FIELD-CONFIRMED 2026-06-10 ("Cannot find native Koffi
  module" observed on pdf-child spawn); behaviour already best-effort
  off-by-default, only the status flips.
- slim-plugin-pivot.md: add a NEW open item for the intermittent pinned-bun
  `Illegal instruction` (SIGILL) on pdf-child spawn — mechanism hypotheses
  (AVX2-baseline mismatch vs. download corruption) and remediation
  hypotheses (-baseline bun build vs. ensure-bun integrity probe), both
  marked unvalidated pending a Windows repro.
- maintenance-readiness.md: note the live entry-path verification predates
  the resolveEntry/import.meta.main relocation (behaviour-preserving, pinned
  by tests/launch.test.ts); the verification still stands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 11, 2026 03:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Windows-only MCP connect timeout caused by ensure-bun.ps1 failing to read bun.exe --version under a detached/no-console spawn, which led to repeated (and slow) re-provisioning. The PR also refactors the JS launcher for testability and adds regression tests plus documentation updates to guard against recurrence.

Changes:

  • Update bin/ensure-bun.ps1 to route bun version probing (and the provision success log) through cmd /c to avoid PowerShell’s native exe activation limitation under detached spawn.
  • Refactor bin/launch.mjs to export a pure resolveEntry(root) and gate side effects behind import.meta.main, with a TS type surface in bin/launch.d.mts.
  • Add regression tests covering launcher entry resolution and the ensure-bun Windows probe form; update relevant docs/audits.

Reviewed changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/launch.test.ts Adds unit tests to lock in resolveEntry() behavior for dist-vs-source installs.
tests/ensure-bun.test.ts Adds a static guard (all OS) + a Windows-only behavioral guard for the cmd /c bun probe.
docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md Updates field-status notes for Windows-native known issues (koffi + SIGILL observation).
docs/audits/2026-06-02-maintenance-readiness.md Notes the launcher refactor and test guard coverage.
bin/launch.mjs Refactors launcher structure to enable safe importing in tests; exports resolveEntry().
bin/launch.d.mts Adds TS type declarations for resolveEntry() when importing the .mjs from TS.
bin/ensure-bun.ps1 Changes bun --version probe/logging to go through cmd /c on Windows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/ensure-bun.test.ts
Comment on lines +29 to +31
const PS1 = join(import.meta.dir, "..", "bin", "ensure-bun.ps1")
const PIN = "1.3.11" // keep in sync with package.json scholar.bundledBunVersion

Comment thread tests/ensure-bun.test.ts
Comment on lines +5 to +7
// launch.mjs's detached/no-console spawn (bin/launch.mjs:56-61 —
// spawnSync("powershell", ["-NoProfile","-ExecutionPolicy","Bypass","-File",ps1],
// { stdio:["ignore",2,2], windowsHide:true })) PowerShell refuses to activate a
Comment thread tests/ensure-bun.test.ts
Comment on lines +69 to +71
// EXACT mirror of launch.mjs's host spawn (bin/launch.mjs:56-61): no console,
// stdin ignored, windowsHide — the precise condition that emptied the probe.
// stdout/stderr are PIPEd (vs the host's fd 2) only so the test can assert on
@zaynram
zaynram merged commit 960d873 into main Jun 16, 2026
3 checks passed
@zaynram
zaynram deleted the fix/windows-connect-timeout branch June 16, 2026 00:48
@zaynram
zaynram restored the fix/windows-connect-timeout branch September 9, 2026 00:07
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.

2 participants