主页
编码 agent 的上下文快满时,会把前面的对话压成一段摘要,后面只带摘要往下干。这叫压缩(compaction)。Compact-Bench 这篇论文(10 月 22 日,中国科大团队)想知道:压缩让本来能做完的活,有多少做不完了。
When a coding agent's context fills up, it squeezes the earlier conversation into a summary and carries on with only the summary. That is compaction. Compact-Bench (October 22, a USTC team) asks how many tasks that were finishable before compaction stop being finishable after it.
答案是:不少。在 14 个做摘要的模型上,22 个"带完整历史能做对"的修复任务里,有 5% 到 64% 压缩后稳定做不对。回头还会再用到的字面细节(路径、commit 哈希、报错类型这些),LLM 写的摘要最多只留下 16.0%,而不用模型、直接机械提取能留 79.1%。
The answer: quite a few. Across 14 summarizer models, 5% to 64% of 22 repairs that full-history runs could solve were reliably lost after compaction. For literal details that come back later (paths, commit hashes, error types), LLM-written summaries keep at most 16.0%, while plain mechanical extraction keeps 79.1%.
长任务里 agent 每走一步,上下文就长一截:读过的文件、跑过的命令、试错的过程。上限一到,就得腾地方。主流做法是让模型把前面的内容总结成一段话,然后丢掉原文,从摘要继续。Claude Code、Codex、Gemini CLI、opencode、Kimi Code 各有自己的压缩 prompt,论文测了这五个。
In a long task the context grows with every step: files read, commands run, dead ends tried. At the limit something has to go. The common approach is to have a model summarize the earlier material, throw away the original, and continue from the summary. Claude Code, Codex, Gemini CLI, opencode and Kimi Code each ship their own compaction prompt, and the paper tests all five.
以前的评测多半看三类东西:省了多少 token、摘要里保留了多少信息、任务最终成没成功。问题是这三类很难分开回答"摘要本身到底造成了多少损失"。
Earlier evaluations mostly looked at three things: tokens saved, information retained, and end-to-end success. It is hard to separate "how much did the summary itself cost us" from those.
核心是成对对比:同一个任务、同一个压缩前的仓库状态,一条跑道带完整历史继续(PRE),一条只带摘要继续(POST)。两边用同一个 agent、同样的工具、同样的 8 步上限,最后都由仓库的 FAIL_TO_PASS 测试判分。结果分四类:保住、受损、捡回、没解出。"稳定受损"的定义是 POST 三次里至少挂两次。
The core is a paired comparison: same task, same pre-compaction repository state. One lane continues with the full history (PRE), the other with only the summary (POST). Both use the same agent, tools and eight-step limit, and both are scored by the repository's FAIL_TO_PASS tests. Outcomes fall into four labels: preserved, damaged, rescued, unsolved. "Stable damage" means POST fails in at least two of three runs.
三套评测:
Three suites:
| 套件 | 规模 | 测什么 |
|---|---|---|
| 任务保留 | 35 个局部 SWE-bench 修复,来自 7 个仓库 | 只带摘要还能不能做完完整历史能做完的修复(22 个是已验证 PRE 能过的) |
| 重复细节保留 | 146 个会话,9,330 个会重复出现的细节 | 路径、SHA、PR 号、报错类型、URL 等字面值,摘要后面有没有留下 |
| 生产链路保留 | 106 个会话,224 个真实压缩边界 | 连续多次压缩后,细节在后续最多 5 个请求里还在不在 |
| Suite | Size | What it tests |
|---|---|---|
| Task preservation | 35 localized SWE-bench repairs from 7 repositories | Can a summary-only run finish the repairs a full-history run finishes (22 were validated PRE-pass cases) |
| Recurring-detail retention | 146 sessions, 9,330 recurring details | Whether literal values (paths, SHAs, PR IDs, error types, URLs) that reappear later survive the summary |
| Production-chain retention | 106 sessions, 224 real compaction boundaries | Whether details survive successive compactions, scored on the next up to five requests |
用 Claude Code 的压缩 prompt、Kimi-K3 当继续干活的 agent,换 14 个模型来写摘要:稳定受损比例从 5%(Claude Opus 4.8,22 个里坏 1 个)到 64%(DeepSeek-Flash,22 个里坏 14 个)。Claude Opus 4.8 保住了 22 个里的 21 个。重复跑确认了第一轮 126 个"摘要模型-任务"受损对里的 120 个。
With the Claude Code compaction prompt and Kimi-K3 as the continuing agent, swapping in 14 summarizer models gave stable damage from 5% (Claude Opus 4.8, 1 of 22) to 64% (DeepSeek-Flash, 14 of 22). Claude Opus 4.8 preserved 21 of 22. Repeat runs confirmed 120 of the 126 damaged model-task pairs from the first round.
换压缩 prompt 也有差别(Kimi-K3 写摘要,22 个任务里 POST 能过的数量):
The compaction prompt matters too (Kimi-K3 as summarizer; POST passes out of 22):
| 压缩 prompt | POST 通过 | 回头细节保留率 |
|---|---|---|
| Kimi Code | 19(86%) | 8.2% |
| Claude Code | 18(82%) | 15.0% |
| Gemini CLI | 17(77%) | 7.2% |
| Codex | 16(73%) | 9.5% |
| opencode | 16(73%) | 9.5% |
| Compaction prompt | POST passes | Recurring-detail retention |
|---|---|---|
| Kimi Code | 19 (86%) | 8.2% |
| Claude Code | 18 (82%) | 15.0% |
| Gemini CLI | 17 (77%) | 7.2% |
| Codex | 16 (73%) | 9.5% |
| opencode | 16 (73%) | 9.5% |
另外,同一个任务会被很多摘要模型一起搞坏:pytest-10081 被 14 个里的 13 个损坏,只有 Claude Opus 4.8 保住;sphinx-9230 被 9 个模型损坏,五个 prompt 下全挂。也有只在某个 prompt 下才坏的(比如 pytest-7490 只在 Claude Code 的 prompt 下坏)。
Failures also cluster on specific tasks: pytest-10081 is damaged by 13 of 14 summarizers and preserved only by Claude Opus 4.8; sphinx-9230 is damaged by nine summarizers and fails under all five prompts. Some failures are prompt-specific (pytest-7490 breaks only under the Claude Code prompt).
"重复细节"指后面的请求里还会原样出现的字面值。七个模型 × 五个 prompt 的矩阵里,LLM 摘要的保留率在 5.0% 到 16.0% 之间。用 Claude Code 的 prompt 时: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%、GPT-5.6-Terra 8.2%。对照组是不用模型的机械提取(anchor_index),保留率 79.1%,比最好的 LLM 摘要高 63.1 个百分点。
"Recurring details" are literal values that reappear verbatim in later requests. Across the seven-model by five-prompt matrix, LLM summaries retain between 5.0% and 16.0%. With the Claude Code prompt: 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%, GPT-5.6-Terra 8.2%. The baseline is mechanical extraction (anchor_index) with no model involved: 79.1%, 63.1 points above the best LLM summary.
生产环境里的会话也一样:第一次压缩边界后只保留了 15.7%(106 个样本),第二次 19.9%(27 个),第三次 4.9%(6 个),第四次 1.8%(1 个)。后几次样本很少,这几个数别当趋势看。
Production sessions tell the same story: 15.7% kept after the first boundary (n=106), 19.9% after the second (n=27), 4.9% after the third (n=6), 1.8% after the fourth (n=1). The later samples are tiny, so do not read them as a trend.
论文分析了受损的几个例子。在 Kimi-K3 的四个稳定受损格子里,每份摘要都保留了目标文件;pytest-7571 的摘要甚至保留了全部五个被审计的 gold-patch token,任务还是挂了。sphinx-9230 的摘要漏掉了一个关键推理:这里的 split(None, 1) 必须改成 rsplit。POST 那一跑就在仓库里到处搜,最后没做出修改。
The paper examines some damaged cases. In the four stably damaged Kimi-K3 cells, every summary kept the target file. The pytest-7571 summary even kept all five audited gold-patch tokens, and the task still failed. The sphinx-9230 summary dropped one key piece of reasoning: split(None, 1) had to become rsplit. The POST run then searched the repository broadly and never made the edit.
这也解释了为什么 Claude Code 2.1.311 的几条修复值得留意:压缩返回没有摘要时重试一次、自动压缩后 CLAUDE.md/MEMORY.md 过期的 bug 修复。这些是 changelog 里的事实;它们和论文的数字没有直接对应关系,论文测的是各家压缩 prompt,不是这一版的行为。
It also explains why a few Claude Code 2.1.311 fixes matter: retrying once when a compaction reply has no summary, and the fix for stale CLAUDE.md/MEMORY.md after automatic compaction. These are changelog facts; they do not map directly onto the paper's numbers, because the paper tests each tool's compaction prompt, not this version's behavior.