fix(vscode): bundled sidecar crashed on startup (ESM loaded as CommonJS)#68
Merged
Merged
Conversation
…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.
This was referenced Jun 3, 2026
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.
The bug (production-breaking)
Every packaged VSIX shipped a dead sidecar. The bundled
sidecar/server.jsis copied from the ESMpackages/corebuild, but itlands outside that package with no module marker, so Node loads it as
CommonJS and the spawned process dies on the first
import: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/coreistype:module;resolveSidecarPathprefers the bundled copy when present, so a stale bundle shadowed the
working dev sidecar.
Fix
bundle-sidecar.mjsnow writessidecar/package.json {"type":"module"}next to the copied bundle → Node loads it as ESM.
.vscodeignorekeepssidecar/, 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
node clients/vscode/sidecar/server.js→agent core ready, answersconnectwith{ack:true,...}.chatSendprobe against the sidecar streams correctly(
{token}frames + terminaldone:truewith usage) — confirming theChatHandler / backend / client code were already correct; only the
bundle's module type was wrong.
clients/vscodetypecheck + 40 vitest tests green.Follow-up (not in scope)
In dev,
resolveSidecarPathprefers the bundled copy over the livepackages/core/dist/server.js, so a stale bundle can shadow live coreedits. Worth preferring the dev path under
extensionDevelopmentMode—separate change.