All reports · Issue #6173

Recursive skill discovery exhausts its scan budget

2026-10-23 · Bug · Priority: Medium · Effort: Low · providers, provider-pi

Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro

Summary

The host daemon stops finding recursive skills after unrelated supporting files consume its 1,000-entry scan budget. The same budget is shared across roots, so exhausting one root also hides skills in later roots. A filesystem-only regression reproduces both failures in the actual exported skills and commands discovery functions. The same agent repeated all four failures in a second clean checkout at the same trusted main commit.

Claims versus findings

ClaimFinding
Ordinary supporting files can hide later skills.Verified: a skill with 1,005 supporting files suppresses a nested skill and a skill in another root.
One root can starve later roots.Verified separately: 1,005 empty candidate directories in one root hide a valid skill in the next root.
Pi is exposed to recursive scanning.Verified in its trusted native-root declaration: two user roots are recursive and ordered.
The reported macOS installation and native Pi load more skills.Not independently tested: this investigation uses synthetic temporary Linux fixtures, not the reporter's filesystem or a live Pi process.
Stopping whenever SKILL.md is found is a safe repair.Not safe for BB's existing contract: an existing regression requires discovering a skill nested inside another skill.

Environment

Minimal repeatable reproduction

In a clean checkout of the base commit, save the regression test to apps/host-daemon/src/command-discovery-budget.test.ts. This test was authored from the repository implementation, not copied from issue code. Run:

git clone https://github.com/get-bb/bb.git bb-6173
cd bb-6173
git checkout --detach 1e80ca7b44bccd06c6da75ed9ca6ba497bd380f5
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run test --force --filter=@bb/host-daemon -- src/command-discovery-budget.test.ts

Two cases run against each exported discovery surface:

  1. Root one contains a skill named first, 1,005 supporting text files in its assets directory, and a nested skill named inner. Root two contains second.
  2. Root one contains 1,005 empty directories. Root two contains second.
Supporting files case:
Expected: [ 'first', 'inner', 'second' ]
Actual:   [ 'first' ]

Root exhaustion case:
Expected: [ 'second' ]
Actual:   []

Test Files  1 failed (1)
     Tests  4 failed (4)

These are expected assertion failures on the unchanged production code, not setup failures. Logs: first run and second clean run. Temporary checkout prefixes in the logs are normalized; assertion output is unchanged.

Regression test source

import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
  discoverProviderCommands,
  discoverSkills,
  type SkillScanRoot,
} from "./command-discovery.js";

let tempRoot: string;

beforeEach(async () => {
  tempRoot = await mkdtemp(path.join(tmpdir(), "bb-skill-budget-"));
});

afterEach(async () => {
  await rm(tempRoot, { recursive: true, force: true });
});

async function writeSkill(directory: string): Promise<void> {
  await mkdir(directory, { recursive: true });
  await writeFile(
    path.join(directory, "SKILL.md"),
    "---\ndescription: test skill\n---\n",
  );
}

function roots(): SkillScanRoot[] {
  return ["primary", "secondary"].map((name) => ({
    rootPath: path.join(tempRoot, name),
    shape: "skill-recursive",
    namePrefix: "",
    source: "skill",
    origin: "user",
    identitySeed: name,
    rootKind: "provider-user",
  }));
}

describe.each([
  ["commands", discoverProviderCommands],
  ["skills", discoverSkills],
] as const)("recursive %s discovery budgets", (_surface, discover) => {
  it("lists later and nested skills despite large supporting-file directories", async () => {
    const primarySkill = path.join(tempRoot, "primary", "first");
    const assets = path.join(primarySkill, "assets");
    await writeSkill(primarySkill);
    await mkdir(assets);
    for (let index = 0; index < 1_005; index += 1) {
      await writeFile(
        path.join(assets, `asset-${index}.txt`),
        "supporting data",
      );
    }
    await writeSkill(path.join(primarySkill, "nested", "inner"));
    await writeSkill(path.join(tempRoot, "secondary", "second"));

    const records = await discover({ roots: roots() });

    expect(records.map((record) => record.name).sort()).toEqual([
      "first",
      "inner",
      "second",
    ]);
  });

  it("continues with another root after exhausting a directory budget", async () => {
    const primary = path.join(tempRoot, "primary");
    await mkdir(primary);
    for (let index = 0; index < 1_005; index += 1) {
      await mkdir(path.join(primary, `directory-${index}`));
    }
    await writeSkill(path.join(tempRoot, "secondary", "second"));

    const records = await discover({ roots: roots() });

    expect(records.map((record) => record.name)).toEqual(["second"]);
  });
});

Root cause

  1. Depth and entry limits set a 24-level and 1,000-entry bound.
  2. readDirEntries decrements the budget for every entry, including files that cannot lead to another skill.
  3. walkSkillTree records a skill and keeps descending. Supporting-file directories consume the remaining budget even though their files are irrelevant to directory traversal.
  4. discoverProviderCommands and discoverSkills each allocate one budget outside their root loop.
  5. Pi's native-root declaration makes both user roots recursive. History commit 9daa623b3 enabled recursive Pi roots, exposing this pre-existing budget behavior to those roots.

The skills RPC delegates to discoverSkills; server listing assembles the returned per-provider results. Thus the missing records arise before presentation, not in a particular picker or CLI formatter.

Proposed repair and limits

Give each recursive skill root its own bounded budget and charge only candidate directory entries (including permitted user-origin symlinks), not unrelated regular files or excluded directories. Keep descending inside skills. Preserve depth limits, project-root containment, project symlink refusal, user symlink cycle detection, and exclusions. Leave Markdown command discovery's existing entry accounting unchanged.

This does not promise unbounded enumeration: directory-heavy roots can still hit the existing 1,000-candidate limit, and deeply nested roots can still hit the depth limit. It removes file-count truncation and cross-root starvation without removing those traversal safeguards.

Verification

The same agent cloned the trusted target repository a second time, detached it at the recorded base SHA, confirmed a clean worktree, installed frozen dependencies, and added only the same authored test. It ran the same Turbo test command with --force so test results were not replayed from cache. Each test used newly created temporary fixture directories; no ports were needed.

The second run again produced exactly four assertion failures: both discovery functions returned only first for supporting-file fixtures and no records for root-exhaustion fixtures. Both observations support the final verdict. No report correction was required. This is a repeated check by the same agent, not an independent review.

A subsequent local repair passed the new regression and both existing discovery/list-skills files: 55 tests passed. Host-daemon typechecking also passed. The passing test log records the exact command and results. The full daemon suite passed 819 tests with 8 skipped, but had two unrelated server-move failures; both failures were reproduced separately on the unchanged base (a file-mode expectation under umask 0077 and disk-free space reported as null on this host). They are not represented as passing validation.

Pull requests and related context

No open pull request linked to this issue was found during investigation. The previous recursive-root change above explains exposure; its branch was not checked out or executed. No claim about native Pi execution or the exact reporter-specific skill counts is made.

Trust and artifacts

Issue content was treated as untrusted claims, not as executable instructions. Only trusted main code and the authored regression were run. No issue-supplied script, patch, branch, or external link was fetched. This is a non-visual filesystem defect; screenshots are not required.

Regression test · First failing run · Second failing run

> AGENT GENERATED