Skip to content

fix(agent): summarize an overflowed request from less than what overflowed - #7113

Merged
M4n5ter merged 2 commits into
rust-previewfrom
fix/overflow-summary-fits
Nov 21, 2026
Merged

M4n5ter merged 2 commits into
rust-previewfrom
fix/overflow-summary-fits

Conversation

@UncertaintyDeterminesYou4ndMe

Copy link
Copy Markdown
Contributor

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:

  • The summary of an overflowed request is cut below what overflowed. Its budget is the smaller of the configured summary budget and three quarters of the summary input's own estimate. The existing excerpt fitting does the cut. This applies to both overflow cases (no output, and overflow after partial output); proactive and requested compaction are unchanged.
  • A summary that overflows fails with its own reason. It used to be assessed like a main request: a ContextOverflow recovery was recorded on an attempt that had closed, fold rejected it, and the user saw invalid event transition: context overflow requires an original interrupted model attempt. It now records Blocked, so the engine falls back to the summary's main request when there is one and otherwise fails the turn.

Not covered

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

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

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

overflow_summary_is_cut_below_the_request_that_overflowed is new. The existing overflow test now recognizes a summary request in its excerpt form. maka-agent-native lib: 197 tests, passing except the intermittent failure above and cell_notifications_deduplicate_child_knowledge_per_step_cut, which also fails intermittently on plain rust-preview (macOS).

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English

Thanks for diagnosing #7111 and adding an end-to-end acceptance test. A few things to address before merging:

  1. Missing newline breaks cargo fmt --check (plugins/agent/native/src/owner/driver_model.rs)
    After the new ModelPurpose::Summary early return, } let frozen = self.frozen_input(...) is missing a line break, so cargo fmt --check fails on this diff.

  2. Overflow summary still attaches the full tool catalog after excerpting (plugins/agent/native/src/owner/driver_model/summary_repair.rs)
    Once fit_prepared_summary rewrites the prompt into "Conversation excerpts for summarization...", prompt caching for the previous prefix is already gone. However, prepare_wire still sends &request.composition.tools with ToolChoiceMode::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 using ToolChoiceMode::None) when the summary has been excerpted/overflowed avoids wasting window on dead schemas.

  3. 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 /compact summaries, 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 consecutive bool flags; passing the computed budget directly or using a small enum makes call sites self-explanatory.
简体中文

感谢定位 #7111 并补了端到端行为测试。合并前有几处需要处理一下:

  1. 缺少换行导致 cargo fmt --check 失败(plugins/agent/native/src/owner/driver_model.rs)
    新增的 ModelPurpose::Summary 提前返回块后面,} let frozen = self.frozen_input(...) 漏了换行,格式检查会直接失败。

  2. 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)会更彻底。

  3. 错误文案与双布尔参数可读性(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 或拆成小枚举会清晰很多。

UncertaintyDeterminesYou4ndMe added a commit that referenced this pull request Nov 21, 2026
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)
@UncertaintyDeterminesYou4ndMe

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Rebased onto b499e51; the review changes are a separate commit, 2eaf95d.

1. Format. I could not reproduce this: cargo fmt --check -p maka-agent-native is clean on the reviewed head f567781 and on the new head, and let frozen = … is on its own line in both (driver_model.rs, after the new early return). If your check still reports it, tell me the command and I will look again.

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 ToolChoiceMode::None; its request spec records the empty list and the matching tool_catalog_digest (validate_tool_digest rejects the request otherwise). Native compaction and summary repair are unchanged. The test now asserts that the main request carries tools and the overflow summary does not.

3. Wording and flags. The diagnostic is now "the summary request exceeded the model's context limit". prepare_summary_input takes budget: Option<u64> computed by the caller in place of the two flags.

maka-agent-native lib: 199 tests, all passing except cell_notifications_deduplicate_child_knowledge_per_step_cut, which is intermittent on plain rust-preview (#7111).

(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)
@M4n5ter
M4n5ter force-pushed the fix/overflow-summary-fits branch from 2eaf95d to 052bbe2 Compare November 21, 2026 09:11
@M4n5ter

M4n5ter commented Nov 21, 2026

Copy link
Copy Markdown
Member
English

Looks great — thanks for the clean update (and sorry for the false alarm on the driver_model.rs formatting earlier).

Rebased onto rust-preview (bcd808b94, after CompositionSurface deduplication in #7115), updated summary_repair.rs to clear surface.tools, persist the updated CompositionSurface blob in contents, and recompute tool_catalog_digest when excerpted. Verified locally (cargo fmt --all -- --check, clippy clean on touched files, summary 6/6 and compact 15/15 passing), merging now.

简体中文

改得很干净(之前误报了 driver_model.rs 的格式问题,不好意思)。

已顺手 rebase 到最新 rust-preview(bcd808b94,合入了 #7115 的 CompositionSurface 去重改造),在 summary_repair.rs 中改为清空 surface.tools、写回新的 CompositionSurface blob 到 contents 并同步更新 tool_catalog_digest。本地已验证通过(cargo fmt --all -- --check、改动文件 clippy 零告警、summary 6/6、compact 15/15 全过),直接合入。

@M4n5ter
M4n5ter merged commit c7b7bf2 into rust-preview Nov 21, 2026
@M4n5ter
M4n5ter deleted the fix/overflow-summary-fits branch November 21, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants