fix: head+tail truncation for execute_code stdout (inspired by openclaw context-pruning)#755
Closed
teknium1 wants to merge 1 commit into
Closed
fix: head+tail truncation for execute_code stdout (inspired by openclaw context-pruning)#755teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
…aw context-pruning) Previously, _drain() only captured the first MAX_STDOUT_BYTES (50KB) of stdout, silently dropping all tail output. Scripts that print() their final results at the end would have those results lost. Now uses a two-buffer approach: 40% head + 60% tail (rolling window). This matches the pattern already used in terminal_tool.py (line 1042-1051) but gives the tail more space since execute_code scripts typically print() their final results at the end. Inspired by openclaw's softTrim context-pruning (headChars/tailChars).
teknium1
added a commit
that referenced
this pull request
Mar 11, 2026
Replaces head-only stdout capture with a two-buffer approach (40% head, 60% tail rolling window) so scripts that print() their final results at the end never lose them. Adds truncation notice between sections. Cherry-picked from PR #755, conflict resolved (test file additions). 3 new tests for short output, head+tail preservation, and notice format.
teknium1
added a commit
that referenced
this pull request
Mar 11, 2026
Replaces head-only stdout capture with 40/60 head/tail split so final print() output is never lost. 3 new tests.
Contributor
Author
|
Merged to main in 359352b. Head+tail truncation for execute_code stdout — cherry-picked and conflict resolved against current main. |
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
Replaces head-only stdout capture with a two-buffer approach (40% head, 60% tail rolling window) so scripts that print() their final results at the end never lose them. Adds truncation notice between sections. Cherry-picked from PR NousResearch#755, conflict resolved (test file additions). 3 new tests for short output, head+tail preservation, and notice format.
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
… stdout Replaces head-only stdout capture with 40/60 head/tail split so final print() output is never lost. 3 new tests.
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
Replaces head-only stdout capture with a two-buffer approach (40% head, 60% tail rolling window) so scripts that print() their final results at the end never lose them. Adds truncation notice between sections. Cherry-picked from PR NousResearch#755, conflict resolved (test file additions). 3 new tests for short output, head+tail preservation, and notice format.
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
… stdout Replaces head-only stdout capture with 40/60 head/tail split so final print() output is never lost. 3 new tests.
olympus-terminal
pushed a commit
to olympus-terminal/hermes-agent
that referenced
this pull request
May 16, 2026
Replaces head-only stdout capture with a two-buffer approach (40% head, 60% tail rolling window) so scripts that print() their final results at the end never lose them. Adds truncation notice between sections. Cherry-picked from PR NousResearch#755, conflict resolved (test file additions). 3 new tests for short output, head+tail preservation, and notice format.
olympus-terminal
pushed a commit
to olympus-terminal/hermes-agent
that referenced
this pull request
May 16, 2026
… stdout Replaces head-only stdout capture with 40/60 head/tail split so final print() output is never lost. 3 new tests.
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
Replaces head-only stdout capture with a two-buffer approach (40% head, 60% tail rolling window) so scripts that print() their final results at the end never lose them. Adds truncation notice between sections. Cherry-picked from PR NousResearch#755, conflict resolved (test file additions). 3 new tests for short output, head+tail preservation, and notice format.
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
… stdout Replaces head-only stdout capture with 40/60 head/tail split so final print() output is never lost. 3 new tests.
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.
Summary
Previously,
execute_code's_drain()function only captured the firstMAX_STDOUT_BYTES(50KB) of stdout, silently dropping all tail output. Scripts thatprint()their final results at the end would have those results lost — a critical issue since execute_code scripts are designed to print their final output.Changes
_drain_head_tail()function: Uses a two-buffer approach — a head buffer (first 40%) and a rolling tail deque (last 60%). Memory usage stays bounded.[OUTPUT TRUNCATED - N chars omitted out of M total]between head and tail sections.Rationale
terminal_tool.pyalready does head+tail truncation (40% head / 60% tail at line 1042-1051), butcode_execution_tool.pywas head-only. The tail is actually more important for execute_code since scripts print their final result at the end.Inspired by openclaw's
softTrimcontext-pruning (headChars/tailCharssplit in v2026.3.7).Tests