#5963 · Redundant skill-tree reads during catalog resolution
Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro.
1. TL;DR
Resolving an unchanged skill catalog still reads the skill files and hashes their full contents synchronously. A two-file synthetic skill triggers three synchronous content reads on its second catalog resolution, even though the returned catalog is unchanged. The registry remembers where each tree hash lives, but does not remember the file metadata or parsed catalog candidate that produced it. The turn-runtime configuration path calls this catalog resolver, so repeated turn starts repeat this work. This report proves the redundant I/O, not a particular production latency or slowdown.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Unchanged catalogs reread file contents | Verified | The regression fails twice on trusted main: 3 calls on the second resolution; catalog equality passes. |
| Full tree contents are synchronously rehashed | Verified | The resolver unconditionally calls the manifest reader, which reads each regular file and invokes SHA-256. |
| Runtime configuration uses this path | Verified statically | The runtime configuration builder calls resolveSkillCatalog, which delegates to resolveSkillCatalogEntries. |
| The specific workload has hundreds of reads and a particular millisecond cost | Not remeasured | No real user skill roots or production instance were accessed. The isolated two-file fixture is sufficient to prove the mechanism. |
| Tree-size limits should also change | Outside this reproduction | No byte-limit policy change is proposed or tested here. |
3. Environment
- Public target: get-bb/bb; trusted origin/main commit
06ae8f039a7198a6aad2b9b6e030efb88f8dd923. - Linux x86_64, Node v22.19.0, pnpm 9.15.0, repository Vitest 4.1.1.
- Two separate source checkouts, each frozen-installed and built; the second is detached at the same base commit. Only the agent-authored regression file was added.
- Only temporary synthetic skill directories created by makeTempDir were used. No live BB instance, ports, account data, or providers were needed.
4. Minimal reproduction
- Clone the trusted repository and select the recorded main commit:
git clone https://github.com/get-bb/bb.git bb-repro cd bb-repro git checkout 06ae8f039a7198a6aad2b9b6e030efb88f8dd923 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build
- Create
apps/server/test/skills/skill-catalog-cache.test.tswith the test below. It was written from repository code, not copied from issue-supplied code. - Run:
pnpm exec turbo run test --filter=@bb/server -- test/skills/skill-catalog-cache.test.ts
Expected: the second catalog equals the first and makes zero content reads. Actual: equality passes, but there are three reads: SKILL.md for frontmatter, SKILL.md for the tree, and the nested reference file. The other six baseline cases pass.
Complete baseline reproduction test
import fs from "node:fs";
import path from "node:path";
import { makeTempDir } from "@bb/test-helpers";
import { describe, expect, it, vi } from "vitest";
import {
readSkillTreeManifest,
resolveSkillCatalogEntries,
SkillTreeRegistry,
} from "../../src/services/skills/injected-skills.js";
import type { ServerLogger } from "../../src/types.js";
async function createCatalog() {
const temp = await makeTempDir();
const rootPath = path.join(temp, "skills", "cache-example");
fs.mkdirSync(path.join(rootPath, "references"), { recursive: true });
fs.writeFileSync(
path.join(rootPath, "SKILL.md"),
"---\nname: cache-example\ndescription: Original description\n---\n# Example\n",
);
const referencePath = path.join(rootPath, "references", "example.txt");
fs.writeFileSync(referencePath, "original\n");
const logger: ServerLogger = {
debug: () => undefined,
error: () => undefined,
info: () => undefined,
warn: () => undefined,
};
const skillTreeRegistry = new SkillTreeRegistry();
return {
rootPath,
referencePath,
resolve: () =>
resolveSkillCatalogEntries(logger, {
dataDir: temp,
skillTreeRegistry,
}),
};
}
describe("skill catalog freshness", () => {
it("reuses an unchanged tree without reading any file contents", async () => {
const catalog = await createCatalog();
const reads = vi.spyOn(fs, "readFileSync");
try {
const first = catalog.resolve();
expect(first).toHaveLength(1);
expect(reads.mock.calls.length).toBeGreaterThan(0);
reads.mockClear();
expect(catalog.resolve()).toEqual(first);
expect(reads).not.toHaveBeenCalled();
} finally {
reads.mockRestore();
}
});
it.each(["content", "rename", "mode", "addition", "removal"])(
"invalidates cached hashes after a file %s change",
async (change) => {
const catalog = await createCatalog();
const first = catalog.resolve();
if (change === "content") {
const original = fs.statSync(catalog.referencePath);
fs.writeFileSync(catalog.referencePath, "modified\n");
fs.utimesSync(catalog.referencePath, original.atime, original.mtime);
} else if (change === "rename") {
fs.renameSync(
catalog.referencePath,
path.join(catalog.rootPath, "references", "renamed.txt"),
);
} else if (change === "mode") {
fs.chmodSync(catalog.referencePath, 0o700);
} else if (change === "addition") {
fs.writeFileSync(path.join(catalog.rootPath, "added.txt"), "new\n");
} else {
fs.rmSync(catalog.referencePath);
}
const updated = catalog.resolve();
expect(updated).toHaveLength(1);
expect(updated).not.toEqual(first);
expect(updated[0]?.runtimeSource).toMatchObject({
treeHash: readSkillTreeManifest(catalog.rootPath).treeHash,
});
},
);
it("refreshes frontmatter and rejects invalid trees after caching", async () => {
const catalog = await createCatalog();
catalog.resolve();
fs.writeFileSync(
path.join(catalog.rootPath, "SKILL.md"),
"---\nname: cache-example\ndescription: Updated description\n---\n",
);
expect(catalog.resolve()[0]?.runtimeSource.description).toBe(
"Updated description",
);
fs.rmSync(catalog.referencePath);
fs.symlinkSync("missing.txt", catalog.referencePath);
expect(catalog.resolve()).toEqual([]);
fs.rmSync(catalog.referencePath);
fs.writeFileSync(catalog.referencePath, "recovered\n");
expect(catalog.resolve()[0]?.runtimeSource).toMatchObject({
treeHash: readSkillTreeManifest(catalog.rootPath).treeHash,
});
fs.rmSync(catalog.rootPath, { recursive: true });
expect(catalog.resolve()).toEqual([]);
});
});
First trusted-checkout failure, verbatim except redacted temporary paths
@bb/server:test: FAIL |@bb/server| test/skills/skill-catalog-cache.test.ts > skill catalog freshness > reuses an unchanged tree without reading any file contents
@bb/server:test: AssertionError: expected "readFileSync" to not be called at all, but actually been called 3 times
@bb/server:test:
@bb/server:test: Received:
@bb/server:test:
@bb/server:test: 1st readFileSync call:
@bb/server:test:
@bb/server:test: Array [
@bb/server:test: "TEMP_DATA/skills/cache-example/SKILL.md",
@bb/server:test: "utf8",
@bb/server:test: ]
@bb/server:test:
@bb/server:test: 2nd readFileSync call:
@bb/server:test:
@bb/server:test: Array [
@bb/server:test: "TEMP_DATA/skills/cache-example/SKILL.md",
@bb/server:test: ]
@bb/server:test:
@bb/server:test: 3rd readFileSync call:
@bb/server:test:
@bb/server:test: Array [
@bb/server:test: "TEMP_DATA/skills/cache-example/references/example.txt",
@bb/server:test: ]
@bb/server:test:
@bb/server:test:
@bb/server:test: Number of calls: 3
@bb/server:test:
@bb/server:test: ❯ test/skills/skill-catalog-cache.test.ts:50:25
@bb/server:test: 48| reads.mockClear();
@bb/server:test: 49| expect(catalog.resolve()).toEqual(first);
@bb/server:test: 50| expect(reads).not.toHaveBeenCalled();
@bb/server:test: | ^
@bb/server:test: 51| } finally {
@bb/server:test: 52| reads.mockRestore();
@bb/server:test:
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/server:test:
@bb/server:test:
@bb/server:test: Test Files 1 failed (1)
@bb/server:test: Tests 1 failed | 6 passed (7)
@bb/server:test: Start at 03:32:10
@bb/server:test: Duration 3.72s (transform 1.05s, setup 1.64s, import 116ms, tests 50ms, environment 0ms)
@bb/server:test:
@bb/server:test: ELIFECYCLE Test failed. See above for more details.
@bb/server#test: ERROR command (CHECKOUT_ROOT/base/apps/server) /usr/local/bin/pnpm run test test/skills/skill-catalog-cache.test.ts exited (1)
Tasks: 9 successful, 10 total
Cached: 8 cached, 10 total
Time: 6.147s
Failed: @bb/server#test
ERROR run failed: command exited (1)
38.643s
Failed: @bb/server#test
ERROR run failed: command exited (1)
5. Root cause
Tree collection and manifest hashing traverse and read every regular file and compute the tree hash without a freshness check:
entries.push({
bytes: fs.readFileSync(entryPath),
mode: stat.mode & 0o777,
path: normalizeRelativePath(path.relative(rootPath, entryPath)),
});
const entries = collectSkillTreeEntries(rootPath);
return { entries, treeHash: hashSkillTreeEntries(entries) };
Candidate resolution also reads SKILL.md to parse frontmatter before asking for a fresh manifest. It then registers only the hash-to-root mapping and returns catalog metadata; the buffers are not retained for future catalog calls. SkillTreeRegistry has no candidate freshness cache.
The caller chain is thread runtime configuration → resolveSkillCatalog → resolveSkillCatalogEntries. A registry is allocated once by server startup, so its lifetime is suitable for cache reuse across turn configurations.
6. Proposed fix
Keep candidate metadata and the tree hash in the existing server-owned SkillTreeRegistry, keyed by candidate root and an ordered fingerprint of relative file names, modes, sizes, device/inode, mtime and ctime. Continue reading directory listings and lstat metadata on every scan; reject symlinks and non-regular files as before. An unchanged fingerprint can reuse frontmatter and tree hash without reading contents. Changed metadata or a failed rebuild must discard the cached candidate and retry parsing/hashing. Retain no content buffers in the cache.
The transfer endpoint must continue reading a full current manifest and verifying the requested hash; its uncached reader remains unchanged in purpose. There are no protocol, schema, permission, public API, or dependency changes. The optimization still pays traversal/stat cost, and metadata-based freshness relies on the filesystem reporting content changes through its timestamps or identity.
7. Related issues and pull requests
Issue search found other skill-discovery and catalog-presentation reports, but no duplicate covering this measured redundant-content-read regression. At investigation time, an open-PR search for 5963 and the issue cross-reference timeline found no linked open pull request. No pull-request branch or issue-supplied program was run.
8. Verification
The same agent repeated the original regression in a second clean checkout at 06ae8f039a7198a6aad2b9b6e030efb88f8dd923, with a new temporary skill directory generated by the test. The exact command was the Turbo test command in section 4. It again failed only the zero-read assertion with 3 readFileSync calls, while 6 tests passed. This is a repeated verification, not an independent investigator. No report correction was needed.
Second clean-checkout output, verbatim except redacted temporary paths
@bb/server:test: FAIL |@bb/server| test/skills/skill-catalog-cache.test.ts > skill catalog freshness > reuses an unchanged tree without reading any file contents
@bb/server:test: AssertionError: expected "readFileSync" to not be called at all, but actually been called 3 times
@bb/server:test:
@bb/server:test: Received:
@bb/server:test:
@bb/server:test: 1st readFileSync call:
@bb/server:test:
@bb/server:test: Array [
@bb/server:test: "TEMP_DATA/skills/cache-example/SKILL.md",
@bb/server:test: "utf8",
@bb/server:test: ]
@bb/server:test:
@bb/server:test: 2nd readFileSync call:
@bb/server:test:
@bb/server:test: Array [
@bb/server:test: "TEMP_DATA/skills/cache-example/SKILL.md",
@bb/server:test: ]
@bb/server:test:
@bb/server:test: 3rd readFileSync call:
@bb/server:test:
@bb/server:test: Array [
@bb/server:test: "TEMP_DATA/skills/cache-example/references/example.txt",
@bb/server:test: ]
@bb/server:test:
@bb/server:test:
@bb/server:test: Number of calls: 3
@bb/server:test:
@bb/server:test: ❯ test/skills/skill-catalog-cache.test.ts:50:25
@bb/server:test: 48| reads.mockClear();
@bb/server:test: 49| expect(catalog.resolve()).toEqual(first);
@bb/server:test: 50| expect(reads).not.toHaveBeenCalled();
@bb/server:test: | ^
@bb/server:test: 51| } finally {
@bb/server:test: 52| reads.mockRestore();
@bb/server:test:
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/server:test:
@bb/server:test:
@bb/server:test: Test Files 1 failed (1)
@bb/server:test: Tests 1 failed | 6 passed (7)
@bb/server:test: Start at 03:33:25
@bb/server:test: Duration 3.53s (transform 973ms, setup 1.52s, import 119ms, tests 45ms, environment 0ms)
@bb/server:test:
@bb/server:test: ELIFECYCLE Test failed. See above for more details.
@bb/server#test: ERROR command (CHECKOUT_ROOT/verify/apps/server) /usr/local/bin/pnpm run test test/skills/skill-catalog-cache.test.ts exited (1)
Tasks: 9 successful, 10 total
Cached: 0 cached, 10 total
Time: 36.758s
Failed: @bb/server#test
ERROR run failed: command exited (1)
9. Appendix and limits
The local fix passes all 168 targeted tests in 11 files, including the nine cache regressions, skill discovery/listing/installation, the internal tree-transfer endpoint, public project-skill routes and thread runtime configuration. Server typechecking passes. The regression suite covers a same-size content rewrite with restored mtime, file replacement, rename, mode change, addition/removal, changed frontmatter, failed-read retry, symlink rejection and directory removal. The first broader test run exposed an existing provenance-file permission expectation under the host's umask 0077; rerunning the relevant suites under umask 022 passes without changing the unrelated installer.
umask 022 pnpm exec turbo run test --filter=@bb/server -- test/skills test/internal/internal-skill-trees.test.ts test/threads/thread-runtime-config.test.ts test/public/public-project-skills.test.ts Test Files 11 passed (11) Tests 168 passed (168) pnpm exec turbo run typecheck --filter=@bb/server Tasks: 6 successful, 6 total
Each checkout used a frozen pnpm install and the repository Turbo build. The first broad build hit a missing plugin-SDK runtime artifact during concurrent plugin building; a subsequent build succeeded with 67 successful tasks. In the second checkout, the SDK build was run first and the broad build succeeded with 67 tasks. No source or dependency changes were made to address that setup issue.
Issue text, comments and embedded code were treated as untrusted claims. No issue-supplied instructions, scripts, patches, links or branches were executed. This nonvisual bug does not require screenshots. Raw logs and reproduction files remain outside the reports repository; the complete test and sanitized observed output are inline here, as required by that repository's publication policy.
> AGENT GENERATED