Skip to content

[copilot-opt] perf: cap session context growth — large MCP file reads cause 2.5× token inflation mid-session #48426

Description

@github-actions

Optimization: Prevent Unbounded Context Growth from Large MCP File Reads

Overview

Session analysis (2026-07-27) shows that sessions using github-mcp-server-get_file_contents experience sharp, late-session token spikes that push input context to 2–2.5× their starting size. This degrades model performance and increases cost.

Evidence

Session Peak input tokens Turn of spike Trigger
30290667268 108,331 Turn 7 of 8 github-mcp-server-get_file_contents for .github/aw/update-agentic-workflow.md + patterns.md
30287906964 93,534 Turn 8 of 9 github-mcp-server-pull_request_read for large CI data analysis file

In session 30290667268, input grew from 44,043 → 108,331 tokens (2.46×) across 8 turns. The spike occurred at turn 7 when two large workflow markdown files were loaded via MCP without any size guard or summarization.

turn=6  input=61,370   ← normal growth
turn=7  input=107,423  ← +46,053 tokens spike (MCP file reads)
turn=8  input=108,331

Root Cause

Workflow markdown files (.github/aw/*.md) and skill files can be very large (hundreds of KB). The github-mcp-server-get_file_contents tool returns the full file content without truncation, injecting thousands of tokens into context at once.

Skills that load files lazily (via glob **/*.md followed by full reads) compound this: the agent reads multiple large files in sequence, accumulating context without any size budget.

Proposed Changes

  1. Add a view_range convention to skills that read workflow markdown: fetch only the relevant sections rather than full files (e.g., use head -150 or view_range in the skill instructions).
  2. Add a context-size guard in AGENTS.md: if a file is larger than a threshold (e.g., 20 KB), require agents to use targeted reads instead of full-file reads.
  3. Prefer bash/grep/glob for large files over MCP get_file_contents, which currently returns full content without truncation.

Expected Impact

  • Reduces peak input token usage by an estimated 30–50% for sessions involving workflow file reads
  • Improves model response quality at high context sizes
  • Reduces per-session cost

References: §30290667268, §30287906964

Generated by ⚡ Copilot Opt · sonnet46 · 32.7 AIC · ⌖ 13.4 AIC · ⊞ 5.6K ·

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions