Skip to content

fix(agent-runtime): fit compaction summaries to the output budget - #59

Merged
kylinmac merged 1 commit into
mainfrom
fix/compaction-summary-budget
Oct 30, 2026
Merged

kylinmac merged 1 commit into
mainfrom
fix/compaction-summary-budget

Conversation

@kylinmac

Copy link
Copy Markdown
Owner

改动

修正 #55 压缩摘要的两处问题,并加强用户原话的保留。缺陷记录 B-039、B-040。

  • 篇幅目标按预算缩放(B-039)。 原来固定要求 4K–8K tokens。输出上限 8K 左右的模型(未知模型默认 8192)和推理共用预算,容易截断;截断不算瞬时错误,pi-ai 不重试,于是每次压缩都失败,自动路径丢掉整段旧历史。现在上限取生成预算的 40%,最多 8K,预算充足时仍是 4K–8K;分割回合的前缀摘要单独用 2K 上限。
  • 截断后重试一次。 用减半的篇幅目标和模型最低支持的推理等级(省略推理时保持省略)再发一次,界面显示为重试;仍截断才判失败。两次用量合计记入检查点。用户停止后不再重试。截断结果仍不落盘。
  • 逐字保留用户原话。 仍有效的约束、禁止、批准/拒绝和纠正逐字引用关键句(每条约 300 字符内);更新摘要时保留旧引用,除非用户已撤销。已完成的请求改写为结果;粘贴的日志、代码不照抄。引用合计不超过摘要约四分之一。
  • 尝试次数(B-040)。 分割回合的前缀请求沿用上一请求的计数,首次重试显示“第 3 次”。现在每个请求从第 1 次计数,只有排定的重试才累加。

刻意未改

压缩后附回文件内容、附完整记录路径、摘要复用提示词缓存,这几项改动面更大,不在本 PR。推理选择规则、静默超时、失败兜底语义都不变。

验证

  • agent-runtime 完整测试:112 个文件、1535 项通过;typecheck、pnpm lint 通过。
  • 新增用例:8K 预算的目标缩放、前缀短目标、截断后短重试(推理降级、用量合计、回调)、停止后不重试、原话规则;runtime 前缀计数用例撤掉修复时失败,修复后通过。
  • git diff --check、文档检查(644 页)通过;6 条提示是既有的上游 ADR 格式提示。

未调用真实模型。40% 的比例和原话规则依据参考实现推算,真实模型的截断率和摘要保真未测。

🤖 Generated with Claude Code

The handoff prompt asked for 4K-8K tokens regardless of the request's
output limit. On models capped near 8K, with reasoning sharing that
budget, summaries hit the limit; a truncated summary is rejected and is
not a transient error, so every compaction failed and auto compaction
fell back to dropping the whole older history.

Scale the length target to 40% of the generation budget (capped at 8K),
give split-turn prefix summaries their own 2K target, and retry a
truncated summary once with a halved target and the lowest supported
reasoning before failing. The prompt now quotes still-applicable user
constraints, approvals and corrections verbatim instead of paraphrasing
them, while completed requests and pasted material stay condensed.

Also restart the progress attempt count for each summary request, so a
split turn's prefix retry no longer reports attempt 3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant