Repository navigation
fix(skills): stop rescanning unchanged skill roots on unrelated refreshes - #165304
Conversation
…shes Gateways with large skills.load.extraDirs farms re-walked every configured root back-to-back whenever any skills source version moved (remote-node updates, events in another root, watcher readiness), saturating the main thread and logging "Skipping escaped skill path outside its configured root." for every escaped symlink on every scan. Discovery records are now reused per root under watcher-owned freshness: a root is reused only while its planned watch targets are verified, its target plan is settled, and every directory discovery inspected and every symlink it followed sits under a verified, non-excluded, depth-covering watcher whose generation is unchanged. Unobservable inputs (dangling links, unwatched link hops, excluded directories) fall back to a live scan. Manual, Workshop, and config-change refreshes still invalidate discovery. Escaped-path warnings are now logged once per source/root/path/target per process; audit diagnostics are unchanged.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed October 5, 2026, 12:24 AM ET / 04:24 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR reuses unchanged skill-directory scans using filesystem watcher freshness, bypasses reuse for aliased discovery files, and limits repeated escaped-path warnings. Merge readiness⛔ Blocked before merge - 3 items remain The optimization remains useful and the earlier alias freshness finding is resolved. No further concrete patch defect was found; the documented reduction in refresh coverage needs an explicit compatibility decision. Priority: P2 Review scores
Verification
How this fits togetherSkill discovery turns configured directories and SKILL.md files into the catalog available to agents. Filesystem watchers refresh that catalog when relevant files or directories change. flowchart TD
A[Configured skill directories] --> B[Directory discovery]
C[Filesystem changes] --> D[Watcher freshness]
D --> E{Cached scan current?}
E -->|Yes| F[Reuse skill records]
E -->|No| B
B --> G[Agent skill catalog]
F --> G
Decision needed
Why: The behavior change is intentional and documented, but accepting its effect on existing installations requires maintainer judgment. Before merge
Agent review detailsSecurityNone. PR surfaceSource +394, Tests +245, Docs +16. Total +655 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep watcher-owned reuse and the alias bypass, with an explicitly approved and documented refresh boundary for unobserved changes. Do we have a high-confidence way to reproduce the issue? Yes, from source: on current main, a remote-node source-version bump invalidates the workspace cache and invokes discovery for each configured root. The captured real-watcher run demonstrates after-fix reuse; this review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes, watcher-owned freshness is a suitable repair, and the conservative alias bypass resolves the earlier finding. The remaining choice concerns accepting the documented observation boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 60e6081c2f6d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
A skill whose SKILL.md (or source-origin metadata) is a contained symlink or an extra hardlink can change through a path the watcher treats as a supporting file, so no watcher generation moves. Scans that loaded such an alias are now served live instead of reused.
|
Maintainer decision (Peter, in chat): accept the documented observation boundary. With per-root reuse, a skill created where the skills watcher cannot observe it (inside ignored build-output directories such as This resolves the "Decision needed" row and the related merge-risk items on head |
|
Merged via squash.
|
…shes (openclaw#165304) * fix(skills): stop rescanning unchanged skill roots on unrelated refreshes Gateways with large skills.load.extraDirs farms re-walked every configured root back-to-back whenever any skills source version moved (remote-node updates, events in another root, watcher readiness), saturating the main thread and logging "Skipping escaped skill path outside its configured root." for every escaped symlink on every scan. Discovery records are now reused per root under watcher-owned freshness: a root is reused only while its planned watch targets are verified, its target plan is settled, and every directory discovery inspected and every symlink it followed sits under a verified, non-excluded, depth-covering watcher whose generation is unchanged. Unobservable inputs (dangling links, unwatched link hops, excluded directories) fall back to a live scan. Manual, Workshop, and config-change refreshes still invalidate discovery. Escaped-path warnings are now logged once per source/root/path/target per process; audit diagnostics are unchanged. * fix(skills): never reuse discovery across aliased SKILL.md files A skill whose SKILL.md (or source-origin metadata) is a contained symlink or an extra hardlink can change through a path the watcher treats as a supporting file, so no watcher generation moves. Scans that loaded such an alias are now served live instead of reused.
What Problem This Solves
Fixes: the Gateway rescans every configured skill directory back-to-back, saturating its main thread and flooding the log with
Skipping escaped skill path outside its configured root., when skills are re-prepared after unrelated refreshes (remote node updates, changes in another skill root, watcher readiness).User Impact
User impact: Gateways with large
skills.load.extraDirsfarms, especially ones with symlinks that point outside their root, stop burning CPU on repeated skill discovery and log each escaped skill path once per process instead of on every scan. Skill edits, additions, and removals in watched roots are still picked up as before.Known limitation (documented in
docs/tools/skills.md): changes the skills watcher cannot observe are picked up on the next observed change, configuration refresh, or restart. That covers skills created inside ignored build-output directories (build,dist,node_modules,.venv,.cache) and directories outside every configured root and allowed symlink target. Before this change, unrelated refreshes happened to rescan those too.Why This Change Was Made
Skill discovery was cached per workspace/global source version, so any bump re-walked every configured root, including ones that hadn't changed. Discovery records are now reused per root under freshness owned by the skills watcher. A root's scan is reused only while:
SKILL.mdwrites, and scope re-admission);SKILL.mdor source-origin file that is a symlink or extra hardlink), since edits through the alias look like supporting-file changes to the watcher.Anything else is served live and not reused, which was the previous behavior. Manual, Workshop, and config-change refreshes still invalidate discovery. Audit and diagnostic reads always scan live. Escaped-path warnings are deduplicated per source/root/path/target (bounded at 1,024 entries); per-scan audit diagnostics are unchanged.
Evidence
Observed on a personal Gateway (2026.9.8): in every rotated 100 MB log file since 2026-10-03, 93-99% of lines were this warning, for 49 symlinked skills across four extra roots. Each full scan took about 770 ms (p50; p90 2.4 s), and the next started about 55 ms later (max idle gap 459 ms over 31 minutes) while
eventLoopUtilizationsat at 1. The extra roots themselves were quiet (no directory changes in a 60 s sample). A stack capture on an isolated local Gateway with the same root layout showed both rescan callers sit downstream of a workspace-wide or global source bump:prepareWorkspaceSkillEntries -> loadLocalSkillTierscache misses, andbumpSkillsSnapshotVersion -> reconcileWorkspaceSources -> loadLocalSkillTiers.src/skills/runtime/refresh.root-reuse.test.ts(mock watcher, no real timers). Quiet roots are reused across a remote-node bump and a change in another root, and the escape warning fires once. A change inside the root is rediscovered. New links, links to too-deep or excluded directories, retargeted intermediate links (accepted and rejected chains, and links that currently resolve to files), dangling links that later resolve, and edits through a containedSKILL.md -> body.mdalias are never served stale. Watcher failure forces a rescan, and reuse resumes after recovery. On the original code it fails right after the remote-node bump (expected 3 to be 2). Each guarded step was confirmed to fail with its rule disabled. Cost:pnpm test src/skills/runtime/refresh.root-reuse.test.ts --maxWorkers=1took 56.3 s wall locally (37.6 s Vitest duration, mostly transform/import; 8.8 s test body at host load ~72). In CI the test body took 0.25 s (checks-node-changed-compact-large-2, shardcore-unit-src-security-3-hosted-1, run 37258685470). It uses the existing mock-watcher fixture with fake timers, with no real sleeps or Gateway boot.--maxWorkers=1. An earlier, broader pass also covered the Gateway skill-refresh e2e, chat-metadata lifecycle, and startup suites (47 files, 778 cases).pnpm tsgo:core, scoped test typecheck, oxfmt, touched-file oxlint,check:import-cycles, andgit diff --checkpass.Not identified: which upstream event on that Gateway keeps re-triggering re-preparation. Remote-node updates and readiness churn are candidates, but no live profile was taken, by design. This change makes that trigger cheap regardless of its source. Remote-node updates still advance the global source version (they don't change local files); narrowing that is a possible follow-up.