Skip a failing `TieredCompaction` tier on model errors, and let tiers omit their trigger
- Fixes #13106
TieredCompaction no longer fails the run when one tier hits a model failure, and its tiers no longer need a placeholder trigger.
[!WARNING]
Compatibility impact: On its own trigger, TieredCompaction now skips a tier that raises ModelAPIError, FallbackExceptionGroup or UnexpectedModelBehavior and moves on to the next tier. Before, the error propagated and ended the run.
Why this can ship in a minor release: a run that used to fail now carries on. Programming errors, UsageLimitExceeded and every exception from a direct compact() call still propagate.
Migration: pass TieredCompaction(..., skip_on=()) to keep the old behaviour.
What changed
- Tier failures become a recorded skip. On its own trigger,
TieredCompactionskips a tier that raises askip_onexception and escalates to the next one. The newskip_onfield defaults to(ModelAPIError, FallbackExceptionGroup, UnexpectedModelBehavior). The skipped tier's receipts are discarded and a warning is logged. Acompact_messagesspan records the tier ascompaction.strategy, along withcompaction.skipped='tier_failed'anderror.type. This is the same span shape #12655 uses forsummary_failed, through a sharedrecord_failed_compactionhelper that #12655 can reuse. Exceptions outsideskip_on(programming errors,UsageLimitExceeded) propagate, as the coordination note asks. - No placeholder tier trigger.
ClearToolResults,SlidingWindowCompactionandSummarizingCompactioncan now be constructed without a trigger. Used as a tier (or aFallbackCompaction/CompactOnRequeststrategy, or aRelevanceCompactionsummarizer), they need none. When one is registered on an agent without a trigger, it raisesUserErrorinbefore_run, so a misconfigured standalone capability is still reported instead of doing nothing. Docs, README and skill examples drop themax_tokens=1/max_messages=1placeholders.
Decisions (picked without asking, open to change)
- Response reservation and hysteresis are deferred. I followed pydanty's recommended split: this PR covers the failure handling and trigger inheritance, which already have a clear direction. The
reserve_output_tokens/max_tokensderivation and the re-trigger gap still need their semantics settled in #11395. - Skips happen on the automatic path only. A direct
TieredCompaction.compact()call (fromcompact_now,CompactOnRequest, or aFallbackCompactionchain) still raises. This matches the automatic/explicit split in #12655, and it means aFallbackCompactionwrapping a tiered chain still falls back. CompactionResult.metadatais not part of this PR. It comes from #11454, which hasn't merged. Once it lands, the skipped tiers and thetarget_unreachedflag (#12650) can be fed into it.skip_onis configurable, mirroringFallbackCompaction.fallback_on, so users can widen it or opt out with().
Tests
Regression tests (all fail on main):
- A failing tier is skipped and recorded (span attributes and warning).
- An agent run with trigger-less tiers whose summarizer raises
ModelAPIErrorfalls through to the sliding window and finishes. - A failed tier's receipts are dropped while a later successful tier's receipts are kept.
- Each strategy registered without a trigger raises
UserError.
The following still propagate: a programming error, an exception on a direct compact() call, and any failure when skip_on=().
This PR only touches pydantic_ai_harness (plus docs/harness).
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.
Summary by cubic
TieredCompaction now skips a tier that raises a model error on its own trigger instead of failing the run, and tiers no longer need a placeholder trigger.
- On its own trigger, a tier raising a
skip_onexception (default:ModelAPIError,FallbackExceptionGroup,UnexpectedModelBehavior) is skipped, its receipts discarded, and acompact_messagesspan records the skip witherror.type. ClearToolResults,SlidingWindowCompaction, andSummarizingCompactioncan now omit a trigger when used as a tier, fallback child,CompactOnRequeststrategy, orRelevanceCompactionsummarizer; registering one directly on an agent without a trigger raisesUserError.- Programming errors,
UsageLimitExceeded, and every exception from a directcompact()call still propagate. Passskip_on=()to keep the previous behavior.