Repository navigation
bt-daemon: log through one rotating tracing subscriber - #288
Merged
Merged
Conversation
A spawned daemon's standard streams are appended to serve.log forever, and it reached gigabytes on long-lived installs. Once the log passes 10 MiB its newest 10 MiB are kept as serve.log.1 and it is truncated in place, both before a daemon is spawned and every minute while one runs. The running daemon writes through an inherited append handle, so truncation (rather than renaming the file away from that handle) works on every platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
BRAINTRUST_DAEMON_LOG_MAX_MB sets the limit in MiB (default 10). Both the spawning hook and the running daemon read it, so it is an environment variable rather than a serve flag the spawner cannot see. An unset, zero or unparsable value keeps the default, so the log stays bounded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Daemon tuning variables use the BT_TRACE_ prefix. The env prefix test now allows them by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Daemon tuning variables are declared in env.rs and read through crate::env like every other variable. AGENTS.md describes the BT_TRACE_ prefix for them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stephen Belanger (Qard)
requested review from
Abhijeet Prasad (AbhiPrasad) and
Andrew Kent (realark)
November 13, 2026 17:30
Member
|
what happens when |
The daemon installs one subscriber with two outputs: newline-delimited JSON to daemon.log at debug (BT_TRACE_LOG_LEVEL) and plain text to stderr at warn, or debug with --verbose (BT_TRACE_STDERR_LEVEL). Panics are logged through it too. Logs rotate by rename and reopen instead of copy and truncate, which lost the start of each generation and anything written between the copy and the truncate. daemon.log rotates in its writer when the next line would pass BT_TRACE_LOG_MAX_MB; serve.log, which now only receives stderr, is rotated by the hook before it spawns a daemon. Each rotation replaces <name>.1, and the two files together hold the latest log in order. Per-event "event received" and "event accepted" logs move to debug: at info they wrote two stderr lines for every hook event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the hand-written rotating writer with file-rotate. daemon.log is a size-limited FileRotate behind the subscriber's writer, and the hook rotates serve.log with the same configuration before spawning a daemon. Each keeps one earlier generation as <name>.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
I rewrote the PR so it just uses the tracing crate for everything and does a proper log rotation. It'll only grow up to the size limit before rotating, and rotating will overwrite the old contents. |
Abhijeet Prasad (AbhiPrasad)
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the fix for SDK-830. In the reported case,
serve.loghad grown to 2.2 GB. Every spawned daemon appended its stderr there forever, and the daemon logged twoinfolines for every hook event.Changes
One subscriber for the daemon.
bt trace daemonand the standaloneserveinstall a singletracingsubscriber with two outputs:daemon.login the data directory: newline-delimited JSON atdebug. Override withBT_TRACE_LOG_LEVEL.warn, ordebugwith--verbose, coloured only on a terminal. Override withBT_TRACE_STDERR_LEVEL.Both overrides use
RUST_LOGsyntax and are read throughenv.rs. An unusable value falls back to the default and logs a warning. Panics are also logged through the subscriber.Rotation via
file-rotate.daemon.logis aFileRotatethat rotates once it passesBT_TRACE_LOG_MAX_MB(default 10) and keeps one earlier generation asdaemon.log.1. It is passed straight to the subscriber as its writer.file-rotateaddsflate2, because its gzip support isn't optional, even though compression is off here.serve.logonly gets stderr now: warnings and anything printed before logging starts. Before spawning a daemon, the hook rotates it with the samefile-rotateconfiguration. Copy-and-truncate and the once-a-minute rotation task are removed. That approach lost the start of every generation, and anything written between the copy and the truncate.Quieter defaults. The per-event
event receivedandevent acceptedlogs move frominfotodebug.The global
tracingsubscriber can only be set once per process. Ifbtinstalls its own subscriber later, it needs to leave the daemon command alone. Otherwise the daemon warns and logs throughbt's subscriber.During a daemon handover, two processes can briefly write
daemon.logat the same time. If both rotate in that window, one generation can be replaced early.Tests
daemon.logkeeps exactly one rotated generation.serve.logrotates before a spawn.debugevents as JSON with their fields, while stderr gets only plain-text warnings.cargo fmt --checkpasses.🤖 Generated with Claude Code