Reports

#7810 · Platform-specific skill status hashes

BugPriority: LowEffort: Lowhost · cliGitHub issue2026-11-19

Verdict: REPRODUCED at the server API boundary · Root-cause confidence: high

Trusted main commit: 755a265098fa4c9269b9b79fce3a0b87dc8546e3. Both reproductions use this exact commit with only the regression test added, not a pull-request branch.

1. TL;DR

The server can call a byte-identical CLI skill installation outdated solely because its files have Windows-style modes rather than the source tree's POSIX modes. The skill-tree digest includes permissions, and the status service compares the daemon's installed digest directly with the server's source digest. A real server route, migrated SQLite database, real files and the existing RPC test boundary reproduce the mismatch twice. The proposed repair computes the expected digest in the connected daemon's platform semantics for status only. Neither the install manifest nor the host protocol needs to change.

2. Claims vs findings

ClaimFindingEvidence
Identical file content can be reported outdated on a Windows host.Verified at server boundaryBoth 0644 → 0666 and 0755 → 0666 fixtures return outdated; the installed files are copied without changing content.
The digest includes file mode and the daemon reads stat mode.VerifiedTrusted source excerpts below show both operations.
A successful native Windows install remains outdated in Settings.Not directly exercisedNo Windows machine or browser session was used. The test simulates only the daemon platform and RPC response; it runs the real server status endpoint.
Reinstalling fixes the mismatch.Not supported by mechanismA source/installed mode mismatch is sufficient even for newly copied files. Native repeat install was not run.
Paths or content corruption are required.Refuted for this reproductionRelative paths and bytes match; only file mode differs in the failing cases.

3. Environment and limits

4. Minimal reproduction

  1. On Linux/macOS, clone the trusted repository and check out the recorded commit:
    git clone https://github.com/get-bb/bb.git source
    cd source
    git checkout --detach 755a265098fa4c9269b9b79fce3a0b87dc8546e3
    pnpm install --frozen-lockfile --prefer-offline
  2. Replace apps/server/test/system/install-cli-skills.test.ts with the complete regression test file below. All production code stays unchanged.
  3. Run the normal Turbo test task, which builds its prerequisite test dependencies:
    pnpm exec turbo run test --filter=@bb/server -- test/system/install-cli-skills.test.ts
  4. Expected: all 13 tests pass. Actual: two Windows-mode matching-content cases fail with expected installed / received outdated; the other 11 pass. Mode numbers in Vitest names are decimal: 420 = 0644, 493 = 0755, 438 = 0666, 292 = 0444.

First checkout: verbatim failure excerpt

@bb/server:test:  FAIL  |@bb/server| test/system/install-cli-skills.test.ts > install cli skills > reports 'installed' on 'win32' for modes 420/438 with changed content false
@bb/server:test:  FAIL  |@bb/server| test/system/install-cli-skills.test.ts > install cli skills > reports 'installed' on 'win32' for modes 493/438 with changed content false
@bb/server:test: AssertionError: expected [ { hostId: 'host-mode-check', …(2) } ] to deeply equal [ { hostId: 'host-mode-check', …(2) } ]
@bb/server:test: 
@bb/server:test: - Expected
@bb/server:test: + Received
@bb/server:test: 
@bb/server:test:   [
@bb/server:test:     {
@bb/server:test:       "hostId": "host-mode-check",
@bb/server:test:       "hostName": "Test Host",
@bb/server:test: -     "status": "installed",
@bb/server:test: +     "status": "outdated",
@bb/server:test:     },
@bb/server:test:   ]
@bb/server:test: 
@bb/server:test:  ❯ test/system/install-cli-skills.test.ts:323:31
@bb/server:test:     321|           await readJson(response),
@bb/server:test:     322|         );
@bb/server:test:     323|         expect(body.machines).toEqual([
@bb/server:test:        |                               ^
@bb/server:test:     324|           { hostId: host.id, hostName: host.name, status },
@bb/server:test:     325|         ]);
@bb/server:test:  ❯ withTestHarness test/helpers/test-app.ts:430:12
@bb/server:test:  ❯ test/system/install-cli-skills.test.ts:273:7
@bb/server:test: 
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
@bb/server:test: 
@bb/server:test: 
@bb/server:test:  Test Files  1 failed (1)
@bb/server:test:       Tests  2 failed | 11 passed (13)
Complete regression test file
import { chmod, copyFile, mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import {
  systemCliSkillsStatusResponseSchema,
  systemInstallCliSkillsResponseSchema,
} from "@bb/server-contract";
import { readJson } from "../helpers/json.js";
import { registerHostRpcResponder } from "../helpers/host-rpc.js";
import { seedHost, seedHostSession } from "../helpers/seed.js";
import { withTestHarness, type TestAppHarness } from "../helpers/test-app.js";
import { resolveServerOwnedSkillCatalogEntries } from "../../src/services/skills/injected-skills.js";

async function writeBuiltinCliSkill(harness: TestAppHarness): Promise<void> {
  const skillDirectory = join(
    harness.deps.config.builtinSkillsRootPath,
    "bb-cli",
  );
  await mkdir(skillDirectory, { recursive: true });
  await writeFile(
    join(skillDirectory, "SKILL.md"),
    "---\nname: bb-cli\ndescription: Control bb from the CLI.\n---\n",
  );
}

async function expectedCliSkillTreeHash(
  harness: TestAppHarness,
): Promise<string> {
  const entry = (
    await resolveServerOwnedSkillCatalogEntries({
      builtinSkillsRootPath: harness.deps.config.builtinSkillsRootPath,
      dataDir: harness.deps.config.dataDir,
      logger: harness.deps.logger,
      skillTreeRegistry: harness.deps.skillTreeRegistry,
    })
  ).find(({ runtimeSource }) => runtimeSource.name === "bb-cli");
  if (entry?.runtimeSource.kind !== "tree") {
    throw new Error("The built-in bb-cli skill did not resolve to a tree");
  }
  return entry.runtimeSource.treeHash;
}

function installRequest(hostIds: string[]): Request {
  return new Request("http://localhost/api/v1/system/cli-skills/install", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ hostIds }),
  });
}

describe("install cli skills", () => {
  it("installs the built-in bb-cli tree on every requested machine", async () => {
    await withTestHarness(async (harness) => {
      await writeBuiltinCliSkill(harness);
      const laptop = seedHostSession(harness.deps, { id: "host-laptop" });
      const studio = seedHostSession(harness.deps, { id: "host-studio" });
      const responders = [laptop, studio].map(({ host, session }) =>
        registerHostRpcResponder(harness, {
          hostId: host.id,
          sessionId: session.id,
          handle: (request) => {
            expect(request.command).toMatchObject({
              type: "host.install_global_skills",
              skills: [{ name: "bb-cli", entryPath: "SKILL.md" }],
            });
            return {
              ok: true,
              result: {
                installations: [
                  { name: "bb-cli", path: `/home/${host.id}/.agents/skills` },
                ],
              },
            };
          },
        }),
      );

      const response = await harness.app.request(
        installRequest([laptop.host.id, studio.host.id]),
      );
      expect(response.status).toBe(200);
      const body = systemInstallCliSkillsResponseSchema.parse(
        await readJson(response),
      );
      expect(body.results.map((entry) => [entry.hostId, entry.ok])).toEqual([
        ["host-laptop", true],
        ["host-studio", true],
      ]);
      for (const responder of responders) {
        expect(responder.requests).toHaveLength(1);
      }
    });
  });

  it("reports a failing machine without dropping the one that worked", async () => {
    await withTestHarness(async (harness) => {
      await writeBuiltinCliSkill(harness);
      const laptop = seedHostSession(harness.deps, { id: "host-laptop" });
      const studio = seedHostSession(harness.deps, { id: "host-studio" });
      registerHostRpcResponder(harness, {
        hostId: laptop.host.id,
        sessionId: laptop.session.id,
        handle: () => ({
          ok: true,
          result: {
            installations: [{ name: "bb-cli", path: "/home/u/.agents/skills" }],
          },
        }),
      });
      registerHostRpcResponder(harness, {
        hostId: studio.host.id,
        sessionId: studio.session.id,
        handle: () => ({
          ok: false,
          errorCode: "install_failed",
          errorMessage: "disk is full",
        }),
      });

      const response = await harness.app.request(
        installRequest([laptop.host.id, studio.host.id]),
      );
      expect(response.status).toBe(200);
      const body = systemInstallCliSkillsResponseSchema.parse(
        await readJson(response),
      );
      const [installed, failed] = body.results;
      expect(installed).toMatchObject({ hostId: "host-laptop", ok: true });
      expect(failed).toMatchObject({ hostId: "host-studio", ok: false });
    });
  });

  it("rejects an unknown machine", async () => {
    await withTestHarness(async (harness) => {
      await writeBuiltinCliSkill(harness);

      const response = await harness.app.request(installRequest(["host-gone"]));
      expect(response.status).toBe(404);
    });
  });

  it("rejects an empty machine list", async () => {
    await withTestHarness(async (harness) => {
      await writeBuiltinCliSkill(harness);

      const response = await harness.app.request(installRequest([]));
      expect(response.status).toBe(400);
    });
  });

  it("maps each machine's reported hashes to a product status", async () => {
    await withTestHarness(async (harness) => {
      await writeBuiltinCliSkill(harness);
      const current = seedHostSession(harness.deps, { id: "host-current" });
      const stale = seedHostSession(harness.deps, { id: "host-stale" });
      const empty = seedHostSession(harness.deps, { id: "host-empty" });
      const expectedHash = await expectedCliSkillTreeHash(harness);
      const hashByHostId: Record<string, string | null> = {
        "host-current": expectedHash,
        "host-stale": "b".repeat(64),
        "host-empty": null,
      };
      for (const { host, session } of [current, stale, empty]) {
        registerHostRpcResponder(harness, {
          hostId: host.id,
          sessionId: session.id,
          handle: (request) => {
            expect(request.command).toMatchObject({
              type: "host.global_skills_status",
              names: ["bb-cli"],
            });
            return {
              ok: true,
              result: {
                entries: [
                  {
                    name: "bb-cli",
                    path: `/home/${host.id}/.agents/skills/bb-cli`,
                    treeHash: hashByHostId[host.id] ?? null,
                  },
                ],
              },
            };
          },
        });
      }

      const response = await harness.app.request("/api/v1/system/cli-skills");
      expect(response.status).toBe(200);
      const body = systemCliSkillsStatusResponseSchema.parse(
        await readJson(response),
      );
      expect(
        Object.fromEntries(
          body.machines.map((machine) => [machine.hostId, machine.status]),
        ),
      ).toEqual({
        "host-current": "installed",
        "host-stale": "outdated",
        "host-empty": "missing",
      });
    });
  });

  it("reports a machine with no daemon session as unknown", async () => {
    await withTestHarness(async (harness) => {
      await writeBuiltinCliSkill(harness);
      seedHost(harness.deps, { id: "host-offline" });

      const response = await harness.app.request("/api/v1/system/cli-skills");
      const body = systemCliSkillsStatusResponseSchema.parse(
        await readJson(response),
      );
      expect(body.machines).toEqual([
        { hostId: "host-offline", hostName: "Test Host", status: "unknown" },
      ]);
    });
  });

  it.skipIf(process.platform === "win32").each([
    {
      platform: "win32",
      sourceMode: 0o644,
      installedMode: 0o666,
      changed: false,
      status: "installed",
    },
    {
      platform: "win32",
      sourceMode: 0o755,
      installedMode: 0o666,
      changed: false,
      status: "installed",
    },
    {
      platform: "win32",
      sourceMode: 0o444,
      installedMode: 0o444,
      changed: false,
      status: "installed",
    },
    {
      platform: "win32",
      sourceMode: 0o644,
      installedMode: 0o666,
      changed: true,
      status: "outdated",
    },
    {
      platform: "win32",
      sourceMode: 0o644,
      installedMode: 0o444,
      changed: false,
      status: "outdated",
    },
    {
      platform: "linux",
      sourceMode: 0o644,
      installedMode: 0o666,
      changed: false,
      status: "outdated",
    },
    {
      platform: "darwin",
      sourceMode: 0o644,
      installedMode: 0o666,
      changed: false,
      status: "outdated",
    },
  ] as const)(
    "reports $status on $platform for modes $sourceMode/$installedMode with changed content $changed",
    async ({ platform, sourceMode, installedMode, changed, status }) => {
      await withTestHarness(async (harness) => {
        await writeBuiltinCliSkill(harness);
        const sourceFile = join(
          harness.deps.config.builtinSkillsRootPath,
          "bb-cli",
          "SKILL.md",
        );
        await chmod(sourceFile, sourceMode);
        const installedDirectory = join(
          harness.deps.config.dataDir,
          "installed-bb-cli",
        );
        await mkdir(installedDirectory);
        const installedFile = join(installedDirectory, "SKILL.md");
        await copyFile(sourceFile, installedFile);
        if (changed) {
          await writeFile(
            installedFile,
            "---\nname: bb-cli\ndescription: Changed content.\n---\n",
          );
        }
        await chmod(installedFile, installedMode);
        const installedTree =
          await harness.deps.skillTreeRegistry.readTree(installedDirectory);
        const { host, session } = seedHostSession(harness.deps, {
          id: "host-mode-check",
          platform,
        });
        registerHostRpcResponder(harness, {
          hostId: host.id,
          sessionId: session.id,
          handle: () => ({
            ok: true,
            result: {
              entries: [
                {
                  name: "bb-cli",
                  path: installedDirectory,
                  treeHash: installedTree.treeHash,
                },
              ],
            },
          }),
        });

        const response = await harness.app.request("/api/v1/system/cli-skills");
        expect(response.status).toBe(200);
        const body = systemCliSkillsStatusResponseSchema.parse(
          await readJson(response),
        );
        expect(body.machines).toEqual([
          { hostId: host.id, hostName: host.name, status },
        ]);
      });
    },
  );
});

The regression guards the externally observable status returned by the route. It uses no added production export or test-only hook. The RPC responder supplies a digest computed from a separate real installed directory rather than mocking the status decision. Existing coverage only compared arbitrary matching and stale hashes, so it missed cross-platform mode representation.

5. Root cause

The shared digest serializes relative path, file mode, size and content SHA. The daemon walks each installed tree and hashes the mode it can observe. The status service constructs one expected digest per skill from the source tree without considering which platform supplied the installed digest. Thus 0644 and 0666 yield different digests even when the bytes match.

packages/host-daemon-contract/src/skill-tree.ts:8

export function hashSkillTreeFiles(
  files: readonly HostDaemonSkillTreeFile[],
): string {
  const hash = createHash("sha256");
  hash.update("bb-skill-tree-v2");
  for (const file of [...files].sort((left, right) =>
    compareStringsByCodePoint(left.path, right.path),
  )) {
    hash.update("\0file\0");
    hash.update(file.path);
    hash.update("\0");
    hash.update(file.mode.toString(8));
    hash.update("\0");
    hash.update(String(file.sizeBytes));
    hash.update("\0");
    hash.update(file.sha256);
  }
  return hash.digest("hex");
}

apps/host-daemon/src/injected-skills.ts:354

      throw new Error(
        `Skill tree exceeds max file count ${MAX_STAGED_SKILL_FILES}: ${args.rootPath}`,
      );
    }
    const hashed = await hashFile(readPath);
    args.state.files.push({
      contentSha256: hashed.sha256,
      mode: entryStat.mode & 0o777,
      relativePath,
      sizeBytes: hashed.sizeBytes,
      sourcePath: readPath,
    });
  }
}

apps/host-daemon/src/injected-skills.ts:816

export async function hashInstalledSkillDirectory(args: {
  name: string;
  skillDirectoryPath: string;
}): Promise<string | null> {
  try {
    const tree = await collectSkillDirectory({
      boundaryPath: null,
      name: args.name,
      sourceRootPath: args.skillDirectoryPath,
      skillFilePath: path.join(args.skillDirectoryPath, SKILL_FILE_NAME),
    });
    return hashSkillTreeFiles(
      tree.files.map((file) => ({
        path: file.relativePath,
        mode: file.mode,
        sizeBytes: file.sizeBytes,
        sha256: file.contentSha256,
      })),
    );
  } catch {
    return null;
  }

apps/server/src/services/skills/global-skill-install.ts:78

function resolveMachineSkillStatus(args: {
  entries: HostGlobalSkillsStatusResult["entries"];
  skills: readonly HostInstallGlobalSkill[];
}): CliSkillMachineStatus {
  const expectedByName = new Map(
    args.skills.map((skill) => [skill.name, skill.treeHash]),
  );
  const relevant = args.entries.filter((entry) =>
    expectedByName.has(entry.name),
  );
  if (relevant.length === 0 || relevant.every((e) => e.treeHash === null)) {
    return "missing";
  }
  return relevant.every(
    (entry) => entry.treeHash === expectedByName.get(entry.name),
  )
    ? "installed"
    : "outdated";
}

The daemon's status operation covers both global destinations; the server's all-entries comparison means either destination with a mismatching digest can keep a host outdated.

apps/host-daemon/src/command-handlers/install-global-skills.ts:42

  command: CommandOf<"host.global_skills_status">,
  options: GlobalSkillsStatusOptions,
): Promise<HostDaemonOnlineRpcResult<"host.global_skills_status">> {
  const homeDir = options.homeDir ?? os.homedir();
  const entries = await Promise.all(
    command.names.flatMap((name) =>
      globalSkillPaths(homeDir, name).map(async (skillDirectoryPath) => ({
        name,
        path: skillDirectoryPath,
        treeHash: await hashInstalledSkillDirectory({
          name,
          skillDirectoryPath,
        }),
      })),
    ),
  );
  return { entries };

6. Proposed fix

Keep source hashes and install RPCs unchanged. For a connected win32 daemon, derive the expected status hash from the registered source files with writable modes represented as 0666 and read-only modes as 0444. Continue comparing exact source modes on Linux/macOS, and continue detecting changed content or read-only state. The daemon's already-available platform identifies which expected hash to use. No files are chmod'ed by this repair, no security or permission enforcement changes, and no wire or stored-data contract changes.

The regression table includes writable, executable and read-only source modes; changed content; unexpected read-only destination state; and Linux/macOS permission mismatch controls.

7. Verification: second clean checkout

The same agent repeated the reproduction in a second clean temporary clone at 755a265098fa4c9269b9b79fce3a0b87dc8546e3. This is a second clean run, not independent review. Only the test diff was applied. There were no pre-existing local changes, shared running app, reused database or network ports.

git clone --shared --no-checkout source verify
git -C verify remote set-url origin https://github.com/get-bb/bb.git
git -C verify checkout --detach 755a265098fa4c9269b9b79fce3a0b87dc8546e3
git -C source diff -- apps/server/test/system/install-cli-skills.test.ts > regression.patch
git -C verify apply ../regression.patch
cd verify
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run test --filter=@bb/server -- test/system/install-cli-skills.test.ts

Result: the same two expected failures, 11 passes, exit 1. No correction to the root-cause claim was needed.

@bb/server:test:  FAIL  |@bb/server| test/system/install-cli-skills.test.ts > install cli skills > reports 'installed' on 'win32' for modes 420/438 with changed content false
@bb/server:test:  FAIL  |@bb/server| test/system/install-cli-skills.test.ts > install cli skills > reports 'installed' on 'win32' for modes 493/438 with changed content false
@bb/server:test: AssertionError: expected [ { hostId: 'host-mode-check', …(2) } ] to deeply equal [ { hostId: 'host-mode-check', …(2) } ]
@bb/server:test: 
@bb/server:test: - Expected
@bb/server:test: + Received
@bb/server:test: 
@bb/server:test:   [
@bb/server:test:     {
@bb/server:test:       "hostId": "host-mode-check",
@bb/server:test:       "hostName": "Test Host",
@bb/server:test: -     "status": "installed",
@bb/server:test: +     "status": "outdated",
@bb/server:test:     },
@bb/server:test:   ]
@bb/server:test: 
@bb/server:test:  ❯ test/system/install-cli-skills.test.ts:323:31
@bb/server:test:     321|           await readJson(response),
@bb/server:test:     322|         );
@bb/server:test:     323|         expect(body.machines).toEqual([
@bb/server:test:        |                               ^
@bb/server:test:     324|           { hostId: host.id, hostName: host.name, status },
@bb/server:test:     325|         ]);
@bb/server:test:  ❯ withTestHarness test/helpers/test-app.ts:430:12
@bb/server:test:  ❯ test/system/install-cli-skills.test.ts:273:7
@bb/server:test: 
@bb/server:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
@bb/server:test: 
@bb/server:test: 
@bb/server:test:  Test Files  1 failed (1)
@bb/server:test:       Tests  2 failed | 11 passed (13)

8. Pull requests and related issues

Existing pull request 7811 — static review only

PR #7811 appeared during verification, after the initial open-PR and issue-timeline searches returned no results. Its GitHub metadata and diff were read as untrusted data; its branch was never checked out, built or run. The diff derives a Windows-mode digest from registered files, precomputes it before awaiting the status RPC, selects it using the connected daemon platform and preserves the original install manifest. It adds API-boundary Windows-mode and concurrent-rescan tests. This addresses the verified mechanism, including source-registry replacement during an in-flight RPC. No concrete blocking defect was identified in this limited static review; execution and CI validation of that PR are not claimed.

A separately authored local repair passed the regression and related suites, but no branch was pushed and no duplicate pull request was opened because #7811 already covers this issue. The verification results below apply to that local repair, not the PR branch.

Local repair proof

umask 0022
pnpm exec turbo run test --filter=@bb/server -- test/system/install-cli-skills.test.ts test/skills test/internal/internal-skill-trees.test.ts
Result: 10 test files passed; 123 tests passed.

pnpm exec turbo run lint typecheck --filter=@bb/server
Result: passed (the package's actual lint task is run separately below).

pnpm exec turbo run lint:type-aware --filter=@bb/server
Result: 0 warnings, 0 errors.

pnpm exec turbo run build --filter=@bb/server --filter=@bb/host-daemon
Result: passed.

git diff --check
Result: passed.

git diff --numstat origin/main
26  2  apps/server/src/services/skills/global-skill-install.ts
111 1  apps/server/test/system/install-cli-skills.test.ts
Total: 140 changed text lines across 2 files. No binary, generated, dependency, protocol or stored-data changes.

The initial broader test run under the shell's restrictive umask 0077 had one unrelated registry-skill test expecting a 0444 marker but observing 0400. Re-running with conventional umask 0022 passed all 123 tests without modifying that test or its implementation.

No external issue links, attachments or code were fetched or executed. The status comparison is distinct from symlink-creation or skill-distribution redesign problems; those were not required to reproduce this defect.

9. Appendix: execution and trust

Issue content was treated as untrusted claims, not instructions. All executed application code came from trusted origin/main plus the locally authored test and repair. No dependency was added. Source links above were checked against the recorded commit with git show.

Initial whole-monorepo build attempts failed before tests because plugin builds could not resolve the not-yet-built SDK runtime. Building SDK types alone did not resolve that runtime dependency. The normal server test task built the needed SDK runtime and other upstream test dependencies and then reached the two specific failing assertions. These prerequisite build failures are not the reproduced product bug.

Raw logs and local patches remain outside this public report repository. The full test and exact diagnostic excerpts are embedded above, as required by its publication policy. No visual screenshot is claimed or fabricated.