# AutoCompact: Learning When to Compact Context in Long-Horizon Coding Agents

- **ID:** 1211
- **Kind:** paper
- **URL:** https://arxiv.org/abs/2610.02163
- **Authors:** Xuan Zhang, Longtao Zheng, Cunxiao Du, Bo An, Xin Dong
- **Venue:** arXiv:2610.02163 (cs.CL), submitted 1 Oct 2026
- **Published:** 2026
- **Source:** arxiv
- **Language:** en
- **Access:** free
- **Tags:** autocompact, context-compaction, coding-agents, swe-bench, harness-co-design, long-horizon, rl
- **Topics:** coding agents, context management, compaction, RL, SWE-bench, harness co-design, long-horizon tasks
- **Added:** 2026-10-03
- **Verified:** 2026-10-03
- **Page:** https://papers.projxon.ai/entries/1211

## Summary

Trains long-horizon coding agents to proactively decide when to compact their own context — a form of model-harness co-design: the harness provides the compaction mechanism, the model learns when to invoke it, what working state to preserve, and how to continue afterward. Data collection: run the base agent on coding tasks, use a judge to review its compaction decisions, summaries, and post-compaction actions; flawed outputs are replaced with corrected ones before environment execution so trajectories continue from corrected decisions. These trajectories feed supervised fine-tuning, then joint RL optimizes coding and compaction with task-success rewards. Absolute gains: +9.2 points on SWE-bench Verified, +5.0 on SWE-PolyBench Verified. Improvements hold across all inference budgets — including with a 256K context window that never overflows (so learned compaction helps even when context space isn't the limit) and with a 16K window whose overflow triggers fallback compaction. Latest in the AutoHarness → AutoContext → AutoCompact trend of moving harness responsibilities into the model itself; related to Meta's Context Language Models paper. Open questions: scaling, robustness across harnesses, combining rule-based compaction packaged in harnesses with model-invoked proactive compaction.

## Research notes

- Discovery: @omarsar0 (elvis, building @dair_ai) X post 2026-10-03 12:11 PM ET (https://x.com/omarsar0/status/2106416745686995025), ~5.9K views
- DAIR.AI 'Chat with Paper' page: https://academy.dair.ai/papers/autocompact-learning-when-to-compact-context-in-long-horizon-coding-agents-2610.02163
- Self-thread reply links: Context Language Models (https://academy.dair.ai/papers/context-language-models-2609.37725), AutoHarness (https://academy.dair.ai/papers/autoharness)
- License: CC BY 4.0

## Similar entries

- [An Empirical Study of Harness Design for Coding Agents](https://papers.projxon.ai/entries/1070) (paper, #1070)
- [GLM-5: from Vibe Coding to Agentic Engineering](https://papers.projxon.ai/entries/532) (paper, #532)
- [Huxley-Gödel Machine: Human-Level Coding Agent Development by an Approximation of the Optimal Self-Improving Machine](https://papers.projxon.ai/entries/539) (paper, #539)
- [Marathoner: Ultra-Long-Horizon Autonomous Intelligence](https://papers.projxon.ai/entries/837) (paper, #837)
- [Context Language Models](https://papers.projxon.ai/entries/793) (paper, #793)
- [AREX-2: Advancing Self-Improving Agents through Long-Horizon Reflective Tasks](https://papers.projxon.ai/entries/866) (paper, #866)
