From a716b43df15abcafb7cd6495f65f70d2a5d0e92b Mon Sep 17 00:00:00 2001 From: ciregenz Date: Thu, 18 Jun 2026 04:36:23 -0700 Subject: [PATCH] [eric] agents: after a mid-stream stop, rebuild history from session.messages so resume/follow-ups see the partial reply --- backend/apps/agents/agent_manager.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/apps/agents/agent_manager.py b/backend/apps/agents/agent_manager.py index 5d22a9de..cb5e03c2 100644 --- a/backend/apps/agents/agent_manager.py +++ b/backend/apps/agents/agent_manager.py @@ -3132,6 +3132,14 @@ class AgentManager: logger.exception("auto-continuation dispatch failed") except asyncio.CancelledError: session.status = "stopped" + # A cancelled turn desyncs the CLI's resume transcript from + # session.messages: the SDK never recorded the interrupted turn, + # so resuming that sdk_session_id replays a history with no trace + # of the stopped reply and the model insists it wrote nothing + # ("nothing to continue"). Force the next turn (resume OR a fresh + # message) to rebuild history from session.messages so the model + # sees the same conversation the user does. + session.needs_fresh_session = True # Stopped mid-stream. The SDK's commit envelope never arrives on # cancel, so persist whatever text already streamed; otherwise the # reply the user just watched appear vanishes (the frontend wipes