Skip to content

fix(plugins): preserve Bun source loader semantics - #150287

Merged
steipete merged 7 commits into
mainfrom
codex/bun-plugin-test-portability
Sep 17, 2026
Merged

steipete merged 7 commits into
mainfrom
codex/bun-plugin-test-portability

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Bun can load OpenClaw's generated plugin artifacts natively, but its resolver and Jiti interop differ from Node at several boundaries: import conditions were lost, JSX and tsconfig settings were applied to captured paths, failed dynamic CommonJS imports could be evaluated twice, and an existing module's missing dependency was mistaken for a missing entry. Those differences broke valid TypeScript and CommonJS plugins or let retained generations observe the wrong module graph.

This change gives the plugin loader one Bun-specific adapter around the existing generation owner. It preserves import/require conditions, captures authored TypeScript edges before the alias map freezes, applies JSX and tsconfig behavior to captured source, memoizes Jiti's async import results without rewriting source text, and separates native entry resolution from evaluation so terminal failures are not retried. A synchronous capability probe keeps shipping Bun on its compatible Jiti path while runtimes with dynamic onResolve support keep computed imports lazy and native.

For Node, each plugin entry's authored references are inspected before loading. Only entries that import a source SDK alias are routed through Jiti, and those source SDK virtual modules remain under the same transform owner. This fixes Node 24.19's mixed require/import assertion without installing a process-wide resolver or changing Bun's native CommonJS path. Bun's resolver also covers OpenClaw's owned internal workspace packages. No dependency or public contract changes.

Validation:

  • final pnpm check:changed
  • Node plugin-loader slice: 272 passed, 1 skipped
  • custom Bun plugin-loader slice: 269 passed, 4 runtime-specific skips
  • runtime-registry contract: 33 passed under Node 24.19 and 33 passed under custom Bun
  • shipping Bun 1.4.2: 103 launcher tests and the focused Bun generation case passed
  • Linux Node 24.19: the formerly failing host-hooks contract, Matrix Doctor, and compact-small-23 passed in one Blacksmith Testbox run (75 tests, 1 test, then 12 files and 146 tests; run, lease tbx_01m2pbq6vffa4xkcdppgmd18gd)
  • fresh Codex autoreview: no actionable P0-P2 findings

Release-note context: preserve generated plugin loading, TypeScript/JSX resolution, and failed dynamic CommonJS import behavior when OpenClaw runs on Bun.

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 16, 2026, 11:16 PM ET / September 17, 2026, 03:16 UTC (Revision 9).

ClawSweeper review

What this changes

Preserves plugin source-loading behavior across Bun and Node by adjusting module resolution, TypeScript and JSX transforms, and failed-import handling.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains useful, maintainer-owned work. The previous Bun conditional-export blocker persists, and the latest source-SDK guard misses imports through helpers.

Priority: P2
Reviewed head: 3985cac61d58e0eefe77b781d7f46577514dd325

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused runtime work with substantial reported validation, but two source-supported compatibility defects remain.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored exemption applies to ordinary contributor proof. Reported loader and registry checks provide supporting validation, while the specific compatibility combinations and upgrade evidence remain separate review blockers.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored exemption applies to ordinary contributor proof. Reported loader and registry checks provide supporting validation, while the specific compatibility combinations and upgrade evidence remain separate review blockers.
Evidence reviewed 9 items Introduced Bun loader selection: With JITI_JSX unset, a computed import enables native loading for the entire TypeScript entry when the capability probe succeeds. The adapter treats import-statement as an import condition rather than a synchronous require condition.
Existing synchronous selection contract: Architecture documentation preserves Jiti CommonJS behavior for synchronous TypeScript loading. The generation fixture expects the require export value, and the interop fixture separately expects require for static imports and import for lazy imports; neither combines this with a computed import in the entry.
Previous finding remains applicable: GitHub returned blob ab5b57ccf2a4435865ec75d2811d32710df48908 for the binder at the previous reviewed revision, exactly matching the current file. The previous blocker is repeated rather than newly discovered. Local comparison of that revision failed because its object was unavailable; the immutable GitHub blob check established continuity.
Findings 2 actionable findings [P1] Preserve synchronous imports when the Bun capability probe succeeds
[P1] Account for source SDK imports reached through entry helpers
Security None None.

How this fits together

The plugin loader turns plugin entrypoints and dependencies into executable registrations while keeping retained instances tied to their captured source. Runtime adapters select native loading or Jiti transformation before those modules execute.

flowchart TD
  A[Plugin entry and dependencies] --> B[Captured source generation]
  B --> C[Runtime and source inspection]
  C --> D[Native module loader]
  C --> E[Jiti source transform]
  D --> F[Plugin registrations]
  E --> F
  B --> G[Retained instance lifecycle]
Loading

Before merge

  • Preserve synchronous imports when the Bun capability probe succeeds (P1) - The previous blocker remains. With JITI_JSX unset, adding export const read = name => import(name) enables native loading for the whole TypeScript entry. Static imports and reexports then reach the Bun adapter as import-statement and select a dependency's import export instead of its require export, even if read is never called. This violates the synchronous startup contract and existing conditional-export fixtures. Preserve synchronous selection and extend the fixture to combine static and computed imports under both probe outcomes.
  • Account for source SDK imports reached through entry helpers (P1) - This inspection covers only the entry file. On Node, an entry.cjs requiring helper.cjs, where the helper imports a source SDK alias whose .mts file references ./peer.mjs backed only by peer.mts, therefore still enters native loading. The SDK peer fails with ERR_MODULE_NOT_FOUND, and this PR's native-error change now propagates that failure instead of reaching Jiti's supported filename fallback. Moving an SDK import into a helper must not break loading. Select the transform owner for the affected dependency graph before evaluation, and cover this transitive fixture without restoring blanket retries of terminal failures.
  • Resolve merge risk (P1) - Fresh-install and published-updater-to-candidate plugin-loading compatibility remain unverified by the supplied evidence; existing plugins exercise the changed loader during startup and recovery.
  • Complete next step (P2) - Fix both loader-selection defects, add the focused regression cases, and record fresh-install and published-updater compatibility results.

Findings

  • [P1] Preserve synchronous imports when the Bun capability probe succeeds — src/plugins/plugin-instance-module-loader.ts:167-173
  • [P1] Account for source SDK imports reached through entry helpers — src/plugins/plugin-module-loader-cache.ts:267-270
Agent review details

Security

None.

PR surface

Source +450, Tests +100, Other 0. Total +550 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 6 508 58 +450
Tests 6 213 113 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 13 722 172 +550

Review metrics

Metric Value Why it matters
Production versus test growth Production +450 net lines; tests +100 net lines The stated growth supports runtime adapters and transform ownership, making cross-runtime compatibility coverage central to review.

Merge-risk options

Maintainer options:

  1. Preserve loader behavior before landing (recommended)
    Repair both module-selection gaps and record fresh-install plus published-updater compatibility results before merging.

Technical review

Best possible solution:

Preserve synchronous package selection and route source SDK graphs through their transform owner before evaluation, including helper imports, while retaining terminal failures and proving upgrade compatibility.

Do we have a high-confidence way to reproduce the issue?

Yes, source identifies focused failing paths: combine static and computed imports under a successful Bun probe, and load a CommonJS entry whose helper imports a source SDK with a TypeScript-backed JavaScript reference. These paths were not executed during this review.

Is this the best way to solve the issue?

No, not yet: extending the existing generation owner is appropriate, but whole-entry native selection and direct-only SDK inspection leave compatibility holes.

Full review comments:

  • [P1] Preserve synchronous imports when the Bun capability probe succeeds — src/plugins/plugin-instance-module-loader.ts:167-173
    The previous blocker remains. With JITI_JSX unset, adding export const read = name => import(name) enables native loading for the whole TypeScript entry. Static imports and reexports then reach the Bun adapter as import-statement and select a dependency's import export instead of its require export, even if read is never called. This violates the synchronous startup contract and existing conditional-export fixtures. Preserve synchronous selection and extend the fixture to combine static and computed imports under both probe outcomes.
    Confidence: 0.98
  • [P1] Account for source SDK imports reached through entry helpers — src/plugins/plugin-module-loader-cache.ts:267-270
    This inspection covers only the entry file. On Node, an entry.cjs requiring helper.cjs, where the helper imports a source SDK alias whose .mts file references ./peer.mjs backed only by peer.mts, therefore still enters native loading. The SDK peer fails with ERR_MODULE_NOT_FOUND, and this PR's native-error change now propagates that failure instead of reaching Jiti's supported filename fallback. Moving an SDK import into a helper must not break loading. Select the transform owner for the affected dependency graph before evaluation, and cover this transitive fixture without restoring blanket retries of terminal failures.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c939e56c3a75.

Labels

Label justifications:

  • P2: This repairs bounded plugin-loader compatibility problems without evidence of an urgent widespread outage.
  • merge-risk: 🚨 compatibility: Merging can change synchronous dependency selection on capable Bun runtimes and reject Node source-SDK imports reached through helpers.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The maintainer-authored exemption applies to ordinary contributor proof. Reported loader and registry checks provide supporting validation, while the specific compatibility combinations and upgrade evidence remain separate review blockers.

Evidence

What I checked:

  • Introduced Bun loader selection: With JITI_JSX unset, a computed import enables native loading for the entire TypeScript entry when the capability probe succeeds. The adapter treats import-statement as an import condition rather than a synchronous require condition. (src/plugins/plugin-instance-module-loader.ts:167, 3985cac61d58)
  • Existing synchronous selection contract: Architecture documentation preserves Jiti CommonJS behavior for synchronous TypeScript loading. The generation fixture expects the require export value, and the interop fixture separately expects require for static imports and import for lazy imports; neither combines this with a computed import in the entry. Public docs: docs/plugins/architecture.md. (docs/plugins/architecture.md:231, 3985cac61d58)
  • Previous finding remains applicable: GitHub returned blob ab5b57ccf2a4435865ec75d2811d32710df48908 for the binder at the previous reviewed revision, exactly matching the current file. The previous blocker is repeated rather than newly discovered. Local comparison of that revision failed because its object was unavailable; the immutable GitHub blob check established continuity. (src/plugins/plugin-instance-module-loader.ts:167, 3985cac61d58)
  • New direct-only source SDK guard: The latest commit inspects only the entry's literal SDK references before permitting native evaluation. An entry requiring a helper is classified as native even when that helper imports a source SDK whose JavaScript specifier needs TypeScript resolution. The native loader now propagates that dependency-resolution failure instead of invoking the previous fallback. (src/plugins/plugin-module-loader-cache.ts:267, 3985cac61d58)
  • Pinned Jiti resolution contract: OpenClaw pins Jiti 2.7.0 and directly invokes its resolver and transformer. That version tries require conditions first for synchronous resolution and supports JavaScript-to-TypeScript filename fallback, supporting both identified compatibility expectations. (src/resolve.ts:53, fd3bb289b75e)
  • Bun dependency boundary: The changed adapter directly consumes Bun's onResolve import kinds. Bun distinguishes import-statement, require-call, require-resolve, and dynamic-import. The related upstream proposal enables extensionless runtime resolver callbacks; it does not preserve Jiti's synchronous compilation semantics for OpenClaw. (packages/bun-types/bun.d.ts:3150, c7f233e23163)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Patrick-Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve synchronous conditional-export selection with combined static and computed imports under both Bun probe outcomes.
  • Cover Node entry-to-helper-to-source-SDK loading without retrying terminal evaluations.
  • Record fresh-install and published-updater-to-candidate plugin-loading compatibility results.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-16T20:37:54.412Z sha e19943295aea2bd163762ce71f2d9ca1dcdcbda8 :: blocked before merge. :: [P1] Preserve synchronous imports when enabling computed-import support
  • reviewed 2026-09-16T21:42:00.811Z sha 8c8fb75fd0b9a9ef98f5bfdf40c78b2d2f6798f2 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds
  • reviewed 2026-09-16T21:53:23.923Z sha 964818cd95d075a2b010f325c150f052da7fd984 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds
  • reviewed 2026-09-16T22:10:54.639Z sha eea2556 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds
  • reviewed 2026-09-16T22:42:53.701Z sha a82e795 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds
  • reviewed 2026-09-16T23:19:39.026Z sha e5544387cad22429950ea7e4012d06fe9bcc06e9 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds
  • reviewed 2026-09-16T23:43:42.832Z sha c95e6689cc7d3becc3fe4ad3d543bee16994c2d7 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds
  • reviewed 2026-09-17T01:16:08.331Z sha 63dfdaec722fae219fbaadb39953ef8c749af2f9 :: blocked before merge. :: [P1] Preserve synchronous imports when the Bun capability probe succeeds

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@steipete
steipete force-pushed the codex/bun-plugin-test-portability branch 3 times, most recently from 63dfdae to 3985cac Compare September 17, 2026 03:04
@steipete
steipete force-pushed the codex/bun-plugin-test-portability branch from 3985cac to 2761acc Compare September 17, 2026 03:28
@steipete
steipete merged commit fdea91e into main Sep 17, 2026
205 checks passed
@steipete
steipete deleted the codex/bun-plugin-test-portability branch September 17, 2026 03:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
* fix(plugins): preserve Bun source loader semantics

* fix(plugins): gate Bun native source resolution

* fix(plugins): resolve source SDK peers natively

* fix(plugins): keep source SDK modules on Jiti

* fix(plugins): scope native source resolution

* fix(plugins): scope source peer resolution

* fix(plugins): isolate source SDK transforms
steipete added a commit that referenced this pull request Oct 16, 2026
Concurrent remote workspace skill requests could call a Jiti handler before
its static imports finished, producing readWorkspaceSkillsRequest errors.
Extend the existing import-result cache to Node and separate the changed
transform from legacy disk-cache output. Preserve native loading, lazy
activation, and request authority.

Regression proof covers cold and pre-existing transform caches. This extends
the import-result preservation introduced in #150287.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
Concurrent remote workspace skill requests could call a Jiti handler before
its static imports finished, producing readWorkspaceSkillsRequest errors.
Extend the existing import-result cache to Node and separate the changed
transform from legacy disk-cache output. Preserve native loading, lazy
activation, and request authority.

Regression proof covers cold and pre-existing transform caches. This extends
the import-result preservation introduced in openclaw#150287.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant