Skip to content

Stop service logs growing without limit - #5933

Merged
ymichael merged 4 commits into
mainfrom
cap-service-log-growth
Oct 20, 2026
Merged

ymichael merged 4 commits into
mainfrom
cap-service-log-growth

Conversation

@ymichael

@ymichael ymichael commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Two log caps were missing (#5821):

  1. The stdio capture files were a second, unrotated copy of every log line. @bb/logger sends each line to the rotating <component>.N.log file and, through pino-pretty, to stdout. Since Prevent terminal backpressure from blocking service logs #3394 the launcher points service stdout directly at the append-only server-stdio.log / host-daemon-stdio.log, so these files grew with all logging and never rotated (437 MB in the report, 562 MB on another Mac).
  2. The rotated logs did not honor their limit across restarts. pino-roll 4's limit.count only deletes files created by the current process. Every restart left the previous run's files behind (88 server.N.log + 81 host-daemon.N.log, 407 MB, on the same Mac with count: 5). pino-roll's removeOtherLogFiles is not a safe fix: it keeps the highest-numbered files, but pino-roll restarts numbering at 1 when a process starts on a day with no log files born yet. After an overnight restart it would delete the new active log and every later roll.

What changed

  • packages/logger: skip the pino-pretty stdout target when stdout is a plain file, which is exactly the launcher's capture. Terminals and pipes keep it: turbo does not give pnpm dev tasks a TTY, so an isTTY check would have blanked the dev console. The capture files now hold startup errors, crashes, and other output that bypasses the logger. Startup failures are written to stderr directly, so the installer's "see host-daemon-stdio.log" hint still applies.
  • packages/logger: when the logger starts, prune <component>.N.log files to the five most recently written, regardless of their numbers. Only exact <component>.<N>.log names match, so stdio captures, crash reports, and other components are untouched. Only the server and host daemon call createLogger, one process each per data directory, so no live file is pruned. pino-roll's per-process limit.count still bounds a long run.
  • packages/bb-app/src/logged-process.ts: when a capture file is over 10 MB as its service starts, rename it to <name>-stdio.1.log (replacing the previous one) before opening a fresh file. The child still writes directly to the file, so the Prevent terminal backpressure from blocking service logs #3394 backpressure protection is unchanged.
  • smoke-tarball.mjs now waits for "Host plugin worker ready" in host-daemon.N.log instead of the stdio capture.
  • Docs: bb-app README, docs/debugging-and-qa.md, the machines guide template, the web guide's "I need bb's logs" answer, and the bb-server help and startup line now point to the rotating logs.

There are no server/daemon wire changes.

How you verified

  • New tests, each failing before its fix and passing after:
    • @bb/logger: 8 server.N.log files from earlier runs, where low numbers are newer than high ones, are pruned at startup to the 5 most recently written, and server-stdio.log / other components' logs are left alone. This test also fails against pino-roll's removeOtherLogFiles.
    • @bb/logger: with stdout redirected to a file, nothing is echoed there and the line still lands in the rotating log.
    • bb-app: an oversized capture file is moved to -stdio.1.log at spawn, and the new file starts fresh.
  • pnpm exec turbo run test typecheck lint --filter='...[origin/main]': 188/189 tasks passed. The one failure, @bb/server "hot-reloads a source-layout builtin server", timed out under load and passes on its own. It does not read logs.
  • pnpm exec turbo run smoke:tarball --filter=bb-app passed, including the moved plugin-ready check.
  • Launched the built bb-app stack against a scratch data dir seeded with 7 backdated server.10x.log files and an 11 MB server-stdio.log: the old logs were pruned to 5, today's server.1.log was kept, the capture moved to server-stdio.1.log, the new server-stdio.log held only Node's SQLite ExperimentalWarning (169 bytes), and host-daemon-stdio.log was empty.
  • Overnight-restart repro (yesterday's server.100–104.log, then start and roll): with removeOtherLogFiles, the new server.1.log / server.2.log were deleted. With startup pruning, both survive.
  • Before the fix, a repro driving the real spawnLoggedProcess + createLogger through 8 restarts grew server-stdio.log linearly to 99 MB and left 9 rotated files despite count: 5.

User-visible change: tail -F ~/.bb/logs/*-stdio.log no longer shows routine activity. Use tail -F ~/.bb/logs/*.log or the desktop log viewer, which already reads the rotating files.

Fixes #5821

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 4 commits October 20, 2026 16:36
pino-roll's limit.count only deleted files created by the current
process, so every restart left the previous run's rotated logs behind
(88 server.N.log files on one Mac). Enable removeOtherLogFiles so each
component keeps its five newest rotated files.

The launcher's append-only server-stdio.log and host-daemon-stdio.log
had no cap at all. When one is over 10 MB as its service starts, rename
it to <name>-stdio.1.log, replacing the previous copy. The child still
writes directly to the file, preserving the backpressure protection.

Refs #5821

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The logger echoed every line to stdout through pino-pretty. Under the
bb-app launcher stdout is server-stdio.log or host-daemon-stdio.log, so
those files were an unrotated duplicate of the rotating application
logs and grew with all logging (562 MB on one Mac).

Skip the pretty stream when stdout is a plain file. Terminals and pipes
keep it, including turbo-run pnpm dev and the desktop app. The capture
files now hold startup errors, crashes, and other output that bypasses
the logger. The tarball smoke now waits for the host plugin worker in
host-daemon.N.log, and the docs point to the rotating logs.

Refs #5821

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pino-roll's removeOtherLogFiles keeps the highest-numbered files, but
pino-roll restarts numbering at 1 when a process starts on a day with
no log files born yet. After an overnight restart it deleted the new
active log and every later roll, keeping the previous day's files.

Prune <component>.N.log files when the logger starts instead, keeping
the five most recently written regardless of their numbers. pino-roll's
own per-process limit still bounds a long run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 35eacba into main Oct 20, 2026
48 checks passed
@ymichael
ymichael deleted the cap-service-log-growth branch October 20, 2026 23:57
ymichael added a commit that referenced this pull request Dec 1, 2026
## Human comments

## What was wrong

#5933 (Oct 20) stopped the logger from copying every line into
`server-stdio.log` / `host-daemon-stdio.log`. Since then those files
only collect output that bypasses the logger, so they grow very slowly.
On a busy server, the live `server-stdio.log` grew 34 KB in 40 days. The
launcher only replaces `<name>-stdio.1.log` when the live file is over
10 MB at spawn, which now practically never happens. A large `.1.log`
left by an earlier, noisier run therefore stays on disk indefinitely:
594 MB on my Mac (last written Oct 21) and 887 MB in the report.

## What changed

- `packages/bb-app/src/logged-process.ts`: at every spawn, the launcher
cuts `<name>-stdio.1.log` down to its last 10 MB, keeping the most
recent output. This covers both a fresh rotation, where the run that
just ended may have written far more than 10 MB, and an oversized file
left by an earlier run. The live file still rotates at spawn as before.
- Updated the stdio log description in `packages/bb-app/README.md`,
`docs/debugging-and-qa.md` and the `bb guide machines` template.

Departures from the issue's suggestions, based on measurements from a
server that had been up 23 h:

- **No runtime rotation.** Since #5933 the live capture grows by KBs per
month (38 KB in total across 80 dev data dirs), so piping or watching
the child's output costs more than it saves.
- **`handlerStats` unchanged.** It holds one counter record per plugin
and does not grow. It measures per-call latency, which is useful in its
own right (for example, a 109 s worktree creation). It is not presented
as CPU time.
- **`inFlightWorkAtObservation` unchanged.** It stayed at 16–20 frames
across 242 stall entries. Each stall entry already names the blocker in
`stallCauseCandidate` / `longestSynchronousWork`; that blocker was a
synchronous DB write in every entry I checked.

## How you verified

- Two regression tests in `packages/bb-app/test/logged-process.test.ts`:
- a 25 MB live capture is rotated, and the `.1.log` keeps exactly its
last 10 MB, ending with the last line written;
  - an orphaned 600 MB `.1.log` is trimmed to 10 MB.
- Both tests fail on the old code and pass with the fix.
- `pnpm exec turbo run test typecheck --filter=bb-app` passes (233
tests).
- Ran the fix against a copy of the real 594 MB orphan: it went from
594,062,408 bytes to 10,485,760, the final 200 bytes were unchanged, and
the new run's output was appended to the live file.

Fixes #8326

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
## Human comments

## What was wrong

get-bb#5933 (Oct 20) stopped the logger from copying every line into
`server-stdio.log` / `host-daemon-stdio.log`. Since then those files
only collect output that bypasses the logger, so they grow very slowly.
On a busy server, the live `server-stdio.log` grew 34 KB in 40 days. The
launcher only replaces `<name>-stdio.1.log` when the live file is over
10 MB at spawn, which now practically never happens. A large `.1.log`
left by an earlier, noisier run therefore stays on disk indefinitely:
594 MB on my Mac (last written Oct 21) and 887 MB in the report.

## What changed

- `packages/bb-app/src/logged-process.ts`: at every spawn, the launcher
cuts `<name>-stdio.1.log` down to its last 10 MB, keeping the most
recent output. This covers both a fresh rotation, where the run that
just ended may have written far more than 10 MB, and an oversized file
left by an earlier run. The live file still rotates at spawn as before.
- Updated the stdio log description in `packages/bb-app/README.md`,
`docs/debugging-and-qa.md` and the `bb guide machines` template.

Departures from the issue's suggestions, based on measurements from a
server that had been up 23 h:

- **No runtime rotation.** Since get-bb#5933 the live capture grows by KBs per
month (38 KB in total across 80 dev data dirs), so piping or watching
the child's output costs more than it saves.
- **`handlerStats` unchanged.** It holds one counter record per plugin
and does not grow. It measures per-call latency, which is useful in its
own right (for example, a 109 s worktree creation). It is not presented
as CPU time.
- **`inFlightWorkAtObservation` unchanged.** It stayed at 16–20 frames
across 242 stall entries. Each stall entry already names the blocker in
`stallCauseCandidate` / `longestSynchronousWork`; that blocker was a
synchronous DB write in every entry I checked.

## How you verified

- Two regression tests in `packages/bb-app/test/logged-process.test.ts`:
- a 25 MB live capture is rotated, and the `.1.log` keeps exactly its
last 10 MB, ending with the last line written;
  - an orphaned 600 MB `.1.log` is trimmed to 10 MB.
- Both tests fail on the old code and pass with the fix.
- `pnpm exec turbo run test typecheck --filter=bb-app` passes (233
tests).
- Ran the fix against a copy of the real 594 MB orphan: it went from
594,062,408 bytes to 10,485,760, the final 200 bytes were unchanged, and
the new run's output was appended to the live file.

Fixes get-bb#8326

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

host-daemon-stdio.log grows without limit (437 MB on one Mac)

1 participant