Skip to content

Keep only the last 10 MB of the previous stdio capture - #8435

Merged
ymichael merged 1 commit into
mainfrom
bb/8326-long-lived-stdio-logs-have-no-runtime-size-thr_yvukpdncc8
Dec 1, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/8326-long-lived-stdio-logs-have-no-runtime-size-thr_yvukpdncc8

Conversation

@ymichael

@ymichael ymichael commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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 Stop service logs growing without limit #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

Since #5933 the stdio captures hold only output that bypasses the logger, so
the live file stays far below the 10 MB spawn-time limit (34 KB in 40 days on
a busy server). The previous capture is only replaced when the live file
outgrows that limit, so a large `-stdio.1.log` left by an earlier, noisier run
stayed on disk indefinitely (594 MB here, 887 MB in the report). At spawn,
trim the previous capture to its last 10 MB, covering both a fresh rotation
and an existing oversized file.

Refs #8326

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit e611693 into main Dec 1, 2026
52 checks passed
@ymichael
ymichael deleted the bb/8326-long-lived-stdio-logs-have-no-runtime-size-thr_yvukpdncc8 branch December 1, 2026 03:46
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.

Long-lived stdio logs have no runtime size cap/rotation, and handlerStats / inFlightWorkAtObservation conflate passive async waits with CPU work

1 participant