Record a summarizer nested in `TieredCompaction` or `FallbackCompaction` as a durable operation
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
TieredCompactionandFallbackCompactionstay 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'scompact_strategydurable 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, wherectx.capabilitiesexists.- An anonymous capability has no stable run id: its synthetic key is random per run. So the composites set
_durable_operations_need_id = False, andbefore_runraisesUserErroronly 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, soskip_on/fallback_onmatch it as they do outside durable execution (exception groups and classes that can't be imported included). Under Temporal it would otherwise arrive asActivityErrorand be retried. - Core change (
pydantic_ai_slim/pydantic_ai/_capability_loads.py, +6 lines):deferred_capability_idsreads the ids serialized with aDurableRunContext(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, asRunContext.is_tool_availablealready 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, theidrequirement 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,FallbackCompactioninTieredCompaction, and two summarizer tiers each recordcompact_strategysteps. A direct summarizer keepssummarizing_compaction.summarize. An anonymous cheap-only composite adds no step, and an anonymous composite holding a summarizer raisesUserError. - Temporal: nested Tiered, Fallback and Fallback-in-Tiered schedule
compact_strategyactivities and replay without calling a summarizer again. A sliding window withreceipts=Trueahead of a summarizer inFallbackCompactionsucceeds in workflow code (it failed on 1a6ecdf71f). AModelAPIErrorfrom 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.