Skip to content

fix(vscode): bundled sidecar crashed on startup (ESM loaded as CommonJS)#68

Merged
matze4u merged 2 commits into
mainfrom
fix/v1-0-vscode-sidecar-stderr-visibility
Jun 3, 2026
Merged

fix(vscode): bundled sidecar crashed on startup (ESM loaded as CommonJS)#68
matze4u merged 2 commits into
mainfrom
fix/v1-0-vscode-sidecar-stderr-visibility

Conversation

@matze4u

@matze4u matze4u commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

The bug (production-breaking)

Every packaged VSIX shipped a dead sidecar. The bundled
sidecar/server.js is copied from the ESM packages/core build, but it
lands outside that package with no module marker, so Node loads it as
CommonJS and the spawned process dies on the first import:

SyntaxError: Cannot use import statement outside a module
[sidecar] process exited (code=1, signal=null)

With the sidecar dead, every request (connect, chatSend, chatCancel)
times out: the index statusbar stays "Index: idle", chat send produces
nothing, and stop can't reach an already-crashed process — in both
API and CLI mode (it's upstream of the provider). The dev path worked
only because packages/core is type:module; resolveSidecarPath
prefers the bundled copy when present, so a stale bundle shadowed the
working dev sidecar.

Fix

bundle-sidecar.mjs now writes sidecar/package.json {"type":"module"}
next to the copied bundle → Node loads it as ESM. .vscodeignore keeps
sidecar/, so the marker ships in the VSIX.

How it was found

The SidecarClient piped the child's stderr but never read it, so the
crash was invisible — only a 120s client timeout showed. Second commit
forwards the child's stderr / spawn-error / exit to console.error
(Extension Host Developer Tools). That surfaced the ESM-load crash
immediately and is kept as a permanent diagnostic.

Verification

  • Regenerated bundle boots: node clients/vscode/sidecar/server.js
    agent core ready, answers connect with {ack:true,...}.
  • Direct chatSend probe against the sidecar streams correctly
    ({token} frames + terminal done:true with usage) — confirming the
    ChatHandler / backend / client code were already correct; only the
    bundle's module type was wrong.
  • clients/vscode typecheck + 40 vitest tests green.

Follow-up (not in scope)

In dev, resolveSidecarPath prefers the bundled copy over the live
packages/core/dist/server.js, so a stale bundle can shadow live core
edits. Worth preferring the dev path under extensionDevelopmentMode
separate change.

matze4u added 2 commits June 3, 2026 16:08
…tarts

The bundled sidecar (`sidecar/server.js`, copied from the ESM
`packages/core` build) sat outside that package with no module marker,
so Node loaded it as CommonJS and the spawned process died on the first
`import` — "Cannot use import statement outside a module", exit 1, no
NDJSON comms. Every request (connect, chatSend, chatCancel) then timed
out: the index statusbar stayed idle, chat send produced nothing, and
stop could not reach a process that had already crashed. The dev path
(`packages/core/dist/server.js`) worked only because `packages/core` is
`type:module`; `resolveSidecarPath` prefers the bundled copy when it
exists, so a stale bundle shadowed the working dev sidecar.

`bundle-sidecar.mjs` now writes `sidecar/package.json {"type":"module"}`
next to the copied bundle, so Node loads it as ESM. Verified: the
regenerated bundle boots (`agent core ready`) and answers `connect`.
`.vscodeignore` keeps `sidecar/`, so the marker ships in the VSIX.
…nsole

The SidecarClient piped the child's stderr but never read it, so a
sidecar that crashed on startup or failed to spawn showed only a
client-side request/stream timeout with no cause — the failure that hid
the ESM-load crash above. Forward the child's stderr, `error`, and
`exit` to `console.error` so they land in the Extension Host Developer
Tools console. No behaviour change to the request/stream paths.
@matze4u matze4u merged commit 47322f3 into main Jun 3, 2026
15 of 16 checks passed
@matze4u matze4u deleted the fix/v1-0-vscode-sidecar-stderr-visibility branch June 3, 2026 14:21
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.

1 participant