Merge pull request #183 from flydreamsec/fix/mcp-execution-binder-race

fix(multiagent): guard MCPExecutionBinder map with RWMutex (concurrent tool callback race)
This commit is contained in:
公明
2026-07-06 14:39:58 +08:00
committed by GitHub
+11 -2
View File
@@ -1,9 +1,13 @@
package multiagent package multiagent
import "strings" import (
"strings"
"sync"
)
// MCPExecutionBinder maps ADK toolCallID → MCP monitor execution ID for a single agent run. // MCPExecutionBinder maps ADK toolCallID → MCP monitor execution ID for a single agent run.
type MCPExecutionBinder struct { type MCPExecutionBinder struct {
mu sync.RWMutex
byToolCall map[string]string byToolCall map[string]string
} }
@@ -20,12 +24,17 @@ func (b *MCPExecutionBinder) Bind(toolCallID, executionID string) {
if tid == "" || eid == "" { if tid == "" || eid == "" {
return return
} }
b.mu.Lock()
b.byToolCall[tid] = eid b.byToolCall[tid] = eid
b.mu.Unlock()
} }
func (b *MCPExecutionBinder) ExecutionID(toolCallID string) string { func (b *MCPExecutionBinder) ExecutionID(toolCallID string) string {
if b == nil { if b == nil {
return "" return ""
} }
return b.byToolCall[strings.TrimSpace(toolCallID)] tid := strings.TrimSpace(toolCallID)
b.mu.RLock()
defer b.mu.RUnlock()
return b.byToolCall[tid]
} }