Repository navigation
fix(agent): summarize an overflowed request from less than what overflowed - #7113
Conversation
M4n5ter
left a comment
There was a problem hiding this comment.
English
Thanks for diagnosing #7111 and adding an end-to-end acceptance test. A few things to address before merging:
-
Missing newline breaks
cargo fmt --check(plugins/agent/native/src/owner/driver_model.rs)
After the newModelPurpose::Summaryearly return,} let frozen = self.frozen_input(...)is missing a line break, socargo fmt --checkfails on this diff. -
Overflow summary still attaches the full tool catalog after excerpting (
plugins/agent/native/src/owner/driver_model/summary_repair.rs)
Oncefit_prepared_summaryrewrites the prompt into"Conversation excerpts for summarization...", prompt caching for the previous prefix is already gone. However,prepare_wirestill sends&request.composition.toolswithToolChoiceMode::Auto. With built-in + MCP tools easily consuming 10k-20k+ tokens, cutting conversation history to 75% while keeping all unused tool schemas means small real-window models (the exact Ollama / misconfigured-window scenario in #7111) can still overflow on the summary request. Dropping tools (and usingToolChoiceMode::None) when the summary has been excerpted/overflowed avoids wasting window on dead schemas. -
Diagnostic wording and boolean parameter clarity (
plugins/agent/native/src/owner/driver_model.rs)- The early return on
request.accounting.purpose == ModelPurpose::Summary && matches!(failure, ContextOverflow { .. })also triggers for proactive compaction and manual/compactsummaries, where no main request overflowed beforehand. Using a neutral message (e.g.,"the summary request exceeded the model's context limit") avoids saying"was also too long"when nothing overflowed first. prepare_summary_input(&mut prompt, model, language, native_compaction, false)now takes two consecutiveboolflags; passing the computed budget directly or using a small enum makes call sites self-explanatory.
- The early return on
简体中文
感谢定位 #7111 并补了端到端行为测试。合并前有几处需要处理一下:
-
缺少换行导致
cargo fmt --check失败(plugins/agent/native/src/owner/driver_model.rs)
新增的ModelPurpose::Summary提前返回块后面,} let frozen = self.frozen_input(...)漏了换行,格式检查会直接失败。 -
overflow summary 裁剪成摘录后仍附带完整工具定义(
plugins/agent/native/src/owner/driver_model/summary_repair.rs)
fit_prepared_summary一旦把历史改写成"Conversation excerpts for summarization...",原本的 prompt cache 前缀就已经失效了;但后面的prepare_wire仍然带着完整的&request.composition.tools和ToolChoiceMode::Auto发给 summary 请求。在内置工具加 MCP 工具动辄一两万 token 的情况下,只把历史裁到 75% 却保留全量无用工具 schema,小窗口模型(正是 #7111 瞄准的 Ollama / 窗口配置偏大场景)依然容易二次爆窗。summary 走裁剪/overflow 路径时去掉 tools(并设ToolChoiceMode::None)会更彻底。 -
错误文案与双布尔参数可读性(
plugins/agent/native/src/owner/driver_model.rs)request.accounting.purpose == ModelPurpose::Summary && matches!(failure, ContextOverflow { .. })这个分支也会命中主动压缩和手动/compact时的 summary 爆窗(此时主请求并未爆窗),文案写成"was also too long"在那些路径上不太准确,改成中性表述(如"the summary request exceeded the model's context limit")更贴切。prepare_summary_input(..., native: bool, overflowed: bool)连续两个布尔参数在调用处不易读,直接传入算好的 budget 或拆成小枚举会清晰很多。
Review of #7113. A summary cut to excerpts no longer shares the request's cached prefix, so its tool definitions only took window: with tens of thousands of tokens of schemas a small real window could overflow again. The excerpted summary is now sent with no tools and no tool choice, and its request spec records the same. The summary budget is computed by the caller instead of two flags, and the diagnostic of a summary that overflows no longer says a main request overflowed first. Generated-by: Claude Code (claude-fable-5-2)
f567781 to
2eaf95d
Compare
|
Thanks for the review. Rebased onto b499e51; the review changes are a separate commit, 2eaf95d. 1. Format. I could not reproduce this: 2. Tools on the excerpted summary. Agreed, and it closes part of what I had listed as not covered. A summary that was cut to excerpts is now sent with no tools and 3. Wording and flags. The diagnostic is now "the summary request exceeded the model's context limit".
(Claude Code, Claude Fable 5.2.) |
…lowed A request the provider rejects as too long was summarized from the same history, the same tools and the summary instruction: more than what had just overflowed. The summary input is trimmed only above the configured window, and a request that overflows unsummarized is below it, so the summary overflowed too and the conversation failed on every later turn. The summary of an overflowed request is now cut to three quarters of its own estimate when that is below the configured budget. A summary that still overflows no longer records an overflow recovery, which fold rejects for an attempt that closed instead of being interrupted; the turn fails with the summary's own reason, or falls back to its main request. Refs #7111 Generated-by: Claude Code (claude-fable-5-2)
Review of #7113. A summary cut to excerpts no longer shares the request's cached prefix, so its tool definitions only took window: with tens of thousands of tokens of schemas a small real window could overflow again. The excerpted summary is now sent with no tools and no tool choice, and its request spec records the same. The summary budget is computed by the caller instead of two flags, and the diagnostic of a summary that overflows no longer says a main request overflowed first. Generated-by: Claude Code (claude-fable-5-2)
2eaf95d to
052bbe2
Compare
EnglishLooks great — thanks for the clean update (and sorry for the false alarm on the Rebased onto 简体中文改得很干净(之前误报了 已顺手 rebase 到最新 |
Summary
Part of #7111.
When the provider rejects a main request as too long, the Host summarizes and continues. The summary input was the same history, the same tool definitions and the summary instruction, so it was larger than the request that had just overflowed. It is trimmed only when its estimate exceeds the configured window, and a request that reaches the provider unsummarized is below that window. Whenever the real window is smaller than the configured one, the summary overflowed too, the turn failed, the history stayed as it was, and every later turn repeated this.
Two changes:
ContextOverflowrecovery was recorded on an attempt that had closed,foldrejected it, and the user sawinvalid event transition: context overflow requires an original interrupted model attempt. It now recordsBlocked, so the engine falls back to the summary's main request when there is one and otherwise fails the turn.Not covered
context_overflow_after_partial_output_compacts_and_continuesfails intermittently on plainrust-preview871e747 (3 of 10 fullmaka-agent-nativelib runs, never when run alone) with the sameinvalid event transitiontext, there for a main request. That is a separate race and this PR does not change it; details in bug(agent): a conversation fails on every turn once the summary after a context overflow fails #7111.AI use
Tool(s) and scope: Claude Code. A Claude Opus 5.5 subagent wrote the reproduction; Claude Fable 5.2 wrote the change and the test.
Checklist
overflow_summary_is_cut_below_the_request_that_overflowedis new. The existing overflow test now recognizes a summary request in its excerpt form.maka-agent-nativelib: 197 tests, passing except the intermittent failure above andcell_notifications_deduplicate_child_knowledge_per_step_cut, which also fails intermittently on plainrust-preview(macOS).Does this PR entail a change in behavior?