From d973f132eb49d8537d17cd600ca96d8d4b83c9f5 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Fri, 28 Aug 2026 10:35:42 -0700 Subject: [PATCH] [eric] agents: ReadAgentWork reads a session that is only on disk, which is most of them (ENG-389) Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01U6zrBsUCNzpMBnov3rTVYV --- backend/apps/agents/agents.py | 10 +++++++++- backend/tests/test_read_agent_work.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/apps/agents/agents.py b/backend/apps/agents/agents.py index 2c914edc..779d025f 100644 --- a/backend/apps/agents/agents.py +++ b/backend/apps/agents/agents.py @@ -344,7 +344,15 @@ async def get_session_work(session_id: str): ) session = agent_manager.get_session(session_id) if not session: - raise HTTPException(status_code=404, detail="Session not found") + # Same disk fallback as GET /sessions/{id}. Without it this 404s on any session the + # dashboard has not restored yet, which is most of them and precisely the ones worth + # reading: the whole point is answering "what did it do" for an agent that is finished, + # stopped or errored. Found on the packaged bits, where the plain GET returned 200 and + # this returned 404 for the same id. + try: + session = await agent_manager.resume_session(session_id) + except ValueError: + raise HTTPException(status_code=404, detail="Session not found") return { "session_id": session_id, "name": session.name, diff --git a/backend/tests/test_read_agent_work.py b/backend/tests/test_read_agent_work.py index 79d8cd35..ba66175f 100644 --- a/backend/tests/test_read_agent_work.py +++ b/backend/tests/test_read_agent_work.py @@ -118,3 +118,15 @@ def test_it_is_reachable_by_default(): register_builtin_mcp_servers(servers, p_session(), perms, None, None) assert "invoke" in servers["openswarm-core"]["env"]["OSW_MCP_MODULES"].split(",") assert perms["ReadAgentWork"] == "always_allow" + + +def test_the_route_reads_a_session_that_is_only_on_DISK(): + """The bug the packaged drill found: the route used the in-memory map alone, so it 404'd on + every session the dashboard had not restored -- which is most of them, and exactly the ones + worth reading. GET /sessions/{id} already had this fallback; the read tool did not.""" + src = open("backend/apps/agents/agents.py", encoding="utf-8").read() + i = src.index('async def get_session_work') + body = src[i:src.index("@agents.router", i + 10)] + assert "resume_session" in body, "a read tool that 404s on a stored session defeats its purpose" + assert body.index("agent_manager.get_session") < body.index("resume_session"), \ + "memory first, disk second: resuming every read would be a pointless load"