mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 20:27:44 +02:00
[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)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user