fix(env): head+tail preview for truncated tool output#66
Merged
Conversation
A truncated tool result previously showed only the HEAD (first lines), so a line-rich oversized output — a directory listing, a log, a JSON array — hid its tail and forced the agent to read the spilled file just to see the end (an extra round-trip for output only modestly over the 50K spill threshold). buildPreview now shows the first AND last lines around an elision marker, each end bounded to half the char budget so a few very long head lines can't starve the tail; it falls back to the head-only char-capped preview for a single giant line. Also reports an accurate omitted-line count and a read-more offset that points at the omitted middle (the old offset could skip char-capped head lines). Found by the AI-SRE production session audit (audit-2026-06-11, sess_a77jGy9XzY2GQLDnUcd3xf).
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.
What
When a tool result exceeds the spill threshold (50K) it's saved to
.outputs/and the agent gets a preview. That preview was head-only (first N lines). For a line-rich output only modestly over the threshold — a directory listing, a log, a JSON array — the tail was hidden, so the agent spent an extra read call on the spilled file just to see the end.Change
buildPreviewnow shows the first AND last lines around an elision marker:N lines omittedcount and a read-more hint whoseoffsetpoints at the omitted middle (the old offset could skip head lines the char-cap had chopped).No threshold change (stays at CC-parity 50K); the spilled file remains the full-content escape hatch for a needle in the middle. No code parses the preview message format.
Verification
go build ./...clean;go test ./environment/green, incl. 3 new tests (head+tail on a 100-line output; char-bounding with 500-char lines so both ends survive; single-giant-line head-only fallback). gofmt clean.Provenance
AI-SRE production session audit
audit-2026-06-11, sessionsess_a77jGy9XzY2GQLDnUcd3xf(a 59665-char / 63-linelsspilled + forced a re-read).