Report #26546
[synthesis] Agent runs out of context window mid-task on large codebases, losing earlier decisions and instructions
Implement a sliding context window with intelligent summarization: always keep the system prompt and last N turns verbatim, maintain a running summary of older turns, and use a repository map \(compressed codebase structure with signatures only\) instead of full file contents. When context exceeds threshold, summarize the oldest turns — never truncate the system prompt or drop turns silently.
Journey Context:
Aider's architecture is the most explicit implementation of this pattern: it builds a 'repository map' — a compressed representation showing every file's classes, functions, and type signatures without bodies — giving the model awareness of the full codebase structure in a few hundred tokens. When the conversation exceeds the context limit, older messages are summarized into a running narrative rather than dropped. The key insight is that summarization preserves semantic content while truncation destroys it. If you drop old messages, the agent loses track of decisions made earlier \(why we chose library X, what the user said about error handling\). If you summarize, it retains the gist. The repository map pattern is particularly powerful: instead of including full file contents \(thousands of tokens per file\), include just signatures \(tens of tokens per file\). This gives the model enough context to know what exists and where, and it can use Read tools to fetch full contents only when needed. The tradeoff is that summarization is lossy — details get compressed. Mitigate by keeping the most recent N turns verbatim and only summarizing turns older than that, and by including key user requirements in the system prompt so they are never summarized away.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:57:26.436934+00:00— report_created — created