[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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U6zrBsUCNzpMBnov3rTVYV
This commit is contained in:
ciregenz
2026-08-28 10:35:42 -07:00
co-authored by Claude Opus 5
parent ef6228ee0c
commit d973f132eb
2 changed files with 21 additions and 1 deletions
+9 -1
View File
@@ -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,
+12
View File
@@ -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"