← reports

#5364 · Pi discovery stops before nested skills

BugPriority: MediumEffort: Lowproviders · provider-piGitHub issue2026-10-11 · base 3aa5ef327093f2834f800370881ac0bed8f2d811

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

1. TL;DR

BB omits skills stored more than one directory below Pi skill roots from both skill and command discovery. The omission reproduces on the current trusted main commit, in two fresh checkouts with isolated temporary files. Repository-pinned Pi loads the same nested and linked-bundle fixtures, keeps them manual-only, and excludes them from its automatic prompt. A top-level link makes BB discover the unchanged skill. Simply enabling recursive root declarations is not a safe complete fix: it recovers real nested directories but still misses linked bundles and removes previously working top-level user links.

2. Claims vs findings

ClaimStatusEvidence
Nested skills are missing in BB discovery.VerifiedBoth inventories are empty for every nested fixture on trusted main.
A top-level link makes the unchanged skill visible.VerifiedNative comparison reports BB skill/command counts changing from 0/0 to 1/1.
Configured and relocated roots have the same omission.VerifiedThe regression matrix exercises both resolver variants, not just source inspection.
A linked bundle behaves differently in Pi and BB.VerifiedPi loads one skill through the bundle link; BB discovers zero.
Manual-only metadata explains the omission.Refuted for this fixtureThe same file becomes discoverable through the top-level link; Pi reports its manual flag true and prompt empty.
The exact installed macOS versions and custom provider behave identically.Unverified hereThis investigation uses Linux source checkouts and the built-in Pi declarations; no custom fork, installed desktop, or Pi 1.1.0 was executed.

3. Environment

4. Minimal reproduction

  1. Check out the pinned public main commit, install the existing lockfile, and build.
  2. Save the complete regression test below as tests/integration/native-roots-golden/pi-nested-skills.test.ts and the complete native comparison as native-comparison.mjs at the repository root.
  3. Run the focused Turbo test and the native comparison using these commands:
git clone https://github.com/get-bb/bb.git bb-5364
cd bb-5364
git checkout 3aa5ef327093f2834f800370881ac0bed8f2d811
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
pnpm exec turbo run test --filter=@bb/integration-tests -- --project=@bb/integration-tests:native-roots-golden native-roots-golden/pi-nested-skills.test.ts
node --conditions=source --import tsx native-comparison.mjs

Expected bug-free result: all eight tests pass and BB discovers the nested leaf in both inventories. Actual trusted-base result: exit 1, 7 failed | 1 passed (8); each nested case fails with AssertionError: expected [] to include 'probe-leaf'. The passing control is the top-level user directory link.

Native comparison exits 0 and produces:

{"layout":"real-nested","nativeSkills":1,"nativeManualOnly":true,"nativeModelPromptEmpty":true,"bbSkills":0,"bbCommands":0}
{"layout":"linked-bundle","nativeSkills":1,"nativeManualOnly":true,"nativeModelPromptEmpty":true,"bbSkills":0,"bbCommands":0}
{"layout":"top-level-link","nativeSkills":1,"nativeManualOnly":true,"nativeModelPromptEmpty":true,"bbSkills":1,"bbCommands":1}

Seven nested cases cover the two declared user roots, two declared project roots, configured roots, relocated roots, and a linked bundle. The fixture contains a manual-only flag and inert text; no agent executes it.

Focused regression test

import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { pipeline } from "./pipeline.js";

let fixtureRoot: string;
let homeDir: string;
let cwd: string;

beforeEach(async () => {
  fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "pi-discovery-check-"));
  homeDir = path.join(fixtureRoot, "home");
  cwd = path.join(fixtureRoot, "workspace");
  await fs.mkdir(homeDir, { recursive: true });
  await fs.mkdir(path.join(cwd, ".git"), { recursive: true });
  vi.stubEnv("PI_CODING_AGENT_DIR", "");
});

afterEach(async () => {
  vi.unstubAllEnvs();
  await fs.rm(fixtureRoot, { recursive: true, force: true });
});

async function writeSkill(directory: string): Promise<void> {
  await fs.mkdir(directory, { recursive: true });
  await fs.writeFile(
    path.join(directory, "SKILL.md"),
    "---\nname: probe-leaf\ndescription: Discovery fixture.\ndisable-model-invocation: true\n---\nFixture content.\n",
  );
}

it.each([
  "user-pi",
  "user-agents",
  "project-pi",
  "project-agents",
  "configured",
  "relocated",
  "linked-bundle",
])("discovers nested Pi skills from %s", async (variant) => {
  let skillRoot = path.join(homeDir, ".pi", "agent", "skills");
  if (variant === "user-agents") {
    skillRoot = path.join(homeDir, ".agents", "skills");
  } else if (variant === "project-pi") {
    skillRoot = path.join(cwd, ".pi", "skills");
  } else if (variant === "project-agents") {
    skillRoot = path.join(cwd, ".agents", "skills");
  } else if (variant === "configured") {
    skillRoot = path.join(fixtureRoot, "configured-skills");
    const agentDir = path.join(homeDir, ".pi", "agent");
    await fs.mkdir(agentDir, { recursive: true });
    await fs.writeFile(
      path.join(agentDir, "settings.json"),
      JSON.stringify({ skills: [skillRoot] }),
    );
  } else if (variant === "relocated") {
    const agentDir = path.join(fixtureRoot, "relocated-agent");
    vi.stubEnv("PI_CODING_AGENT_DIR", agentDir);
    skillRoot = path.join(agentDir, "skills");
  }
  if (variant === "linked-bundle") {
    const bundleRoot = path.join(fixtureRoot, "bundle");
    await writeSkill(path.join(bundleRoot, "collection", "probe-leaf"));
    await fs.mkdir(skillRoot, { recursive: true });
    await fs.symlink(bundleRoot, path.join(skillRoot, "bundle"), "dir");
  } else {
    await writeSkill(path.join(skillRoot, "bundle", "probe-leaf"));
  }

  const result = await pipeline({ providerId: "pi", homeDir, cwd });
  console.info(
    JSON.stringify({
      variant,
      skills: result.skills.map((skill) => skill.name),
      commands: result.commands.map((command) => command.name),
    }),
  );
  expect(result.skills.map((skill) => skill.name)).toContain("probe-leaf");
  expect(result.commands.map((command) => command.name)).toContain(
    "probe-leaf",
  );
});

it("preserves discovery of a top-level user skill directory link", async () => {
  const target = path.join(fixtureRoot, "external", "probe-leaf");
  await writeSkill(target);
  const skillRoot = path.join(homeDir, ".pi", "agent", "skills");
  await fs.mkdir(skillRoot, { recursive: true });
  await fs.symlink(target, path.join(skillRoot, "probe-leaf"), "dir");

  const result = await pipeline({ providerId: "pi", homeDir, cwd });
  expect(result.skills).toEqual([
    expect.objectContaining({ name: "probe-leaf", linked: true }),
  ]);
  expect(result.commands.map((command) => command.name)).toContain(
    "probe-leaf",
  );
});

Native comparison script

import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import {
  formatSkillsForPrompt,
  loadSkills,
} from "./plugins/provider-pi/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.js";
import { pipeline } from "./tests/integration/native-roots-golden/pipeline.ts";

const fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "pi-native-compare-"));
const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
try {
  process.env.PI_CODING_AGENT_DIR = "";
  const homeDir = path.join(fixtureRoot, "home");
  const cwd = path.join(fixtureRoot, "workspace");
  const agentDir = path.join(homeDir, ".pi", "agent");
  const skillRoot = path.join(agentDir, "skills");
  const leaf = path.join(skillRoot, "bundle", "probe-leaf");
  await fs.mkdir(leaf, { recursive: true });
  await fs.mkdir(path.join(cwd, ".git"), { recursive: true });
  await fs.writeFile(
    path.join(leaf, "SKILL.md"),
    "---\nname: probe-leaf\ndescription: Discovery fixture.\ndisable-model-invocation: true\n---\nFixture content.\n",
  );
  for (const layout of ["real-nested", "linked-bundle", "top-level-link"]) {
    if (layout === "linked-bundle") {
      const externalBundle = path.join(fixtureRoot, "external-bundle");
      await fs.rename(path.join(skillRoot, "bundle"), externalBundle);
      await fs.symlink(externalBundle, path.join(skillRoot, "bundle"), "dir");
    }
    if (layout === "top-level-link") {
      await fs.symlink(
        path.join(fixtureRoot, "external-bundle", "probe-leaf"),
        path.join(skillRoot, "probe-leaf"),
        "dir",
      );
    }
    const native = loadSkills({
      cwd,
      agentDir,
      skillPaths: [skillRoot],
      includeDefaults: false,
    });
    const bb = await pipeline({ providerId: "pi", homeDir, cwd });
    console.log(JSON.stringify({
      layout,
      nativeSkills: native.skills.length,
      nativeManualOnly: native.skills.every((skill) => skill.disableModelInvocation),
      nativeModelPromptEmpty: formatSkillsForPrompt(native.skills) === "",
      bbSkills: bb.skills.length,
      bbCommands: bb.commands.length,
    }));
  }
} finally {
  if (previousAgentDir === undefined) {
    delete process.env.PI_CODING_AGENT_DIR;
  } else {
    process.env.PI_CODING_AGENT_DIR = previousAgentDir;
  }
  await fs.rm(fixtureRoot, { recursive: true, force: true });
}

5. Root cause

plugins/provider-pi/src/native-roots.ts (L14-L18) declares all four Pi roots as strings. packages/domain/src/native-roots.ts (L174-L184) normalizes strings to recursive: false. The configured/relocated resolver in plugins/provider-pi/src/native-roots.ts (L83-L94) also omits a recursive flag, which defaults false in the resolved-root contract.

user: [".pi/agent/skills", ".agents/skills"]
project: [".pi/skills", ".agents/skills"]
return { path: entry, recursive: false, ancestors: false, namePrefix: "" };

packages/domain/src/native-roots.ts (L315-L323) fills the resolved root's missing recursive value with false. apps/host-daemon/src/command-handlers/list-commands.ts (L142-L151) chooses a shallow skill root when recursion is false. apps/host-daemon/src/command-discovery.ts (L252-L280) only tests each immediate child directory for SKILL.md; it does not descend into a bundle. The shared native-root pipeline drives both skill records and command records, explaining the matching omissions.

A second mechanism makes a provider-only repair insufficient: apps/host-daemon/src/command-discovery.ts (L283-L309) skips every symlink while walking recursively. The shallow path deliberately follows user-origin skill links, unlike project-origin links. apps/host-daemon/src/command-discovery.ts (L313-L329) separately enforces the project boundary for recursive roots. These distinct trust rules must not be silently replaced while repairing Pi discovery.

6. Proposed fix and simple-fix check

Enable recursion for Pi's declared and resolved skill roots only together with a deliberate shared-scanner repair that preserves supported user links, canonical-file deduplication, cycle/entry/depth limits, and existing project containment. Keep manual-only prompt behavior unchanged; the comparison confirms that Pi itself handles it correctly, but no BB model turn was tested.

The smallest provider-only experiment changed one production file (9 additions + 2 deletions) and was tested after the regression's expected pre-fix failures. It produced 2 failed | 6 passed (8): real nested roots became discoverable, but the linked bundle remained absent and the previously passing top-level user-link control regressed. The existing 22 native-root golden tests still passed, demonstrating why they alone are insufficient.

The simple fix was stopped and reverted. No fix commit, push, or pull request was created. It cannot pass the focused regression, and completing the repair requires changing shared, security-sensitive symlink traversal rather than a contained provider declaration. That exceeds this rule's no-security-boundary-change safety constraint. The rejected experiment is included only as evidence, not as a recommended patch:

diff --git a/plugins/provider-pi/src/native-roots.ts b/plugins/provider-pi/src/native-roots.ts
index cd581f104..be3ba812a 100644
--- a/plugins/provider-pi/src/native-roots.ts
+++ b/plugins/provider-pi/src/native-roots.ts
@@ -12,8 +12,14 @@ export const PI_NATIVE_ROOTS_DECLARATION: Pick<
   "experimental_nativeSkillRoots" | "experimental_resolvesNativeRoots"
 > = {
   experimental_nativeSkillRoots: {
-    user: [".pi/agent/skills", ".agents/skills"],
-    project: [".pi/skills", ".agents/skills"],
+    user: [
+      { path: ".pi/agent/skills", recursive: true },
+      { path: ".agents/skills", recursive: true },
+    ],
+    project: [
+      { path: ".pi/skills", recursive: true },
+      { path: ".agents/skills", recursive: true },
+    ],
   },
   experimental_resolvesNativeRoots: true,
 };
@@ -87,6 +93,7 @@ export async function resolvePiNativeRoots(
           path: rootPath,
           origin: "user" as const,
           shape: "skills" as const,
+          recursive: true,
         })),
       },
       { warn: console.warn },

7. Verification

The same agent repeated the reproduction in a second freshly cloned checkout at exactly 3aa5ef327093f2834f800370881ac0bed8f2d811, with a separate frozen install and full build. No production patch was applied in that checkout; only the newly authored reproduction sources were copied. Every test allocated new temporary roots; no live ports or database directory were necessary.

pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
pnpm exec turbo run test --filter=@bb/integration-tests -- --project=@bb/integration-tests:native-roots-golden native-roots-golden/pi-nested-skills.test.ts
node --conditions=source --import tsx native-comparison.mjs

Build: 65 successful tasks
Focused regression: exit 1; 7 failed | 1 passed (8)
Native comparison: exit 0; identical three JSON rows to the first checkout

The second run supports the final verdict without correction. This is a repeat check by the same agent, not independent verification. Existing shared-scanner tests passed: 25 passed (25), including scan caps and symlink boundaries.

8. Pull requests and related issues

GitHub issue timeline metadata and an open-PR search found no linked open pull request during this investigation. No PR code was checked out or run. Other native-root defects exist, but no claim about their equivalence is needed for this direct reproduction.

9. Appendix and trust boundary

The issue was treated as untrusted evidence. Its scripts, suggested patch, external links, and fixture instructions were not executed or fetched. Test code was authored from trusted-main provider declarations and the existing host discovery pipeline. Only existing locked dependencies were installed; no dependency, protocol, stored data, packaging, or release change was made.

Trusted base, checkout one: Tests  7 failed | 1 passed (8)
Trusted base, checkout two: Tests  7 failed | 1 passed (8)
Declaration-only experiment: Tests  2 failed | 6 passed (8)
Existing native-root goldens with experiment: Tests  22 passed (22)
Existing host scanner suite on restored base: Tests  25 passed (25)
git diff --check: exit 0

The existing-suite commands were pnpm exec turbo run test --filter=@bb/integration-tests -- --project=@bb/integration-tests:native-roots-golden native-roots-golden/native-roots-golden.test.ts and pnpm exec turbo run test --filter=@bb/host-daemon -- command-discovery.test.ts. Raw logs remain private outside the public reports repository. Complete reproduction sources and exact native results are embedded above; no runtime data is published.