From 6ff052479bdf7d125cd07eebd205c82ef5c705bd Mon Sep 17 00:00:00 2001 From: bb Date: Fri, 7 Aug 2026 13:07:02 -0500 Subject: [PATCH] fix(tui_gateway): report a lazy session's own cwd, not the launch dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_fallback_session_info` returned `_default_session_cwd()` — the directory the gateway process happened to start in — so a session resumed without a built agent told its client the wrong workspace, and the desktop Files pane painted the wrong project even after the renderer rebound correctly. Return the session's own cwd and always emit `branch` ("" outside a git repo) so a client can clear a stale label instead of retaining it. This matches the contract `_lazy_session_info` already follows a few hundred lines above. Co-authored-by: ZHJay --- tests/test_tui_gateway_server.py | 35 ++++++++++++++++++++++++++++++++ tui_gateway/server.py | 10 ++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py index c8e6679aa5..cc7b94b61c 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 462b89ff24..a146c3ebcb 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(),