From 270814c3c9db281128f57206e4a203e2e167b66f Mon Sep 17 00:00:00 2001 From: swordandart <36768075+swordandart@users.noreply.github.com> Date: Tue, 10 Mar 2026 00:01:13 +0800 Subject: [PATCH] fix: save placeholder message when task is cancelled When user cancels a task with /stop, the user message was saved but the assistant response was not, causing orphaned user messages in session history. Now saves '[Task cancelled by user]' placeholder to keep conversation history complete. --- pkg/agent/loop.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 0fbdec61f..09130da0b 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -846,6 +846,12 @@ func (al *AgentLoop) runAgentLoop( // 3. Run LLM iteration loop finalContent, iteration, err := al.runLLMIteration(ctx, agent, messages, opts) if err != nil { + // If task was cancelled, save a placeholder message to session + // This prevents the user message from being orphaned without a response + if errors.Is(err, context.Canceled) { + agent.Sessions.AddMessage(opts.SessionKey, "assistant", "[Task cancelled by user]") + agent.Sessions.Save(opts.SessionKey) + } return "", err }