Repository navigation
fix(core): keep the start and end of long shell output - #67159
Conversation
There was a problem hiding this comment.
This works as described. On the base, a 3,000-line output came back as lines 1001–3000 only. With this PR it comes back as lines 1–1000, the [lines 1001-2000 of 3000 cut (5 KB); …] note, then lines 2001–3000. The shell, daemon and shell-result tests pass, except one that fails the same way on the base. tsc -b in packages/core and the text-boundary test pass too.
I checked the cut logic for overlap between the two ends, odd limits, empty ends, one huge line, ends that start mid-line and an unknown line count, and found no problems. Memory use stays bounded because each end is read on its own.
Public API: unchanged. Only the wording of the shell truncation note changes.
One small inaccuracy in the note is flagged inline.
Related: #62718
| const tailWindow = yield* readRange(info.file, Math.max(0, tailStart - 1), size - Math.max(0, tailStart - 1)) | ||
| const lineStart = tailStart === 0 || tailWindow[0] === 10 | ||
| const end = TextBoundary.utf8Tail(tailWindow, size - tailStart) | ||
| const head = firstLines( |
There was a problem hiding this comment.
When the start ends exactly on a line break (headWindow[headSize] === 10), the last line of head is complete but has no trailing \n. So firstLines either drops it (if it is over half the window) or keeps it, and the note then says "part of" a line that is fully shown. The extra byte is already read here, so treating it as a line end (or passing a flag to firstLines) would make the note exact.
There was a problem hiding this comment.
The new commit fixes the earlier point: a line that ends exactly where the start is cut is now kept whole, and the note no longer calls it "part of" a line. The shell, daemon and shell-result tests pass, except one that also fails on the base. tsc -b in packages/core is clean. Nothing new to raise. Public API: unchanged.
There was a problem hiding this comment.
The earlier point about a line ending right at the cut is still fixed after the byte-based rewrite: startEnd keeps the line break just past the limit when it does not overlap the end.
I checked the new cut logic by fuzzing startEnd/endStart (300k random outputs with CRLF, multi-byte characters and small limits) for overlap, the byte and line limits and UTF-8 boundaries: no failures. The shell, daemon and shell-result tests pass, except one that also fails on the base. Type checks for packages/core and packages/util are clean.
Public API: unchanged. Removing TextBoundary.utf8Head/utf8Tail from @opencode/util only affects internal code, and nothing else used them.
Nothing new to raise.
There was a problem hiding this comment.
The new commit moves the cut logic into keepEnds and cutNote without changing the output. I compared the two helpers with the inline code they replace and found the same calculations. The shell, daemon and shell-result tests pass, except one that also fails on the base, and tsc -b in packages/core is clean. Public API: unchanged. Nothing new to raise.
23e5aa0 to
5b7207f
Compare
There was a problem hiding this comment.
The rebase onto the shared output-store code (shell/capture.ts) keeps the cut logic I reviewed and fuzzed earlier. Local, daemon and remote shells now all get the start-and-end cut. The output file is still created in the same cases as on dev. lineStarts is removed from the internal OutputStore type, and nothing outside packages/core used it. The shell, daemon, remote and shell-result tests pass, except one that also fails on the base, and tsc -b in packages/core is clean. Public API: unchanged. Nothing new to raise.
5b7207f to
091729b
Compare
There was a problem hiding this comment.
This push only rebases onto a newer dev: git range-diff shows the pull request's commit is identical to the one I last reviewed, and the new dev commits don't touch the shell code or its tests. The shell, daemon, remote and shell-result tests pass, except one that also fails on the base, and tsc -b in packages/core is clean. Public API: unchanged. Nothing new to raise.
Issue for this PR
Closes #
Type of change
What does this PR do?
When shell output is over
tool_output(2,000 lines / 50 KiB by default), the shell tool kept only the end and put the note at the bottom. Anything at the start was lost, and the result looked like complete output. Models missedrgmatches and files in listings that were in the cut start, and scripts that edited acatresult and wrote it back deleted the top of the file.It now keeps the start and the end, half of each limit each, with the note where the cut is. Normal mode and Code Mode get the same text.
How the cut works:
\r\n; they reusesplitCharacter, whichShell.outputalready uses. A running command's unfinished last character is left out.TextBoundary.utf8Tailhad no other users and is removed.Only the shell changes. Other tools keep the start through
ToolOutput.truncateas before.How did you verify your code works?
End-to-end A/B in full Code Mode (dev
0fd4df1cavs this PR, 6 smaller models, fresh project per run). On a task where the needed match is on a 208 KB line, dev's tail-only cut drops that line entirely; this PR shows it with the note: 144/180 vs 166/180 correct (+12 pts, 95% CI +5 to +19, Fisher p = 0.001; gpt-6-luna 17/30 vs 30/30). A multi-file task was 90/90 in both. No corrupted files or timeouts in either. Models re-ran shell commands about half as often after a cut (299 vs 142 calls).Updated the truncation assertions in
test/tool-shell.test.tsandtest/shell-daemon.test.ts(whole lines at both ends, a line ending right at the cut, blank and CRLF lines next to the note, one long line, UTF-8 characters at both cuts, line limits, unknown line count).A separate review ran a fuzzer outside the repo (about 400,000 cases: exited and running commands, incomplete trailing UTF-8,
max_lines1-10,max_bytes1-100 and the default, binary bytes, CRLF, blank lines) checking line numbers, cut size, overlap and UTF-8 against ground truth: no failures.bun testfor every shell and codemode test file inpackages/core: 3608 pass. 4 fail the same way ondevon this machine (system bash 3.2 and temp-path tests).bun run typecheckinpackages/core,bunx tsc -p tsconfig.build.json --noEmitinpackages/server,packages/sdkandpackages/simulation.Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #62718