Give `Coder` summarizing compaction with the run's model, and add `keep_fraction` and `CannotSummarizeError` to harness compaction

DO
2d ago
+467-74

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_fraction on SummarizingCompaction and SlidingWindowCompaction sets the kept-tail floor as a fraction of the request model's window, resolved like max_fraction. Next to keep_tokens (a minimum retention floor since #9784) the smaller floor applies. Without it, a keep_tokens=50_000 floor on a 32K model kept the whole history, so compaction did nothing.
  • CannotSummarizeError(UserError) is raised by SummarizingCompaction when its model is realtime or can't write text. Previously this was a plain UserError with the same message. The check now runs in compact() rather than in the durable summarize operation, so a FallbackCompaction can catch it under durable execution.

Details:

  • The summarizer gets its own durable-operation id, coder_summarizing_compaction, so it never dispatches to a separately bound SummarizingCompaction. A new Temporal test confirms that Coder's summary request runs through an activity.
  • clai2: the coder plugin binds Coder(compaction=False), so the compaction plugin 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 without keep_fraction or the CannotSummarizeError fallback, since protected_tokens is documented as never compacted. Adopting those is a follow-up. The compatibility matrix is unchanged: coder still binds no history compaction. clai2 sessions no longer clear tool results at 70%; the compaction plugin 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.md and README.md (with their parity markers), the harness skill reference, and the clai2 docs/reference.md, PLUGINS.md, and config/builtins.py notes.

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.