truncateTail returns empty content when the last line exceeds the byte budget, so long single-line output reaches the model as (no output) #1551
Jiaaqiliu
started this conversation in
Bug reports
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Environment. prime-agent 0.7.3,
mainat f8f0036, Node 22.17.0, macOS 15 (darwin 25.5.0).Summary
truncateTailreturns empty content whenever the output ends with a newline and its last line is longer than the byte budget. Because almost every command's stdout ends with a newline, a single long line means the model receives(no output).Reproduction
In practice this is
caton a single-line JSON file,jq -c,base64 file, a minified bundle, or one long log line. What the model sees is:The footer says content was shown, and
lastLinePartialisfalse, so nothing downstream can tell that the output was lost rather than empty.Root cause
core/tools/truncate.ts:182. The backwards scan is supposed to fall back to keeping the end of an oversized last line, which the function's own doc comment describes. The fallback is gated onoutputLinesArr.length === 0:content.split("\n")on content ending in a newline yields a trailing""element. The scan starts at that element, sooutputLinesArr.lengthis already 1 when it reaches the oversized line. The guard is false, the rescue is skipped, and the loop breaks with only[""]collected.Scope
truncateTailis on the model-facing path throughOutputAccumulator.snapshot(core/tools/output-accumulator.ts:90) andexecuteBashWithOperations(core/bash-executor.ts:96,115), and on the display path throughinteractive-mode.ts:4464andcomponents/bash-execution.ts:117.Suggested fix
Gate the fallback on whether any line with content has been collected, and subtract the newline the already-collected empty element contributes so the result still fits
maxBytes. No currently-correct case changes: with no trailing newline the collected array is empty and the arithmetic is identical, and a tail that already holds real content still prefers whole lines.There is currently no test file for this module; I added one.
I have a fix with a regression test on a branch:
fix/truncate-tail-empty-output.npm run checkpasses and the surrounding suites still pass. I opened it as a PR first and the contribution gate closed it, which is what CONTRIBUTING.md says should happen, so I am bringing it here instead. Happy to leave it as is, adjust it, or drop it entirely if you would rather fix this differently.All reactions