The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui_gateway): a warm session.resume reports the chat's own model, not the profile default
teknium133a30fdd815a
diff --git a/tests/tui_gateway/test_resume_live_lazy_session.py b/tests/tui_gateway/test_resume_live_lazy_session.pyindex 1bb2149039d..28740881815 100644--- a/tests/tui_gateway/test_resume_live_lazy_session.py+++ b/tests/tui_gateway/test_resume_live_lazy_session.py@@ -76,3 +76,32 @@ def test_unscoped_resume_of_profile_session_fails_closed(live_lazy_session):def test_unknown_id_still_404s(home):out = _resume({"profile": "ops", "session_id": "ghost-9999", "omit_messages": True})assert out.get("error", {}).get("code") == 4007+++class _Agent:+ model = "claude-opus-5-5[1m]"+ provider = "claude-subscription-directsdk-experimental"++[email protected]("shape", ["override_only", "built_agent", "pending_switch"])+def test_live_reattach_reports_the_sessions_own_model_not_the_profile_default(live_lazy_session, monkeypatch, shape):+ """A reload of a still-live session must not flip the Desktop picker to the config default. The eager+ (cold) resume already reports the chat's own model; the warm reattach reported `_resolve_model()`, so+ the pick a user made in the composer appeared to change at random depending on whether the backend had+ dropped the session in between."""+ sid, record = live_lazy_session+ monkeypatch.setattr(srv, "_resolve_model", lambda: "z-ai/glm-5.2")+ expected = ("claude-opus-5-5[1m]", "claude-subscription-directsdk-experimental")+ if shape == "override_only":+ record["model_override"] = {"model": expected[0], "provider": expected[1]}+ elif shape == "built_agent":+ record["agent"] = _Agent()+ else:+ record["agent"] = _Agent()+ record["pending_model_switch"] = {"display_model": "claude-sonnet-5[1m]", "display_provider": expected[1]}+ expected = ("claude-sonnet-5[1m]", expected[1])+ out = _resume({"profile": "ops", "session_id": record["session_key"], "omit_messages": True})+ assert "error" not in out, out+ info = out["result"]["info"]+ assert (info["model"], info["provider"]) == expected+ assert info["lazy"] is Truediff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.pyindex b5f5fce3ec1..233d85d14d2 100644--- a/tui_gateway/methods_session.py+++ b/tui_gateway/methods_session.py@@ -604,10 +604,14 @@ def _resume_live_unpersisted(ctx: _Resume, live_sid: str, live: dict) -> dict:else:_cancel_ws_orphan_reap(live_sid)messages = ctx.messages(live.get("history") or []) # count the wire, as every other resume path does+ # The chat's own pick, not the profile default: a warm reattach that reported `_resolve_model()` flipped the+ # Desktop picker on every reload while the session was still live, and back once it had been dropped.+ model, provider = _live_session_identity(live)return _ok(ctx.rid, _attach_todo_state({"session_id": live_sid, "stored_session_id": str(live.get("session_key") or ""),"message_count": len(messages), "messages": messages,- "info": {"model": _resolve_model(), "lazy": True, "profile_name": profile_name_for_home(live.get("profile_home")) or _response_profile_name(ctx.profile)}}, live))+ "info": {"model": model, "provider": provider, "lazy": True,+ "profile_name": profile_name_for_home(live.get("profile_home")) or _response_profile_name(ctx.profile)}}, live))def _resume_adopt_stranded(ctx: _Resume) -> None:diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex abc6627a313..15fcea8a9fa 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -2095,6 +2095,21 @@ def _turn_started_at(session: dict | None) -> float | None:return float(inflight["started_at"]) if isinstance(inflight, dict) and inflight.get("started_at") else None+def _live_session_identity(session: dict) -> tuple[str, str]:+ """``(model, provider)`` the live session actually runs — the same precedence ``_session_info`` reports:+ a switch queued mid-turn, the metadata mirror, the built agent, the composer override a deferred record+ carries. The profile default is the LAST resort, never the answer for a chat that made its own pick."""+ pending = session.get("pending_model_switch") or {}+ mirror = _metadata_mirror(session)+ agent = session.get("agent")+ override = session.get("model_override") or {}+ model = (str(pending.get("display_model") or "").strip() or mirror.get("model")+ or getattr(agent, "model", "") or override.get("model") or _resolve_model())+ provider = (str(pending.get("display_provider") or "").strip() or mirror.get("provider")+ or getattr(agent, "provider", "") or override.get("provider") or "")+ return str(model), str(provider or "")++def _session_info(agent, session: dict | None = None) -> dict:if session is None:session = next((c for c in _sessions.values() if c.get("agent") is agent), None)