Skip to content

fix: keep Core diagnostics out of the active workload terminal - #353

Merged
gautamsirdeshmukh merged 3 commits into
strands-agents:mainfrom
gautamsirdeshmukh:gsird-task/native-run-logs
Nov 9, 2026
Merged

gautamsirdeshmukh merged 3 commits into
strands-agents:mainfrom
gautamsirdeshmukh:gsird-task/native-run-logs

Conversation

@gautamsirdeshmukh

@gautamsirdeshmukh gautamsirdeshmukh commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Late MCP permission reports and other Core messages can overwrite the native agent screen. This affects runs with and without a CLI banner.

Keep startup disclosures before launch. Retain later Core messages until the workload and hosted services stop, while the agent keeps its original terminal streams. Piped Core messages remain live. Public APIs, flags, configuration, policy, and record formats are unchanged.

Type of Change

Bug fix

Testing

  • Three integration tests use real Core and MCP processes. They cover normal and nonzero exits, termination, native input and control bytes, startup disclosure order, and live piped output.

  • One isolated stderr test covers bounded retention, overflow draining and notice, restoration, cleanup on drop, and shutdown with a retained writer.

  • All four tests pass. Seven unit mutations and two integration mutations fail on the behaviors above. Restoring the code makes the tests pass again.

  • I ran the relevant suites (cargo test -p strands-box --all-features; baseline failure documented above).

  • I ran cargo fmt -p strands-box --check and cargo clippy -p strands-box --all-targets --all-features.

Demo

Screen.Recording.2026-11-09.at.10.48.59.AM.mov

Documentation

No guide changes. Commands and startup disclosures are unchanged.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added necessary tests that prove the fix works
  • I have reviewed the documentation impact
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem
Late Core reports share stderr with a native terminal workload and can overwrite its screen. Disabling a caller's banner does not prevent those writes.

## Solution
Keep the workload on its original terminal streams. Capture only Core stderr during terminal runs, drain it into bounded memory, and restore and replay it after hosted services stop. Leave piped output live. Update the config and architecture docs. No public API, policy, config, or record format changes.

## Tests
terminal_diagnostics_follow_successful_and_failed_agent_exits and terminal_diagnostics_survive_core_termination fail on the baseline and pass with the fix. piped_core_diagnostics_remain_live preserves piped behavior. Isolated diagnostics tests and mutation checks cover the retention bound, truncation notice, Drop restoration and inherited writers. Actual CLI probes pass with and without the banner, including native bytes, input, resize, idle silence, Ctrl-C and terminal restoration.

All-feature and no-default builds, Clippy and formatting pass on macOS. The Core suite has 1,259 passing tests and five existing ignored tests. The grammar test's copied false executable exits 137 on both this change and untouched base 028b2ff. Deterministic containment passes 129 cases with 12 declared Linux-only skips. The example runner has no scripted examples. Linux cross-checking requires a missing x86_64-linux-gnu-gcc; Linux runtime validation remains for CI. No model calls were made.
Comment thread crates/box/src/run/diagnostics.rs Resolved
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Comment

Deferring Core's stderr during a terminal run fixes the screen overwrite, and cleanup on every path is correct. The open questions are about which messages the 32 KiB limit throws away, and the process-wide fd 2 redirect for library callers.

Review Categories
  • Correctness/scope: The buffer keeps the first 32 KiB, so the workload can choose which later disclosures and failures get dropped. Library hosts have their own stderr captured.
  • Testing: The integration tests cover timing (before and after exit) but not overflow with a real Core. On x86_64 Linux the tests skip with no output (namespace_launcher_is_usable), so I could only run the run::diagnostics unit tests here. Both pass.
  • Residual: If Core is SIGKILLed or OOM-killed during a terminal run, every deferred message is lost. The architecture page could say so.

Checks that held:

  • Capture condition: interactive, 2>file, >file, and caller-pty runs each get the intended stream.
  • The agent still receives the original fd 2.
  • Startup grant disclosures still print before launch (root AGENTS.md "disclose each grant on stderr at startup").
  • MCP server stderr is Stdio::null(), so a server cannot fill the buffer.
  • Drop restores fd 2 and replays on error and panic paths ("cleanup is unconditional").
  • No diagnostic log file is created ("must not grow one").
  • shutdown(Write) stops descendants that kept fd 2 from blocking the replay.
  • A hosted failure is still returned and printed after fd 2 is restored.

The Drop-based restoration and the inherited-writer test are well built.

Comment thread crates/box/src/run/contain/supervise.rs Resolved
@gautamsirdeshmukh
gautamsirdeshmukh marked this pull request as ready for review November 9, 2026 15:54
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Comment

I re-reviewed at a60b027. The runtime code (diagnostics.rs capture, drain, and finish, plus the supervise.rs wiring) is the same as in the commit I reviewed before. This commit merges the two unit tests into one and removes the doc additions. I found no new issues. I won't repeat the two earlier threads: the buffer limit is going to a follow-up PR, and the process-wide fd 2 redirect is intentional.

Checks that held at this head:

  • The merged unit test still compares the whole output byte for byte for the restore, overflow, and drop scenarios. It passes locally.
  • The integration tests still check that startup disclosures come before the agent's screen, that nothing is written while the agent's screen is active, that the report comes after NATIVE_EXIT, that exit codes 0, 7, and 143 are preserved, and that piped stderr stays live.
  • None of the user pages I checked tells the reader to watch stderr while a run is going (getting-started.md "If something goes wrong", mcp.md errors, config.md disclosures). Removing the doc additions leaves no wrong instruction.

Comment thread crates/box/src/run/diagnostics.rs Resolved
@gautamsirdeshmukh
gautamsirdeshmukh merged commit 1e94f57 into strands-agents:main Nov 9, 2026
31 of 33 checks passed
gautamsirdeshmukh added a commit that referenced this pull request Nov 9, 2026
## Problem

Late Core messages overwrite the native workload screen. Boxy continues to consume feature/allow-multilink-commands while the command alias scan on main awaits #381.

## Solution

Apply merged commit 1e94f57 without changes to this feature branch. The workload keeps its terminal streams. Core retains later diagnostics and prints them after the workload exits.

## Tests

- Builds with all features and no default features, Clippy, and formatting pass.
- The workspace suite reports 4,766 passed, 2 failed, and 17 ignored. Both failures reproduce on unchanged 53a6c04: the same-folder hard-link refusal test and the tool grammar exit-status test.
- Deterministic containment reports 129 passed and 12 Linux-only skips.
- The diagnostics unit test and all three terminal integration tests pass. Each fails under its relevant deliberate mutation and passes after restoration.
- The local Linux cross-check requires the absent x86_64-linux-gnu-gcc compiler. The merged patch passed Linux CI on its original base.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants