Repository navigation
perf(plugins): cache existence probes within bundle manifest scan [AI-assisted] - #93919
Conversation
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
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.
|
Codex review: needs maintainer review before merge. Reviewed June 22, 2026, 12:38 AM ET / 04:38 UTC. Summary PR surface: Source +63, Tests +160. Total +223 across 4 files. Reproducibility: yes. Current main and Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the scan-scoped manifest discovery cache if maintainers accept the focused proof, then profile Do we have a high-confidence way to reproduce the issue? Yes. Current main and 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 changesLabel justifications:
Evidence reviewedPR surface: Source +63, Tests +160. Total +223 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
|
Friendly nudge for review — this is the scan-scoped On the bot's two pre-merge reservations, for maintainer visibility:
This is the canonical path the bot points to over the broader process-global sibling (#94170). Ready to address any review feedback. |
1585ec5
into
openclaw:main
…-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.
Summary
What problem does this PR solve?
Cold-start plugin discovery makes a large number of synchronous
fs.existsSynccalls. For each bundle plugin,
detectBundleManifestFormatprobes marker paths(
skills/,commands/,agents/,.mcp.json,.lsp.json,settings.json,hooks/hooks.json, ...) andloadBundleManifest's capability builders probethe 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.existsSyncself-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.tsandbundled-dir.tsalso callfs.existsSync, but they alreadyhave their own lifecycle caches (
pluginSdkPackageJsonByRoot/PluginLruCacheand
bundledPluginsDirCache), so they are left for a follow-up if profilingstill 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?
plugin-scan-existence-cache.ts(lifecyclepush/pop, fallback to plain
fs.existsSyncoutside a scan).discoverBundleInRootis the only place a cache is entered, so everybundle-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
discoverBundleInRootinsrc/plugins/discovery.ts;bundle-manifest.tsprobes go throughpluginScanExistsSync, which memoizes inside the active scan and falls back toplain
fs.existsSyncotherwise. 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-reproissue.
Real behavior proof (required for external PRs)
fs.existsSyncprobesduring plugin manifest discovery on cold start (issue [Bug]: #76209).
source checkout at upstream
main(788eb2e). Node is below the recommended22.19.0 so a
[WARN] Unsupported engineis emitted on every pnpm invocation;this does not affect the probe-count measurement.
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 patchedfunctions
detectBundleManifestFormat+loadBundleManifest.fs.existsSyncis spied via
vi.spyOn. The scan runs once unwrapped (before: cache inactive =plain
fs.existsSync) and once wrapped inwithPluginScanExistenceCache(after: scan-scoped cache active). Run with
pnpm test src/plugins/plugin-scan-existence-cache.test.ts.Terminal capture (console output) from the benchmark run:
fs.existsSynccalls(41% fewer) and 294.75ms -> 208.49ms (~29% faster) for the 25-plugin fixture.
Discovery results are identical before/after.
24). Full
openclaw agent --localcold start was not re-profiled end-to-endwith
node --cpu-prof; the proof is a focused measurement of the patcheddiscovery functions.
sdk-alias/bundled-dirpaths are out of scope (seeSummary). Swift host-env-policy check skipped on Windows (no Swift).
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.
(550 calls / 294.75ms) is the before state, captured on the same patched code
with the scan cache inactive (plain
fs.existsSync), equivalent tomain.Tests and validation
Which commands did you run?
pnpm format:check <touched files>— passpnpm tsgo— pass (exit 0)pnpm lint <touched files>(runsscripts/run-oxlint-shards.mjs, the samerunner CI uses) — pass (exit 0)
pnpm build— pass (exit 0)pnpm test src/plugins/plugin-scan-existence-cache.test.ts— 5/5 passpnpm test src/plugins/bundle-manifest.test.ts— 16/16 passpnpm test src/plugins/bundled-dir.test.ts— 20/20 passWhat regression coverage was added or updated?
src/plugins/plugin-scan-existence-cache.test.ts:pluginScanExistsSyncis a plain passthrough outside a scan (no caching).withPluginScanExistenceCachehit thefilesystem exactly once.
staleness — the freshness bug a process-global cache would reintroduce).
fs.existsSynccalls 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/trueserved across aninstall/repair pass would be a regression. This is mitigated by scoping the cache
to a single
discoverBundleInRootcall (push on enter, pop infinallyonexit), and by falling back to plain
fs.existsSyncoutside any scan, so install/ hooks / doctor flows are uncached.
How is that risk mitigated?
discoverBundleInRootand always popped (try/finally).pluginScanExistsSyncis plainfs.existsSync.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.tsoverlay/tmpdir tests is pre-existing onmainand notcaused by this change — verified by stashing the change and re-running).
Which bot or reviewer comments were addressed?
None yet (new PR).