fix: keep managed runs fail-open when nothing was traced - #22
Merged
Conversation
Stephen Belanger (Qard)
force-pushed
the
fix/managed-run-fail-open
branch
from
August 14, 2026 18:54
f0e6cde to
0d77cfe
Compare
`run_traced` bailed when a managed run flushed zero accepted sessions, which discarded the wrapped agent's `ExitStatus` and turned a successful agent into a failed `bt trace run`. Tracing is fail-open everywhere else in this repo — hooks are thin fail-open launchers, and a flush that times out or fails outright only warns — so a flush that succeeds and honestly reports nothing should not be the one fatal case. Zero accepted sessions now logs at warn like its siblings and the child's exit status is returned unchanged. Legitimate zero-event runs exist: `bt trace run codex -- --version` never opens a session, and Ctrl-C before the first turn reaches the same flush. The message stays a `tracing` diagnostic rather than going to stderr. A managed run wraps an interactive agent, so the integration should record what it could not trace without printing into that agent's terminal. Extends the managed-run exit-status test with an agent that emits no hook events at all, asserting that both a success and a failure pass through untouched. That test fails against the previous behavior. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Stephen Belanger (Qard)
force-pushed
the
fix/managed-run-fail-open
branch
from
August 14, 2026 19:00
0d77cfe to
14a0450
Compare
Stephen Belanger (Qard)
requested review from
Abhijeet Prasad (AbhiPrasad) and
Andrew Kent (realark)
August 14, 2026 19:01
Abhijeet Prasad (AbhiPrasad)
approved these changes
Aug 14, 2026
Andrew Kent (realark)
approved these changes
Aug 14, 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.
run_tracedbails when a managed run flushes zero accepted sessions:That
bail!meansstatusis never returned, so the wrapped agent'sExitStatusis discarded. Abt trace runwhose agent succeeded exits non-zero whenever tracing happened to record nothing. Intrace_runtime.rstheRunarm doesrun_traced(...).await?and only then checksstatus.success(), so the?swallows a perfectly good run before its status is ever examined.It's also inconsistent with its own neighbors: a flush that times out or fails outright only warns, while a flush that succeeds and honestly reports nothing is the single fatal case. That inverts the severity, and it cuts against the fail-open design this repo states for tracing ("Plugin hooks are thin fail-open shell launchers").
Legitimate zero-event runs exist —
bt trace run codex -- --versionnever opens a session, and Ctrl-C before the first turn reaches the same flush.Change
Zero accepted sessions now logs at
warnlike its siblings, and the child's exit status is returned unchanged. All four arms are consistent: record what could not be traced, then fall through to the child's own outcome.It stays a
tracingdiagnostic rather than going to stderr. A managed run wraps an interactive agent, and the integration should stay out of that agent's terminal — this is debug information for whoever is diagnosing the daemon, not guidance the user needs mid-session.Worth noting separately: when this runtime is embedded in
bt, none of these warnings are visible, becausebtnever installs atracingsubscriber outside the daemon command (init_daemon_loggingis only called from theDaemonarm). That is pre-existing and applies equally to the two existing arms, so it is out of scope here — but if we want managed-run diagnostics to be reachable underbt, the fix is a subscriber onbt's side, not stderr writes from this crate.Testing
managed_run_flushes_after_success_failure_and_signal_exitalready asserted that success, failure, and signal statuses pass through — it only passed because its fake agent emits aSessionStarthook. Renamed tomanaged_run_flushes_and_preserves_agent_exit_statusand extended withuntraced-success/untraced-failuremodes whose agent emits no hook event at all, asserting both an exit 0 and an exit 7 survive untouched.Verified the new test fails against the previous behavior:
Full suite passes (
cargo test --manifest-path bt-daemon/Cargo.toml --all-features),cargo fmt --checkandclippyclean.Context
Found while bumping
bt's pin to latestmain(braintrustdata/bt#314). The bail arrived in 1f52bb0 (#21) alongside the managed-run acceptance accounting; that commit's message describes the persistence andRouteRequirementswork but doesn't mention making zero-accepted fatal, and the line had no test or doc coverage.🤖 Generated with Claude Code