When the primary model fails and the agent switches to a fallback provider, the CLI session header continues to display the primary model name instead of the fallback model.
Root cause: _build_system_prompt() caches the system prompt in self._cached_system_prompt. When _try_activate_fallback() swaps the model/provider, and when _restore_primary_runtime() restores them at the start of a new turn, neither method invalidates the cache. The stale model name therefore persists in the system prompt until something else triggers a rebuild.
Fix: Call self._invalidate_system_prompt() in both _try_activate_fallback() and _restore_primary_runtime() so the prompt is rebuilt with the correct model/provider. Also harden _invalidate_system_prompt() with getattr to avoid attribute errors in test fixtures.
Verification:
python -m pytest tests/run_agent/test_compressor_fallback_update.py tests/run_agent/test_primary_runtime_restore.py -xvs passes (27/27).
When the primary model fails and the agent switches to a fallback provider, the CLI session header continues to display the primary model name instead of the fallback model.
Root cause:
_build_system_prompt()caches the system prompt inself._cached_system_prompt. When_try_activate_fallback()swaps the model/provider, and when_restore_primary_runtime()restores them at the start of a new turn, neither method invalidates the cache. The stale model name therefore persists in the system prompt until something else triggers a rebuild.Fix: Call
self._invalidate_system_prompt()in both_try_activate_fallback()and_restore_primary_runtime()so the prompt is rebuilt with the correct model/provider. Also harden_invalidate_system_prompt()withgetattrto avoid attribute errors in test fixtures.Verification:
python -m pytest tests/run_agent/test_compressor_fallback_update.py tests/run_agent/test_primary_runtime_restore.py -xvspasses (27/27).