Repository navigation
fix(showcase): harness crash-loops at boot on extensionless ESM imports - #5952
Merged
Merged
Conversation
…pure-ESM boot
The harness runs as pure Node ESM (package.json "type":"module", built
with tsc moduleResolution:"bundler" which preserves extensionless import
specifiers at emit, launched via node dist/orchestrator.js). Under pure
Node ESM, relative import specifiers must carry the .js extension — a
convention the harness already honors everywhere (79/79 relative imports
in orchestrator.ts end in .js).
The relocated shared/cell-model fold broke that convention: cell-model.ts,
live-status.ts, staleness.ts, and the equivalence fixtures/test imported
sibling modules extensionless ("./live-status", "./staleness", etc). tsc,
vitest, and tsx all resolve those fine, so it built and tested green — but
at container boot node threw ERR_MODULE_NOT_FOUND on
dist/shared/cell-model/live-status and crash-looped the orchestrator,
breaking the staging auto-deploy.
Add the .js extension to every offending relative import to match the
harness convention. Minimal fix — no tsconfig change.
…t crash-loops CI missed the extensionless-import regression because tsc (bundler resolution), vitest, and tsx all resolve extensionless relative specifiers fine — no existing step ever ran the real node dist module graph, which is what the container actually does at boot. Add a boot-smoke to the Validate Showcase job (already gated on showcase/harness/**): after building the harness dist, load dist/orchestrator.js via a node import() and fail hard on ERR_MODULE_NOT_FOUND. A later runtime error from missing env/PocketBase is expected and passes — only a module-resolution failure reddens the build. Verified red-green: the guard exits 1 on the pre-fix extensionless imports and 0 once the .js extensions are added.
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
July 14, 2026 00:39
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
Contributor
Production Digest-Pinning AuditAll 41 services digest-pinned. Run 2026-07-13 21:12:41 PDT — 0 finding(s). |
Contributor
|
Size Change: 0 B Total Size: 1.19 MB ℹ️ View Unchanged
|
…odule-resolution error class The boot-smoke step only treated ERR_MODULE_NOT_FOUND as failure, so other module-resolution regressions (ERR_UNSUPPORTED_DIR_IMPORT, ERR_PACKAGE_PATH_NOT_EXPORTED, ERR_UNKNOWN_FILE_EXTENSION, ERR_INVALID_MODULE_SPECIFIER) were swallowed as BOOT_OK/exit 0 — the very class of bug this gate exists to catch could slip through. It also had no process.exit(0) on the success/expected-error paths and no bounded timeout, so a future open handle at import time could hang node -e to the job's 25-minute ceiling. - Broaden the failure condition to a MODULE_RESOLUTION_CODES set (any of the five codes => BOOT_FAIL, exit 1). Non-module-resolution runtime errors (e.g. the HARNESS_ROLE env guard, no such code) stay BOOT_OK/exit 0. - Add explicit process.exit(0) on both the success and expected-error paths. - Wrap the node invocation in `timeout 120s` (non-zero on timeout => step fails) and add step-level timeout-minutes: 5. Red-green proof (extracted guard logic vs synthetic modules): current logic passes ERR_UNSUPPORTED_DIR_IMPORT / ERR_PACKAGE_PATH_NOT_EXPORTED at exit 0 (RED gap); hardened logic fails all five codes at exit 1, keeps benign runtime error at exit 0, and against the real built dist/orchestrator.js reports BOOT_OK and exits promptly (779ms, no hang).
…e classifier The boot-smoke gate classified pass/fail using only the top-level `e.code`. A module-resolution error that arrives WRAPPED — nested in `e.cause` (possibly a chain), bundled inside an `AggregateError` (`e.errors[]`), or rethrown without preserving `.code` at the top — showed no code to the `MODULE_RESOLUTION_CODES.has(e.code)` check and was misclassified as BOOT_OK, defeating the gate. Add a `collectErrorCodes` helper that gathers every code reachable from the thrown error: the error itself, its cause chain (recursively), and any AggregateError members (recursively), with a depth cap to bound cause cycles. If ANY collected code is a module-resolution code -> BOOT_FAIL / exit 1. Purely additive to the FAIL set: direct top-level codes still redden, and a benign non-resolution runtime error (e.g. the `HARNESS_ROLE must be set` guard, which carries no such code anywhere) still passes as BOOT_OK / exit 0. The `timeout 120s` wrapper, `timeout-minutes: 5`, and success/expected-error `process.exit(0)` are unchanged. Local red-green (classifier extracted to a temp file, driven against synthetic errors): - RED (top-level-only): wrapped cause -> BOOT_OK exit 0 (swallowed); AggregateError member -> BOOT_OK exit 0 (swallowed). - GREEN (hardened): wrapped -> exit 1; aggregate -> exit 1; direct ERR_MODULE_NOT_FOUND -> still exit 1; benign ERR_INVALID_ARG_TYPE and HARNESS_ROLE error -> BOOT_OK exit 0; real built dist/orchestrator.js -> BOOT_OK exit 0 in <200ms (prompt exit, no hang).
…r fails
The boot-smoke previously failed only when the thrown error carried a
module-RESOLUTION code (ERR_MODULE_NOT_FOUND + siblings, walked through
the cause chain / AggregateError members) and passed everything else.
That defaults-to-pass on module-EVALUATION crashes — a top-level throw,
an await-rejection, a bad named binding, or a SyntaxError — none of which
carry a resolution code, so a real boot-crashing regression of that class
would ship green.
The smoke runs `node -e "import('./dist/orchestrator.js')"` with
process.argv[1] UNSET, so bootFleet() (the env/PocketBase validation that
legitimately throws) never runs — only the module graph is linked and
evaluated. A clean build therefore loads with no thrown error, so ANY
error thrown by import() here is a boot regression and must fail the gate.
Now: any rejection -> BOOT_FAIL / exit 1 (resolution AND
evaluation/link/binding/syntax/top-level-throw). Successful load ->
BOOT_OK / exit 0. The collectErrorCodes cause/AggregateError walk is
retained ONLY to label the failure ("module-resolution failure" vs
"boot/evaluation failure") — both exit 1, richer diagnostics preserved.
Kept process.exit(0) on success, the timeout 120s wrapper, and
timeout-minutes: 5 (a hang still fails).
No-false-red proof: built the real harness dist and ran the strict guard
against the real dist/orchestrator.js under node -e (argv[1] unset) —
BOOT_OK, exit 0, ~0.28s, no hang, confirming a clean graph loads without
throwing and the strict guard does not false-red real CI.
jpr5
added a commit
that referenced
this pull request
Jul 14, 2026
…ose CI gap (#5955) ## What broke PR #5952 (`9a8cf615`) added explicit `.js` extensions to the relative imports inside the harness's shared cell-model fold (`showcase/harness/src/shared/cell-model/{cell-model,live-status,staleness}.ts`). Those `.js` extensions are **REQUIRED** for the harness's pure-Node-ESM runtime and are **correct** — this PR does not revert them. The problem: the dashboard re-exports that fold via re-export shims (`showcase/shell-dashboard/src/lib/{cell-model,live-status,staleness,format-ts}.ts`, each `export * from "../../../harness/src/shared/cell-model/*"`), which pulls the fold **into the dashboard's `next build`**. `export *` does not rewrite the fold's *internal* `.js` edges, and the dashboard's `next.config.ts` was empty (no `extensionAlias`), so webpack resolved `./live-status.js` **literally**, found only the `.ts` source, and failed: ``` ../harness/src/shared/cell-model/cell-model.ts Module not found: Can't resolve './live-status.js' Module not found: Can't resolve './staleness.js' ../harness/src/shared/cell-model/live-status.ts Module not found: Can't resolve './format-ts.js' > Build failed because of webpack errors ``` First-red at `9a8cf615`; reproduced in CI run `29306712559` (shell-dashboard build job). ## The fix (two parts, one coherent subject) **1. Resolution** — `showcase/shell-dashboard/next.config.ts`: add a webpack `resolve.extensionAlias` so `.js`/`.mjs` specifiers resolve to `.ts`/`.tsx`/`.mts` sources. This is the standard bundler complement to TypeScript NodeNext's `.js`-import convention, and it applies to the `next build` (webpack) path CI uses. A shim-only fix does **not** work — `export *` doesn't intercept the fold's internal `.js` edges; the alias in the dashboard build is the correct layer. The harness fold `.js` imports are **left untouched**. **2. CI gap** — `.github/workflows/showcase_build.yml`: the dashboard build didn't run on #5952 because the build matrix is path-filtered and #5952 only touched `showcase/harness/**`, which selects `showcase_harness` but **not** `shell_dashboard`. Added `showcase/harness/src/shared/**` to the `shell_dashboard` `dorny/paths-filter` set. Now any change to the shared fold the dashboard compiles in also selects the dashboard build — a fold change can never again ship an unbuilt dashboard. (Verified only `shell-dashboard` consumes this fold, so the gate is scoped precisely.) ## Local red-green proof **RED** (latest main, before the `next.config.ts` fix) — from `showcase/shell-dashboard`, `next build`: ``` ../harness/src/shared/cell-model/cell-model.ts Module not found: Can't resolve './live-status.js' Module not found: Can't resolve './staleness.js' ../harness/src/shared/cell-model/live-status.ts Module not found: Can't resolve './format-ts.js' Module not found: Can't resolve './staleness.js' > Build failed because of webpack errors ``` (4 fold-resolve errors.) **GREEN** (after the `extensionAlias` fix) — same `next build`: ``` (0 fold-resolve errors — the fold resolves) ``` The only remaining `Module not found` errors are `@/data/{catalog,registry,docs-status}.json`, which are generated by the dashboard's `prebuild` scripts (`generate-registry.ts` / `probe-docs.ts`) that were skipped in the local repro. CI's Docker build runs `prebuild` first, so those files exist there — unrelated to this fix. ## CI-gap trace `dorny/paths-filter` emits `changes` as the JSON array of filter keys whose patterns matched. A change to `showcase/harness/src/shared/cell-model/live-status.ts` now matches both `showcase_harness` (via `showcase/harness/**`) **and** `shell_dashboard` (via the new `showcase/harness/src/shared/**`), so the matrix `select` (`$dispatch == "" and ($changes | index($fk) != null)`) includes the `shell-dashboard` slot. Gap closed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pull Bot
pushed a commit
to HinchK/copilotkit
that referenced
this pull request
Jul 14, 2026
…ose CI gap PR CopilotKit#5952 (9a8cf61) added explicit `.js` extensions to the relative imports inside the harness's shared cell-model fold (showcase/harness/src/shared/cell-model/{cell-model,live-status,staleness}.ts) — REQUIRED for the harness's pure-Node-ESM runtime and correct as-is. But the dashboard re-exports that fold via shims (showcase/shell-dashboard/src/lib/{cell-model,live-status,staleness,format-ts}.ts `export * from "../../../harness/src/shared/cell-model/*"`), pulling the fold into the dashboard's `next build`. `export *` does not rewrite the fold's INTERNAL `.js` edges, and the dashboard's empty next.config.ts had no extensionAlias, so webpack resolved `./live-status.js` literally, found only the `.ts` source, and failed: Module not found: Can't resolve './live-status.js' Module not found: Can't resolve './staleness.js' Module not found: Can't resolve './format-ts.js' > Build failed because of webpack errors Two-part fix (one coherent subject): 1. Resolution: add `webpack.resolve.extensionAlias` to showcase/shell-dashboard/next.config.ts so `.js`/`.mjs` specifiers resolve to `.ts`/`.tsx`/`.mts` sources — the bundler complement to TS NodeNext's `.js`-import convention. Covers the `next build` (webpack) path CI uses. The harness fold's `.js` imports are left untouched (they are correct). 2. CI gap: the dashboard build did not run on CopilotKit#5952 because the build matrix is path-filtered and CopilotKit#5952 only touched `showcase/harness/**`, which selects `showcase_harness` but not `shell_dashboard`. Add `showcase/harness/src/shared/**` to the `shell_dashboard` paths-filter so any change to the shared fold the dashboard compiles in also selects the dashboard build — a fold change can never again ship an unbuilt dashboard. Local red-green proof: - RED (main, before fix): `next build` in showcase/shell-dashboard emitted the 4 fold-resolve errors above. - GREEN (after extensionAlias): same build → 0 fold-resolve errors; the fold resolves. Remaining `@/data/*.json` errors are the prebuild-generated files (generate-registry/probe-docs) skipped in the local repro, produced in CI's Docker build — unrelated to this fix.
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.
What broke
The showcase control-plane harness crash-looped at boot on
origin/mainHEAD, breaking the staging auto-deploy:Root cause
The harness ships as pure Node ESM:
showcase/harness/package.jsonhas"type": "module"tsc -p tsconfig.build.jsonwithmoduleResolution: "bundler", which preserves extensionless import specifiers at emit (it does not rewrite./live-status→./live-status.js)CMDand thestartscript both runnode dist/orchestrator.jsUnder pure Node ESM, relative import specifiers must carry the
.jsextension. The harness already honors this convention everywhere —orchestrator.tshas 79 relative imports, 79/79 ending in.js.The relocated
showcase/harness/src/shared/cell-model/fold broke the convention:cell-model.ts,live-status.ts,staleness.ts, and the equivalence fixtures/test imported their siblings extensionless ("./live-status","./staleness", etc).tsc,vitest, andtsxall resolve extensionless specifiers fine, so it built green and passed every test — thennode dist/orchestrator.jsthrewERR_MODULE_NOT_FOUNDat boot and crash-looped.The fix
Add the
.jsextension to every offending relative import in the cell-model fold, matching the harness convention. No tsconfig change (deliberately not switching tonodenext) — the minimal, convention-matching fix is the extensions.Files fixed (7 relative import specifiers across 5 files):
cell-model.ts— 4 specifiers (./live-status×3,./staleness×2 counting the re-export)live-status.ts—./format-ts,./stalenessstaleness.ts—./live-statuscell-model.equivalence-fixtures.ts—./live-status×2,./cell-model,./stalenesscell-model.equivalence.test.ts—./cell-model,./cell-model.equivalence-fixturesThe shell-dashboard re-export shims (
showcase/shell-dashboard/src/lib/{cell-model,live-status,staleness,format-ts}.ts) were intentionally left unchanged: that package is a Next.js build (notnode dist) and uses extensionless relative imports as its own convention, including reaching into harnesssrc. Adding.jsthere would break it.Local RED / GREEN proof
Same
node dist/orchestrator.jsboot probe, before and after the fix.RED (unmodified branch code, after
pnpm --filter @copilotkit/showcase-harness build):GREEN (after the fix, rebuilt):
The orchestrator module graph now loads fully —
ERR_MODULE_NOT_FOUNDis gone.Docker boot result
Built the harness image locally from repo root (
docker build -f showcase/harness/Dockerfile -t harness-esm-test .) — build succeeded (exit 0). Ran the container (docker run harness-esm-test, no env supplied). It did not crash-loop on module resolution: the full ESM module graph loaded and boot reachedbootFleetinorchestrator.js, then exited cleanly on the expected missing-env application error — noERR_MODULE_NOT_FOUND:Every
dist/module resolved (notefile:///app/dist/fleet/role-config.jsandfile:///app/dist/orchestrator.js); the crash was the intended env-validation guard, exactly the "later runtime error is acceptable" case. On pre-fix code this same container would have thrownERR_MODULE_NOT_FOUNDat import time and crash-looped.CI regression guard
CI missed this because
tsc(bundler resolution),vitest, andtsxall resolve extensionless specifiers — no existing CI step ever ran the realnode distmodule graph that the container boots.Added a harness ESM boot-smoke step to the
Showcase: Validatejob (already gated onshowcase/harness/**, a required PR check): after building the harness dist, it loadsdist/orchestrator.jsvianode import()and fails hard onERR_MODULE_NOT_FOUND. A later runtime error from missing env/PocketBase is expected and passes — only a module-resolution failure reddens the build.Guard red-green (the guard's own proof, run locally against both code states):
BOOT_FAIL: ERR_MODULE_NOT_FOUND …/dist/shared/cell-model/live-status→ exit 1 ✅ caught.js):BOOT_OK: orchestrator module graph loaded→ exit 0 ✅ passesVerification
pnpm typecheck/tsc --noEmit: cleancell-model.equivalence.test.ts: 7/7 passDo not merge — merge is user-gated after code review.