Skip to content

Plugin loader LRU cache key includes workspaceDir unnecessarily, causing redundant cold loads across workspaces #77347

@jared-rebel

Description

@jared-rebel

Summary

buildCacheKey() in loader-CLyHx60E.js includes workspaceDir as part of the LRU cache key for PluginLoaderCacheState. However, workspaceDir does not affect which plugins are loaded or how they are configured — the plugin trust list, onlyPluginIds, runtimeSubagentMode, and installRecords are all derived from the global openclaw config, not the workspace directory.

The result: on a host with multiple agent workspaces (e.g. main, debug-agent, haiku-utility, bug-fixer), each workspace generates a separate LRU cache entry even when their plugin configurations are identical. With main running at high frequency, it displaces secondary workspace entries, causing 12–16s synchronous cold loads on every secondary workspace spawn.

Root cause

In resolvePluginLoadCacheContext(), the cache key is built with:

const cacheKey = buildCacheKey({
  workspaceDir: options.workspaceDir,   // included, but shouldn't affect plugin loading
  plugins: trustNormalized,
  ...
});

The plugin registry construction (loadOpenClawPlugins) does not vary by workspace — all enabled plugins register identically regardless of which workspace triggered the load. The LRU is the only protection layer; Node module cache and jiti cache do not help across cache-key transitions.

Impact

Each cache miss reruns the full register() pipeline for all enabled plugins: 12–16s synchronous event loop block measured in the core-plugin-tools stage of the prep trace. Top contributors:

  • acpx: 1,375ms, qwen: 1,062ms, alibaba: 1,053ms, azure-speech: 916ms, amazon-bedrock: 783ms

Proposed fix

Remove workspaceDir from buildCacheKey() inputs, or only include it when a plugin factory actually reads workspaceDir from its activation context. Alternatively, expose a first-class config field gateway.plugins.loaderCacheSize so operators can tune the LRU size.

Workaround applied

Patched loader-CLyHx60E.js:3287 to make the LRU size env-configurable and running with OPENCLAW_PLUGIN_LOADER_CACHE_SIZE=512, which prevents eviction on our host. Temporary workaround — root cause is the key granularity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions