Skip to content

fix(plugin-loader): prefer native loading for compiled SDK imports#85353

Closed
FelixIsaac wants to merge 1 commit into
openclaw:mainfrom
FelixIsaac:fix/plugin-loader-native-first
Closed

fix(plugin-loader): prefer native loading for compiled SDK imports#85353
FelixIsaac wants to merge 1 commit into
openclaw:mainfrom
FelixIsaac:fix/plugin-loader-native-first

Conversation

@FelixIsaac

@FelixIsaac FelixIsaac commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

This changes the plugin module loader to try native loading before forcing jiti source transformation for compiled JavaScript files that import openclaw/plugin-sdk/*.

The loader still preserves the existing safety fallback: if native loading declines and the file needs plugin-sdk alias rewriting, it falls back to the alias-aware jiti path.

Why

On a 2026.5.18 install, openclaw infer audio providers --json spent most of its cold-start time loading the Codex plugin through jiti even though the plugin is already compiled JS.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: compiled JavaScript plugins that import openclaw/plugin-sdk/* should prefer native loading before falling back to alias-aware jiti, reducing real CLI/plugin discovery startup time without breaking transcription.
  • Real environment tested: Real OpenClaw install/checkout on Linux, Node.js v24.2.0, patched into a throwaway copy of the installed runtime from the 2026.5.18 install.
  • Exact steps or command run after this patch:
OPENCLAW_PLUGIN_LOAD_PROFILE=1 openclaw infer audio providers --json
openclaw infer audio providers --json
openclaw infer audio transcribe /tmp/openclaw-proof.ogg --provider openai --model gpt-4o-transcribe
corepack pnpm exec vitest run src/plugins/plugin-module-loader-cache.test.ts
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): Copied live timing output from the throwaway patched runtime:
Current live install: openclaw infer audio providers --json ~35-38s
OPENCLAW_PLUGIN_LOAD_PROFILE=1: Codex discovery alone ~25-30s
CPU profile: dominated by jiti loading/transformation under @openclaw/codex/dist/...
Direct native import of @openclaw/codex/dist/index.js: ~3.6s
Patched runtime: infer audio providers --json ~12.8s
Patched runtime: infer audio transcribe on the same 5.48s OGG test file ~15.5s
Actual hosted OpenAI transcription request inside that run: ~1.7-2.8s
  • Observed result after fix: The real patched runtime kept provider listing and OpenAI transcription working while reducing the provider-listing path from roughly 35-38s to roughly 12.8s, with plugin load overhead no longer dominated by the Codex jiti transform path.
  • What was not tested: I did not run every third-party plugin or every provider; this proof covered the compiled Codex plugin path and one real OpenAI audio transcription path.
  • Before evidence (optional but encouraged): Baseline live install measurement above showed openclaw infer audio providers --json at roughly 35-38s, with Codex discovery alone around 25-30s under OPENCLAW_PLUGIN_LOAD_PROFILE=1.

Tests

  • corepack pnpm exec vitest run src/plugins/plugin-module-loader-cache.test.ts

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already has the native-first plugin-loader behavior this branch proposed, with regression coverage, and the proof commit is included in v2026.6.6.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the shipped v2026.6.6 native-first loader implementation as the canonical fix and close this stale branch rather than merging a conflicting duplicate.

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

Yes. The old base forced source transformation for SDK-importing compiled JavaScript, while current main now prefers native loading and has regression coverage for SDK aliases plus fallback behavior.

Is this the best way to solve the issue?

Yes. Current main uses the existing native loader and jiti fallback path, matching the narrow maintainable fix without adding a new loader surface.

Security review:

Security review cleared: The PR diff changes loader ordering and tests only; it adds no dependency, workflow, credential, install-script, or publishing surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current main source: Current main routes tryNative=true plugin module loads through tryNativeRequireJavaScriptModule before source-transform fallback, so compiled JavaScript plugin entries can hit native loading first. (src/plugins/plugin-module-loader-cache.ts:270, cae64ee360a8)
  • Current main regression coverage: Current main tests that compiled plugin SDK alias imports are handled by native loading before source-transform fallback, and separately tests fallback when native loading declines. (src/plugins/plugin-module-loader-cache.test.ts:489, cae64ee360a8)
  • Fix provenance: Commit 68e6f03 removed the forced SDK-alias source-transform branch and added native-first SDK alias coverage; git show gives the proof commit timestamp and subject. (src/plugins/plugin-module-loader-cache.ts:270, 68e6f03fd94f)
  • Fix patch provenance: GitHub commit inspection for 68e6f03 shows the plugin-module-loader-cache patch deleting shouldForceSourceTransformForPluginSdkAlias and adding the native SDK alias test. (src/plugins/plugin-module-loader-cache.ts:270, 68e6f03fd94f)
  • Release provenance: GitHub compare reports v2026.6.6 ahead of 68e6f03 with merge-base equal to 68e6f03, proving the release contains the fix commit; gh release view confirms v2026.6.6 is the published release. (68e6f03fd94f)
  • Dependency contract: jiti 2.7.0 documents tryNative as trying native require/import before transformations, and its require path falls back to transform after native errors; current main's fallback path aligns with that contract.

Likely related people:

  • @steipete: GitHub file history and the fix patch identify Peter Steinberger as the author of the current native-first plugin-loader implementation and several adjacent loader/cache changes. (role: recent area contributor; confidence: high; commits: 68e6f03fd94f, 049c1158c9f6, 705bde459471; files: src/plugins/plugin-module-loader-cache.ts, src/plugins/plugin-module-loader-cache.test.ts, src/plugins/sdk-alias.ts)
  • @vincentkoc: Vincent Koc authored earlier SDK alias fallback and duplicate native fallback fixes in the same loader boundary. (role: adjacent owner; confidence: medium; commits: baecb6b4d64b, 7482754aca89; files: src/plugins/plugin-module-loader-cache.ts, src/plugins/plugin-module-loader-cache.test.ts)
  • Jason (Json): Jason authored the later jiti transform-cache fix touching the central plugin module loader and SDK root alias CJS loader. (role: recent area contributor; confidence: medium; commits: 1610b4983fc5; files: src/plugins/plugin-module-loader-cache.ts, src/plugins/plugin-module-loader-cache.test.ts)

Codex review notes: model internal, reasoning high; reviewed against cae64ee360a8; fix evidence: release v2026.6.6, commit 68e6f03fd94f.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Tiny Branchling

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: guards the happy path.
Image traits: location proof lagoon; accessory shell-shaped keyboard; palette violet, aqua, and starlight; mood calm; pose guarding a tiny green check; shell matte ceramic shell; lighting clean product lighting; background tiny shells and proof notes.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Tiny Branchling in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@FelixIsaac
FelixIsaac force-pushed the fix/plugin-loader-native-first branch from 3a1d38c to 766c0b5 Compare May 22, 2026 12:41
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@FelixIsaac

Copy link
Copy Markdown
Contributor Author

Follow-up PR for the media/provider discovery optimization work is open here: #85368.\n\nIt is split onto a fresh branch from main so this PR can stay focused on the plugin-loader native-first change.

@FelixIsaac

Copy link
Copy Markdown
Contributor Author

Additional independent performance-audit follow-up is open as #85396. This one is separate from the plugin-loader native-first path here and from the media/provider discovery work in #85368: it fixes default root-help startup by avoiding the config/validation stack when static help is safe.

@FelixIsaac

Copy link
Copy Markdown
Contributor Author

Performance-audit harness follow-up is open as #85400: saved CLI startup benchmark reports can now be compared directly in text or JSON. This supports the small follow-up PR series with reusable before/after proof.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 22, 2026
@FelixIsaac

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Normalized the Real behavior proof section using the required field labels and copied live timing/output evidence already captured for this change.

@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant