Skip to content

The agent that grows with you

fix(sessions): stamp launch-profile name on new session rows instead of NULL

Teknium6874b99d4906
diff --git a/run_agent.py b/run_agent.py
index 60301d5cbbf..87e8c941d3a 100644
--- a/run_agent.py
+++ b/run_agent.py
@@ -656,8 +656,13 @@ class AIAgent:
try:
from hermes_cli.profiles import get_active_profile_name
_profile_for_session = get_active_profile_name()
- if _profile_for_session == "default":
- _profile_for_session = None
+ # Persist the profile name EXPLICITLY, including "default".
+ # NULL used to stand in for the default profile, but the
+ # #94724 legacy-owner backfill already stamps literal
+ # "default" onto old rows, and profile-keyed consumers
+ # (sidebar scope matching, @session:<profile>/<id> deep
+ # links) treat NULL as unowned — rows minted NULL after the
+ # one-shot backfill vanished from the sidebar (#99222).
except Exception:
_profile_for_session = None
# Carry the live YOLO bypass into the creation-time model_config so
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index 6166c5e57f3..4ac97a3f200 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -7639,6 +7639,28 @@ def test_ensure_session_db_row_stamps_profile_name(monkeypatch, tmp_path):
assert created[0]["db_path"] == profile_home / "state.db"
+def test_ensure_session_db_row_stamps_launch_profile_name(monkeypatch):
+ """A launch-profile session row is stamped with the ACTUAL profile name,
+ never NULL. NULL-as-launch-profile rows vanish from the desktop sidebar
+ (profile-keyed matching) and break @session:<profile>/<id> deep links, and
+ the #94724 one-shot backfill cannot keep repairing rows minted after it
+ ran (#99222)."""
+ created = []
+
+ class _FakeDB:
+ def create_session(self, key, **kwargs):
+ created.append({"key": key, "profile_name": kwargs.get("profile_name")})
+
+ monkeypatch.setattr(server, "_get_db", lambda: _FakeDB())
+ monkeypatch.setattr(server, "_resolve_model", lambda: "test-model")
+ monkeypatch.setattr(server, "_current_profile_name", lambda: "default")
+
+ server._ensure_session_db_row({"session_key": "k1"})
+
+ assert created and created[0]["key"] == "k1"
+ assert created[0]["profile_name"] == "default"
+
+
def test_session_title_clears_pending_after_persist(monkeypatch):
class _FakeDB:
def __init__(self):
diff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.py
index c3a9d7c86c3..7d827cc895e 100644
--- a/tui_gateway/methods_session.py
+++ b/tui_gateway/methods_session.py
@@ -3218,11 +3218,13 @@ def _(rid, params: dict) -> dict:
cwd=_session_cwd(session),
# The branch stays on its parent's profile. Explicit stamp (not
# just the parent-backfill) so it holds even when the parent row
- # predates the profile_name column.
+ # predates the profile_name column. Launch-profile branches are
+ # stamped explicitly too — NULL rows drop out of profile-keyed
+ # sidebar matching and deep-link resolution (#99222).
profile_name=(
Path(session["profile_home"]).name
if session.get("profile_home")
- else None
+ else _current_profile_name()
),
)
# Copy the whole parent history in bounded-chunk transactions —
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index c36eebd7dfb..fcc5cac0b1b 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -3916,9 +3916,15 @@ def _ensure_session_db_row(session: dict) -> None:
parent_session_id=parent_session_id,
cwd=_persisted_session_cwd(session),
# Self-describing rows: aggregators that merge multiple profile DBs
- # into one list can't rely on which file a row came from alone. NULL
- # means the launch/default profile (matches run_agent's convention).
- profile_name=Path(profile_home).name if profile_home else None,
+ # into one list can't rely on which file a row came from alone.
+ # Stamp the launch profile explicitly instead of leaving NULL —
+ # NULL is exactly what the #94724 legacy-owner backfill exists to
+ # repair, and rows minted AFTER that one-shot backfill ran stayed
+ # NULL forever: profile-keyed matching then drops them from the
+ # sidebar and deep links can't resolve them (#99222).
+ profile_name=(
+ Path(profile_home).name if profile_home else _current_profile_name()
+ ),
)
# A session can be born hidden (session.create hidden=true, or a
# session.set_hidden that arrived before the row existed): apply the