Existing agent sessions keep using a stale model after API key or model configuration changes
Summary
After saving a new API key or changing model configuration, an already opened session can continue using the old model/runtime until Pi Web is restarted.
Steps to reproduce
- Open an existing session while its intended provider is unavailable, so the session falls back to another available model (for example, Ollama).
- In Models, add/save a valid API key for the intended provider (for example, DeepSeek).
- Confirm the provider is configured and the intended model is visible/default in the model list.
- Send another message in the same already opened session.
Actual behavior
The existing session continues sending requests through its previously created model runtime.
In my case, after DeepSeek was configured and deepseek/deepseek-v4-pro became the default model, the active session still sent requests to:
ollama/qwen2.5-coder:3b
Design question
Reloading an existing AgentSession refreshes settings/resources, but does not re-run the session model restoration/fallback logic.
Should Pi Web:
- recreate an idle cached
AgentSessionafter model/auth configuration changes, or - expose/use an SDK operation that re-evaluates the session model after credentials become available?
The implementation also needs to preserve or reconnect the session SSE stream.
Thanks for the report. After reviewing Pi's session and model lifecycle, this behavior is expected.
Pi does not switch to another model when a request fails; retries continue using the same model. The fallback described here only occurs when opening an existing session: if the model saved in the session cannot be restored because its authentication is unavailable, the SDK selects another currently available model for the newly created in-memory AgentSession.
Once the session is open, that selected model remains the session's current model. Adding credentials or changing the default model later updates the available models and defaults, but intentionally does not change an already-open session. Automatically reloading or switching active sessions on authentication changes could interrupt an active run or unexpectedly change the provider and cost.
After configuring the credentials, the intended model can be selected explicitly from the model selector. /reload can be used first if the model list needs to be refreshed.
Closing this as expected behavior.