Apply `FallbackModel` response handlers when continuing a suspended response

Merged
DO
1mo ago
+118-18

FallbackModel skipped its response handlers (fallback_on callables that take a ModelResponse) when continuing a suspended response on the model it is pinned to: the pinned path returned the response before judging it, so a response the handler rejects was accepted as the run's output. This was found by a stress test of #9348, where the same scenario through the ModelFallback capability does call the handler.

The pinned continuation's response is now judged like any other non-streamed response. A rejection is handled the way a fallback-eligible error on the pinned continuation already is:

  • If the rejected response is still suspended, its server-side job is best-effort cancelled. A finished response has no job left, so nothing is cancelled.
  • The suspended response is rewound and the fallback chain is retried. The chain's response replaces the abandoned turn.
  • The rejected response is recorded as a rejected attempt in failed_attempts, so its usage counts towards the run, and it is counted in ResponseRejected if every model fails.

Before, with fallback_on=reject rejecting model primary and history ending in a suspended primary response, the run's output was the rejected oldbad and the handler was never called. Now the handler is called, the output is the fallback's good, and both rejected primary attempts appear in failed_attempts and in the run usage.

Streamed requests are unchanged: response handlers still don't apply to them. Responses that don't come from a pinned continuation are also unchanged.

Checklist

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

šŸ¤– Generated with Claude Code