From af3b056eb7e6b538651db43afed1ac32e2ae183b Mon Sep 17 00:00:00 2001 From: David Gageot Date: Tue, 10 Mar 2026 16:35:19 +0100 Subject: [PATCH] fix: move registerDefaultTools to constructor to prevent concurrent map writes registerDefaultTools() was called inside the RunStream() goroutine, which writes to the plain map r.toolMap. When multiple goroutines call RunStream on the same LocalRuntime concurrently (e.g. background agent sessions), this causes a fatal 'concurrent map writes' panic. Move the call to NewLocalRuntime() so the map is fully populated before any concurrent access. All subsequent reads in processToolCalls are safe without synchronization. Assisted-By: docker-agent --- pkg/runtime/runtime.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index d3445f19f..7c7a719bf 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -311,6 +311,11 @@ func NewLocalRuntime(agents *team.Team, opts ...Opt) (*LocalRuntime, error) { r.sessionCompactor = newSessionCompactor(model, r.sessionStore) + // Register runtime-managed tool handlers once during construction. + // This avoids concurrent map writes when multiple goroutines call + // RunStream on the same runtime (e.g. background agent sessions). + r.registerDefaultTools() + slog.Debug("Creating new runtime", "agent", r.currentAgent, "available_agents", agents.Size()) return r, nil