From be99a18c6bcb1506a6fe970964b30e46aa854bab Mon Sep 17 00:00:00 2001 From: zaynram Date: Wed, 10 Jun 2026 21:55:10 -0500 Subject: [PATCH 1/3] fix(launcher): route ensure-bun.ps1 bun probe through `cmd /c` (Windows connect timeout) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- bin/ensure-bun.ps1 | 19 +++++- tests/ensure-bun.test.ts | 121 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 tests/ensure-bun.test.ts diff --git a/bin/ensure-bun.ps1 b/bin/ensure-bun.ps1 index 0ec0acf..8784b1e 100644 --- a/bin/ensure-bun.ps1 +++ b/bin/ensure-bun.ps1 @@ -15,9 +15,21 @@ if (-not $env:CLAUDE_PLUGIN_DATA) { [Console]::Error.WriteLine("ensure-bun: CLAU $BunDir = Join-Path $env:CLAUDE_PLUGIN_DATA "bun" $BunBin = Join-Path $BunDir "bun.exe" +# Probe the pinned bun's --version. MUST route through `cmd /c`, NOT the PS call +# operator `& $BunBin`: under the host's detached/no-console spawn (launch.mjs +# stdio:"ignore"/inherit with no attached console) PowerShell refuses to activate +# a native .exe in the pipeline (CantActivateDocumentInPipeline) and `& $BunBin` +# yields EMPTY — so the version compare fails even for a valid pinned bun, and +# every launch re-downloads ~110 MB, overrunning the 30 s MCP connect budget +# (Cowork Windows field finding, 2026-06-10). `cmd /c` invokes the exe via the +# command interpreter, which has no such restriction. POSIX ensure-bun.sh uses +# $(...) capture and is unaffected. function Test-Ok { if (-not (Test-Path $BunBin)) { return $false } - try { return ((& $BunBin --version 2>$null) -eq $Pin) } catch { return $false } + try { + $v = (cmd /c "`"$BunBin`" --version" 2>$null | Select-Object -First 1) + return ("$v".Trim() -eq $Pin) + } catch { return $false } } if (Test-Ok) { exit 0 } @@ -43,7 +55,10 @@ try { Expand-Archive -Path $Zip -DestinationPath $Tmp -Force Move-Item -Force (Join-Path $Tmp "bun-windows-x64\bun.exe") $BunBin Remove-Item -Recurse -Force $Tmp - [Console]::Error.WriteLine("ensure-bun: provisioned $(& $BunBin --version)") + # Same cmd /c routing as Test-Ok — a bare `& $BunBin` prints blank under the + # detached spawn, making this success line read "provisioned " with no version. + $ver = (cmd /c "`"$BunBin`" --version" 2>$null | Select-Object -First 1) + [Console]::Error.WriteLine("ensure-bun: provisioned $("$ver".Trim())") } finally { if ($haveLock) { Remove-Item -Recurse -Force $Lock -ErrorAction SilentlyContinue } } diff --git a/tests/ensure-bun.test.ts b/tests/ensure-bun.test.ts new file mode 100644 index 0000000..c3b847a --- /dev/null +++ b/tests/ensure-bun.test.ts @@ -0,0 +1,121 @@ +// tests/ensure-bun.test.ts — Windows provisioner regression guard. +// +// PRIMARY BUG (Cowork Windows field finding, 2026-06-10): bin/ensure-bun.ps1's +// version probe used the PowerShell call operator `& $BunBin --version`. Under +// 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 +// native .exe in the pipeline (CantActivateDocumentInPipeline) and `& $BunBin` +// yields EMPTY. So Test-Ok reported "not provisioned" even for a VALID pinned +// bun, and every launch re-downloaded ~110 MB — overrunning the 30 s MCP connect +// budget ("connection timed out after 30000ms"). The --provision-only +// SessionStart pre-warm shares the same script and is fixed by the same change. +// Fix: route the version probe AND the 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). +import { test, expect } from "bun:test" +import { + readFileSync, + mkdtempSync, + mkdirSync, + copyFileSync, + existsSync, + rmSync, +} from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { spawnSync } from "node:child_process" + +const PS1 = join(import.meta.dir, "..", "bin", "ensure-bun.ps1") +const PIN = "1.3.11" // keep in sync with package.json scholar.bundledBunVersion + +// ── Static guard — runs on EVERY host (incl. the Linux dev box / CI) ────────── +// The behavioral test below only runs on win32 hardware, so this content guard +// is the load-bearing, Linux-verifiable assertion. It pins the FORM of the fix: +// no bun invocation may use the bare PS call operator `& $BunBin` (the defect), +// and every --version read must route through `cmd /c`. +test("ensure-bun.ps1 reads bun --version via `cmd /c`, never the PS call operator `& $BunBin` (detached-spawn empty-probe regression)", () => { + const src = readFileSync(PS1, "utf8") + // Strip full-line PS comments (`#...`) before asserting: the doc comments + // legitimately NAME the defect form (`& $BunBin`) to explain why the fix + // exists, so the guard must target executable code, not prose. + const code = src + .split(/\r?\n/) + .filter((l) => !/^\s*#/.test(l)) + .join("\n") + // Assert the DEFECT form is ABSENT from code. More robust than merely + // asserting `cmd /c` is present: it fails if a future edit reintroduces an + // `& $BunBin ...` invocation — the probe (Test-Ok) OR the success-log line. + expect(code).not.toMatch(/&\s*\$BunBin/) + // And positively: every bun version read goes through the cmd interpreter. + expect(code).toMatch(/cmd \/c .*\$BunBin.*--version/) +}) + +// ── Behavioral guard — win32 ONLY (skipped on the Linux dev host / CI) ───────── +// Reproduces the field repro at the real entry path: a VALID pinned bun is +// present, yet the host's detached spawn re-launches the provisioner. On the +// buggy probe Test-Ok falsely returns false → it re-provisions (prints +// "provisioning bun", re-downloads, slow). On the fixed probe Test-Ok returns +// true → exit 0, fast, no provisioning. UNEXECUTED on this Linux host — it is a +// guard for Windows hardware / CI only. +function bunVersionViaCmd(exe: string): string | null { + // Mirror Test-Ok's FIXED probe exactly: invoke via cmd /c (works detached). + const r = spawnSync("cmd", ["/c", `"${exe}" --version`], { encoding: "utf8" }) + if (r.status !== 0) return null + return (r.stdout ?? "").trim().split(/\r?\n/)[0] ?? null +} + +function runProvisionerDetached(dataDir: string) { + // 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 + // stderr; the console-attachment state the bug depends on is unchanged. + return spawnSync( + "powershell", + ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", PS1], + { + stdio: ["ignore", "pipe", "pipe"], + windowsHide: true, + env: { ...process.env, CLAUDE_PLUGIN_DATA: dataDir }, + encoding: "utf8", + }, + ) +} + +test.skipIf(process.platform !== "win32")( + "ensure-bun.ps1: valid pinned bun present → detached re-launch exits 0 in <2s and does NOT re-provision", + () => { + const dataDir = mkdtempSync(join(tmpdir(), "scholar-ensure-bun-")) + try { + const bunDir = join(dataDir, "bun") + mkdirSync(bunDir, { recursive: true }) + const stagedBun = join(bunDir, "bun.exe") + + // Seed a valid pinned bun. Prefer copying the host-provisioned one to skip + // a 110 MB download; otherwise let a one-time warm-up run provision it. + const hostData = process.env.CLAUDE_PLUGIN_DATA + const hostBun = hostData ? join(hostData, "bun", "bun.exe") : undefined + if (hostBun && existsSync(hostBun) && bunVersionViaCmd(hostBun) === PIN) { + copyFileSync(hostBun, stagedBun) + } else { + const warm = runProvisionerDetached(dataDir) + expect(warm.status).toBe(0) // first run provisions (may download) + } + // Precondition: a valid pinned bun is now present at the expected path. + expect(bunVersionViaCmd(stagedBun)).toBe(PIN) + + // MEASURED run: the host's exact detached spawn with the pinned bun in + // place. Buggy probe → re-provisions (slow + "provisioning bun"); fixed + // probe → Test-Ok true → exit 0 fast, silent. + const t0 = performance.now() + const r = runProvisionerDetached(dataDir) + const elapsedMs = performance.now() - t0 + + expect(r.status).toBe(0) + expect(elapsedMs).toBeLessThan(2000) + expect(String(r.stderr ?? "")).not.toContain("provisioning bun") + } finally { + rmSync(dataDir, { recursive: true, force: true }) + } + }, +) From a47674d05bc5cf21c5418399536801e8523857db Mon Sep 17 00:00:00 2001 From: zaynram Date: Wed, 10 Jun 2026 21:59:55 -0500 Subject: [PATCH 2/3] test(launcher): pin launch.mjs entry resolution (source-sync no-dist fallback) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- bin/launch.d.mts | 13 +++++ bin/launch.mjs | 124 ++++++++++++++++++++++++------------------- tests/launch.test.ts | 41 ++++++++++++++ 3 files changed, 124 insertions(+), 54 deletions(-) create mode 100644 bin/launch.d.mts create mode 100644 tests/launch.test.ts diff --git a/bin/launch.d.mts b/bin/launch.d.mts new file mode 100644 index 0000000..927c337 --- /dev/null +++ b/bin/launch.d.mts @@ -0,0 +1,13 @@ +// Type surface for bin/launch.mjs (a hand-written .mjs launcher that must stay +// runnable as `bun bin/launch.mjs`). Only the pure, exported resolveEntry is +// consumed by TS (tests/launch.test.ts, Guard 3b); the rest of launch.mjs is the +// side-effectful launch sequence gated by import.meta.main. Under +// moduleResolution:"bundler", an import of "../bin/launch.mjs" resolves this +// `.d.mts` for types while bun loads the real `.mjs` at runtime. + +/** + * Resolve the server entrypoint for a plugin install rooted at `root`. Prefers + * the built bundle `dist/server.js` if present; otherwise falls through to the + * source-sync TS entrypoint `src/server/index.ts`. + */ +export function resolveEntry(root: string): string; diff --git a/bin/launch.mjs b/bin/launch.mjs index 6711e3f..85a2209 100644 --- a/bin/launch.mjs +++ b/bin/launch.mjs @@ -32,6 +32,12 @@ // Modes: // bun launch.mjs provision bun, then run the server // bun launch.mjs --provision-only pre-warm bun and exit (SessionStart hook) +// +// STRUCTURE: the side-effectful launch sequence (env reads, provision, spawn) is +// wrapped in `main()` and gated by `import.meta.main`, so launch.test.ts can +// `import { resolveEntry }` to assert entry resolution WITHOUT triggering the +// provisioner or a server spawn. When the host runs `bun bin/launch.mjs`, +// launch.mjs IS the entry → import.meta.main is true → main() runs unchanged. import { spawn, spawnSync } from "node:child_process"; import { existsSync } from "node:fs"; @@ -43,65 +49,75 @@ const die = (msg) => { process.exit(1); }; -const root = process.env.CLAUDE_PLUGIN_ROOT; -const data = process.env.CLAUDE_PLUGIN_DATA; -if (!root) die("CLAUDE_PLUGIN_ROOT is unset"); -if (!data) die("CLAUDE_PLUGIN_DATA is unset"); +// Resolve the server entrypoint. The built bundle (dist/server.js) wins if +// present; source-sync has no dist/, so it falls through to the TS entrypoint +// bun runs directly (auto-installing the reached import graph into BUN_INSTALL's +// cache on first call). Pure (no env, no spawn, no exit) so it is unit-testable +// in isolation — the side-effectful sequence lives in main(), below. +export function resolveEntry(root) { + return existsSync(join(root, "dist", "server.js")) + ? join(root, "dist", "server.js") + : join(root, "src", "server", "index.ts"); +} -// ── 1. Provision the pinned bun runtime (synchronous correctness gate) ─────── -// Delegates to the same ensure-bun.{sh,ps1} the built bundles use. ALL of the -// provisioner's output is mapped to OUR stderr (the stdio integer `2` shares the -// parent's fd 2): stdout (fd 1) stays clean for the JSON-RPC stream the child -// bun will own. -const provision = isWin - ? spawnSync( - "powershell", - ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", join(root, "bin", "ensure-bun.ps1")], - { stdio: ["ignore", 2, 2], windowsHide: true }, - ) - : spawnSync("sh", [join(root, "bin", "ensure-bun.sh")], { stdio: ["ignore", 2, 2] }); -if (provision.error) die(`failed to launch provisioner: ${provision.error.message}`); -if (provision.status !== 0) die(`provisioner exited with status ${provision.status}`); +function main() { + const root = process.env.CLAUDE_PLUGIN_ROOT; + const data = process.env.CLAUDE_PLUGIN_DATA; + if (!root) die("CLAUDE_PLUGIN_ROOT is unset"); + if (!data) die("CLAUDE_PLUGIN_DATA is unset"); -if (process.argv.includes("--provision-only")) process.exit(0); + // ── 1. Provision the pinned bun runtime (synchronous correctness gate) ───── + // Delegates to the same ensure-bun.{sh,ps1} the built bundles use. ALL of the + // provisioner's output is mapped to OUR stderr (the stdio integer `2` shares + // the parent's fd 2): stdout (fd 1) stays clean for the JSON-RPC stream the + // child bun will own. + const provision = isWin + ? spawnSync( + "powershell", + ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", join(root, "bin", "ensure-bun.ps1")], + { stdio: ["ignore", 2, 2], windowsHide: true }, + ) + : spawnSync("sh", [join(root, "bin", "ensure-bun.sh")], { stdio: ["ignore", 2, 2] }); + if (provision.error) die(`failed to launch provisioner: ${provision.error.message}`); + if (provision.status !== 0) die(`provisioner exited with status ${provision.status}`); -// ── 2. Resolve bun + the server entrypoint ─────────────────────────────────── -const bun = join(data, "bun", isWin ? "bun.exe" : "bun"); -if (!existsSync(bun)) die(`provisioned bun not found at ${bun}`); -// Built bundle (dist/server.js) wins if present; source-sync has no dist/, so it -// falls through to the TS entrypoint bun runs directly (auto-installing the -// reached import graph into BUN_INSTALL's cache on first call). -const entry = existsSync(join(root, "dist", "server.js")) - ? join(root, "dist", "server.js") - : join(root, "src", "server", "index.ts"); + if (process.argv.includes("--provision-only")) process.exit(0); -// ── 3. Cross-OS env defaults derived from the REAL env var ─────────────────── -// CLAUDE_PLUGIN_DATA persists across plugin updates and is set on every host, so -// it is the correct cross-OS anchor for both the bun auto-install cache and -// runtime state. We derive these in JS (not via manifest ${...} interpolation) -// so the manifest needs no CLAUDE_PLUGIN_DATA expansion. An already-set value -// (manifest env or user shell) wins. -const env = { ...process.env }; -if (!env.BUN_INSTALL) env.BUN_INSTALL = join(data, "bun-cache"); -if (!env.SCHOLAR_RUNTIME_ROOT) env.SCHOLAR_RUNTIME_ROOT = join(data, "runtime"); + // ── 2. Resolve bun + the server entrypoint ───────────────────────────────── + const bun = join(data, "bun", isWin ? "bun.exe" : "bun"); + if (!existsSync(bun)) die(`provisioned bun not found at ${bun}`); + const entry = resolveEntry(root); -// ── 4. Spawn bun. stdio:"inherit" → client <-> bun own fd 0/1 directly. ────── -const passthrough = process.argv.slice(2).filter((a) => a !== "--provision-only"); -const child = spawn(bun, [entry, ...passthrough], { - stdio: "inherit", - cwd: root, - env, - windowsHide: true, -}); + // ── 3. Cross-OS env defaults derived from the REAL env var ───────────────── + // CLAUDE_PLUGIN_DATA persists across plugin updates and is set on every host, + // so it is the correct cross-OS anchor for both the bun auto-install cache and + // runtime state. We derive these in JS (not via manifest ${...} interpolation) + // so the manifest needs no CLAUDE_PLUGIN_DATA expansion. An already-set value + // (manifest env or user shell) wins. + const env = { ...process.env }; + if (!env.BUN_INSTALL) env.BUN_INSTALL = join(data, "bun-cache"); + if (!env.SCHOLAR_RUNTIME_ROOT) env.SCHOLAR_RUNTIME_ROOT = join(data, "runtime"); -for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) { - process.on(sig, () => { - try { - child.kill(sig); - } catch { - /* child already gone */ - } + // ── 4. Spawn bun. stdio:"inherit" → client <-> bun own fd 0/1 directly. ──── + const passthrough = process.argv.slice(2).filter((a) => a !== "--provision-only"); + const child = spawn(bun, [entry, ...passthrough], { + stdio: "inherit", + cwd: root, + env, + windowsHide: true, }); + + for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) { + process.on(sig, () => { + try { + child.kill(sig); + } catch { + /* child already gone */ + } + }); + } + child.on("error", (err) => die(`failed to spawn bun: ${err.message}`)); + child.on("exit", (code, signal) => process.exit(signal ? 1 : (code ?? 0))); } -child.on("error", (err) => die(`failed to spawn bun: ${err.message}`)); -child.on("exit", (code, signal) => process.exit(signal ? 1 : (code ?? 0))); + +if (import.meta.main) main(); diff --git a/tests/launch.test.ts b/tests/launch.test.ts new file mode 100644 index 0000000..7219f11 --- /dev/null +++ b/tests/launch.test.ts @@ -0,0 +1,41 @@ +// tests/launch.test.ts — launcher entry-resolution regression guard (Guard 3b). +// +// The committed source-sync manifest runs `bun ${CLAUDE_PLUGIN_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 run it directly; +// a built bundle ships dist/server.js and the launcher must prefer it. If that +// fallback ever regressed (e.g. someone hard-coded dist/server.js), a no-dist +// install would die "provisioned bun not found"/"cannot find module" and never +// boot — the exact "source-sync launchable on Windows" guard the field pass needs. +// +// resolveEntry is pure and exported; the side-effectful launch sequence is gated +// by `import.meta.main` in launch.mjs, so importing it here does NOT trigger the +// provisioner or a server spawn. (That this import does not process.exit on the +// unset CLAUDE_PLUGIN_ROOT/DATA env is itself proof the guard holds.) +import { test, expect } from "bun:test" +import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { resolveEntry } from "../bin/launch.mjs" + +test("resolveEntry: prefers dist/server.js when the built bundle is present", () => { + const root = mkdtempSync(join(tmpdir(), "scholar-launch-dist-")) + try { + mkdirSync(join(root, "dist"), { recursive: true }) + writeFileSync(join(root, "dist", "server.js"), "// built bundle\n") + expect(resolveEntry(root)).toBe(join(root, "dist", "server.js")) + } finally { + rmSync(root, { recursive: true, force: true }) + } +}) + +test("resolveEntry: falls through to src/server/index.ts when no dist/ (source-sync install)", () => { + const root = mkdtempSync(join(tmpdir(), "scholar-launch-src-")) + try { + // No dist/ — the source-sync ship tree. The launcher must hand bun the TS + // entrypoint so it boots from source (auto-installing the import graph). + expect(resolveEntry(root)).toBe(join(root, "src", "server", "index.ts")) + } finally { + rmSync(root, { recursive: true, force: true }) + } +}) From 2d142215518c5fefd90012ac26a9b1f5fb25daad Mon Sep 17 00:00:00 2001 From: zaynram Date: Wed, 10 Jun 2026 22:20:56 -0500 Subject: [PATCH 3/3] test(launcher): widen win32 probe budget to 5s; surface koffi + bun-SIGILL field findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../2026-06-02-maintenance-readiness.md | 8 ++++++ .../specs/2026-06-01-slim-plugin-pivot.md | 28 ++++++++++++++++++- tests/ensure-bun.test.ts | 9 ++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/docs/audits/2026-06-02-maintenance-readiness.md b/docs/audits/2026-06-02-maintenance-readiness.md index 24ff612..23657a3 100644 --- a/docs/audits/2026-06-02-maintenance-readiness.md +++ b/docs/audits/2026-06-02-maintenance-readiness.md @@ -39,6 +39,14 @@ been run** against a live server. Everything else is tidiness. > `src/server/index.ts` path (cold pinned-bun provision + cold bun auto-install of > the import graph into the `CLAUDE_PLUGIN_DATA` cache, leaving the shipped tree > pristine → clean MCP `initialize`). vec0-ABI pin unchanged. +> +> **Refactor note (2026-06-10, `fix/windows-connect-timeout`).** That live run +> exercised the *pre-refactor* `launch.mjs`. `launch.mjs` was since refactored to +> extract a pure `resolveEntry(root)` and gate the side-effectful launch sequence +> behind `import.meta.main` — a **behaviour-preserving relocation** (provision / +> resolve / spawn logic byte-identical, only re-indented), now pinned by +> `tests/launch.test.ts` (entry resolution: `dist/server.js` when built, else +> `src/server/index.ts`). The live entry-path verification above still stands. --- diff --git a/docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md b/docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md index 5fac0a0..9a96eaf 100644 --- a/docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md +++ b/docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md @@ -250,7 +250,12 @@ enumerated with its failure symptom in **HUMAN.md §5**. §5 leg 7 — confirm a Desktop restart recovers cleanly. - **ensure-bun.ps1**: the PowerShell download/extract path is unexecuted on the dev host. Validate `Invoke-WebRequest`/`Expand-Archive` + the lock-dir guard. -- **koffi.node (win32-x64) — KNOWN REGRESSION (decided: accept + document).** +- **koffi.node (win32-x64) — KNOWN REGRESSION (decided: accept + document). + FIELD-CONFIRMED 2026-06-10 (Cowork Windows):** the predicted `require("koffi")` + failure surfaced live as `Cannot find native Koffi module` on pdf-child spawn — + exactly the swallowed-throw path below, now observed rather than inferred. The + prediction held; no behaviour change is required (it remains best-effort, off by + default), only this status flip from "predicted" to "observed." `attachJobObject` does a runtime `require("koffi")` inside `server.js`. `bun build --target=bun` keeps native modules external, and the slim package ships **no `node_modules`**, so on Windows that `require` throws and is swallowed by @@ -268,6 +273,27 @@ enumerated with its failure symptom in **HUMAN.md §5**. `node_modules/koffi`), *or* tree-kill the pdf child from the cmd-side launcher. Not done blind here — koffi's native-binding resolution cannot be validated off the target. +- **Pinned-bun SIGILL on pdf-child spawn — NEW, field-observed 2026-06-10 + (intermittent; single occurrence).** On one Cowork Windows boot the **pinned** + `bun.exe` (`bun-windows-x64` `1.3.11`, the vec0-ABI-matched runtime ensure-bun + provisions) crashed with `Illegal instruction` as the pdf child was spawned, so + `spawnPdfChild` saw the child die immediately. It did not reproduce on the next + boot. **Mechanism — hypothesis, NOT confirmed:** the default `bun-windows-x64` + release is built for a modern x86-64 baseline (uses AVX2-class instructions); on + a CPU/VM that does not expose them, the process traps `SIGILL`. The intermittency + fits a host that sometimes schedules the MCP onto a constrained vCPU, or a flaky + download leaving a corrupt `bun.exe` (Expand-Archive over a partial zip) — both + are guesses pending a Windows repro. **Remediation hypotheses (unvalidated, do + NOT ship blind):** (a) if it is the instruction-set mismatch, provision bun's + **`-baseline`** Windows build (`bun-windows-x64-baseline.zip`) instead of / as a + SIGILL-triggered fallback — it targets older CPUs and is the canonical bun fix + for `Illegal instruction`, but it must still carry the **same vec0 ABI** as the + pin, so the swap has to be version-locked the way the current pin is; (b) if it + is download corruption, have ensure-bun verify the extracted `bun.exe` + (size/hash, or the very `cmd /c "" --version` probe the connect-timeout fix + added) before declaring provision success, and re-download on mismatch. Pick the + branch only after a Windows repro distinguishes them — a `--version` that itself + SIGILLs points at (a); a `--version` that mismatches the pin points at (b). - **UI bundling** — *RESOLVED 2026-06-04 (`eda8026`+`306e3f8`).* This bullet predicted the defect: `build:ui` emits a multi-file `ui/index.html` + `chunk-*.js`, and the sandboxed MCP-App iframe (SEP-1865) cannot fetch sibling chunks — so the diff --git a/tests/ensure-bun.test.ts b/tests/ensure-bun.test.ts index c3b847a..da59bc6 100644 --- a/tests/ensure-bun.test.ts +++ b/tests/ensure-bun.test.ts @@ -83,7 +83,7 @@ function runProvisionerDetached(dataDir: string) { } test.skipIf(process.platform !== "win32")( - "ensure-bun.ps1: valid pinned bun present → detached re-launch exits 0 in <2s and does NOT re-provision", + "ensure-bun.ps1: valid pinned bun present → detached re-launch exits 0 in <5s and does NOT re-provision", () => { const dataDir = mkdtempSync(join(tmpdir(), "scholar-ensure-bun-")) try { @@ -112,7 +112,12 @@ test.skipIf(process.platform !== "win32")( const elapsedMs = performance.now() - t0 expect(r.status).toBe(0) - expect(elapsedMs).toBeLessThan(2000) + // 5 s, not 2 s: a no-op probe on Windows CI (cold process spawn + AV scan + + // slower FS) can blow past 2 s without re-downloading. A real re-provision + // pulls ~110 MB — far above 5 s — so the bound still positively distinguishes + // "Test-Ok true, fast exit" from "Test-Ok false, re-download", and stays well + // under the 30 s MCP connect budget the fix exists to protect. + expect(elapsedMs).toBeLessThan(5000) expect(String(r.stderr ?? "")).not.toContain("provisioning bun") } finally { rmSync(dataDir, { recursive: true, force: true })