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"