From 7564f9c301e2b438b8e95abf4705ed34f08ee480 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Thu, 25 Jun 2026 02:42:20 -0700 Subject: [PATCH] [eric] agents: on restart, a session whose last message is a finished assistant reply restores as completed not stopped (kills the spurious Resume button on done chats) --- .../apps/agents/manager/session/SessionPersistence.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/apps/agents/manager/session/SessionPersistence.py b/backend/apps/agents/manager/session/SessionPersistence.py index 64e1d98b..0930ad24 100644 --- a/backend/apps/agents/manager/session/SessionPersistence.py +++ b/backend/apps/agents/manager/session/SessionPersistence.py @@ -80,7 +80,14 @@ class SessionPersistence(AgentManagerProtocol): if session.closed_at is not None: continue if session.status in ("running", "waiting_approval"): - session.status = "stopped" + # The app died mid-turn. If the last message in the active branch is already an + # assistant reply, the turn finished streaming and only the status finalize was lost + # (-> completed, no spurious "Resume" button); otherwise the agent was genuinely cut + # off owing a response (-> stopped, resumable). + branch = session.active_branch_id or "main" + p_branch_msgs = [m for m in session.messages if (m.branch_id or "main") == branch] + p_last = p_branch_msgs[-1] if p_branch_msgs else None + session.status = "completed" if (p_last is not None and p_last.role == "assistant") else "stopped" session.pending_approvals = [] apply_context_window(session) self.sessions[session.id] = session