[eric] sessions: get_all_sessions reads disk too so imported (and post-restart) dashboard cards render instead of blank

This commit is contained in:
ciregenz
2026-06-16 03:03:28 -07:00
parent 2301ff7a70
commit 131b3136eb
2 changed files with 31 additions and 3 deletions
+23 -3
View File
@@ -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)
+8
View File
@@ -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