Preserve rejected-response usage when an outer `FallbackModel` handles an exception

Closed
XX
23d ago
+55-6

Closes #12853

Why we make these changes

When an inner FallbackModel rejects a response and then raises an exception handled only by an outer fallback, AttemptLog.record() drops the attempts carried on that exception. Preserve those records using carried_attempts(), alongside the existing response and exception-group paths.

New public surface

none

User-visible behavior

A rejected response billed at 120 input tokens / 0.012 cost followed by a successful outer backup at 45 / 0.0045 previously reported only 45 / 0.0045. It now reports 165 / 0.0165, and token limits of 150 or cost limits of 0.015 raise UsageLimitExceeded.

Verification

  • Extended nested attempt preservation to cover unhandled inner exceptions.
  • Added accounting and limit regressions through both FallbackModel and ModelFallback, including a passing budget that would fail if rejected usage were counted twice.
  • Before the fix: the nested test selection had 5 failures and 5 passes. After: all 10 pass; the full fallback test file passes 143 tests.
  • An additional 24-case offline matrix passes. Changed-file Pyright, make format lint, and all pre-commit hooks pass. Full repository CI, including coverage, passed on 5f63067.

What changes for existing users

Nested fallback runs retain all billed usage and enforce the configured token and cost limits without double-counting.

PR decisions

2026-11-08 · pre-push review 1 of 3 at 5f6306727a14fcbd48b5426a184182cb79c5d54b · iter -

2026-11-08 · pre-push review 1 of 3 at 5f6306727a14fcbd48b5426a184182cb79c5d54b · iter -

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. (Not applicable: restores documented usage accounting without a public API change.)
  • PR title is fit for the release changelog.