Skip to content

fix(cli): reach the probe TUI lazily — @opentui load-death under --isolate - #390

Merged
jsboige merged 1 commit into
mainfrom
fix/386-opentui-isolate-tdz
Oct 8, 2026
Merged

jsboige merged 1 commit into
mainfrom
fix/386-opentui-isolate-tdz

Conversation

@jsboige

@jsboige jsboige commented Oct 7, 2026

Copy link
Copy Markdown
Owner

cli.ts statically imported ./probe/probe-tui-runtime.js, which pulls @opentui/core. That dependency's module scope reads a namespace produced by a dynamic import() inside its own top-level await (zig.ts: const module = await import(...); let targetLibPath = module.default). Under bun test --isolate the namespace is handed out before that module finishes evaluating, so the read throws ReferenceError: Cannot access 'default' before initialization during @OpenTui's own evaluation — killing the load of every file whose static graph reaches it.

What was measured (not assumed)

po-204, bun 1.3.14, main 6f732eb9.

  • Import ORDER is irrelevant. A bare import "@opentui/core" fails alone under --isolate; a file importing core-then-react and a file importing react-then-core both fail. @opentui 0.1.87 TDZ load-death under per-file isolation — 3 baseline load errors, fix is an import-order change #386's proposed import-order fix cannot work — it was refuted before being attempted.
  • --isolate is the whole trigger. Every failing case passes without it.
  • Not @opentui-specific. A 6-line synthetic reproducing the same shape (A: const inner = await import("./plain.ts"); export default inner.default; then an importer reading A.default) reproduces the byte-identical error under --isolate and passes without it. @opentui is simply the one dependency in our tree using TLA + dynamic import at module scope.
  • Deferring the edge fixes it — the lever that worked, and the only one that did.

Result under --isolate

file before after
cli.test.ts 0 pass · 1 error 26 pass
cli-passthrough.test.ts 0 pass · 1 error 22 pass
handlers/native-handler-advisor.test.ts 0 pass · 1 error 40 pass

88/0 across the three — the figure #386 reported for the non-isolated run. The three permanent load error baseline entries are gone.

bunx tsc -p packages/cli/tsconfig.json --noEmit error set is byte-identical before and after (the pre-existing tree-wide baseline is untouched).

The pin

packages/cli/src/probe/probe-tui-import-graph.test.ts guards reachability — not ordering — with three controls that keep it honest: a premise control (probe-tui-runtime really does pull @opentui/core, else the pin guards nothing), a detector control (the static-import regex matches a synthetic positive), and a tree-wide scan for any other static importer. Mutation-checked: reverting cli.ts to the static edge fails 3 of 5 tests while both controls stay green.

Rescope of #386's third option

Option 3 (report upstream) was mis-targeted: @opentui is the victim, not the cause. The defect is bun's --isolate not sequencing top-level await across the module graph. That report is a separate, outward-facing grain and is tracked in a follow-up issue rather than folded in here.

Closes #386
Refs #175

🤖 Generated with Claude Code

…olate

`cli.ts` statically imported `./probe/probe-tui-runtime.js`, which pulls
`@opentui/core`. That dependency's module scope reads a namespace produced by a
dynamic `import()` inside its own top-level await (`zig.ts`:
`const module = await import(...); let targetLibPath = module.default`). Under
`bun test --isolate` the namespace is handed out before that module finishes
evaluating, so the read throws `Cannot access 'default' before initialization`
*during @OpenTui's own evaluation* — killing the load of every file whose static
graph reaches it.

Measured, not assumed (po-204, bun 1.3.14, main 6f732eb):

- Import ORDER is irrelevant: a bare `import "@opentui/core"` fails alone under
  `--isolate`, and core-first and react-first both fail. #386's proposed
  import-order fix cannot work.
- `--isolate` is the whole trigger: every failing case passes without it.
- Not @opentui-specific: a 6-line synthetic reproducing the same pattern
  reproduces the byte-identical error under `--isolate`.
- Deferring the edge fixes it: `cli.test.ts` 0 pass/1 error -> 26 pass,
  `cli-passthrough.test.ts` -> 22 pass, `native-handler-advisor.test.ts` -> 40
  pass, all under `--isolate` (88/0 across the three — the non-isolated figure).

The pin (`probe-tui-import-graph.test.ts`) guards *reachability*, the lever that
worked, with a premise control (the runtime really does pull @OpenTui), a
detector control (the regex matches a positive) and a tree-wide scan, so a green
line cannot stand for a regex that stopped matching.

Refs #386
@jsboige

jsboige commented Oct 8, 2026

Copy link
Copy Markdown
Owner Author

Review myia-ai-01 — approved at f258a31. Lazy import removes the CLI static reachability of the TUI. Pin 5/5; reverting to static import makes 3 pins fail while both detector controls stay green. Targeted isolated tests 88/0; note that the original load death does not reproduce on ai-01 bun 1.3.13 (reported on po-2024 1.3.14). Closes #386 is appropriate: upstream reproduction tracked separately on #391. Verification delegated; authors, current head and merge-tree checked by coordinator.

@jsboige
jsboige merged commit dd4d704 into main Oct 8, 2026
1 check passed
@jsboige
jsboige deleted the fix/386-opentui-isolate-tdz branch October 8, 2026 11:41
jsboige added a commit that referenced this pull request Oct 9, 2026
…nd don't read a seat's bun as CI's

Measured on po-2024: the `.test-strict-baseline.json` learned at `fb16ef2d`
(2026-10-06) still listed 3 `load error` entries that #390 had already fixed on
2026-10-08. Re-learning at `4989cdd3` dropped it 6 -> 1 (the by-design TEST-15,
0 added) and the comparison run returned `observed ⊆ baseline`. Reading the stale
file as current had already produced one "the defect still bites" conclusion.

Also recorded: the repo pins no bun, CI installs `bun-version: latest`, so a seat
on an older bun is not commensurable with CI — bun 1.3.14's `--isolate`
module-loader regression (oven-sh/bun#30634, #31410; fixed in 1.4.0) fires for a
static import as much as a dynamic one, and for every TLA flavor measured (6/6).

Refs #175, Refs #391

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jsboige added a commit that referenced this pull request Oct 9, 2026
…nd don't read a seat's bun as CI's (#425)

* docs(tests): a learned strict baseline is a snapshot — re-learn it, and don't read a seat's bun as CI's

Measured on po-2024: the `.test-strict-baseline.json` learned at `fb16ef2d`
(2026-10-06) still listed 3 `load error` entries that #390 had already fixed on
2026-10-08. Re-learning at `4989cdd3` dropped it 6 -> 1 (the by-design TEST-15,
0 added) and the comparison run returned `observed ⊆ baseline`. Reading the stale
file as current had already produced one "the defect still bites" conclusion.

Also recorded: the repo pins no bun, CI installs `bun-version: latest`, so a seat
on an older bun is not commensurable with CI — bun 1.3.14's `--isolate`
module-loader regression (oven-sh/bun#30634, #31410; fixed in 1.4.0) fires for a
static import as much as a dynamic one, and for every TLA flavor measured (6/6).

Refs #175, Refs #391

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* docs(tests): slim the baseline/bun rule to the decision layer (~300 chars)

Review a1d2885 (ai-01, changes requested): the host paragraph states the
live baseline count lives in each machine's gitignored file, "never in this
file" — the first cut wrote one seat's counts (`6 -> 1`, `fb16ef2d`,
`4989cdd3`) into it. Kept to the two decisions: re-learn after any land that
removes a cause of load-time death, and a seat on an older bun is not
commensurable with CI. The measurements (TLA 6/6, upstream issues, 1.3.14 ->
1.4.0) already live on #391.

Refs #175, Refs #391

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

@opentui 0.1.87 TDZ load-death under per-file isolation — 3 baseline load errors, fix is an import-order change

1 participant