From 638eedc2a05ca799b6e855b7a633c85625e1bbe5 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 20 Mar 2025 22:46:54 +0100 Subject: [PATCH] fix: correctly stop agents Signed-off-by: Ettore Di Giacinto --- core/action/definition.go | 2 +- core/agent/agent.go | 1 + core/state/pool.go | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/action/definition.go b/core/action/definition.go index 58ac980..1473d72 100644 --- a/core/action/definition.go +++ b/core/action/definition.go @@ -14,7 +14,7 @@ type ActionContext struct { } func (ac *ActionContext) Cancel() { - if ac.cancelFunc == nil { + if ac.cancelFunc != nil { ac.cancelFunc() } } diff --git a/core/agent/agent.go b/core/agent/agent.go index 432b4f6..280941d 100644 --- a/core/agent/agent.go +++ b/core/agent/agent.go @@ -198,6 +198,7 @@ var ErrContextCanceled = fmt.Errorf("context canceled") func (a *Agent) Stop() { a.Lock() defer a.Unlock() + xlog.Debug("Stopping agent", "agent", a.Character.Name) a.context.Cancel() } diff --git a/core/state/pool.go b/core/state/pool.go index f31c1db..2092dcf 100644 --- a/core/state/pool.go +++ b/core/state/pool.go @@ -369,7 +369,6 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error go func() { if err := agent.Run(); err != nil { xlog.Error("Agent stopped", "error", err.Error(), "name", name) - panic(err) } }()