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