chainStartIndex returns the index in the model chain (primary at 0, fallbacks at 1+) at which to begin trying. Normally 0, but during an active cooldown it returns the position of the pinned fallback so the primary is skipped.
(a *agent.Agent, fallbackCount int)
| 151 | // active cooldown it returns the position of the pinned fallback so the |
| 152 | // primary is skipped. |
| 153 | func (e *fallbackExecutor) chainStartIndex(a *agent.Agent, fallbackCount int) int { |
| 154 | state := e.cooldowns.Get(a.Name()) |
| 155 | if state == nil || fallbackCount <= state.fallbackIndex { |
| 156 | return 0 |
| 157 | } |
| 158 | slog.Debug("Skipping primary due to cooldown", |
| 159 | "agent", a.Name(), |
| 160 | "start_from_fallback_index", state.fallbackIndex, |
| 161 | "cooldown_until", state.until.Format(time.RFC3339)) |
| 162 | // +1 to convert from a.FallbackModels() index to modelChain index |
| 163 | // (modelChain[0] is the primary, modelChain[1] is the first fallback). |
| 164 | return state.fallbackIndex + 1 |
| 165 | } |
| 166 | |
| 167 | // recordSuccess updates the per-agent cooldown state after a successful |
| 168 | // model attempt. If a fallback rescued a non-retryable primary failure, |