@@ -351,6 +351,8 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
351351 if currentAssistant == nil {
352352 return result, err
353353 }
354+ // Ensure we finish thinking on error to close the reasoning state
355+ currentAssistant.FinishThinking()
354356 toolCalls := currentAssistant.ToolCalls()
355357 // INFO: we use the parent context here because the genCtx has been cancelled
356358 msgs, createErr := a.messages.List(ctx, currentAssistant.SessionID)