Skip to content

The agent that grows with you

fix(tui_gateway): report a lazy session's own cwd, not the launch dir

bb6ff052479bdf
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index c8e6679aa50..cc7b94b61c8 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -16375,3 +16375,38 @@ def test_prompt_submit_releases_old_history_before_heap_trim(monkeypatch):
assert cleanup_order == ["trim", "reset_home"]
finally:
server._sessions.pop("sid_trim", None)
+
+
+def test_fallback_session_info_reports_session_cwd_not_launch_dir(monkeypatch):
+ """A lazily-resumed session must report ITS workspace, not the gateway's.
+
+ ``_fallback_session_info`` used ``_default_session_cwd()`` — the directory the
+ gateway process happened to start in — so the desktop Files pane painted the
+ wrong project for any session resumed without a built agent (#71254).
+ """
+ monkeypatch.setattr(server, "_default_session_cwd", lambda: "/gateway/launch/dir")
+ monkeypatch.setattr(server, "_git_branch_for_cwd", lambda cwd: "bb/feature")
+ monkeypatch.setattr(server, "_project_info_for_cwd", lambda cwd: None)
+ monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
+
+ info = server._fallback_session_info({"cwd": "/projects/session-own-repo"})
+
+ assert info["cwd"] == "/projects/session-own-repo"
+ assert info["branch"] == "bb/feature"
+
+
+def test_fallback_session_info_always_emits_branch(monkeypatch):
+ """``branch`` is always present so a client can CLEAR a stale label.
+
+ Omitting the key left the desktop showing the previous conversation's branch
+ after switching into a non-git session.
+ """
+ monkeypatch.setattr(server, "_default_session_cwd", lambda: "/gateway/launch/dir")
+ monkeypatch.setattr(server, "_git_branch_for_cwd", lambda cwd: "")
+ monkeypatch.setattr(server, "_project_info_for_cwd", lambda cwd: None)
+ monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
+
+ info = server._fallback_session_info({"cwd": "/plain/folder"})
+
+ assert "branch" in info
+ assert info["branch"] == ""
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index 462b89ff249..a146c3ebcb7 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -7968,9 +7968,17 @@ def _fallback_session_info(session: dict) -> dict:
agent = session.get("agent")
if agent is not None:
return _session_info(agent)
- cwd = _default_session_cwd()
+ # The SESSION's own workspace, not the gateway's launch directory. Reporting
+ # `_default_session_cwd()` here told a lazily-resumed session's client that
+ # its workspace was wherever the gateway process happened to start, so the
+ # desktop Files pane painted the wrong project even after the renderer
+ # rebound correctly (#71254). `branch` is always emitted ("" outside a git
+ # repo) so a client can clear a stale label instead of retaining it — the
+ # same contract `_lazy_session_info` above already follows.
+ cwd = _session_cwd(session)
return {
"cwd": cwd,
+ "branch": _git_branch_for_cwd(cwd),
"project": _project_info_for_cwd(cwd),
"lazy": True,
"model": _resolve_model(),