Skip to content

fix(plugins): guard runtime facade activation - #59412

Merged
vincentkoc merged 10 commits into
mainfrom
pr/plugin-facade-guard
Apr 2, 2026
Merged

vincentkoc merged 10 commits into
mainfrom
pr/plugin-facade-guard

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Problem: bundled plugin runtime-api.js facades and the session-key-api.js fallback in src/channels/plugins/session-conversation.ts could still import bundled plugin code without going through an activation-aware boundary.
  • Why it matters: disabled or merely discovered plugins could still execute import-time code through generated SDK facades or bundled session parsing fallbacks.
  • What changed: added an activation-aware facade loader, switched selected runtime facades onto it, and gated bundled session-conversation fallback loads through the same boundary.
  • What did NOT change (scope boundary): this PR does not add a new user-facing activation concept or redesign plugin enablement config/state.
  • AI-assisted: yes. Testing: fully tested 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

Root Cause / Regression History (if applicable)

  • Root cause: src/plugin-sdk/facade-runtime.ts was a raw bundled public-surface loader with no activation check, and src/channels/plugins/session-conversation.ts bypassed plugin activation by deep-loading session-key-api.js directly.
  • Missing detection / guardrail: no central runtime-facade guard existed, and there was no regression coverage for inactive bundled session-key fallbacks.
  • Prior context (git blame, prior PR, issue, or refactor if known): this is the next tranche after the earlier ambient-load cleanup on plugin loading.
  • Why this regressed now: the system already had a metadata-first loader boundary, but generated runtime facades and the session-conversation fallback were still outside it.
  • If unknown, what was ruled out: N/A.

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/plugin-sdk/facade-runtime.test.ts
    • src/channels/plugins/session-conversation.test.ts
    • src/plugin-activation-boundary.test.ts
    • src/tts/tts.test.ts
  • Scenario the test should lock in: inactive bundled runtime facades stay blocked, runtime-core exemptions stay available, configured bootstrap parsing still works, and inactive bundled session-key fallbacks stay cold.
  • Why this is the smallest reliable guardrail: it exercises the shared boundary and the known bypass directly without depending on full gateway bootstrap.
  • Existing test that already covers this (if any): src/plugin-activation-boundary.test.ts already covered the ambient-load tranche and now remains green with the guarded runtime seam.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Disabled bundled channel/runtime plugins no longer load through generated runtime facades or bundled session-conversation fallback parsing unless current config semantics activate them.

Diagram (if applicable)

Before:
[runtime facade call] -> [raw bundled public surface loader] -> [plugin import]
[session key fallback] -> [deep session-key-api load] -> [plugin import]

After:
[runtime facade call] -> [activation-aware facade boundary] -> [allowed import or hard block]
[session key fallback] -> [activation-aware boundary check] -> [allowed import or no fallback load]

Security Impact (required)

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

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 / pnpm workspace
  • Model/provider: N/A
  • Integration/channel (if any): bundled browser / Discord / Line / Matrix / Slack runtime facades, Telegram / Feishu session fallback
  • Relevant config (redacted): runtime config snapshots in tests; no persistent user config changes

Steps

  1. Call a generated bundled runtime facade for a disabled plugin, or resolve a bundled session-key-api.js fallback before registry bootstrap.
  2. Observe whether bundled plugin code is imported.
  3. Re-run with the plugin explicitly/configurationally activated.

Expected

  • Disabled bundled runtime/session-key surfaces stay blocked.
  • Activated/configured surfaces still load.
  • Shared runtime-core facades remain available.

Actual

  • Now matches expected.

Evidence

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

Human Verification (required)

  • Verified scenarios:
    • pnpm test -- src/plugin-sdk/facade-runtime.test.ts src/channels/plugins/session-conversation.test.ts src/plugin-activation-boundary.test.ts src/tts/tts.test.ts src/plugins/runtime/index.test.ts
    • pnpm build
    • pnpm check before rebase; post-rebase targeted tests + build re-run clean
  • Edge cases checked:
    • bundled runtime-core exemptions without manifest records
    • browser enabled-by-default vs blocked runtime surface selection in tests
    • Feishu bootstrap fallback requiring explicit plugin enablement rather than channel-config shortcut
    • ollama.ts intentionally left unguarded after build proved it is a helper surface, not a runtime-only entrypoint
  • What you did not verify:
    • full pnpm test
    • a dedicated pnpm plugin-sdk:facades:check pass was not kept as a gate because the generator process was abnormally slow/noisy in this worktree while the committed/generated outputs were already validated by pnpm build

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.

Compatibility / Migration

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

Risks and Mitigations

  • Risk:

    • Guarding every runtime-api.js facade was too broad and broke helper-style surfaces such as ollama.ts during plugin bootstrap.
  • Mitigation:

    • The generator now uses an explicit guarded facade allowlist instead of assuming every runtime-api.js surface is runtime-only.
  • Risk:

    • Bootstrap session parsing could lose bundled fallbacks for inactive plugins.
  • Mitigation:

    • Tests now cover both sides: configured/explicitly enabled fallback still works, inactive fallback stays cold.

@vincentkoc vincentkoc self-assigned this Apr 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: M maintainer Maintainer-authored PR labels Apr 2, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review April 2, 2026 04:20
@greptile-apps

greptile-apps Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces an activation-aware facade boundary for bundled plugin runtime surfaces. It adds loadActivatedBundledPluginPublicSurfaceModuleSync and canLoadActivatedBundledPluginPublicSurface to facade-runtime.ts, migrates 12 generated plugin SDK facades to use the guarded loader, and gates the session-key-api.js fallback in session-conversation.ts behind the same boundary. The overall approach is sound and the change fits cleanly into the existing plugin-loading architecture.

Key points:

  • The ALWAYS_ALLOWED_RUNTIME_DIR_NAMES set (speech-core, image-generation-core, media-understanding-core) correctly exempts shared core facades from requiring explicit activation, while all channel-specific facades (discord, slack, line, matrix, browser, memory-core, etc.) now require the plugin to be activated.
  • Cache invalidation in getFacadeBoundaryResolvedConfig relies on loadConfig() returning a stable object reference via the runtimeConfigSnapshot singleton — this is correct in production but the cache silently becomes ineffective when no config file exists (see inline comment).
  • The canLoad + loadActivated pattern in session-conversation.ts calls resolveBundledPluginPublicSurfaceAccess twice per blocked-plugin path; both calls are fast due to caching but consolidation would be cleaner (see inline comment).
  • Test coverage is thorough: the new tests cover blocking inactive facades, allowing explicitly-enabled facades, always-allowing runtime-core facades, and verifying no bundled session-key fallbacks load for inactive channel plugins.

Confidence Score: 4/5

  • Safe to merge; no logic bugs found and test coverage is solid. Two minor style concerns noted but neither affects correctness.
  • The security hardening logic is correct — the activation boundary is enforced before module load, the always-allowed exemptions are intentional and tested, and the cache relies on an established singleton pattern in loadConfig(). The two noted issues are both style/performance concerns (a silently ineffective cache in the no-config-file edge case, and a redundant double access-check in session-conversation.ts), not bugs. Tests cover the key invariants well.
  • src/plugin-sdk/facade-runtime.ts (cache invalidation edge case) and src/channels/plugins/session-conversation.ts (double access-check pattern).
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/plugin-sdk/facade-runtime.ts
Line: 136-153

Comment:
**Cache validity depends on `loadConfig()` reference stability**

`getFacadeBoundaryResolvedConfig` uses reference equality (`===`) to decide whether to reuse the cached resolved config. This works correctly as long as `loadConfig()` returns the same object reference when the config hasn't changed — which is guaranteed by the `runtimeConfigSnapshot` singleton in `io.ts`.

However, there's one edge case: if `loadConfig()` throws (e.g., no config file present in the environment), `readFacadeBoundaryConfigSafely()` returns a fresh `{}` literal on every call, so the cache will never hit. The consequence is that `loadPluginManifestRegistry` and `resolveEffectiveEnableState` get re-invoked on every facade access in that environment. Since `loadPluginManifestRegistry` uses `cache: true` internally, the practical impact is low — but the intent of the outer cache is silently defeated.

Consider documenting this implicit dependency on `loadConfig()`'s snapshot semantics, or adding a fallback stable sentinel for the "no config" path:

```typescript
// Example: replace the bare {} fallback with a stable reference
const EMPTY_CONFIG: OpenClawConfig = {};

function readFacadeBoundaryConfigSafely(): OpenClawConfig {
  try {
    return loadConfig();
  } catch {
    return EMPTY_CONFIG;
  }
}
```

This would make the cache effective even when no config file is present.

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

---

This is a comment left during a code review.
Path: src/channels/plugins/session-conversation.ts
Line: 156-169

Comment:
**Redundant double invocation of `resolveBundledPluginPublicSurfaceAccess`**

`canLoadActivatedBundledPluginPublicSurface` and `loadActivatedBundledPluginPublicSurfaceModuleSync` both call `resolveBundledPluginPublicSurfaceAccess` internally, so the access check is performed twice for every path that reaches the `loadActivated…` call. 

The pattern is understandable — using `canLoad` to return `null` gracefully instead of catching an exception — but the double-resolve includes a manifest registry scan each time (even with `cache: true`, it iterates the plugin list). Since `session-conversation.ts` can be called in a hot path before bootstrap, consider consolidating into a single access-check call, for example by letting `loadActivated…` accept an optional "or return null" mode, or by simply adding a try/catch here so the full resolve only happens once:

```typescript
let resolveSessionConversation: BundledSessionKeyModule["resolveSessionConversation"];
try {
  resolveSessionConversation = loadActivatedBundledPluginPublicSurfaceModuleSync<BundledSessionKeyModule>({
    dirName,
    artifactBasename: SESSION_KEY_API_ARTIFACT_BASENAME,
  }).resolveSessionConversation;
} catch {
  return null;
}
```

This is a minor efficiency suggestion — the current code is functionally correct because both calls share the same `getFacadeBoundaryResolvedConfig` cache and `loadPluginManifestRegistry({cache: true})`.

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

Reviews (1): Last reviewed commit: "fix(plugins): guard runtime facade activ..." | Re-trigger Greptile

Comment thread src/plugin-sdk/facade-runtime.ts Resolved

@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: 671dcd9903

ℹ️ 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/plugin-sdk/line-surface.ts Resolved

@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: 7470d8b9d0

ℹ️ 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/plugin-sdk/browser-runtime.ts Resolved

@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: 06ca15e938

ℹ️ 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".

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Apr 2, 2026

@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: 6ca97f9cba

ℹ️ 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/plugin-sdk/browser-maintenance.ts Resolved
@vincentkoc
vincentkoc merged commit 52a0186 into main Apr 2, 2026
10 checks passed
@vincentkoc
vincentkoc deleted the pr/plugin-facade-guard branch April 2, 2026 05:37
ngutman pushed a commit that referenced this pull request Apr 3, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
* fix(plugins): guard runtime facade activation

* refactor(plugin-sdk): localize facade load policy

* fix(plugin-sdk): narrow facade activation guards

* fix(browser): keep cleanup helpers outside activation guard

* style(browser): apply formatter follow-ups

* chore(changelog): note plugin activation guard regressions

* fix(discord): keep cleanup thread unbinds outside activation guard

* fix(browser): fallback when trash exits non-zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant