Skip to content

fix(cli): preserve theme microtask error context on Node 22.13 - #12032

Closed
astracat-bot[bot] wants to merge 3 commits into
mainfrom
codebunny/fix/fix-cli-preserve-theme-microtask-error-context-on-node-22-13-0547c5
Closed

astracat-bot[bot] wants to merge 3 commits into
mainfrom
codebunny/fix/fix-cli-preserve-theme-microtask-error-context-on-node-22-13-0547c5

Conversation

@astracat-bot

@astracat-bot astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

validation: not run: the repository's test runner was not rerun for this documentation-only follow-up; the implementation and tests are unchanged. pnpm check:changesets passed (552 valid); pnpm exec prettier --check .changeset/cli-theme-microtask-context.md passed; pnpm review:pre --json reported no findings; git diff --check passed. Prior implementation validation is recorded below.

User impact

On the supported minimum Node version, a theme whose folder has its own Core and that throws from a queued microtask while loading answers --json with ERR_UNKNOWN, rather than the theme-load refusal and source path. Consumers cannot identify that failed theme load from its stable error code.

Cause and smallest restoration

Node 22.13 reports a queueMicrotask exception after restoring its AsyncLocalStorage context. The existing exception classifier therefore cannot find the guarded load. Node 24.22.1 retains that context.

Record the originating load only when a guarded microtask callback throws, then rethrow the original value through the existing exception boundary. The classifier consumes the record; a following microtask clears an unused record. Calls outside guarded loads and native callback validation remain unchanged. No timeout, assertion, public API, Node compatibility floor, or stylesheet-loader behavior changes.

Expected behavior and authority

architecture:cli-surface INV2 and INV3 preserve the single error envelope and stable code meanings. ERR_THEME_LOAD means a theme file could not load or parse. The existing N37 regression in #11937 explicitly requires a microtask throw during loading to refuse that load; this restores that case on the minimum supported runtime when the theme's folder has its own Core.

This does not fix the existing standalone-theme race: when the theme's folder has no Core of its own, its synchronous load can win the guarded-load race and drop the microtask exception on both Node 22.13 and Node 24. The release note is narrowed to the case this change fixes. On Node 22.13, a theme microtask callback that throws after its load now produces a warning instead of failing the build.

Evidence

  • GitHub failure: cli-minimum-node.yml, run 43825339875, job 133157785259, commit 0f4c0aa4850ea527b91cc82ccc259b054bd1b303.
  • Before: the unchanged N37 test failed 2/2 runs with expected ERR_THEME_LOAD, received ERR_UNKNOWN. After recording the reproduction and fetching current main, it failed another 2/2 runs at the same commit.
  • After: the unchanged four-test F42 file and five focused regression cases passed twice on Node 22.13.0. The wider loader/F42/hunt241L suites passed on the pinned Node version.
  • Regression coverage keeps both Error and primitive throws associated with their load, reports late microtask callbacks as warnings, leaves an unrelated exception unclaimed during an overlapping load, and preserves native callback validation. The focused load cases await before returning; they do not cover the standalone synchronous-load race.
  • Representative unchanged paths include ordinary module loading, stdout routing, process listeners, late callbacks, and stylesheet imports on the pinned runtime.

The fallback applies on both tested Node versions instead of relying on a version-number check. The full repository suite was not run.

Prior implementation validation

Ran pnpm exec vitest run packages/cli/api/theme/build/build-stable-L-final42.test.mjs packages/cli/foundation/fs/module-loader.microtasks.test.mjs --project node twice on Node 22.13.0 (9/9 passed each); ran pnpm exec vitest run packages/cli/foundation/fs/module-loader packages/cli/api/theme/build/build-stable-L-final42.test.mjs packages/cli/api/theme/build/build-stable-hunt241L.test.mjs --project node on Node 24.22.1 (71 passed, 1 skipped). Targeted strict ESLint, Prettier, pnpm check:changesets, and pnpm check:cli-structure passed. pnpm -F @astryxdesign/theme-neutral build and then pnpm -F @astryxdesign/cli typecheck:strict passed.

Review follow-up

Narrow the changeset and matching description claims to themes whose folder has its own Core, and make the Node 22.13 late-microtask warning change explicit. No behavior change in this follow-up; no implementation or test files changed. The broader standalone race is intentionally left unchanged rather than expanding this compatibility fix.

Failing test fixed

a3853608afff4c78618397d631b4d70b0c221a4f5a1a6ccc0e0a35923e617ffb

packages/cli/api/theme/build/build-stable-L-final42.test.mjs › chaos N37: a theme module that throws from a microtask while it loads › is a refused load naming the error, never exit 7, a stack or ERR_UNKNOWN

@astracat-bot
astracat-bot Bot requested a review from cixzhang as a code owner November 16, 2026 08:08
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 16, 2026 9:15am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@astracat-bot

astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Nov 16, 2026, 9:28 AM UTC

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 6c83a36

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 5.12 MB packed (+188 B); no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the loader fix is sound, but the release note credits the wrong contributor.

  • Replace @codebunny on line 6 of .changeset/cli-theme-microtask-context.md with the account or person that authored this change (@astracat-bot, as the changeset in #11186 does), because the changelog publishes that line as the contributor credit.

The queueMicrotask fallback restores ERR_THEME_LOAD with the theme path on Node 22.13: the new tests and the N37 regression fail on the base and pass on the head on that version, and Node 24 behaves as before. Optionally, the changeset could also say that, on Node 22.13, a microtask callback that throws after the theme loads is now a warning instead of a failed build.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim: on Node 22.13 a theme that throws from a queued microtask while loading answered ERR_UNKNOWN — verified: the N37 test and the new tests fail on the base on Node 22.13.0, as in the failing minimum-Node CI run.
  • Claim: Node 22.13 reports the exception after restoring the async context, and Node 24 keeps it — verified with a plain Node check on 22.13.0 and 24.20.0.
  • Claim: the origin is recorded only when a guarded callback throws, and the original value is rethrown — verified, module-loader.mjs:564-577.
  • Claim: the classifier consumes the record, and a later microtask clears an unused one — verified, module-loader.mjs:574 and :584-585.
  • Claim: calls outside guarded loads and native argument validation are unchanged — verified, module-loader.mjs:566 and the native-validation test.
  • Claim: no timeout, assertion, public API, Node floor or stylesheet-loader change — verified from the diff; an API surface comparison shows no changed rows and the published themes build identical CSS.
  • Claim: the regression cases cover Error and string throws, late warnings, an unrelated throw during a load, and native validation — verified in module-loader.microtasks.test.mjs.
  • Claim: the wider loader suites pass on the pinned Node — verified on Node 24.20.0; on Node 22.13.0, three stylesheet cases in build-stable-hunt241L.test.mjs fail on base and head alike.
  • Claim: there is no Node version check — verified.
  • Claim: lint, formatting, the changeset check, the CLI structure check and the strict typecheck pass — verified on the head.
  • Changeset: theme build reports a loading theme's microtask exception as ERR_THEME_LOAD on Node 22.13 with the theme path and the original error — verified by N37 on Node 22.13.0.
  • Changeset: late theme callbacks remain warnings — true at the head, but on Node 22.13 a late microtask throw used to fail the build, so the wording understates the change.
  • Changeset: unrelated exceptions keep their own error boundary — verified by the unrelated-exception test.
  • Changeset: contributor @codebunny — false; the change was authored by astracat-bot.
  • File .changeset/cli-theme-microtask-context.md: the blocking contributor finding and the optional wording note.
  • File packages/cli/foundation/fs/module-loader.mjs: clear.
  • File packages/cli/foundation/fs/module-loader.microtasks.test.mjs: clear.

Automated review (maintainer link)

@astracat-bot

astracat-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

validation: not run: this follow-up changes only the contributor-credit line. Verified the one-line diff and checked the credited account against the reviewed commit's author; no runtime or test changes.

Addressed the blocking review finding by replacing @codebunny with @astracat-bot in .changeset/cli-theme-microtask-context.md.

The reviewed commit is authored by astracat-bot[bot], so the release note now credits the change's actual author. The release-note prose, loader implementation, regression tests, and PR description remain unchanged. The optional wording change was intentionally left out to keep this follow-up minimal.

git diff --check passed. The repository test runner was not rerun for this attribution-only correction. The requested spec lookup was unavailable because the package-manager tooling is not installed in this fresh environment.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the Node 22.13 fix works for a theme whose folder has its own Core, but the release note promises more than the change delivers.

  • Miss: .changeset/cli-theme-microtask-context.md line 5 says a loading theme's microtask exception is reported as ERR_THEME_LOAD on Node 22.13, but a standalone theme with no Core of its own still builds with exit 0 and the exception dropped, because its synchronous load wins the race in withThemeModuleGuards (module-loader.mjs:720-724), so either make the recorded failure win that race and add a test whose load returns without awaiting, or narrow the sentence to themes whose folder has its own Core.

The contributor credit is fixed. The standalone path already drops the exception on Node 24, so the race is shared code rather than something this change introduced there. Optionally, the changeset could also say that on Node 22.13 a microtask callback that throws after the theme loads is now a warning instead of a failed build.

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Claim: on Node 22.13 a theme that throws from a queued microtask while loading answered ERR_UNKNOWN — verified: the N37 test and the new tests fail on the base on Node 22.13.0, as in the failing minimum-Node CI run.
  • Claim: Node 22.13 reports the exception after restoring the async context, and Node 24 keeps it — verified with a plain Node check on 22.13.0 and 24.20.0.
  • Claim: the origin is recorded only when a guarded callback throws, and the original value is rethrown — verified, module-loader.mjs:564-577.
  • Claim: the classifier consumes the record, and a later microtask clears an unused one — verified, module-loader.mjs:574 and :584-585.
  • Claim: calls outside guarded loads and native argument validation are unchanged — verified, module-loader.mjs:566 and the native-validation test.
  • Claim: no timeout, assertion, public API, Node floor or stylesheet-loader change — verified from the diff; an API surface comparison shows no changed rows and the published themes build identical CSS.
  • Claim: this restores the load refusal on the minimum supported runtime — partly false: restored when the theme's folder has its own Core; a standalone theme builds with the exception dropped.
  • Claim: the regression cases cover Error and string throws, late warnings, an unrelated throw during a load, and native validation — verified in module-loader.microtasks.test.mjs; each case awaits before its load returns.
  • Claim: the wider loader suites pass on the pinned Node — verified on Node 24.20.0.
  • Claim: there is no Node version check — verified.
  • Claim: lint, formatting, the changeset check, the CLI structure check and the strict typecheck pass — verified on the head.
  • Changeset: theme build reports a loading theme's microtask exception as ERR_THEME_LOAD on Node 22.13 with the theme path and the original error — false for a standalone theme; verified for a theme whose folder has its own Core.
  • Changeset: late theme callbacks remain warnings — true at the head, but on Node 22.13 a late microtask throw used to fail the build, so the wording understates the change.
  • Changeset: unrelated exceptions keep their own error boundary — verified by the unrelated-exception test.
  • Changeset: contributor @astracat-bot — verified; it is the commits' author.
  • File .changeset/cli-theme-microtask-context.md: the blocking scope finding on line 5 and the optional wording note.
  • File packages/cli/foundation/fs/module-loader.mjs: the fallback is correct; the refusal race it relies on is the blocking finding's cause.
  • File packages/cli/foundation/fs/module-loader.microtasks.test.mjs: clear.

Automated review (maintainer link)

@astracat-bot

astracat-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

validation: not run: the repository's test runner was not rerun for this documentation-only follow-up; the implementation and tests are unchanged. pnpm check:changesets passed (552 valid); pnpm exec prettier --check .changeset/cli-theme-microtask-context.md passed; pnpm review:pre --json reported no findings; git diff --check passed.

Address the requested release-note correction by narrowing the loading-time ERR_THEME_LOAD claim to themes whose folder has its own Core. Also state that on Node 22.13 a microtask callback that throws after the theme loads now produces a warning instead of failing the build. Keep the contributor credit unchanged.

The PR description uses the same scope and explicitly records that the existing standalone synchronous-load race is not fixed. This chooses the reviewer's minimal wording correction rather than expanding shared loader behavior. No implementation or test files changed, and no tests were re-investigated on the default branch.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the Node 22.13 fix works for a single theme whose folder has its own Core, but the narrowed release note still covers --family builds, which drop the exception.

  • Miss: .changeset/cli-theme-microtask-context.md line 5 promises ERR_THEME_LOAD on Node 22.13 for any loading theme whose folder has its own Core, but a --family build of such themes always loads through Core interception's synchronous path and now exits 0 with the exception dropped (the base answered ERR_UNKNOWN), so either say "a single theme whose folder has its own Core" and match the description's scope paragraph, or make the recorded failure win the race in withThemeModuleGuards (module-loader.mjs:720-724) and add a test whose load returns without awaiting.

Sorry for the extra round: the wording suggested in the previous review missed the --family path. The late-warning sentence and the exclusion of themes without their own Core are now accurate. A project whose selected Core does not generate adaptation CSS appears to take the same synchronous path (build.mjs:3170), so the race fix is the change that makes the original sentence true everywhere.

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Claim: this follow-up changes only the release note, and the implementation and tests are unchanged — verified: line 5 of the changeset is the only change since the previous head.
  • Claim: the changeset check, Prettier on the changeset, the pre-review report and the whitespace check pass — verified on the head (552 valid changesets, formatted, no findings, clean).
  • Claim: on Node 22.13, a theme whose folder has its own Core and throws from a queued microtask while loading answered ERR_UNKNOWN — verified: the base answers ERR_UNKNOWN on Node 22.13.0 on every load path.
  • Claim: Node 22.13 reports the exception after restoring the async context, and Node 24 keeps it — verified with a plain Node check on 22.13.0 and 24.20.0.
  • Claim: the origin is recorded only when a guarded callback throws, and the original value is rethrown — verified, module-loader.mjs:564-577.
  • Claim: the classifier consumes the record, and a later microtask clears an unused one — verified, module-loader.mjs:574 and :584-585.
  • Claim: calls outside guarded loads and native argument validation are unchanged — verified, module-loader.mjs:566 and the native-validation test.
  • Claim: no timeout, assertion, public API, Node floor or stylesheet-loader change — verified from the diff; an API surface comparison shows no changed rows and the published themes build identical CSS.
  • Claim: this restores the N37 case on the minimum runtime when the theme's folder has its own Core — verified for a single-theme build: N37 fails on the base and passes on the head on Node 22.13.0.
  • Claim: the standalone race for a theme without its own Core is left unfixed and drops the exception on both runtimes — true but incomplete: --family builds take the same synchronous path.
  • Claim: the release note is narrowed to the case this change fixes — false: it still covers --family builds.
  • Claim: on Node 22.13, a microtask callback that throws after its load now produces a warning instead of failing the build — verified: the base fails with ERR_UNKNOWN, the head warns and exits 0.
  • Claim: the cited minimum-Node CI failure ran at the base commit — verified from the run and job metadata.
  • Claim: N37 failed before, and the F42 file and the focused cases pass after on Node 22.13 — verified (base N37 fails; head 9 of 9 pass).
  • Claim: the regression cases cover Error and string throws, late warnings, an unrelated throw during a load and native validation, and each awaits before returning — verified in module-loader.microtasks.test.mjs.
  • Claim: the wider loader suites pass on the pinned Node — verified on Node 24.20.0 (71 passed, 1 skipped).
  • Claim: there is no Node version check — verified.
  • Claim: lint, formatting, the changeset check, the CLI structure check and the strict typecheck pass — verified on the head.
  • Changeset: on Node 22.13, theme build reports a microtask exception from a loading theme whose folder has its own Core as ERR_THEME_LOAD, with the theme path and the original error — false for --family builds; verified for a single-theme build.
  • Changeset: a theme microtask callback that throws after the load now produces a warning instead of failing the build — verified on Node 22.13.
  • Changeset: unrelated exceptions keep their own error boundary — verified by the unrelated-exception test.
  • Changeset: contributor @astracat-bot — verified; it is the commits' author.
  • File .changeset/cli-theme-microtask-context.md: the blocking scope finding on line 5.
  • File packages/cli/foundation/fs/module-loader.mjs: the fallback is correct; the refusal race it relies on is the blocking finding's cause.
  • File packages/cli/foundation/fs/module-loader.microtasks.test.mjs: clear.

Automated review (maintainer link)

'@astryxdesign/cli': patch
---

[fix] On Node 22.13, `astryx theme build` reports a microtask exception from a loading theme whose folder has its own Core as `ERR_THEME_LOAD`, with the theme path and the original error. A theme microtask callback that throws after the load now produces a warning instead of failing the build. Unrelated exceptions keep their own error boundary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss: this sentence still covers --family builds, and they drop the exception. A family build always loads its members through Core interception (api/theme/build/build.mjs:4760-4761, :6437-6458), which takes the synchronous jiti(filePath) load (:2875). That load settles before load.fail can reject the race in withThemeModuleGuards (module-loader.mjs:720-724). On Node 22.13, a family (ocean + ocean-calm, folder with its own Core) whose member throws from a microtask while it loads answered ERR_UNKNOWN on the base; with this change it builds with exit 0 and nothing on stderr. A single-theme build of the same member answers ERR_THEME_LOAD. The wording suggested in the previous review missed this path.

Either make the recorded failure win the race (for example, fail stores the error on the load and the guard rethrows it after the race) and add a case whose load returns without awaiting, or narrow the sentence, for example:

[fix] On Node 22.13, `astryx theme build` of a single theme whose folder has its own Core reports a microtask exception from the loading theme as `ERR_THEME_LOAD`, with the theme path and the original error.

@astracat-bot

astracat-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing: every test this PR fixes passes on main without it, fixed on main by ba7490a (#12011).

@astracat-bot astracat-bot Bot closed this Nov 17, 2026
@github-actions
github-actions Bot deleted the codebunny/fix/fix-cli-preserve-theme-microtask-error-context-on-node-22-13-0547c5 branch November 18, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 6c83a364 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants