Skip to content

Commit 9d19b45

Browse files
committed
fix(agent-loop): Stop spurious "fallback expired" toast at startup
`_last_resolved_model_alias` is initialized to `None`, so the first call to `_resolve_model_with_fallback` saw `previous_alias=None` and treated it as a transition from a non-primary model back to primary, firing a "Fallback expired, back to <primary>" toast on every launch. Treat `None` as "no previous resolution yet" and skip the restored notification in that case.
1 parent 06c110e commit 9d19b45

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎albert_code/core/agent_loop.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ def _resolve_model_with_fallback(self) -> ModelConfig:
319319
from albert_code.core.llm.throttling import get_throttler
320320

321321
primary = self.config.get_active_model()
322-
previous_alias = getattr(self, "_last_resolved_model_alias", primary.alias)
322+
# `None` means "no previous resolution yet" (e.g. first call after
323+
# init). Treat it as already-on-primary so we don't surface a
324+
# spurious "fallback expired" toast at startup.
325+
previous_alias = self._last_resolved_model_alias
323326

324327
if not primary.fallback_model or not self.config.auto_fallback_enabled:
325328
self._last_resolved_model_alias = primary.alias
@@ -328,7 +331,7 @@ def _resolve_model_with_fallback(self) -> ModelConfig:
328331
provider = self.config.get_provider_for_model(primary)
329332
throttler = get_throttler(provider)
330333
if not throttler.should_fallback(primary.alias):
331-
if previous_alias != primary.alias:
334+
if previous_alias is not None and previous_alias != primary.alias:
332335
self._notify_fallback(
333336
"restored", f"Fallback expired, back to {primary.alias}", 0.0
334337
)

0 commit comments

Comments
 (0)