Skip to content

perf(plugins): cache existence probes within bundle manifest scan [AI-assisted] - #93919

Merged
openclaw-clownfish[bot] merged 2 commits into
openclaw:mainfrom
ml12580:fix/perf-plugin-scan-exists-cache-76209
Jun 22, 2026
Merged

openclaw-clownfish[bot] merged 2 commits into
openclaw:mainfrom
ml12580:fix/perf-plugin-scan-exists-cache-76209

Conversation

@ml12580

@ml12580 ml12580 commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

[AI-assisted] This PR was generated using Claude Code.

Summary

What problem does this PR solve?

Cold-start plugin discovery makes a large number of synchronous fs.existsSync
calls. For each bundle plugin, detectBundleManifestFormat probes marker paths
(skills/, commands/, agents/, .mcp.json, .lsp.json, settings.json,
hooks/hooks.json, ...) and loadBundleManifest's capability builders probe
the same paths again. Across the bundled plugin tree this is thousands of
redundant synchronous filesystem probes; issue #76209 reports 41 probes across
hot paths and 25.4s of fs.existsSync self-time on a Windows cold start.

Why does it matter now?

It is pure startup latency on the main event loop with no correctness benefit —
plugin metadata is process-stable (installs/manifests change only on restart or
an explicit owner reload/install/doctor flow, per AGENTS.md), so re-probing the
same path inside one scan pass can never observe a different result.

What is the intended outcome?

Eliminate the redundant within-scan existence probes by memoizing existence
results for the lifetime of a single bundle-plugin discovery, with no
process-global staleness.

What is intentionally out of scope?

sdk-alias.ts and bundled-dir.ts also call fs.existsSync, but they already
have their own lifecycle caches (pluginSdkPackageJsonByRoot / PluginLruCache
and bundledPluginsDirCache), so they are left for a follow-up if profiling
still shows them as hot. Only the un-cached per-plugin manifest discovery path
is changed here, keeping the patch small and focused.

What does success look like?

Fewer synchronous filesystem probes during plugin discovery with identical
discovery results, and no risk of serving stale existence results across
install/repair passes.

What should reviewers focus on?

  • The scan-scoped cache boundary in plugin-scan-existence-cache.ts (lifecycle
    push/pop, fallback to plain fs.existsSync outside a scan).
  • That discoverBundleInRoot is the only place a cache is entered, so every
    bundle-plugin detect+load pair shares one cache and the cache is always popped
    before the next plugin / install flow.
Summary guidance

This PR adds a scan-scoped existence cache to the plugin manifest discovery hot
path. The cache is entered only around discoverBundleInRoot in
src/plugins/discovery.ts; bundle-manifest.ts probes go through
pluginScanExistsSync, which memoizes inside the active scan and falls back to
plain fs.existsSync otherwise. No process-global state, no callback threading.

Linked context

Which issue does this close?

Closes #76209

Which issues, PRs, or discussions are related?

Related #76350 (a prior attempt that was closed for being too large after trying
to thread a cache callback through every helper across three files; this PR takes
the narrower, no-threading approach the maintainer/Codex review suggested).

Was this requested by a maintainer or owner?

No — contributor fix for a clawsweeper:queueable-fix / clawsweeper:source-repro
issue.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Redundant synchronous fs.existsSync probes
    during plugin manifest discovery on cold start (issue [Bug]: #76209).
  • Real environment tested: Windows 10 (LTSC 2019), Node v22.17.1, OpenClaw
    source checkout at upstream main (788eb2e). Node is below the recommended
    22.19.0 so a [WARN] Unsupported engine is emitted on every pnpm invocation;
    this does not affect the probe-count measurement.
  • Exact steps or command run after this patch:
    A fixture of 25 claude-format bundle plugins (each with
    .claude-plugin/plugin.json + skills/ + commands/ + agents/ +
    .mcp.json + .lsp.json + settings.json) is scanned with the real patched
    functions detectBundleManifestFormat + loadBundleManifest. fs.existsSync
    is spied via vi.spyOn. The scan runs once unwrapped (before: cache inactive =
    plain fs.existsSync) and once wrapped in withPluginScanExistenceCache
    (after: scan-scoped cache active). Run with
    pnpm test src/plugins/plugin-scan-existence-cache.test.ts.
  • Evidence after fix (terminal capture of the benchmark run):
    Terminal capture (console output) from the benchmark run:
    BENCH pluginCount=25 unwrappedExistsSyncCalls=550 wrappedExistsSyncCalls=325
    callReductionPct=41 unwrappedMs=294.75 wrappedMs=208.49
    
  • Observed result after fix: 550 -> 325 synchronous fs.existsSync calls
    (41% fewer) and 294.75ms -> 208.49ms (~29% faster) for the 25-plugin fixture.
    Discovery results are identical before/after.
  • What was not tested: macOS/Linux not tested locally (CI truth is Linux Node
    24). Full openclaw agent --local cold start was not re-profiled end-to-end
    with node --cpu-prof; the proof is a focused measurement of the patched
    discovery functions. sdk-alias / bundled-dir paths are out of scope (see
    Summary). Swift host-env-policy check skipped on Windows (no Swift).
  • Proof limitations or environment constraints: The 25-plugin fixture is smaller
    than a real bundled-plugin tree, so absolute numbers differ from a real cold
    start; the relative reduction (within-plugin detect+load re-probes eliminated)
    is the signal. Node engine WARN noted above.
  • Before evidence (optional but encouraged): The "unwrapped" measurement above
    (550 calls / 294.75ms) is the before state, captured on the same patched code
    with the scan cache inactive (plain fs.existsSync), equivalent to main.

Tests and validation

Which commands did you run?

  • pnpm format:check <touched files> — pass
  • pnpm tsgo — pass (exit 0)
  • pnpm lint <touched files> (runs scripts/run-oxlint-shards.mjs, the same
    runner CI uses) — pass (exit 0)
  • pnpm build — pass (exit 0)
  • pnpm test src/plugins/plugin-scan-existence-cache.test.ts — 5/5 pass
  • pnpm test src/plugins/bundle-manifest.test.ts — 16/16 pass
  • pnpm test src/plugins/bundled-dir.test.ts — 20/20 pass

What regression coverage was added or updated?

src/plugins/plugin-scan-existence-cache.test.ts:

  • pluginScanExistsSync is a plain passthrough outside a scan (no caching).
  • Repeated probes of the same path inside withPluginScanExistenceCache hit the
    filesystem exactly once.
  • Different paths are not conflated inside a scan.
  • Two separate scans observe filesystem changes between them (no process-global
    staleness — the freshness bug a process-global cache would reintroduce).
  • A claude-format bundle's detect+load pair makes strictly fewer fs.existsSync
    calls when run under one scan cache than without.

What failed before this fix, if known?

No test failed before the fix — this is a performance regression-prevention
test. The benchmark shows 550 -> 325 probes; the regression test asserts
cachedCalls < uncachedCalls.

If no test was added, why not?

N/A — a regression test was added.

Risk checklist

Did user-visible behavior change? (Yes/No)

No. Discovery results are identical; only the number of internal filesystem
probes changes.

Did config, environment, or migration behavior change? (Yes/No)

No.

Did security, auth, secrets, network, or tool execution behavior change?
(Yes/No)

No. The cache only memoizes boolean path-existence results for the lifetime of a
synchronous, read-only discovery scan. It does not touch auth, secrets, network,
or tool execution. No CODEOWNERS secops paths are modified.

What is the highest-risk area?

Correctness of the cache boundary: a stale false/true served across an
install/repair pass would be a regression. This is mitigated by scoping the cache
to a single discoverBundleInRoot call (push on enter, pop in finally on
exit), and by falling back to plain fs.existsSync outside any scan, so install
/ hooks / doctor flows are uncached.

How is that risk mitigated?

  • Cache is entered only in discoverBundleInRoot and always popped (try/finally).
  • Outside a scan, pluginScanExistsSync is plain fs.existsSync.
  • Cross-scan freshness is covered by a regression test.
  • Plugin metadata is documented as process-stable (AGENTS.md), so memoizing
    existence within one read-only scan is safe by the project's own contract.

Current review state

What is the next action?

Maintainer / ClawSweeper review.

What is still waiting on author, maintainer, CI, or external proof?

CI on Linux Node 24 (local Windows flakiness in unrelated discovery.test.ts /
sdk-alias.test.ts overlay/tmpdir tests is pre-existing on main and not
caused by this change — verified by stashing the change and re-running).

Which bot or reviewer comments were addressed?

None yet (new PR).

Bundle plugin discovery re-probes the same marker paths (skills/, commands/,
agents/, .mcp.json, .lsp.json, settings.json, hooks/hooks.json) once in
detectBundleManifestFormat and again in loadBundleManifest's capability
builders. Across the bundled plugin tree this is thousands of redundant
synchronous fs.existsSync calls; openclaw#76209 reports 25.4s of self-time on a
Windows cold start.

Add a scan-scoped existence cache (plugin-scan-existence-cache.ts) entered
only around discoverBundleInRoot. pluginScanExistsSync memoizes inside the
active scan and falls back to plain fs.existsSync outside it, so install,
hooks, and doctor flows stay uncached. The cache is push/pop per
discoverBundleInRoot call (try/finally), so a later install/repair pass
re-reads the filesystem — no process-global staleness.

Measured on Windows over a 25-plugin fixture: 550 -> 325 fs.existsSync
calls (41% fewer), 294.75ms -> 208.49ms. Discovery results unchanged.

Closes openclaw#76209
@openclaw-barnacle openclaw-barnacle Bot added size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
Remove __resetPluginScanExistenceCacheForTest: the scan cache is push/pop
balanced by try/finally in withPluginScanExistenceCache, so the stack never
leaks between tests and the helper was dead code. It also tripped oxlint
no-underscore-dangle. Refactor the integration test to count existsSync calls
via a const-returning helper so there is no useless assignment.
@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. labels Jun 17, 2026
@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. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 22, 2026, 12:38 AM ET / 04:38 UTC.

Summary
The PR adds a scan-scoped fs.existsSync cache around bundle discovery, routes bundle-manifest probes through it, and adds focused cache-scope/probe-reduction tests.

PR surface: Source +63, Tests +160. Total +223 across 4 files.

Reproducibility: yes. Current main and v2026.6.9 still repeat direct fs.existsSync probes in the bundle detect/load path; I did not run a fresh Windows cold-start profile in this read-only review.

Review metrics: 1 noteworthy metric.

  • Focused probe reduction: 550 -> 325 calls; 294.75ms -> 208.49ms. This is the contributor-supplied before/after measurement for the changed manifest-scan path, and its fixture scope matters before merge.

Stored data model
Persistent data-model change detected: persistent cache schema: src/plugins/bundle-manifest.ts, persistent cache schema: src/plugins/discovery.ts, persistent cache schema: src/plugins/plugin-scan-existence-cache.test.ts, persistent cache schema: src/plugins/plugin-scan-existence-cache.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #93919
Summary: This PR is the canonical open scan-scoped fix candidate for the plugin-scan fs.existsSync cold-start issue; sibling process-scoped attempts overlap but are broader or already closed.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Attach a full cold-start before/after profile only if maintainers want end-to-end startup impact quantified before landing.

Risk before merge

  • [P1] The supplied proof is a focused Windows fixture benchmark of the patched discovery functions, not a full openclaw agent --local cold-start profile, so the end-to-end startup gain remains bounded by focused evidence.
  • [P1] sdk-alias and bundled-dir probes are intentionally left unchanged because they already have lifecycle caches or freshness-sensitive behavior; fresh profiling after landing may still justify a separate follow-up.

Maintainer options:

  1. Decide the mitigation before merge
    Land the scan-scoped manifest discovery cache if maintainers accept the focused proof, then profile bundled-dir and sdk-alias separately before adding any lifecycle-owned follow-up cache there.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair lane is needed because there is no concrete patch defect; maintainers should review/land this PR or request broader profiling.

Security
Cleared: Security review cleared: the diff adds no dependencies, workflows, secret handling, network access, or new code-execution path; the relevant safety question is cache lifetime, covered by scan scope and tests.

Review details

Best possible solution:

Land the scan-scoped manifest discovery cache if maintainers accept the focused proof, then profile bundled-dir and sdk-alias separately before adding any lifecycle-owned follow-up cache there.

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

Yes. Current main and v2026.6.9 still repeat direct fs.existsSync probes in the bundle detect/load path; I did not run a fresh Windows cold-start profile in this read-only review.

Is this the best way to solve the issue?

Yes. The scan-scoped cache is the best current fix shape because it sits at the synchronous bundle discovery boundary, avoids process-global stale filesystem results, and is narrower than the sibling process-cache attempts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a594d2ce7325.

Label changes

Label justifications:

  • P2: This is a bounded plugin discovery startup performance fix with source-level evidence and limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output from a Windows source checkout measuring the patched real bundle-manifest functions with before/after probe counts and timing; it is focused rather than a full cold-start profile.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from a Windows source checkout measuring the patched real bundle-manifest functions with before/after probe counts and timing; it is focused rather than a full cold-start profile.
Evidence reviewed

PR surface:

Source +63, Tests +160. Total +223 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 124 61 +63
Tests 1 160 0 +160
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 284 61 +223

What I checked:

  • Root and scoped policy applied: Root AGENTS.md and src/plugins/AGENTS.md were read fully; both support bounded lifecycle-owned plugin metadata caches and require whole-surface review of plugin hot paths. (src/plugins/AGENTS.md:21, a594d2ce7325)
  • Current main still repeats bundle probes: Current main calls direct fs.existsSync from bundle default path/capability helpers and from detectBundleManifestFormat, so the central performance issue is not implemented on main. (src/plugins/bundle-manifest.ts:142, a594d2ce7325)
  • Current discovery has no scan cache: discoverBundleInRoot calls detectBundleManifestFormat and then loadBundleManifest directly, which is the repeated detect/load probe pair the PR wraps. (src/plugins/discovery.ts:812, a594d2ce7325)
  • Latest release is not fixed: Release v2026.6.9 still contains the same direct bundle manifest probes and direct detect/load caller, so this is not shipped-fixed. (src/plugins/bundle-manifest.ts:142, c645ec4555c0)
  • PR cache boundary: PR head pushes a fresh cache for one synchronous scan, pops it in finally, memoizes true and false values, and falls back to plain fs.existsSync outside the scan. (src/plugins/plugin-scan-existence-cache.ts:26, 50be24ce7ecb)
  • PR wraps the intended owner boundary: PR head enters the cache only in discoverBundleInRoot, so each bundle detect/load pair shares one cache while other callers remain uncached fallback users. (src/plugins/discovery.ts:813, 50be24ce7ecb)

Likely related people:

  • steipete: Peter Steinberger introduced compatible bundle support and has repeated history around plugin discovery, bundled metadata, and loader startup surfaces. (role: feature introducer and adjacent owner; confidence: high; commits: dd40741e1852, 171b24c5c5b6, 8e0ab35b0ed0; files: src/plugins/bundle-manifest.ts, src/plugins/discovery.ts, src/plugins/bundled-dir.ts)
  • vincentkoc: Current blame for the direct-probe lines points to Vincent Koc's current-main carrier commit, and recent history includes Claude bundle skill/hook work plus bundled runtime dependency changes. (role: recent area contributor; confidence: high; commits: 095a44c8de4d, 50a81c873101, b9b891b614fd; files: src/plugins/bundle-manifest.ts, src/plugins/discovery.ts, src/plugins/bundled-dir.ts)
  • Ayaan Zaidi: Ayaan Zaidi authored the recent fix(plugins): reuse shared discovery cache change in src/plugins/discovery.ts, which is adjacent to this PR's scan-cache boundary. (role: adjacent cache contributor; confidence: medium; commits: 9da4d5f5df5d, 353950894a28; files: src/plugins/discovery.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@ml12580

ml12580 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Friendly nudge for review — this is the scan-scoped fs.existsSync cache for plugin manifest discovery (#76209). ClawSweeper rated it 🐚 platinum hermit (proof + patch quality both platinum), all CI is green, no merge-risk flags, and it's mergeable: clean.

On the bot's two pre-merge reservations, for maintainer visibility:

  1. End-to-end cold-start not re-profiled — the focused fixture shows 550→325 existsSync calls (294.75ms→208.49ms). I can attach a full openclaw agent --local cold-start before/after capture if that would unblock landing; happy to add it.
  2. sdk-alias / bundled-dir probes left intentionally untouched — scoped this PR to the manifest scan only to keep it a focused, low-risk change. Those would be a separate follow-up if profiling after landing shows they're worth it.

This is the canonical path the bot points to over the broader process-global sibling (#94170). Ready to address any review feedback.

@openclaw-clownfish
openclaw-clownfish Bot merged commit 1585ec5 into openclaw:main Jun 22, 2026
210 of 219 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 23, 2026
…-assisted] (openclaw#93919)

* perf(plugins): cache existence probes within bundle manifest scan

Bundle plugin discovery re-probes the same marker paths (skills/, commands/,
agents/, .mcp.json, .lsp.json, settings.json, hooks/hooks.json) once in
detectBundleManifestFormat and again in loadBundleManifest's capability
builders. Across the bundled plugin tree this is thousands of redundant
synchronous fs.existsSync calls; openclaw#76209 reports 25.4s of self-time on a
Windows cold start.

Add a scan-scoped existence cache (plugin-scan-existence-cache.ts) entered
only around discoverBundleInRoot. pluginScanExistsSync memoizes inside the
active scan and falls back to plain fs.existsSync outside it, so install,
hooks, and doctor flows stay uncached. The cache is push/pop per
discoverBundleInRoot call (try/finally), so a later install/repair pass
re-reads the filesystem — no process-global staleness.

Measured on Windows over a 25-plugin fixture: 550 -> 325 fs.existsSync
calls (41% fewer), 294.75ms -> 208.49ms. Discovery results unchanged.

Closes openclaw#76209

* fix(plugins): drop unused test reset helper and satisfy oxlint

Remove __resetPluginScanExistenceCacheForTest: the scan cache is push/pop
balanced by try/finally in withPluginScanExistenceCache, so the stack never
leaks between tests and the helper was dead code. It also tripped oxlint
no-underscore-dangle. Refactor the integration test to count existsSync calls
via a const-returning helper so there is no useless assignment.
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: M 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.

[Bug]:

1 participant