Skip a failing `TieredCompaction` tier on model errors, and let tiers omit their trigger

Closed
MP
19d ago
+281-70

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, TieredCompaction skips a tier that raises a skip_on exception and escalates to the next one. The new skip_on field defaults to (ModelAPIError, FallbackExceptionGroup, UnexpectedModelBehavior). The skipped tier's receipts are discarded and a warning is logged. A compact_messages span records the tier as compaction.strategy, along with compaction.skipped='tier_failed' and error.type. This is the same span shape #12655 uses for summary_failed, through a shared record_failed_compaction helper that #12655 can reuse. Exceptions outside skip_on (programming errors, UsageLimitExceeded) propagate, as the coordination note asks.
  • No placeholder tier trigger. ClearToolResults, SlidingWindowCompaction and SummarizingCompaction can now be constructed without a trigger. Used as a tier (or a FallbackCompaction / CompactOnRequest strategy, or a RelevanceCompaction summarizer), they need none. When one is registered on an agent without a trigger, it raises UserError in before_run, so a misconfigured standalone capability is still reported instead of doing nothing. Docs, README and skill examples drop the max_tokens=1 / max_messages=1 placeholders.

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_tokens derivation and the re-trigger gap still need their semantics settled in #11395.
  • Skips happen on the automatic path only. A direct TieredCompaction.compact() call (from compact_now, CompactOnRequest, or a FallbackCompaction chain) still raises. This matches the automatic/explicit split in #12655, and it means a FallbackCompaction wrapping a tiered chain still falls back.
  • CompactionResult.metadata is not part of this PR. It comes from #11454, which hasn't merged. Once it lands, the skipped tiers and the target_unreached flag (#12650) can be fed into it.
  • skip_on is configurable, mirroring FallbackCompaction.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 ModelAPIError falls 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_on exception (default: ModelAPIError, FallbackExceptionGroup, UnexpectedModelBehavior) is skipped, its receipts discarded, and a compact_messages span records the skip with error.type.
  • ClearToolResults, SlidingWindowCompaction, and SummarizingCompaction can now omit a trigger when used as a tier, fallback child, CompactOnRequest strategy, or RelevanceCompaction summarizer; registering one directly on an agent without a trigger raises UserError.
  • Programming errors, UsageLimitExceeded, and every exception from a direct compact() call still propagate. Pass skip_on=() to keep the previous behavior.