diff --git a/CHANGELOG.md b/CHANGELOG.md index 892ba469c..101914346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ NOTE: all releases may include dependency updates, not specifically mentioned +UNRELEASED + +- fix: check topic actor status before publishing events [#918](https://github.com/hypermodeinc/modus/pull/918) + ## 2025-06-25 - Runtime v0.18.2 - fix: validate inference history is valid json [#916](https://github.com/hypermodeinc/modus/pull/916) diff --git a/runtime/actors/agents.go b/runtime/actors/agents.go index f0cdbfe64..1cb6bf1af 100644 --- a/runtime/actors/agents.go +++ b/runtime/actors/agents.go @@ -267,6 +267,12 @@ func PublishAgentEvent(ctx context.Context, agentId, eventName string, eventData } topicActor := _actorSystem.TopicActor() + if !topicActor.IsRunning() { + // If the topic actor is not running, we cannot publish the event. + // This can happen during shutdown if the topic actor is stopped before the agent actors. + logger.Warn(ctx).Str("event", eventName).Any("data", eventData).Msg("Topic actor is not running. Cannot publish event.") + return nil + } // if the pid is in context, we're being called as a host function if pid, ok := ctx.Value(pidContextKey{}).(*goakt.PID); ok {