Compact-Bench: Measuring What Context Compaction Costs Long-Horizon Coding Agents
Organizations: University of Science and Technology of China
Abstract
Context compaction lets long-horizon coding agents continue beyond their context windows, but can erase the state needed to finish a task. Prior evaluations measure efficiency, retained information, or end-to-end success, leaving the effect of a specific history replacement difficult to isolate. Compact-Bench pairs full-history and summary-only continuations from a shared repository state, and evaluates recurring details and successive production compactions. It covers 35 SWE-bench repairs, 146 agentic sessions, and 106 production chains. Across 14 summarizer backbones, stable damage ranges from 5-64% of 22 full-history successes: Claude Opus 4.8 preserves the most repairs, while DeepSeek-Flash damages the most. With Kimi-K3 as summarizer, the Kimi Code prompt preserves the most task continuations (19/22), whereas Claude Code retains the most recurring details (15.0%). LLM summaries retain at most 16.0% of recurring details, compared with 79.1% for mechanical extraction; production summaries retain 15.7% at the first boundary. Failures recur across methods: one repair is damaged by 13/14 backbones, and another by all 5 prompts. These results show that reliable compaction requires preserving the progress needed to complete a task, and that retaining relevant information alone does not ensure successful continuation. Code is available at https://github.com/cai-jianfeng/compact-bench and data is available at https://huggingface.co/datasets/caijanfeng/compact-bench.
Figures & tables
| Evaluation | Size | Composition |
|---|---|---|
| Task Preservation | 35 instances | Localized SWE-bench repairs from 7 repositories: pytest (18), sympy (6), xarray (3), pylint (3), requests (2), sphinx (2), and flask (1). |
| Recurring-Detail Retention | 146 sessions | 143 real and 3 simulator-synthesized sessions; clients: Kimi Code (73), Claude Code (50), opencode (14), and other clients (9); 9,330 recurring details. |
| Production-Chain Retention | 106 sessions | 224 production compaction boundaries; median 2 and maximum 4 boundaries per session. |
| Summarizer | Round 1 | Stable | 95% CI |
|---|---|---|---|
| Claude Opus 4.8 | (1) | (1) | |
| Kimi-K3 | (4) | (4) | |
| GPT-5.6-Luna | (4) | (4) | |
| GPT-5.6-Sol | (6) | (6) | |
| Claude Fable 5 | (9) | (8) | |
| Claude Fable 5.1 | (8) | (8) |
| Prompt | POST pass | Detail retention |
|---|---|---|
| Kimi Code | 19/22 = 86% | 8.2% |
| Claude Code | 18/22 = 82% | 15.0% |
| Gemini CLI | 17/22 = 77% | 7.2% |
| Codex | 16/22 = 73% | 9.5% |
| opencode | 16/22 = 73% | 9.5% |
| Backbone | Detail-retention score |
|---|---|
| DeepSeek-Flash | 16.0% |
| Kimi-K3 | 15.0% |
| GPT-5.6-Sol | 14.8% |
| GPT-5.6-Luna | 13.3% |
| DeepSeek-V4-Pro | 11.9% |
| GLM-5.3 | 9.5% |
| Damaged cell | Target file in | Fix evidence in |
|---|---|---|
| pytest-10081 | yes (1/1) | 8/12 |
| pytest-7490 | yes (1/1) | 10/12 |
| pytest-7571 | yes (1/1) | 5/5 |
| sphinx-9230 | yes (1/1) | 4 listed strings |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Instance | K3 | Luna | Sol | Astra | Terra | Opus | F5 | F5.1 | O5.5 | Qwen | GLM | V4Pro | Hy4 | Flash |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| flask-5014 | P | P | P | D | D | P | D | P | P | P | P | D | D | D |
| req-5414 | P | P | P | P | P | P | P | P | P | P | P | P | P | P |
| req-6028 | U | – | – | – | – | – | – | – | – | – | – | – | – | – |
| xa-3677 | P | P | D | P | P | P | D | P | P | P | P | P | D | D |
| xa-4629 | P | P | P | P | P | P | P | P | P | P | P | P | P | P |
| xa-6721 | P | D | P | P | P | P | P | P | P | D | P | P | P | P |
| Model | Instance | Result | |||
|---|---|---|---|---|---|
| K3 | pt-10081 | D | P | D | SD |
| K3 | pt-7490 | D | P | D | SD |
| K3 | pt-7571 | D | P | D | SD |
| K3 | sp-9230 | D | U | D | SD |
| Luna | xa-6721 | D | D | D | SD |
| Luna | pt-10081 | D | D | D | SD |
| Instance | v1 | v2 | v3 | Observation |
|---|---|---|---|---|
| sympy-13480 | U | P | P | environment fix; preserved in v3 |
| sympy-13091 | R | U | U | v1 rescue not reproduced |
| xarray-6721 | – | D | P | v2 path-leak damage |
| requests-5414 | R | – | P | v1 rescue not reproduced |
| sphinx-9230 | – | D | D | damage persists in v3 |
| pytest-7521 | – | D | P | v2 path-leak damage |
| Instance | Repo | #F2P | Environment |
|---|---|---|---|
| flask-5014 | flask | 1 | werkzeug<3 |
| req-5414 | requests | 1 | urllib3<2 |
| req-6028 | requests | 2 | urllib3<2 |
| pt-10051 | pytest | 1 | setuptools_scm shim |
| pt-10081 | pytest | 1 | setuptools_scm shim |
| pt-10356 | pytest | 1 | setuptools_scm shim |
| Instance | Claude | Codex | Gemini | opc | Kimi |
|---|---|---|---|---|---|
| flask-5014 | P | P | P | P | P |
| req-5414 | P | F | P | P | F |
| xa-3677 | P | P | P | F | P |
| xa-4629 | P | P | P | P | P |
| xa-6721 | P | P | P | P | P |
| pl-6903 | P | P | P | F | P |
| # | tool | PRE (full history) | POST (summary only) |
|---|---|---|---|
| 1 | c / r | sed -n 290,340p sphinx/domains/python.py | sphinx/util/docfields.py |
| 2 | c | cd /tmp && rm -rf reprotest && mkdir reprotest && cd reprotest && cat > index.rst <<’… | cd /testbed && git log –oneline -3 && git status |
| 3 | c | cd /tmp/reprotest && python - <<’EOF’ import re html = open(’_build/index.html’).read… | pwd && ls && git log –oneline -3 2>/dev/null | head |
| 4 | c | cd /tmp/reprotest && python - <<’EOF’ import re html = open(’_build/index.html’).read… | sed -n 190,320p sphinx/util/docfields.py |
| 5 | c | sed -n 295,310p sphinx/util/docfields.py | grep -n "split|import|def " sphinx/util/docfields.py | head -40 |
| 6 | c | cd /home/user/sphinx 2>/dev/null || pwd; python - <<’EOF’ import re path = ’sphinx/ut… | sed -n 890,1010p tests/test_domain_py.py |
| Cell | PRE redo-reads | POST redo-reads |
|---|---|---|
| pytest-10081 | 1 | 0 |
| pytest-7490 | 1 | 0 |
| pytest-7571 | 0 | 1 |
| sphinx-9230 | 1 | 1 |