feat: 10KB hard cap on tool output entering context - #155
Merged
Conversation
Any single tool result (bash, edit, ipython cell output) is truncated middle-out at 10KB before joining the conversation, with a warning naming the original size and line count — Codex's output policy, byte-compatible with the bash-harness truncation in verifiers#2454 and the version bundled inside nano-rlm#147. Scope: only what enters CONTEXT is capped. The session log keeps the full output, and skill return values inside the kernel (e.g. `out = await bash(...)`) stay uncapped — only the printed cell output is subject to the cap, so capture-then-filter workflows keep full fidelity.
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
Hard-caps any single tool result entering the conversation at 10KB, middle-out (keep head+tail), with a warning header naming the original size and line count:
Applies at the engine tool-result boundary — so it covers all tools (
bash,edit, andipythoncell output) uniformly.Scope: context only — tools yes, skills no
out = await bash(...)holds the complete string for in-cell filtering; only what the cell prints (the tool result) is subject to the cap. Capture-then-filter workflows keep full fidelity — the cap only protects the context window.Compatibility
The function is byte-compatible with the truncation in verifiers#2454 (bash harness) and the copy bundled inside #147 (auto-compaction) — extracted standalone here so the cap can ship independently; #147 can relocate/dedupe it when it lands.
Motivation from eval traces: unclipped tool results produced single-turn context blowups (observed up to ~690k tokens from one
caton a large file), which no compaction threshold can save you from after the fact.Tests: truncation unit test added; 139 passed (6 pre-existing
test_acp.pyenv failures, same as clean main); ruff clean.Note
Medium Risk
Changes what every tool returns to the model mid-run; large outputs lose middle content in context (by design), though logs retain full fidelity.
Overview
Adds a 10KB UTF-8 hard cap on each tool result before it is appended to the conversation. Oversized output is head+tail truncated with a warning that includes estimated original token count and line count.
Truncation runs in
RLMEnginewhen building thetoolmessage (truncate_tool_output);session.log_tool_resultstill records the full string, so audit trails and in-kernel skill return values are unchanged—only what the model sees in context is limited.A unit test in
test_tools.pychecks passthrough for small output and warning/size behavior for large output.Reviewed by Cursor Bugbot for commit 32bb729. Bugbot is set up for automated code reviews on this repo. Configure here.