From 131b3136eb142f485047ecc0a042b5fd7c3832a7 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Tue, 16 Jun 2026 03:03:28 -0700 Subject: [PATCH] [eric] sessions: get_all_sessions reads disk too so imported (and post-restart) dashboard cards render instead of blank --- backend/apps/agents/agent_manager.py | 26 +++++++++++++++++++++++--- backend/tests/test_swarm_bundle.py | 8 ++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/backend/apps/agents/agent_manager.py b/backend/apps/agents/agent_manager.py index a12a1e56..ad665e7c 100644 --- a/backend/apps/agents/agent_manager.py +++ b/backend/apps/agents/agent_manager.py @@ -4551,9 +4551,29 @@ class AgentManager: } def get_all_sessions(self, dashboard_id: str | None = None) -> list[AgentSession]: - if dashboard_id: - return [s for s in self.sessions.values() if s.dashboard_id == dashboard_id] - return list(self.sessions.values()) + if not dashboard_id: + return list(self.sessions.values()) + # Memory first, then promote any on-disk sessions for this dashboard + # that aren't loaded yet. Imported sessions (and ones not resumed since + # a restart) live on disk but not in memory, so without the disk pass + # their cards render blank, the frontend's AgentCard returns null when + # a card's session is missing from the agents slice. Promoting into + # self.sessions bounds the disk read to once per session per run, like + # resume_session. Mirrors get_browser_agent_children's memory+disk walk. + result = [s for s in self.sessions.values() if s.dashboard_id == dashboard_id] + seen = {s.id for s in result} + for sid, data in _load_all_session_data(): + if sid in seen or data.get("dashboard_id") != dashboard_id: + continue + try: + sess = AgentSession(**data) + except Exception: + logger.warning(f"get_all_sessions: skipping unloadable session {sid}", exc_info=True) + continue + _apply_context_window(sess) + self.sessions[sid] = sess + result.append(sess) + return result def get_session(self, session_id: str) -> Optional[AgentSession]: return self.sessions.get(session_id) diff --git a/backend/tests/test_swarm_bundle.py b/backend/tests/test_swarm_bundle.py index b7b822e8..8dfef88b 100644 --- a/backend/tests/test_swarm_bundle.py +++ b/backend/tests/test_swarm_bundle.py @@ -314,6 +314,14 @@ def test_dashboard_export_import_carries_agent_cards_and_transcript(tmp_path, mo assert doc["active_mcps"] == [], "import must not grant MCP access" assert total_msgs == 2, "each agent's transcript must carry through" + # The bug behind "the chats didn't even show up": after import the sessions + # are on disk but not in memory, and the dashboard-open fetch + # (get_all_sessions) was memory-only, so the cards rendered blank. The fetch + # must now see the freshly-imported sessions straight off disk. + found = am.agent_manager.get_all_sessions(dashboard_id=root_id) + assert len(found) == 2, f"dashboard-open fetch must see imported agent sessions, got {len(found)}" + assert sum(len(s.messages) for s in found) == 2, "and with their transcripts" + def test_dashboard_serialize_rewrites_refs_to_bundle_ids(): from backend.apps.swarm.entities.dashboards import DashboardExportable