Record a summarizer nested in `TieredCompaction` or `FallbackCompaction` as a durable operation

PY
1d ago
+947-35

A SummarizingCompaction nested as a TieredCompaction tier or in a FallbackCompaction chain is not registered on the agent, so its summarize durable operation never bound: under Temporal the summary call ran in the workflow sandbox and failed, and on DBOS, Prefect and the Harness engines it ran in workflow code without being recorded.

[!WARNING]
Compatibility impact: Under durable execution, a TieredCompaction or FallbackCompaction with no id that holds a strategy with durable operations (a summarizer, at any depth) now raises UserError asking for id=. On DBOS and Prefect this previously ran unbound in workflow code; on Temporal it failed (#14743). A workflow that compacted through a nested summarizer on an earlier version has no record of the new compact_strategy unit, so recovering it on this version replays a history that no longer lines up.

Why this can ship in a minor release: it fixes a durable-execution defect. Plain agents, non-durable runs, and composites without such a strategy behave as before, and core already raises UserError for any id-less capability with durable operations.

Migration: pass a stable id= to the composite and keep it, and the strategy order, fixed. Let in-flight workflows that use nested summarizers finish on the previous version before upgrading workers.

Changes

  • TieredCompaction and FallbackCompaction stay anonymous (no default id; several compose on one agent) and run in workflow code. Only a nested strategy with durable operations runs as the outermost composite's compact_strategy durable operation, taking its path of indices as an argument. The name is <agent>__capability__<composite id>.compact_strategy (Temporal activity: agent__<agent>__capability__<id>__compact_strategy). Cheap strategies and receipts stay in workflow code, where ctx.capabilities exists.
  • An anonymous capability has no stable run id: its synthetic key is random per run. So the composites set _durable_operations_need_id = False, and before_run raises UserError only when the run is durable and a nested durable strategy exists.
  • An exception the composite handles (skip_on / fallback_on) comes back from the operation as data and is restored as its original class in workflow code, so skip_on / fallback_on match it as they do outside durable execution (exception groups and classes that can't be imported included). Under Temporal it would otherwise arrive as ActivityError and be retried.
  • Core change (pydantic_ai_slim/pydantic_ai/_capability_loads.py, +6 lines): deferred_capability_ids reads the ids serialized with a DurableRunContext (the registry doesn't cross a Temporal activity), so a summarizer runs inside an activity. This is the one change outside the harness, and it applies to any capability that reads deferred capability ids inside a durable unit, as RunContext.is_tool_available already does.
  • The capability tree is not changed, so plain-agent merging is unaffected. The PR's first approach exposed tiers to apply, which merged two summarizer tiers and let a top-level summarizer delete a tier.
  • Docs (docs/harness/compaction.md, README twin) and the harness skill describe the naming, the id requirement and the upgrade note.

Tests

  • Plain Agent: two summarizer tiers keep escalating cheap to strong, and a summarizer tier runs beside a top-level summarizer.
  • DBOS: nested TieredCompaction, FallbackCompaction, FallbackCompaction in TieredCompaction, and two summarizer tiers each record compact_strategy steps. A direct summarizer keeps summarizing_compaction.summarize. An anonymous cheap-only composite adds no step, and an anonymous composite holding a summarizer raises UserError.
  • Temporal: nested Tiered, Fallback and Fallback-in-Tiered schedule compact_strategy activities and replay without calling a summarizer again. A sliding window with receipts=True ahead of a summarizer in FallbackCompaction succeeds in workflow code (it failed on 1a6ecdf71f). A ModelAPIError from the activity still skips a tier and falls back in a chain.

Closes #14743

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.