Skip to content

Shell: keep both ends of output past 1 MiB instead of failing - #236

Merged
lydakis merged 1 commit into
mainfrom
claude/project-thread-dcbv64
Oct 28, 2026
Merged

lydakis merged 1 commit into
mainfrom
claude/project-thread-dcbv64

Conversation

@lydakis

@lydakis lydakis commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What

Before this change, once a command wrote more than 1 MiB to stdout or stderr, shell killed it and failed the call with {"error":"shell_output_limit"}. That lost all the output and the exit code. A verbose build or test log could hit it and be killed partway.

Now:

  • Each stream keeps everything up to 1 MiB, as before.
  • Past that, it keeps its first and last 512 KiB, minus a little room for a marker. The marker in the retained artifact counts the dropped middle bytes.
  • The command runs to its end and reports its real exit code.
  • The model's preview (64 KiB head and tail) says how many bytes were omitted from view and how many were not kept at all. The kept artifact is still readable with read artifact=TURN/CALL/stdout.

How

bounded_read becomes capture, which fills Captured:

  • Up to 512 KiB is read straight into the head with read_to_end, so the common small-output path is unchanged.
  • After that, 64 KiB chunks go into a VecDeque tail that is trimmed back to 512 KiB whenever head plus tail would pass 1 MiB.
  • Peak memory per stream stays around 1 MiB plus one chunk.
  • Reads are still cancel-safe, so a timed-out command keeps what it wrote.

This came out of the Codex tool comparison. Codex keeps a 1 MiB head and tail buffer the same way (codex-rs/core/src/unified_exec).

Tests

  • cargo test (lib, tool_contract and the store suites): all pass.
  • cargo clippy --all-targets and cargo fmt --check: clean.
  • New unit test captured_output_keeps_both_ends_past_the_bound: exact bound, dropped count, marker.
  • Updated contract test: head -c 3000000 /dev/zero | tr '\0' x; echo; echo done now exits 0 and shows both ends. The tail ends in done, and the artifact stays within ARTIFACT_BYTES.

No UI change, so no screenshots.

A stream past 1 MiB used to kill the command and fail the call with
shell_output_limit, losing all output and the exit code. Now the stream
keeps its first and last 512 KiB in the retained artifact, a marker
counts the dropped middle, and the command runs to its end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFtCdGun1rPhhwTSrG
@lydakis lydakis self-assigned this Oct 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T23:55:37.820836Z 7e46522 PR opened
🔒 Security Review ✅ Completed 2026-10-27T23:57:06.248550Z 7e46522 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lydakis
lydakis merged commit 3226af6 into main Oct 28, 2026
1 check passed
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.

2 participants