Repository navigation
fix(launcher): Windows MCP connect timeout — route ensure-bun.ps1 bun probe through cmd /c - #6
Merged
Merged
Conversation
…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>
There was a problem hiding this comment.
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.ps1to route bun version probing (and the provision success log) throughcmd /cto avoid PowerShell’s native exe activation limitation under detached spawn. - Refactor
bin/launch.mjsto export a pureresolveEntry(root)and gate side effects behindimport.meta.main, with a TS type surface inbin/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 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 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 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 |
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.
Primary fix — Windows MCP connect timeout
On Windows,
plugin:scholar:scholarfailed withconnection timed out after 30000ms. Root cause:bin/ensure-bun.ps1's version probe used the PowerShell call operator& $BunBin --version. Underlaunch.mjs's detached/no-console spawn (stdio:["ignore",2,2],windowsHide:true) PowerShell refuses to activate a native.exein the pipeline (CantActivateDocumentInPipeline) and the probe returns empty — soTest-Okreported "not provisioned" even for a valid pinnedbun.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-onlySessionStart pre-warm shares the same script and is fixed by the same change. POSIXensure-bun.shuses$(...)capture and was never affected (Windows-only bug).Verification (bounded)
tests/ensure-bun.test.tsstatic guard (runs on every host incl. Linux CI): asserts the defect form& $BunBinis absent from executable code and every--versionread routes throughcmd /c.bin/ensure-bun.ps1from inside both built archives (out/scholar.pluginwin32 +out/scholar.mcpbDesktop): identical 3190 bytes,cmd /cprobe present at both call sites, zero bare& $BunBinin code. The fix reaches the real shipped bundles, not just source.bun bin/launch.mjsrun as a process entry on Linux firesmain()(diesCLAUDE_PLUGIN_ROOT is unset, exit 1 — not a silent exit 0), proving the post-refactorimport.meta.mainguard is intact. Samelaunch.mjsships to all three targets.cmd /cbehavioral efficacy — that the probe now returns the version under the host's detached spawn — is guarded by atest.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
launch.mjsrefactored to a pure, exportedresolveEntry(root)(prefersdist/server.js, elsesrc/server/index.ts) gated behindimport.meta.main;tests/launch.test.tspins both branches. Behaviour-preserving relocation — provision/resolve/spawn logic byte-identical.bin/launch.d.mtstypes the import undermoduleResolution:"bundler"._meta) and 2 (persisted-corpus rehydrate on server start) were already covered —registry.test.ts(UI extension gating +_meta.ui.resourceUriwire serialization) andcli.test.ts/reopenPersistedCorpus(rehydrate across CLI + stdio restart). No new code needed; cited here for traceability.Known-open disposition (all pulled into scope)
Cannot find native Koffi module— the predicted slim-bundlerequire("koffi")failure, now field-confirmed 2026-06-10. Already best-efforttry/catchoff-by-default (Job-Object pdf-child reaping); doc flipped from "predicted" to "observed", no behaviour change required.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 (-baselinebun build vs. ensure-bun integrity probe), all marked unvalidated pending a Windows repro that distinguishes them.scope_key "section:<x>"cache poisoning — ALREADY FIXED + GUARDED.digest.tsresolves rows +effectiveScopeKeyper scope and persists under it, failing closed on unsupported scopes. Pinned bysrc/server/tools/digest.test.ts:174(section:<label>filters to that section and persists under it).scholar.pdf.refresh-extractioningesting the viewer error sentinel — ALREADY FIXED + GUARDED.parseGetTextResultthrowsPDF_GET_TEXT_FAILEDon the MCPisErrorenvelope rather than ingesting it. Pinned bysrc/server/tools/pdf.test.ts:337(caller-propagation with a realisErrorenvelope).Descoped
-TimeoutSeconInvoke-WebRequest): not addressed. After the probe fix, provisioning only runs on first install — where the SessionStart pre-warm absorbs it — and PS 5.1-TimeoutSecbounds 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