Skip to content

Consolidate the four grep-output truncation implementations into one - #400

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-5674-four-different-tool-output-truncation-implementations
Aug 8, 2026
Merged

Consolidate the four grep-output truncation implementations into one#400
TheGreatAxios merged 2 commits into
mainfrom
cl-5674-four-different-tool-output-truncation-implementations

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • Grep results could carry two differently-worded "truncated" notices (or a mangled fragment of one), because rg-output.ts's byte-cap breach, ripgrep-plugin.ts's line-count cap, bounded-grep-fallback.ts's own byte-cap loop, and result-truncation-plugin.ts's char cap each independently truncated and attached their own notice.
  • truncateToolResultContent in result-truncation-plugin.ts is now the single primitive that produces a truncation notice (takes an optional threshold for reuse at other cap sizes). The grep-specific caps now trim silently and leave notice duty to that pass, which runs last in the plugin chain. bounded-grep-fallback.ts's own byte-cap loop is deleted outright — ripgrep-plugin.ts's boundedContent already re-checks its output downstream.
  • rg-output.ts's timeout notice is untouched — a run timing out is a different fact from output being oversized, not part of the size-truncation duplication.

Test plan

  • RED-first test in tests/unit/ripgrep-plugin.test.ts (scripted rg stream bypassing real rg's --max-count) proved two notices stacked pre-fix, verified single/no notice post-fix
  • bun run typecheck
  • bun run build
  • bun run test — full suite green except one pre-existing, unrelated failure (lsp-availability.test.ts, an environment/install check on the worktree's node_modules, untouched by this change)
  • Ran a real oversized grep against this repo (grep -e -context 3 -max_results 5000 src) through the actual plugin chain: 80,115-char result, exactly one truncation notice

@linear-code

linear-code Bot commented Aug 8, 2026

Copy link
Copy Markdown

CL-5674

@TheGreatAxios
TheGreatAxios force-pushed the cl-5674-four-different-tool-output-truncation-implementations branch from b602705 to e16c36e Compare August 8, 2026 19:10
Grep results passed through both ripgrep-plugin's line cap and
rg-output's byte cap on the way in, then result-truncation-plugin's
character cap on the way out, each with its own wording. Whenever more
than one of those caps actually fired on the same result, the notices
concatenated (or one silently clobbered another), so the model would
sometimes see two differently-worded "truncated" notices, or a
mangled fragment of one.

result-truncation-plugin.ts's truncateToolResultContent is now the
only place that attaches a truncation notice; it takes an optional
threshold so other callers can reuse the same wording at a different
cap size. The grep-specific cappers (rg-output's byte-cap breach,
ripgrep-plugin's line-count cap) now trim silently and rely on that
final pass to report the truncation once. bounded-grep-fallback's own
byte-cap loop is removed outright — ripgrep-plugin's boundedContent
already re-checks the fallback walker's output against the same
byte-cap primitive downstream, making the fallback's own pass
redundant. rg-output's timeout notice is untouched, since a run
timing out is a different, non-redundant fact from output being
oversized.
ripgrepPlugin answers grep and search_files without calling next, so the
result-truncation middleware later in the plugin array never observed
those results and an oversized grep reached the model uncapped. Apply
the shared primitive at ripgrepPlugin's own return paths, and restore
the match-count notice, which reports an omission no size-based pass can
infer.
@TheGreatAxios
TheGreatAxios force-pushed the cl-5674-four-different-tool-output-truncation-implementations branch from e16c36e to 664d799 Compare August 8, 2026 20:05
@TheGreatAxios
TheGreatAxios merged commit fbc2c69 into main Aug 8, 2026
3 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