Repository navigation
Description
Summary
Every thread turn start builds runtime config and calls resolveSkillCatalog, which scans dataDir/skills, generated skills, and all plugin skill roots. For every accepted skill candidate, readSkillTreeManifest reads every file into memory synchronously via collectSkillTreeEntries, hashes the content to compute treeHash, and discards the read buffers. A second resolve on unchanged trees repeats all reads and hashes unconditionally without a freshness cache.
Versions and environment
- Node v26.12.0. From source at
405592c0b71b1655a6ab2e1cc7498b5beeb78caa. - Linux x86_64, 4 cores.
- Reproduction runs directly against repository sources with
node --conditions=source --import tsx.
Steps to reproduce
Run this standalone reproduction script from the root of a BB checkout:
node --conditions=source --import tsx - <<'REP'
import fs from "node:fs";
import path from "node:path";
import { performance } from "node:perf_hooks";
const realReadFileSync = fs.readFileSync;
let reads = 0;
let bytes = 0;
fs.readFileSync = function (...args) {
const res = realReadFileSync.apply(this, args);
reads += 1;
bytes += Buffer.isBuffer(res) ? res.byteLength : Buffer.byteLength(String(res));
return res;
};
const { resolveSkillCatalogEntries, SkillTreeRegistry } = await import(
"./apps/server/src/services/skills/injected-skills.ts"
);
const repoPlugins = path.resolve("./plugins");
const pluginSkillRoots = fs
.readdirSync(repoPlugins, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => ({
pluginId: entry.name,
rootPath: path.join(repoPlugins, entry.name, "skills"),
}))
.filter((entry) => fs.existsSync(entry.rootPath));
const logger = { warn() {}, debug() {}, info() {}, error() {}, fatal() {}, trace() {}, child() { return logger; } };
function scan() {
reads = 0;
bytes = 0;
const start = performance.now();
const entries = resolveSkillCatalogEntries(logger, {
additionalSkillsRootPaths: [`${process.env.HOME}/.bb/skills-generated`],
dataDir: `${process.env.HOME}/.bb`,
pluginSkillRoots,
skillTreeRegistry: new SkillTreeRegistry(),
});
return { durationMs: performance.now() - start, entries: entries.length, reads, bytes };
}
const first = scan();
const second = scan();
console.log(JSON.stringify({
firstCallMs: Number(first.durationMs.toFixed(2)),
firstReads: first.reads,
firstBytes: first.bytes,
secondCallMs: Number(second.durationMs.toFixed(2)),
secondReads: second.reads,
secondBytes: second.bytes,
identicalEntryCount: first.entries === second.entries,
}, null, 2));
REPExpected vs actual
Expected:
When skill files and directory listings have not changed, resolveSkillCatalog reuses cached tree hashes without re-reading file contents from disk.
Actual output:
{
"firstCallMs": 44.25,
"firstReads": 287,
"firstBytes": 1450161,
"secondCallMs": 19.72,
"secondReads": 287,
"secondBytes": 1450161,
"identicalEntryCount": true
}The second resolve re-executes 287 readFileSync calls, re-reads 1,450,161 bytes into temporary Buffer objects, and recomputes all SHA-256 tree hashes synchronously on the server main thread.
Evidence
Source comparison
collectSkillTreeEntriesinapps/server/src/services/skills/injected-skills.ts#L218-L251reads every file into memory withfs.readFileSync(entryPath).readSkillTreeManifestinapps/server/src/services/skills/injected-skills.ts#L253-L276hashes those bytes with SHA-256 and discards the file buffers.readSkillCandidateinapps/server/src/services/skills/injected-skills.ts#L361-L372callsreadSkillTreeManifestafter frontmatter accepts the skill, registersmanifest.treeHashinskillTreeRegistry, and dropsmanifest.entries.resolveSkillCataloginapps/server/src/services/skills/skill-catalog.ts#L17-L38delegates toresolveSkillCatalogEntriesondataDir/skills, inherited roots, generated skills, and each plugin skills root.thread-runtime-config.ts#L204-L208callsresolveSkillCatalogsynchronously on every turn start.- Other call sites: plugin skill listing in
apps/server/src/services/skills/skill-listing.ts(listBbPluginSkills) and project command list inapps/server/src/routes/projects.ts. - In
apps/server/src/services/threads/workspace-agent-context.ts, project skill RPC limits file size (maxFileBytes: 10 * 1024 * 1024). By contrast,collectSkillTreeEntrieshas no byte cap and reads files into memory regardless of size.
Measured cost
- Benchmark:
node --conditions=source --import tsx /home/tiberriver256/bb-perf-audit/bench/46/repro.mjs - Test machine: Linux, 4 cores, load average 0.31, 0.26, 0.17.
- Catalog workload:
resolveSkillCatalogEntriesover~/.bb/skills,skills-generated, and 28 repo plugin skill roots. - Timings: Warmup 67.640 ms (excluded from median). Five warm runs recorded median wall time 19.348 ms (range 16.299 ms to 20.338 ms).
- Operation counts per warm run: 85 returned entries (identical names), 287
readFileSynccalls, 1,450,161 bytes read, 344lstatSynccalls, 0 errors. - Unprofiled CPU split: User CPU ~13 to 24 ms, system CPU ~4 to 10 ms (warm cost is primarily CPU once page cache is warm).
- Separate
readSkillTreeManifestloop on 86 directories (hash-only.mjs, finished 2026-10-21T03:22:50Z): 5 warm runs, median 11.945 ms (range 10.480 to 17.450 ms), 201 files, 1,122,218 bytes, 0 errors.
Suggested fix and verification
- Cache tree hashes keyed by skill root path, file set, and file mtimes.
- Subsequent calls on unchanged trees reuse the cached hash and perform zero
readFileSynccalls. - A modified file, missing directory, or failed hash rebuilds the manifest entry.
- Suggested test: Run
resolveSkillCatalogEntriestwice on a temporary skill directory fixture. Assert the second call returns identical hashes with 0 contentreadFileSynccalls. Touch a file in the fixture and verify the subsequent call recalculates the updated tree hash.
What you ruled out
- Not ACP skills catalog repeats the full staged root path on every line (57% of the injected list) #4481: ACP skills catalog repeats the full staged root path on every line (57% of the injected list) #4481 addresses ACP session instructions repeating path strings in the prompt. This issue concerns server-side skill tree hashing and synchronous disk reads.
- Not Replace multi-file global skill syncing with dynamic CLI-served skills #2985: Replace multi-file global skill syncing with dynamic CLI-served skills #2985 proposes replacing multi-file global skill syncing with dynamic CLI-served skills. This issue concerns caching unchanged skill manifests in
resolveSkillCatalog. - Not Skills have no first-class invocation path on most providers: models read SKILL.md into context (read:invoke ~90:1, ~3.5M tokens measured) #4460: Skills have no first-class invocation path on most providers: models read SKILL.md into context (read:invoke ~90:1, ~3.5M tokens measured) #4460 measured agents re-reading
SKILL.mdinto context due to lack of a native invocation tool. This issue is server event-loop blocking during catalog resolution. - Not an unverified claim: verified locally on
mainat405592c0b71b1655a6ab2e1cc7498b5beeb78caa.
Suggested priority and effort
Medium priority, small effort. It introduces ~19 ms of synchronous disk I/O on the server main thread during every turn start, scaling with the number of installed plugins and skills.
AGENT GENERATED
Investigation thread: @thread:thr_j4ihwv2cuc (parent: @thread:thr_dzt4erif6e)
Activity
bb-slop-cop commentedon Oct 21, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotthreads,perf,confirmed-repro.Reuse unchanged skill file hashes across catalog scans
Cache unchanged skill catalog candidates (#5966)