Skip to content

The agent that grows with you

fix(gateway): make profile-scoped project session rows self-describing

evan-bradford208549432ea3
diff --git a/tests/tui_gateway/test_projects_rpc.py b/tests/tui_gateway/test_projects_rpc.py
index 1cd5a320c21..f2faa74262c 100644
--- a/tests/tui_gateway/test_projects_rpc.py
+++ b/tests/tui_gateway/test_projects_rpc.py
@@ -763,11 +763,13 @@ def test_projects_reads_are_scoped_to_the_requested_profile(monkeypatch, tmp_pat
assert coder_tree["projects"][0]["sessionCount"] == 1
assert launch_tree["scoped_session_ids"] == ["launch-session"]
assert coder_tree["scoped_session_ids"] == ["coder-session"]
+ assert [s["profile"] for s in coder_tree["projects"][0]["previewSessions"]] == ["coder"]
assert coder_sessions["project"]["id"] == coder_project["id"]
assert coder_sessions["project"]["sessionCount"] == 1
lane = coder_sessions["project"]["repos"][0]["groups"][0]
assert [s["id"] for s in lane["sessions"]] == ["coder-session"]
+ assert [s["profile"] for s in lane["sessions"]] == ["coder"]
def test_projects_tree_is_scoped_to_the_requested_profile(monkeypatch, tmp_path):
diff --git a/tui_gateway/methods_config.py b/tui_gateway/methods_config.py
index 916abfc1823..991390dd9a0 100644
--- a/tui_gateway/methods_config.py
+++ b/tui_gateway/methods_config.py
@@ -123,6 +123,9 @@ def _(rid, params: dict) -> dict:
Lanes carry no session rows here; drill-in uses ``projects.project_sessions``.
"""
try:
+ from tui_gateway.project_tree import stamp_profile
+ from tui_gateway.server import _response_profile_name
+
with _profile_db(params) as db:
if db is None:
return _ok(
@@ -136,6 +139,9 @@ def _(rid, params: dict) -> dict:
session_limit=int(params.get("session_limit") or 2000),
include_discovered=True,
)
+ stamp_profile(
+ tree["projects"], _response_profile_name(params.get("profile"))
+ )
return _ok(
rid,
{
@@ -155,6 +161,9 @@ def _(rid, params: dict) -> dict:
built from the same authoritative grouping as ``projects.tree`` so ids and
membership match exactly. Used when the user enters a project."""
try:
+ from tui_gateway.project_tree import stamp_profile
+ from tui_gateway.server import _response_profile_name
+
project_id = str(params.get("project_id") or "")
if not project_id:
return _err(rid, 5063, "project_id required")
@@ -172,6 +181,9 @@ def _(rid, params: dict) -> dict:
session_limit=int(params.get("session_limit") or 5000),
include_discovered=False,
)
+ stamp_profile(
+ tree["projects"], _response_profile_name(params.get("profile"))
+ )
proj = next((p for p in tree["projects"] if p["id"] == project_id), None)
return _ok(rid, {"project": proj})
except Exception as e:
diff --git a/tui_gateway/project_tree.py b/tui_gateway/project_tree.py
index 4f2d1eaaae1..0b4310ddaa7 100644
--- a/tui_gateway/project_tree.py
+++ b/tui_gateway/project_tree.py
@@ -63,6 +63,21 @@ NO_PROJECT_LABEL = "Home"
_MAX_SIBLING_PROBES = 4
+def stamp_profile(projects: list[dict], profile: str) -> None:
+ """Make every session row self-describing for cross-profile routing.
+
+ A scoped project tree is built from one profile's state.db, so the request
+ scope is authoritative even for legacy rows whose ``profile_name`` is NULL.
+ """
+ for project in projects:
+ for session in project.get("previewSessions") or []:
+ session["profile"] = profile
+ for repo in project.get("repos") or []:
+ for group in repo.get("groups") or []:
+ for session in group.get("sessions") or []:
+ session["profile"] = profile
+
+
def _branch_lane_id(repo_root: str, branch: str = "") -> str:
"""The one definition of a main-checkout lane id (must match the desktop)."""
return f"{repo_root}::branch::{(branch or '').strip()}"