Skip to content

Cache unchanged skill catalog candidates - #5966

Merged
ymichael merged 2 commits into
mainfrom
slopcop/issue-5963
Oct 29, 2026
Merged

ymichael merged 2 commits into
mainfrom
slopcop/issue-5963

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Every turn start (and the project command list and plugin skill listing) calls resolveSkillCatalog, and SkillTreeRegistry.readTree streamed and SHA-256-hashed every file of every skill tree on every call, even when nothing had changed. The registry already recorded a per-file statKey (dev, inode, size, mtime, ctime) in each manifest for the tree-content endpoint, but never consulted it before rehashing. On a real ~/.bb plus the repo's plugin skill roots, each resolve re-read 74 files (576 KB).

Reproduction and root-cause report: https://get-bb.github.io/reports/issues/5963.html

What changed

This replaces the original commit on this branch, which targeted the old synchronous skill code and no longer applied after #6330, #6335 and #6185.

  • apps/server/src/services/skills/injected-skills.ts: readTree looks up the root's previous manifest and reuses a file's sha256 when its statKey is unchanged, instead of reading it again. Mode, size and path still come from the fresh lstat/stat, and symlink and non-regular-file rejection are unchanged.
  • Racy timestamps: on filesystems with coarse timestamps (the Linux CI runner), a same-size rewrite can land in the same ctime tick as the version already hashed and produce an identical statKey. Following Git's racy-clean rule, a hash is reusable only if the file's ctime is at least 2 s older than the moment hashing started (HASH_REUSE_SETTLE_NS). Recently changed files are rehashed until they settle.
  • hashReusable is a server-only field on SkillTreeFile; the /skills/tree/:hash route projects fields explicitly, so the wire format is unchanged. There are no protocol, public API, schema, CLI or config changes.

How you verified

  • New apps/server/test/skills/skill-catalog-cache.test.ts (8 tests):
    • Settled unchanged files are not reread on the second resolve (createReadStream not called). This fails on origin/main (2 reads).
    • Unchanged files changed too recently to trust are reread. This fails on the previous commit, which had no settle window and failed CI on Linux.
    • Content (size change with restored mtime), replacement (new inode), rename, mode, addition and removal changes to settled files each produce the same tree hash as a fresh registry.
  • Real-data repro (resolveSkillCatalogEntries over ~/.bb plus repo plugin skill roots, one shared registry): before, 74 reads / 576,146 bytes per resolve, ~12 ms warm median; after, 0 reads / 0 bytes on repeat resolves, ~7 ms, with an identical catalog.
  • End to end on pnpm start:worktree: a Claude Code thread read a qa-canary user skill's reference file (ALPHA). The file was then rewritten at the same size with its mtime restored (BRAVO), and the next turn read BRAVO. This still held after a server restart on the final commit.
  • pnpm exec turbo run test --filter=@bb/server -- test/skills test/internal test/threads/thread-runtime-config.test.ts: 296 tests pass in 26 files.
  • pnpm exec turbo run typecheck lint --filter=@bb/server: passes. oxfmt --check: passes.

Fixes #5963

AGENT GENERATED

🤖 Generated with Claude Code

SkillTreeRegistry.readTree reuses a file's previous sha256 when its
dev/ino/size/mtime/ctime stat key is unchanged, so repeated catalog
resolves stop rereading and rehashing every skill file on each turn.

Fixes #5963

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Filesystems with coarse timestamps (the Linux CI runner) can give a
same-size rewrite the same ctime as the version already hashed, so its
stat key matches and the stale hash was reused. Like Git's racy-clean
rule, a hash is reusable only when the file's ctime is at least two
seconds older than the moment hashing started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 2b1700b into main Oct 29, 2026
31 checks passed
@ymichael
ymichael deleted the slopcop/issue-5963 branch October 29, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skill catalog resolution rereads and rehashes every file across all skill trees on every turn

1 participant