Skip to content

Prevent terminal backpressure from blocking service logs - #3394

Merged
ymichael merged 2 commits into
mainfrom
bb/investigate-server-hang-thr_wqgi65c282
Sep 10, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/investigate-server-hang-thr_wqgi65c282

Conversation

@ymichael

@ymichael ymichael commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The launcher forwarded service stdout from a data callback into process.stdout.write() and inherited terminal stderr. On macOS, a stalled terminal can block that synchronous write and stop the launcher from draining child output. A log burst can consequently freeze the service. Replacing the callback with pipe() still blocks in the terminal write; an isolated pseudo-terminal reproduction confirmed this.

What changed

Send both service stdout and stderr directly to private append-only server-stdio.log and host-daemon-stdio.log files in the selected logs directory. Apply this to full-stack launches and the standalone server and host-daemon commands, and remove the launcher output buffer and forwarding callbacks. Close the parent's log descriptor after spawning each child.

Update launcher help, the package README, debugging docs, CLI guide, and skill with the capture locations and tail -F usage. Existing application logs retain their rotation and remain the desktop log viewer's source. The new capture files append across restarts without automatic rotation. There are no server/daemon wire changes.

How you verified

  • pnpm exec turbo run smoke:tarball --filter=bb-app — passed locally, including full-stack startup and separate daemon enrollment. The smoke harness now checks each daemon capture file for its plugin-ready message and includes that output on failure.

  • pnpm exec turbo run test typecheck --filter=bb-app — passed; 79 tests across four files.

  • New real-child tests cover multi-megabyte stdout/stderr bursts without parent stream readers, file permissions, retained output across restarts and early failures, inaccessible log paths, and executable spawn failures.

  • Isolated macOS pseudo-terminal check: leave terminal output undrained, write 8 MiB across child stdout/stderr, and verify the child health endpoint responds and the launcher heartbeat advances. All 8,388,610 output bytes were captured.

  • git diff --check — passed. No production processes were restarted; desktop UI was not exercised.

AGENT GENERATED

@ymichael
ymichael merged commit 126888f into main Sep 10, 2026
16 checks passed
@ymichael
ymichael deleted the bb/investigate-server-hang-thr_wqgi65c282 branch September 10, 2026 17:31
ymichael added a commit that referenced this pull request Oct 20, 2026
## 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 #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 #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](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.

1 participant