Skip to content

fix(skills): stop rescanning unchanged skill roots on unrelated refreshes - #165304

Merged
steipete merged 2 commits into
mainfrom
fix/skills-escaped-path-rescan
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/skills-escaped-path-rescan

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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.extraDirs farms, 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:

  • every watch target planned for the root is verified and ready with an unchanged generation (generations advance on watcher creation, readiness, scheduled discovery changes, in-flight SKILL.md writes, and scope re-admission);
  • the root's target plan is settled (a discovery change marks the changed roots for re-planning, and every publisher re-plans them immediately, so new or retargeted links get watchers first);
  • every directory discovery inspected, and every symlink it listed or followed, resolved from the filesystem root, lies under a verified, non-excluded, depth-covering watcher whose generation is unchanged;
  • the scan hit no unresolvable path (for example a dangling link).
  • no discovered skill has an aliased discovery file (a SKILL.md or 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 eventLoopUtilization sat 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 -> loadLocalSkillTiers cache misses, and bumpSkillsSnapshotVersion -> reconcileWorkspaceSources -> loadLocalSkillTiers.

  • Real layout: with the same four roots on a local Mac (real watcher, read-only), all four roots reached verified coverage, and five remote-node refreshes caused zero rediscoveries (previously one full rescan of every root per refresh).
  • Regression test 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 contained SKILL.md -> body.md alias 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=1 took 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, shard core-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.
  • 28 related test files (refresh lifecycle, loading, remote, workshop, session snapshots) pass locally with --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, and git diff --check pass.
  • Autoreview (Codex, P2 threshold) ran 8 passes; each finding was fixed with a regression step, except the two out-of-observation-boundary cases above, which are documented instead.

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.

…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.
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 5, 2026
@steipete
steipete marked this pull request as ready for review October 5, 2026 03:15
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 5, 2026, 12:24 AM ET / 04:24 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: 55240cc06021dc2bc33b2b83cabeba88f280de31
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Real performance observations and meaningful freshness regressions support a good patch; the remaining compatibility choice does not reduce its implementation rating.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body exercises the changed skill loader with real watchers against four actual roots on a local Mac and reports zero rediscoveries across five remote-node refreshes after verified coverage. The alias repair has supplemental workspace-loader regression coverage. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body exercises the changed skill loader with real watchers against four actual roots on a local Mac and reports zero rediscoveries across five remote-node refreshes after verified coverage. The alias repair has supplemental workspace-loader regression coverage. No stored-data contract changes.
Evidence reviewed 9 items Pinned introduced changes: Reviewed the introduced delta from f755c32 to 55240cc, including the loader, discovery, watcher registry, target planning, refresh lifecycle, documentation, and tests. The supplied test merge is stale and was not used to infer removal of current-main behavior.
Earlier alias finding resolved: The new commit checks SKILL.md, .openclaw, and source-origin metadata for symlinks or extra hardlinks and prevents those scans from entering the reusable cache. The added workspace-loader regression edits body.md behind a contained SKILL.md alias and expects the updated skill name after a remote-node refresh. GitHub's comparison against the previously reviewed head confirms these are new changes.
Current main still lacks root-record reuse: At the pinned fetched-main revision, loadSkillRootRecords directly invokes discovery and loads candidates without the proposed per-root cache. This establishes that the central optimization remains necessary; no merged replacement was established.
Findings None None.
Security None None.

How this fits together

Skill 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
Loading

Decision needed

Question Recommendation
May unrelated refreshes stop discovering newly created skills inside ignored directories, with discovery deferred to an observed change, configuration refresh, or restart? Accept the documented observation boundary: Approve deferred discovery for unobserved changes while retaining the performance improvement and explicit refresh escape paths.

Why: The behavior change is intentional and documented, but accepting its effect on existing installations requires maintainer judgment.

Before merge

  • Resolve merge risk (P1) - Existing setups that rely on unrelated refreshes to discover newly created skills in ignored directories will retain the previous catalog until an observed discovery change, configuration refresh, or restart; explicit acceptance of that compatibility tradeoff remains outstanding.
  • Complete next step (P2) - Record explicit maintainer acceptance of deferred discovery for unobserved additions, or request a bounded compatibility repair before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +394, Tests +245, Docs +16. Total +655 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 6 428 34 +394
Tests 2 246 1 +245
Docs 1 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 690 35 +655

Review metrics

Metric Value Why it matters
Production versus test growth production net +394 lines; tests net +245 lines The production growth is justified by watcher-owned generations, dependency coverage, and conservative cache bypasses needed to preserve freshness.

Merge-risk options

Maintainer options:

  1. Approve the documented refresh boundary (recommended)
    Explicitly accept that unobserved additions wait for an observed discovery change, configuration refresh, or restart.
  2. Retain discovery for unobserved additions
    Request a bounded compatibility path if existing installations must continue discovering ignored-directory additions after unrelated refreshes.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body exercises the changed skill loader with real watchers against four actual roots on a local Mac and reports zero rediscoveries across five remote-node refreshes after verified coverage. The alias repair has supplemental workspace-loader regression coverage. No stored-data contract changes.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This addresses costly repeated discovery in large skill installations with a bounded compatibility tradeoff.
  • merge-risk: 🚨 compatibility: Unrelated refreshes cease opportunistically discovering new skills inside ignored directories, changing behavior for existing layouts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body exercises the changed skill loader with real watchers against four actual roots on a local Mac and reports zero rediscoveries across five remote-node refreshes after verified coverage. The alias repair has supplemental workspace-loader regression coverage. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body exercises the changed skill loader with real watchers against four actual roots on a local Mac and reports zero rediscoveries across five remote-node refreshes after verified coverage. The alias repair has supplemental workspace-loader regression coverage. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the introduced delta from f755c32 to 55240cc, including the loader, discovery, watcher registry, target planning, refresh lifecycle, documentation, and tests. The supplied test merge is stale and was not used to infer removal of current-main behavior. (55240cc06021)
  • Earlier alias finding resolved: The new commit checks SKILL.md, .openclaw, and source-origin metadata for symlinks or extra hardlinks and prevents those scans from entering the reusable cache. The added workspace-loader regression edits body.md behind a contained SKILL.md alias and expects the updated skill name after a remote-node refresh. GitHub's comparison against the previously reviewed head confirms these are new changes. (src/skills/loading/skill-root-loader.ts:294, 55240cc06021)
  • Current main still lacks root-record reuse: At the pinned fetched-main revision, loadSkillRootRecords directly invokes discovery and loads candidates without the proposed per-root cache. This establishes that the central optimization remains necessary; no merged replacement was established. (src/skills/loading/skill-root-loader.ts:132, 60e6081c2f6d)
  • Real watcher performance evidence: The captured PR body reports the changed loader running with real watchers against four actual skill roots on a local Mac: all roots reached verified coverage, and five remote-node refreshes caused zero rediscoveries. This directly supports the central performance claim. Focused regression and related-suite results are supplemental; no tests or target code were executed during this read-only review. (55240cc06021)
  • Documented compatibility limitation: The PR expressly documents that newly created skills inside ignored build-output directories, and other unobserved changes, may wait for an observed discovery change, configuration refresh, or restart. Previously unrelated refreshes could discover them. This is intentional and disclosed, but the supplied discussion contains no explicit maintainer acceptance of this changed refresh contract. Public docs: docs/tools/skills.md. (docs/tools/skills.md:831, 55240cc06021)
  • Dependency signal and watcher depth adapter: refresh.ts directly consumes @openclaw/fs-safe/watch, and reuse relies on that watcher's depth and symlink observation contract. The OpenClaw scope adapter adds two entries to the logical directory depth, covering SKILL.md and source-origin metadata below the deepest skill directory. (src/skills/runtime/refresh-observation-source.ts:34, 55240cc06021)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-05T03:21:03.267Z sha c140f3b :: needs changes before merge. :: none
  • reviewed 2026-10-05T03:37:55.393Z sha c140f3b :: blocked before merge. :: [P1] Invalidate reuse for contained SKILL.md file aliases

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Oct 5, 2026
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.
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

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 build, dist, node_modules, .venv, .cache, or outside every configured root and allowed symlink target) is discovered on the next observed skills change, configuration refresh, or restart. Previously an unrelated refresh would have picked it up, but only because of the rescan storm this PR removes. The limitation is documented in docs/tools/skills.md, and manual, Workshop, and configuration refreshes keep their explicit invalidation.

This resolves the "Decision needed" row and the related merge-risk items on head 55240cc06021dc2bc33b2b83cabeba88f280de31.

@steipete
steipete merged commit c5baaee into main Oct 5, 2026
132 of 134 checks passed
@steipete
steipete deleted the fix/skills-escaped-path-rescan branch October 5, 2026 04:58
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant