#5705 · Read-only runtime trees reject completed host artifacts
Verdict: REPRODUCED · Root-cause confidence: high.
Trusted base: ee36dfda7815e8c72672ab57e2bdb1b395ada9be from the public repository's main branch.
1. TL;DR
The enrolled-host artifact service rejects an otherwise successful build when its installed runtime has read-only directories. Its recursive copy preserves the chunk directory modes, so the temporary copy contains directories that its non-root owner cannot clean up. Real npm packing succeeds and the final tarball is present, but the awaited cleanup throws EACCES and overrides the return value. A retry rebuilds the package and leaves another temporary directory. This was reproduced at the real service boundary in two clean checkouts; the HTTP 500 consequence follows from the verified route mapping, not from a live enrollment test.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Read-only installed chunks lead to copied read-only directories. | Verified | Source fixture uses directories 0555 and files 0444. Copied chunk directories report mode 555 in both runs. |
| Cleanup fails after npm has already produced the artifact. | Verified | Real npm 11.16.0 completes. Final digest-named tarball exists and tar lists the nested chunk, but getArtifact rejects with EACCES. |
| Retries leave additional temporary packages. | Verified | One temporary directory after the first request; two after the retry, using the same service object. |
| The HTTP route responds with host_package_unavailable and 500. | Verified by source and existing route test; not a live request in this reproduction. | The route catches service rejection and explicitly maps EACCES to the permission diagnostic and HTTP 500. |
| The same happens on NixOS, macOS, and an installed npm release. | Not directly retested | This experiment uses Linux, Node 22.19.0, and a minimal immutable-layout fixture. No Nix store, macOS, or release installation was used. |
| A downstream modification permits full machine enrollment. | Unverified | No reporter patch was executed. No machine was enrolled. |
3. Environment
- bb source: the exact trusted commit above; package manifest version 0.46.1.
- Linux x86_64, gVisor kernel 4.19.0; Node v22.19.0; repository-locked npm 11.16.0; esbuild 0.28.0.
- Two detached temporary worktrees, each freshly installed with the frozen lockfile and built through Turbo. Both builds completed all 67 tasks.
- The test child ran as an unprivileged numeric uid/gid. Writable control succeeded before the installed fixture was made read-only.
- No HTTP listener, browser, provider, production instance, credential, or imported store was used. Each test made a fresh isolated temporary data directory and removed it in its finally block.
4. Minimal reproduction
The script below is newly authored from the trusted artifact service and its existing fixture tests. It calls the actual exported service, uses real filesystem permissions and real npm pack, and asserts that both read-only requests should return artifacts. It does not implement a replacement copy or cleanup routine. Its existing command-runner seam only selects the repository-locked npm CLI in an accessible location; the production artifact materialization, digest, rename, and cleanup run unchanged.
- Obtain the trusted source and build it. Run the following Bash setup from a scratch directory. No external issue script or PR code is required.
git clone --branch main --single-branch https://github.com/get-bb/bb.git bb-5705
cd bb-5705
git checkout --detach ee36dfda7815e8c72672ab57e2bdb1b395ada9be
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
ARTIFACTS=$(mktemp -d /tmp/bb-artifact-repro.XXXXXX)
chmod 755 "$ARTIFACTS"
pnpm exec esbuild apps/server/src/services/install/bb-app-artifact.ts --bundle --platform=node --format=esm --conditions=source '--banner:js=import { createRequire as createBundledRequire } from "node:module"; const require = createBundledRequire(import.meta.url);' --outfile="$ARTIFACTS/artifact-under-test.mjs"
cp packages/bb-app/package.json "$ARTIFACTS/package.json"
cp -R packages/plugin-build/node_modules/npm/. "$ARTIFACTS/npm"
- Save this complete script as
repro.mjsin the artifacts directory. The public reports repository permits inline test code, not committed scripts or logs.
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { chmod, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { pathToFileURL } from "node:url";
import { promisify } from "node:util";
import { createBbAppArtifactService } from "./artifact-under-test.mjs";
const execute = promisify(execFile);
const manifestPath = process.argv[2];
const npmCliPath = process.argv[3];
assert.ok(process.getuid() !== 0, "Run this test without root privileges");
const root = await mkdtemp(join(tmpdir(), "bb-artifact-permissions-"));
const packageRoot = join(root, "installed");
const chunks = join(packageRoot, "host-daemon/dist/bb-chunks");
const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
async function setTreeMode(directory, writable) {
await chmod(directory, 0o755);
for (const entry of await readdir(directory, { withFileTypes: true })) {
const entryPath = join(directory, entry.name);
if (entry.isDirectory()) await setTreeMode(entryPath, writable);
else await chmod(entryPath, writable ? 0o644 : 0o444);
}
await chmod(directory, writable ? 0o755 : 0o555);
}
try {
await mkdir(join(chunks, "nested"), { recursive: true });
await mkdir(join(packageRoot, "dist"), { recursive: true });
await mkdir(join(packageRoot, "server/dist"), { recursive: true });
await writeFile(join(packageRoot, "package.json"), JSON.stringify(manifest));
for (const name of ["bb-app.js", "bb-host-daemon.js", "bb.js"]) {
await writeFile(join(packageRoot, "dist", name), "#!/usr/bin/env node\n");
}
for (const name of ["bb", "bb.cmd", "bb-parcel-watcher-child.mjs", "bb-plugin-host-worker.mjs", "bb-provider-bridge-worker.mjs", "daemon-bundle.mjs"]) {
await writeFile(join(packageRoot, "host-daemon/dist", name), "export {};\n");
}
await writeFile(join(chunks, "entry.js"), "export {};\n");
await writeFile(join(chunks, "nested/leaf.js"), "export {};\n");
const runner = async (command, args, cwd) => {
assert.equal(command, "npm");
const result = await execute(process.execPath, [npmCliPath, ...args], {
cwd,
env: { PATH: "/usr/local/bin:/usr/bin:/bin", HOME: root, npm_config_cache: join(root, "npm-cache"), npm_config_update_notifier: "false" },
});
return result.stdout;
};
const serviceFor = (dataDir) => createBbAppArtifactService({
dataDir,
commandRunner: runner,
serverEntryUrl: pathToFileURL(join(packageRoot, "server/dist/server.js")).href,
});
const control = await serviceFor(join(root, "control-data")).getArtifact();
assert.ok(control.size > 0);
console.log("writable control: artifact returned");
await setTreeMode(packageRoot, false);
const dataDir = join(root, "readonly-data");
const service = serviceFor(dataDir);
const failures = [];
for (const attempt of [1, 2]) {
try {
const artifact = await service.getArtifact();
assert.ok(artifact.size > 0);
console.log("readonly attempt " + attempt + ": artifact returned");
} catch (error) {
failures.push(error);
console.log("readonly attempt " + attempt + ": " + error.code + " during " + error.syscall);
}
const cache = join(dataDir, "install-cache");
const entries = await readdir(cache);
const leftovers = entries.filter((name) => name.startsWith("host-package-"));
const tarballs = entries.filter((name) => name.endsWith(".tgz"));
console.log("cache: " + tarballs.length + " tarball(s), " + leftovers.length + " temporary package(s)");
for (const leftover of leftovers) {
const mode = (await stat(join(cache, leftover, "host-daemon/dist/bb-chunks"))).mode & 0o777;
console.log("copied chunk directory mode: " + mode.toString(8));
}
if (tarballs.length > 0) {
const listing = await execute("tar", ["-tzf", join(cache, tarballs[0])]);
assert.ok(listing.stdout.includes("package/host-daemon/dist/bb-chunks/nested/leaf.js"));
console.log("tarball includes nested chunk: true");
}
}
assert.equal(failures.length, 0, "Read-only installation must return an artifact and clean its temporary package");
} catch (error) {
console.log("REGRESSION FAILED: " + error.message.split("\n")[0]);
process.exitCode = 1;
} finally {
await setTreeMode(root, true);
await rm(root, { recursive: true, force: true });
}
- Run the test without root filesystem privileges. The setup works as either a regular user or root; root uses setpriv for the child.
chmod -R a+rX "$ARTIFACTS"
RUNNER=()
if [ "$(id -u)" = 0 ]; then
RUNNER=(setpriv --reuid=65534 --regid=65534 --clear-groups)
fi
"${RUNNER[@]}" node "$ARTIFACTS/repro.mjs" "$ARTIFACTS/package.json" "$ARTIFACTS/npm/bin/npm-cli.js"
Expected: writable control and both read-only requests return nonempty artifacts, no temporary host-package directories remain, and the test exits 0.
Actual, first checkout (exit 1):
writable control: artifact returned readonly attempt 1: EACCES during rmdir cache: 1 tarball(s), 1 temporary package(s) copied chunk directory mode: 555 tarball includes nested chunk: true readonly attempt 2: EACCES during rmdir cache: 1 tarball(s), 2 temporary package(s) copied chunk directory mode: 555 copied chunk directory mode: 555 tarball includes nested chunk: true REGRESSION FAILED: Read-only installation must return an artifact and clean its temporary package
5. Root cause
materializePackagedHostPackage makes fresh writable parent directories but uses a recursive fs.cp for the chunk subtree without normalizing the copied directory write bits:
await cp(
join(hostDaemonSource, "bb-chunks"),
join(hostDaemonTarget, "bb-chunks"),
{ recursive: true },
);
For a 0555 source, the copied directories are also 0555. Deleting children requires write permission on their parent directories; owning the copied files is not enough. Depending on which recursive deletion reports first, Node exposes EACCES during unlink or rmdir. This variation does not change the cause.
buildArtifact packs and renames the completed artifact, then awaits removal of the temporary package in a finally block:
return { digest, path: artifactPath, size: artifactStats.size };
} finally {
if (temporaryHostPackageRoot !== undefined) {
await rm(temporaryHostPackageRoot, { force: true, recursive: true });
}
}
That rejection overrides the pending return. The service catch clears artifactPromise, so the next call starts another build instead of using the existing tarball. The download route converts the propagated permission error into HTTP 500 with code host_package_unavailable. force does not bypass operating-system permission checks.
6. Proposed fix and automation safety
Ensure that the service-owned temporary copy has owner-writable directories before its cleanup runs, without modifying the installed source or broadening permissions outside that temporary tree. Walk nested directories, not just the top-level chunk directory. Decide deliberately whether to normalize before packing or only before removal, because that affects packaged modes. Cleanup policy should not silently hide failed builds or create unbounded leftovers.
No automatic fix or PR: this rule excludes fixes that change permission handling or packaging. This defect concerns both copied permission modes and host-package preparation, so the simple-fix safety gate fails even though the likely edit is small. No production change, branch, commit, or push was made in get-bb/bb. The regression above is suitable evidence for a maintainer-authorized fix; a post-fix pass is not claimed.
No open PR linking to #5705 was found in the issue timeline or an open-PR search during this run.
7. Related issues
Repository search also surfaced #2343, another packaged-runtime execution problem. Its environment/command lookup symptoms are distinct from the observed post-pack filesystem cleanup failure here. No duplicate PR was created.
8. Verification
The same agent created a second clean detached worktree at the exact recorded base commit, ran a separate frozen install and full Turbo build, and rebundled the untouched artifact service from that checkout. The same newly authored test then ran under unprivileged credentials with a new isolated fixture and data directory. This is a second clean reproduction, not an independent review.
Actual, second checkout (exit 1):
writable control: artifact returned readonly attempt 1: EACCES during rmdir cache: 1 tarball(s), 1 temporary package(s) copied chunk directory mode: 555 tarball includes nested chunk: true readonly attempt 2: EACCES during unlink cache: 1 tarball(s), 2 temporary package(s) copied chunk directory mode: 555 copied chunk directory mode: 555 tarball includes nested chunk: true REGRESSION FAILED: Read-only installation must return an artifact and clean its temporary package
The second run supports the same root cause and outcome. The only correction to a too-specific hypothesis is that recursive cleanup can fail at rmdir or unlink; the syscall is not stable. Neither log claims that npm packing failed.
9. Appendix and limits
Relevant existing checks were run through pnpm exec turbo run test --filter=@bb/server -- test/app/bb-app-artifact.test.ts test/app/skeleton.test.ts: 2 test files passed, 30 tests passed; 9 Turbo tasks successful. Existing writable-layout and diagnostic-mapping tests pass, while the new read-only-layout regression fails on unchanged main. There is no post-fix result because the automation safety gate excludes the repair.
Both trusted production trees remain unchanged; git diff --check passes and git diff --numstat origin/main is empty. No binary changes were made. Local bundling is a deliberate investigation step; normal installs, builds, and existing tests use repository orchestration.
Root-cause links use the recorded commit and were checked against that source. No screenshots are appropriate for a filesystem/service bug. NixOS, macOS, a live HTTP server, and full machine enrollment remain outside the experiment. The report does not claim to validate the reported downstream fix.
Untrusted-data note: the issue contained executable examples and suggested actions. They were treated only as hypotheses. No issue-supplied code, patch, branch, URL, or instructions were executed or followed.
Raw evidence stays in local thread storage; only this self-contained HTML and report metadata are published.