Skip to content

fix(plugins): localize bundled runtime deps to extensions - #67099

Merged
vincentkoc merged 10 commits into
mainfrom
pr-65478-security-fix
Apr 15, 2026
Merged

vincentkoc merged 10 commits into
mainfrom
pr-65478-security-fix

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: bundled plugins with stageRuntimeDependencies were still effectively root-owned because root dist/ chunks imported extension runtime deps like @buape/carbon, and staged plugin package scopes broke some plugin-local runtime loading paths.
  • Why it matters: npm install/packaging stayed heavier than necessary, extension dependency ownership was wrong, and bundled plugin runtime isolation was brittle.
  • What changed: staged bundled plugins now build into isolated dist/extensions/<id> graphs, Discord-owned deps moved out of the root package, plugin-local package version lookups were hardened for staged layouts, and the plugin loader now keeps dist/extensions/* modules on the aliased Jiti path so openclaw/plugin-sdk/* still resolves inside nested plugin package scopes.
  • What did NOT change (scope boundary): no user-facing channel behavior changes were intended beyond packaging/runtime ownership correctness; unrelated existing pi-embedded-runner worktree changes were left untouched.
  • AI-assisted: yes. This PR was prepared with a coding agent and manually verified locally.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: bundled plugins that staged runtime deps were still sharing the root build graph, so root dist/ emitted extension-owned chunks and root dependency ownership could not be reduced safely. Once plugins were split into isolated staged graphs, two hidden assumptions surfaced: some plugin code assumed ../package.json from src/* would still be valid after bundling, and the native-loader fast path bypassed plugin-sdk alias resolution inside nested dist/extensions/<id>/package.json scopes.
  • Missing detection / guardrail: there was no contract asserting that staged bundled plugin dist modules must still resolve plugin-local manifests and openclaw/plugin-sdk/* imports under nested package scopes.
  • Contributing context (if known): Discord ownership pressure exposed the packaging issue first, but the same staged-runtime assumptions also affected Feishu, QQBot, and any staged plugin relying on plugin-sdk aliasing.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/channels/plugins/contracts/directory.registry-backed.contract.test.ts, src/plugins/contracts/package-manifest.contract.test.ts, src/plugins/sdk-alias.test.ts, test/scripts/root-dependency-ownership-audit.test.ts
  • Scenario the test should lock in: staged bundled plugins load from dist/extensions/<id> without reaching back into root-owned runtime deps, plugin-local package manifests still resolve, and bundled plugin dist modules still resolve openclaw/plugin-sdk/* through the loader alias boundary.
  • Why this is the smallest reliable guardrail: the regression only appears after build output exists and the bundled plugin loader reads staged plugin dist modules through the real runtime boundary.
  • Existing test that already covers this (if any): the directory contract suite and package manifest contract suite now cover the broken runtime and manifest ownership paths directly.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • Bundled Discord runtime deps are now extension-owned instead of root-owned.
  • npm pack / staged bundled plugin packaging no longer requires Discord runtime deps to remain mirrored at the root package surface.
  • pnpm build is green again after narrowing OpenAI Responses reasoning-effort typing.

Diagram (if applicable)

Before:
[root dist graph] -> [bundled plugin chunks in root dist] -> [root package must own extension runtime deps]

After:
[root dist graph] -> [core + non-staged plugins]
[staged plugin build] -> [dist/extensions/<id>] -> [plugin-local runtime deps + plugin-sdk alias boundary]

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22.20.0 / pnpm 10.32.1
  • Model/provider: N/A
  • Integration/channel (if any): Discord, Slack, Feishu, QQBot, bundled plugin packaging
  • Relevant config (redacted): default local repo config

Steps

  1. Build the repo with staged bundled plugin outputs.
  2. Load bundled channel/plugin contracts from built dist/extensions/<id> artifacts.
  3. Verify root dependency ownership and manifest contracts.

Expected

  • Extension-owned staged runtime deps stay under the owning extension.
  • Bundled plugin dist modules still resolve plugin-local manifests and openclaw/plugin-sdk/* imports.
  • pnpm build passes.

Actual

  • Before this change, root dist/ still imported Discord-owned deps, staged plugin dist paths broke some ../package.json lookups, and native loading of dist/extensions/* bypassed plugin-sdk alias resolution.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: pnpm build; pnpm test src/plugins/sdk-alias.test.ts; pnpm exec vitest run --config test/vitest/vitest.contracts.config.ts src/channels/plugins/contracts/directory.registry-backed.contract.test.ts --reporter=verbose; pnpm exec vitest run --config test/vitest/vitest.contracts.config.ts src/plugins/contracts/package-manifest.contract.test.ts --reporter=verbose; pnpm test test/scripts/root-dependency-ownership-audit.test.ts; pnpm test test/release-check.test.ts test/openclaw-npm-postpublish-verify.test.ts; pnpm test src/agents/openai-transport-stream.test.ts -t 'defaults OpenAI Responses reasoning effort to high when unset'
  • Edge cases checked: staged plugin package version lookup in flattened dist output; plugin-sdk alias resolution under nested dist/extensions/<id>/package.json scopes; root ownership audit after build only still flags hono.
  • What you did not verify: full repo-wide pnpm test; external npm publish/install smoke beyond local packaging/runtime checks.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: staged bundled plugin dist modules have a different loader resolution path than other built modules.
    • Mitigation: loader policy is now covered by src/plugins/sdk-alias.test.ts and exercised by the bundled directory contract suite.
  • Risk: plugin-local manifest version lookups can still hide similar relative-path assumptions in other staged plugins.
    • Mitigation: Feishu and QQBot were updated now, and the staged-plugin runtime/contract coverage catches the runtime class of failure.

@vincentkoc vincentkoc self-assigned this Apr 15, 2026
@openclaw-barnacle openclaw-barnacle Bot added channel: line Channel integration: line scripts Repository scripts agents Agent runtime and tooling channel: feishu Channel integration: feishu channel: qqbot extensions: qa-lab size: XL maintainer Maintainer-authored PR labels Apr 15, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review April 15, 2026 09:19
@vincentkoc
vincentkoc marked this pull request as draft April 15, 2026 09:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49e3c0b054

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/openai-transport-stream.ts Resolved
@vincentkoc
vincentkoc force-pushed the pr-65478-security-fix branch from 49e3c0b to 2ff3f19 Compare April 15, 2026 09:38
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed agents Agent runtime and tooling extensions: qa-lab size: XL labels Apr 15, 2026
@greptile-apps

greptile-apps Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR isolates staged bundled plugin builds into dist/extensions/<id> graphs, moves Discord-owned runtime deps out of the root package, hardens plugin-local package.json version lookups with a multi-candidate fallback, and adds a new root-dependency ownership audit tool. The sdk-alias.ts change correctly disables native Jiti loading for dist/extensions/* paths so the openclaw/plugin-sdk/* alias map stays active inside nested plugin scopes.

  • The installPluginRuntimeDeps refactor splits required/optional dep installs correctly, but the !fs.existsSync(stagedNodeModulesDir) guard at line 742 still throws unconditionally — including when requiredSpecs is empty and all optional installs silently failed, contradicting the "optional deps must not block staging" intent.

Confidence Score: 4/5

Safe to merge for current plugins, but has a latent logic bug in the optional-only deps path of the new install refactor.

One P1 finding: the node_modules existence guard fires unconditionally even when only optional specs were attempted and swallowed — contradicting the comment at line 737. No current staged plugin has only optional runtime deps (all have at least one dependencies entry), so the bug is latent today but would manifest if any future plugin or a current plugin update lands in that state.

scripts/stage-bundled-plugin-runtime-deps.mjs lines 741–746

Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/stage-bundled-plugin-runtime-deps.mjs
Line: 741-746

Comment:
**Optional-only deps can still block staging**

When a plugin has only `optionalDependencies` (no `dependencies`) and `stageRuntimeDependencies: true`, the required-install block is skipped entirely, the optional install silently swallows failures (line 736–738), and then this check fires — throwing an error even though the intent is that optional deps must not block staging.

```suggestion
    const stagedNodeModulesDir = path.join(tempInstallDir, "node_modules");
    if (requiredSpecs.length > 0 && !fs.existsSync(stagedNodeModulesDir)) {
      throw new Error(
        `failed to stage bundled runtime deps for ${pluginId}: explicit npm install produced no node_modules directory`,
      );
    }
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/qqbot/src/slash-commands.ts
Line: 17-43

Comment:
**`readPluginVersion` duplicated within qqbot**

The same `PACKAGE_JSON_CANDIDATES` + `readPluginVersion()` helper is defined independently in both `extensions/qqbot/src/api.ts` and here. Since both files are in the same package, extracting it to a shared local helper (e.g. `utils/plugin-version.ts`) would eliminate the duplication. The same pattern was also necessary in `extensions/feishu/src/client.ts`, but that's in a different package.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "Merge branch 'main' into pr-65478-securi..." | Re-trigger Greptile

@vincentkoc
vincentkoc marked this pull request as ready for review April 15, 2026 10:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4631cb8117

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac7b3b2880

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +14 to +18
const IMPORT_PATTERNS = [
/\bfrom\s*["']([^"']+)["']/g,
/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g,
/\brequire\s*\(\s*["']([^"']+)["']\s*\)/g,
/\b(?:require|[_$A-Za-z][\w$]*require[\w$]*)\.resolve\s*\(\s*["']([^"']+)["']\s*\)/gi,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Match side-effect imports in dependency ownership scan

collectModuleSpecifiers only matches from, dynamic import(...), and require(...), so bare side-effect imports like import "pkg"; are never counted. This makes collectRootDependencyOwnershipAudit underreport real usage and can misclassify required root deps as unreferenced/localizable, which is risky because this script is used to drive dependency-removal decisions. Add a static bare-import pattern (as used in scripts/lib/bundled-plugin-root-runtime-mirrors.mjs) so these imports are included.

Useful? React with 👍 / 👎.

@vincentkoc
vincentkoc merged commit c727388 into main Apr 15, 2026
45 of 50 checks passed
@vincentkoc
vincentkoc deleted the pr-65478-security-fix branch April 15, 2026 11:04
xudaiyanzi pushed a commit to xudaiyanzi/openclaw that referenced this pull request Apr 17, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
kvnkho pushed a commit to kvnkho/openclaw that referenced this pull request Apr 17, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
iT2afL0rd pushed a commit to iT2afL0rd/openclaw that referenced this pull request Apr 22, 2026
…tall

When `openclaw update` runs `openclaw doctor` after replacing the package
files, bundled plugin runtime deps (grammy etc.) haven't been installed yet —
`ensureBundledPluginRuntimeDeps` only runs later during plugin loader
initialisation.

The static `import * as grammy from 'grammy'` at the top of allowed-updates.ts
is pulled in transitively before the installer has a chance to run:

  doctor → channel-doctor → bundled channel registry
  → telegram/channel.ts → telegram/monitor.ts
  → telegram/allowed-updates.ts  ← static ESM import grammy  💥

The fix replaces the top-level import with a lazy `createRequire()` call so
grammy is only resolved when `resolveTelegramAllowedUpdates()` / the module
constant is first evaluated, by which point the installer has already placed
grammy under dist/extensions/telegram/node_modules/.  Fallback constants
(already present) ensure correct behaviour when grammy is genuinely absent.

Reproduces with:
  rm -rf dist/extensions/telegram/node_modules
  openclaw doctor --non-interactive
  # → Error: Cannot find module 'grammy'

Fixes the regression introduced by openclaw#67099 (localize bundled plugin runtime deps).
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
Heetisk pushed a commit to Heetisk/openclaw that referenced this pull request Sep 28, 2026
…7099)

* fix(plugins): localize bundled runtime deps to extensions

* fix(plugins): move staged runtime deps out of root

* fix(packaging): harden prepack and runtime dep staging

* fix(packaging): preserve optional runtime dep staging

* Update CHANGELOG.md

* fix(packaging): harden runtime staging filesystem writes

* fix(docker): ship preinstall warning in bootstrap layers

* fix(packaging): exclude staged plugin node_modules from npm pack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu channel: line Channel integration: line channel: qqbot docker Docker and sandbox tooling maintainer Maintainer-authored PR scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant