Skip to content

fix(env): head+tail preview for truncated tool output#66

Merged
ysyneu merged 1 commit into
mainfrom
fix/large-output-head-tail-preview
Jun 11, 2026
Merged

fix(env): head+tail preview for truncated tool output#66
ysyneu merged 1 commit into
mainfrom
fix/large-output-head-tail-preview

Conversation

@ysyneu

@ysyneu ysyneu commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

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

buildPreview now shows the first AND last lines around an elision marker:

  • Each end is bounded to half the character budget, so a few very long head lines can't starve the tail.
  • Falls back to the existing head-only, char-capped preview for the degenerate single-giant-line case.
  • Reports an accurate N lines omitted count and a read-more hint whose offset points 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, session sess_a77jGy9XzY2GQLDnUcd3xf (a 59665-char / 63-line ls spilled + forced a re-read).

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).
@ysyneu ysyneu merged commit 10b41a7 into main Jun 11, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant