Skip to content

Cap get_terminal_output first-poll and non-prefix responses to a tail#320140

Merged
meganrogge merged 4 commits into
mainfrom
megan/terminal-output-tail-default
Jun 5, 2026
Merged

Cap get_terminal_output first-poll and non-prefix responses to a tail#320140
meganrogge merged 4 commits into
mainfrom
megan/terminal-output-tail-default

Conversation

@meganrogge
Copy link
Copy Markdown
Collaborator

@meganrogge meganrogge commented Jun 5, 2026

Fixes the spillover side of microsoft/vscode-internalbacklog#7869.

PR #315543 already shrinks repeated get_terminal_output polls by returning only the delta. But the first poll and the non-prefix fallback still returned the full buffer (up to the ~60 KB upstream cap in outputHelpers.ts), which is well above the Copilot SDK's ~10 KB spillover threshold and causes the agent to thrash with read_file calls on the spillover temp file.

This change adds a second, tighter cap inside the tool itself: when the full output exceeds 8 KB, return only the last 8 KB (line-aligned). The truncation marker includes both the omitted character count and a hint telling the agent how to recover the head if it needs to: re-run the command and redirect output to a file, then read that file.

Snapshot tracking (length + hash) still uses the full buffer, so subsequent delta polls work unchanged.

Behavior

The tail cap applies on every code path (always on — not gated by an experiment), because the SDK spillover issue affects all users regardless of whether chat.tools.terminal.outputDeltas is enabled. The delta-tracking semantics introduced by #315543 remain gated by that experiment.

  • Experiment off: full output if ≤ 8 KB; otherwise tail + recovery hint.
  • Experiment on, first poll: same.
  • Experiment on, unchanged poll: unchanged since previous poll marker (no output).
  • Experiment on, pure-prefix delta poll: only the new characters (already small).
  • Experiment on, non-prefix fallback: same tail treatment as first poll.

Risks / follow-ups

  • 8 KB is a tuned guess. Picked to stay under the ~10 KB SDK spillover threshold with headroom for the prefix text. If the SDK threshold changes we may need to retune.
  • No telemetry on how often truncation kicks in or whether the agent successfully recovers via the redirect hint. Worth adding to validate.
  • Line-alignment edge case: single-line outputs with no \n in the last 8 KB fall back to a raw character cut, which could land mid-ANSI-escape. Rare.

Tests

getTerminalOutputTool.test.ts — all 11 tests pass, including two added for the new behavior:

  • returns only the tail on first poll when output exceeds the tail budget
  • returns only the tail on non-prefix fallback when output exceeds the tail budget

Copilot AI review requested due to automatic review settings June 5, 2026 16:46
@meganrogge meganrogge self-assigned this Jun 5, 2026
@meganrogge meganrogge added this to the 1.125.0 milestone Jun 5, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented Jun 5, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@anthonykim1

Matched files:

  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/getTerminalOutputTool.ts
  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/getTerminalOutputTool.test.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR further reduces get_terminal_output payload sizes (when chat.tools.terminal.outputDeltas is enabled) by tail-truncating the first poll and non-prefix fallback responses to ~8 KB (line-aligned), preventing Copilot SDK spillover thrash while keeping full-buffer snapshotting for delta detection.

Changes:

  • Add an internal 8 KB “tail budget” and tail-formatting helper to cap first-poll and non-prefix-fallback outputs.
  • Preserve full-buffer snapshot (length + hash) so unchanged/delta detection continues to work.
  • Add unit tests for tail behavior on first poll and on non-prefix fallback.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/getTerminalOutputTool.ts Adds tail-capping helpers and applies them to first-poll and non-prefix fallback outputs under the output-deltas experiment.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/getTerminalOutputTool.test.ts Adds tests validating tail truncation behavior for large outputs on first poll and non-prefix fallback.

Copilot's findings

Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/getTerminalOutputTool.ts:117

  • When output exceeds the tail budget, the first poll returns only a tail, but the unchanged-marker still says "(… characters already shown)". That text becomes inaccurate/misleading because the tool did not actually return the full buffer previously, only the tail. Consider adjusting the unchanged-marker when output.length exceeds the tail budget so it doesn’t imply the full output was already shown.
		if (currentOutputSnapshot.length === previousOutputSnapshot.length && currentOutputSnapshot.hash === previousOutputSnapshot.hash) {
			return `Output of terminal ${id} unchanged since previous poll (${output.length} characters already shown). No new output.`;
		}
  • Files reviewed: 2/2 changed files
  • Comments generated: 1

@meganrogge
Copy link
Copy Markdown
Collaborator Author

/requires-eval-assessment terminalbench2 gpt-5.4,claude-opus-4.6,claude-opus-4.7

@meganrogge meganrogge added the ~requires-eval-assessment Evals will be run and will generate a report upon completion label Jun 5, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

⏳ Queued vscode build for cfa3e205c3b8cc5b0781f6cc131705f127422c8f (step 1/2).

@meganrogge meganrogge added ~requires-eval-assessment Evals will be run and will generate a report upon completion and removed ~requires-eval-assessment Evals will be run and will generate a report upon completion labels Jun 5, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

⏳ Queued vscode build for 1c5fbc4ace19cf07b0991876cedc33cc0a88ce4a (step 1/2).

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🚀 Queued eval-assessment publish build for 6c9af180cecf3741c176b354ca3e842a5e1a35fc (step 2/2).

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🔬 Queued eval-assessment benchmark for 627279b46c.

Results will be posted back here when the run completes.

@vs-code-engineering
Copy link
Copy Markdown
Contributor

✅ Eval-assessment build published.

@vs-code-engineering vs-code-engineering Bot removed the ~requires-eval-assessment Evals will be run and will generate a report upon completion label Jun 5, 2026
@meganrogge meganrogge modified the milestones: 1.125.0, 1.124.0 Jun 5, 2026
@meganrogge meganrogge merged commit a9efb8d into main Jun 5, 2026
25 checks passed
@meganrogge meganrogge deleted the megan/terminal-output-tail-default branch June 5, 2026 20:13
@vs-code-engineering
Copy link
Copy Markdown
Contributor

📊 Eval-assessment benchmark complete.

🧪 Results

@vs-code-engineering
Copy link
Copy Markdown
Contributor

📊 Eval-assessment benchmark complete.

🧪 Results

@vs-code-engineering
Copy link
Copy Markdown
Contributor

📊 Eval-assessment benchmark complete.

🧪 Results

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.

3 participants