#5821 · Unbounded append-only service capture files
Trusted base: 7e4232ef241b5cdfb7d272cee044fe6f82702c70
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro
1. TL;DR
The launcher captures each service's stdout and stderr in a separate append-only file. Unlike the structured application logs, these capture files have no size check, rotation, or restart retention limit. Using the exact production helper, a real child grew each service capture to 48 MiB while running and 64 MiB after one restart, with no backup files created. A second clean checkout produced identical results. The issue affects both server and host-daemon captures and does not require multiple servers or a particular warning message.
2. Claims vs findings
| Reported claim | Finding | Evidence |
|---|---|---|
| Service capture grows without rotation, including across restarts. | Verified | Both real-child runs: 16 → 32 → 48 MiB while running; 64 MiB after restart; only one file per service. |
| Application logs rotate separately. | Verified configuration | The logger configures pino-roll with a daily frequency, a 10m size option, and a count limit of five. The capture helper does not use that transport. |
| A particular Mac capture reached approximately 437 MB. | Unverified historical measurement | No access to the reporter's files; the mechanism is reproduced, not that exact disk state. |
| Thousands of older files accumulated in the same directory. | Unverified; not explained by this capture helper | This helper opens one fixed path per service and creates no rotated files. A separate inventory/retention investigation would be needed. |
| A repeating warning caused the growth. | Warning-specific claim unverified | The capture layer accepts all stdout/stderr bytes. Reproduction uses deterministic writes to isolate storage behavior rather than the warning source. |
| Deleting the pathname is a complete workaround. | Unsafe to assume for a live process | The child keeps the open descriptor. The rename probe continued writing to the original inode and left the replacement empty. Removing a live file can leave its disk blocks held until the service closes that descriptor. |
3. Environment
- Public target repository:
get-bb/bb; base commit recorded above, fetched from the trusted upstream main branch. - Linux x64; Node
v22.19.0. No macOS or desktop-session verification was performed. - Two separate clean detached checkouts at the same base, each with a frozen pnpm install and normal Turbo build.
- No provider session, server, host enrollment, or real user data was used. No ports were opened.
- Each invocation created a new temporary directory and deleted it after closing all test children.
- Both full builds passed: 67 tasks each. Existing capture suite passed: five tests.
4. Minimal reproduction
- Prepare the trusted checkout and dependencies:
git clone https://github.com/get-bb/bb.git bb-capture-check cd bb-capture-check git checkout --detach 7e4232ef241b5cdfb7d272cee044fe6f82702c70 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build
- Save the complete script below as
capture-growth.mjsin the checkout. It calls the production helper without modifying it, checks that both child descriptors are regular files, writes 8 MiB per stream per batch, and measures the file before stopping the child. - Run:
node --import tsx capture-growth.mjs . pnpm exec turbo run test --filter=bb-app -- test/logged-process.test.ts
Expected storage property: an explicitly bounded retention policy should eventually stop one active capture from retaining every byte indefinitely, while preserving useful recent diagnostics. This report does not invent a new numeric product limit.
Actual: every batch is appended intact, the same capture remains after restarting, and no retention machinery runs. Each capture retained all 67,108,864 bytes. Finite execution alone cannot prove infinite growth; the absence of any limiting branch in the actual write path explains why these observations continue.
Complete repeatable evidence script
import assert from "node:assert/strict";
import { once } from "node:events";
import { mkdtempSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
const checkout = resolve(process.argv[2] ?? ".");
const { spawnLoggedProcess } = await import(pathToFileURL(join(checkout, "packages/bb-app/src/logged-process.ts")));
const scratch = mkdtempSync(join(tmpdir(), "bb-capture-growth-"));
const children = new Set();
const batchBytes = 16 * 1024 * 1024;
const childSource = `
const assert = require("node:assert/strict");
const { fstatSync, writeSync } = require("node:fs");
assert(fstatSync(1).isFile());
assert(fstatSync(2).isFile());
const chunk = Buffer.alloc(1024 * 1024, 120);
process.on("message", (message) => {
if (message === "stop") {
process.disconnect();
return;
}
for (const descriptor of [1, 2]) {
for (let index = 0; index < 8; index++) {
let offset = 0;
while (offset < chunk.length) {
offset += writeSync(descriptor, chunk, offset, chunk.length - offset);
}
}
}
process.send("written");
});
process.send("ready");
`;
async function start(logDir, logName) {
const child = spawnLoggedProcess({
command: process.execPath,
args: ["-e", childSource],
env: {},
ipc: true,
logDir,
logName,
});
children.add(child);
assert.deepEqual(await once(child, "message"), ["ready", undefined]);
return child;
}
async function writeBatch(child) {
const message = once(child, "message");
child.send("write");
assert.equal((await message)[0], "written");
}
async function stop(child) {
const closed = once(child, "close");
child.send("stop");
assert.deepEqual(await closed, [0, null]);
children.delete(child);
}
const timeout = setTimeout(() => {
for (const child of children) child.kill("SIGKILL");
process.exitCode = 1;
}, 30_000);
try {
console.log(`environment: ${process.platform} ${process.arch} node ${process.version}`);
for (const logName of ["host-daemon", "server"]) {
const logDir = join(scratch, logName);
const logPath = join(logDir, `${logName}-stdio.log`);
const child = await start(logDir, logName);
for (let batch = 1; batch <= 3; batch++) {
await writeBatch(child);
const size = statSync(logPath).size;
assert.equal(size, batch * batchBytes);
console.log(`${logName} running batch ${batch}: ${size} bytes`);
}
await stop(child);
const restarted = await start(logDir, logName);
await writeBatch(restarted);
await stop(restarted);
assert.equal(statSync(logPath).size, 4 * batchBytes);
assert.deepEqual(readdirSync(logDir), [`${logName}-stdio.log`]);
console.log(`${logName} after restart: ${statSync(logPath).size} bytes; files: ${readdirSync(logDir).join(", ")}`);
}
const logDir = join(scratch, "rename-probe");
const logPath = join(logDir, "host-daemon-stdio.log");
const child = await start(logDir, "host-daemon");
await writeBatch(child);
renameSync(logPath, `${logPath}.1`);
writeFileSync(logPath, "");
await writeBatch(child);
await stop(child);
assert.equal(statSync(`${logPath}.1`).size, 2 * batchBytes);
assert.equal(statSync(logPath).size, 0);
console.log(`rename probe: renamed file ${statSync(`${logPath}.1`).size} bytes; replacement ${statSync(logPath).size} bytes`);
console.log("RESULT: both capture files grow without rotation while running and across restarts; rename alone does not redirect the child descriptors.");
} finally {
clearTimeout(timeout);
for (const child of children) {
const closed = once(child, "close");
child.kill("SIGKILL");
await closed;
}
rmSync(scratch, { recursive: true, force: true });
}
Verbatim output from both runs
environment: linux x64 node v22.19.0 host-daemon running batch 1: 16777216 bytes host-daemon running batch 2: 33554432 bytes host-daemon running batch 3: 50331648 bytes host-daemon after restart: 67108864 bytes; files: host-daemon-stdio.log server running batch 1: 16777216 bytes server running batch 2: 33554432 bytes server running batch 3: 50331648 bytes server after restart: 67108864 bytes; files: server-stdio.log rename probe: renamed file 33554432 bytes; replacement 0 bytes RESULT: both capture files grow without rotation while running and across restarts; rename alone does not redirect the child descriptors.
Both invocations exited zero. These assertions validate the observed defect mechanism; they are not a passing regression test for a fix.
5. Root cause
The service launcher calls spawnLoggedProcess for managed services. That helper opens one capture path in append mode and hands the descriptor directly to the child's two output streams:
const fd = openSync(
join(args.logDir, `${args.logName}-stdio.log`),
"a",
0o600,
);
try {
return spawn(args.command, args.args, {
cwd: process.cwd(),
env: args.env,
stdio: args.ipc === true ? ["ignore", fd, fd, "ipc"] : ["ignore", fd, fd],
});
} finally {
closeSync(fd);
}
Complete helper at the trusted base. The parent closes its copy after spawning; the child's copies remain open. There is no size check before opening, no live accounting, and no reopen or rotation hook. Restarting opens the same pathname with append semantics.
Structured logging is a separate sink: pino-roll receives the application file while pino-pretty also emits console output. Rotation in that transport does not rotate the launcher's stdout/stderr descriptor.
The direct-file design was intentional: the earlier backpressure repair removed parent/terminal forwarding to prevent service freezes. The current capture tests protect direct regular-file descriptors and output retention across restarts; they do not check a storage bound. Debugging guidance accurately documents the append-across-restarts behavior.
6. Proposed fix and simple-fix gate
Introduce bounded capture retention for the shared helper, with explicit handling of a continuously running child, restart retention, diagnostics on capture failure, and shutdown. Preserve the property that terminal or parent-output backpressure cannot block a service. Add a failing-before/passing-after regression at the real-child boundary once the retention contract is selected.
A rename at startup cannot bound a long-lived writer. A periodic rename and fresh pathname also cannot redirect the already-open child descriptors: the probe leaves the new file at zero bytes while the renamed file grows to 32 MiB. Routing through a parent stream would remove the direct-file protection; truncating in place discards retained diagnostics and needs an explicit loss/retention policy. These are design choices, not a safe mechanical patch.
No pull request: the rule forbids fixes requiring a product or architecture decision. Safe live capture rotation requires a retention/reopen design that preserves the existing backpressure guarantee. No production change or fix branch was made, so no red/green fix claim is made. No open pull request linked to this issue was found in cross-reference metadata or an open-PR search at investigation time.
7. Related issues
#5822 concerns recurring host-daemon warnings and was found through the repository's host-label issue listing. Warning frequency is a separate amplifier, not necessary for this capture-layer reproduction. Fixing one warning would not impose a capture storage bound.
8. Verification
The same investigator repeated the complete script in a second newly created detached checkout at 7e4232ef241b5cdfb7d272cee044fe6f82702c70, after a separate frozen install and normal build. This is a second clean run, not an independent review. The verification checkout was clean before and after the script. The same script source was used, but it created new children and a fresh temporary log directory.
pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build node --import tsx /path/to/capture-growth.mjs . pnpm exec turbo run test --filter=bb-app -- test/logged-process.test.ts
Both capture names again grew 16 → 32 → 48 → 64 MiB, with identical verbatim output above. The descriptor-renaming probe again wrote to the old inode. Existing capture tests passed, including the no-parent-reader contract. No report conclusion required correction. The historical Mac measurements remain explicitly unverified.
9. Appendix
Relevant check results
First trusted checkout build: Tasks: 67 successful, 67 total Cached: 4 cached, 67 total Second clean checkout build: Tasks: 67 successful, 67 total Cached: 65 cached, 67 total Existing capture suite: ✓ |bb-app| test/logged-process.test.ts (5 tests) Test Files 1 passed (1) Tests 5 passed (5)
Frozen installs emitted missing local-bin warnings before build outputs existed; both installs and both full builds succeeded. This is a unit-level reproduction at the actual production spawn boundary, not a reproduction of an entire macOS desktop enrollment or the original warning source.
Investigation commands
git fetch https://github.com/get-bb/bb.git main:refs/remotes/origin/main git rev-parse origin/main git worktree add --detach /path/to/base-checkout 7e4232ef241b5cdfb7d272cee044fe6f82702c70 git worktree add --detach /path/to/verification-checkout 7e4232ef241b5cdfb7d272cee044fe6f82702c70 git log origin/main -- packages/bb-app/src/logged-process.ts git show 126888fad62ea4250b9f8c19de5aaf314ede4d65 -- packages/bb-app/src/logged-process.ts packages/bb-app/test/logged-process.test.ts gh pr list --repo get-bb/bb --state open --search '5821 in:body' --json number,title,url git status --short
GitHub GraphQL reads checked repository visibility, issue properties, comments, and cross-referenced PR metadata. The issue had no comments. Issue data was used only as untrusted claims; no supplied command, external issue link, or linked branch was executed. All runtime source came from the trusted base. No application or database was started, and the reproduction cleaned up every temporary child and log directory.
The complete script and outputs are inline because this public reports repository forbids separately committed scripts, logs, and per-issue artifact directories.