Give `Coder` summarizing compaction with the run's model, and add `keep_fraction` and `CannotSummarizeError` to harness compaction
Coder now compacts long conversations itself. It binds FallbackCompaction over SummarizingCompaction then SlidingWindowCompaction, the same chain clai2's compaction plugin uses, in place of ClearToolResults(max_fraction=0.7) (WarnNearLimits already left Coder in #9969). Above 85% of the model's context window, the run's own model summarizes older messages, keeping at least the newest 50,000 tokens, or 40% of the window if that is less (keep_tokens=50_000, keep_fraction=0.4). When summarizing fails (a model API error, an exhausted FallbackModel, a usage limit, or a realtime or text-less model that can't summarize), those messages are dropped instead. Coder(compaction=False) leaves it out, for hosts that bind their own compaction, matching repo_context=False and sub_agents=False.
[!WARNING]
Compatibility impact: Existing Coder() agents now summarize their history with an extra model request when it passes 85% of the context window, instead of clearing old tool results at 70%. That request counts toward the run's usage and cost.
Why this can ship in a minor release: pydantic-ai-harness is 0.x. The change is a default composition, and the new argument restores full control.
Migration: pass Coder(compaction=False) and add ClearToolResults(max_fraction=0.7) yourself (documented under "Upgrading" on the Coder page).
Supporting public additions to harness compaction:
keep_fractiononSummarizingCompactionandSlidingWindowCompactionsets the kept-tail floor as a fraction of the request model's window, resolved likemax_fraction. Next tokeep_tokens(a minimum retention floor since #9784) the smaller floor applies. Without it, akeep_tokens=50_000floor on a 32K model kept the whole history, so compaction did nothing.CannotSummarizeError(UserError)is raised bySummarizingCompactionwhen its model is realtime or can't write text. Previously this was a plainUserErrorwith the same message. The check now runs incompact()rather than in the durablesummarizeoperation, so aFallbackCompactioncan catch it under durable execution.
Details:
- The summarizer gets its own durable-operation id,
coder_summarizing_compaction, so it never dispatches to a separately boundSummarizingCompaction. A new Temporal test confirms thatCoder's summary request runs through an activity. clai2: thecoderplugin bindsCoder(compaction=False), so thecompactionplugin stays the only chain, with its settings,/compact, and context gauge. Its behaviour is unchanged here: same shape and trigger (0.85,protected_tokens=50_000), but withoutkeep_fractionor theCannotSummarizeErrorfallback, sinceprotected_tokensis documented as never compacted. Adopting those is a follow-up. The compatibility matrix is unchanged:coderstill binds no history compaction.clai2sessions no longer clear tool results at 70%; thecompactionplugin already compacts at 85%.- Docs: the Coder page and harness README (composition and an Upgrading note), the harness index, the front-page "blocks" example in
docs/index.mdandREADME.md(with their parity markers), the harness skill reference, and theclai2docs/reference.md, PLUGINS.md, andconfig/builtins.pynotes.
No issue: this follows a maintainer decision (Douwe).
Checklist
- No breaking changes in accordance with the version policy. (Harness 0.x default change; see the warning above.)
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.