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
import "strings"
import (
"strings"
"sync"
)
// MCPExecutionBinder maps ADK toolCallID → MCP monitor execution ID for a single agent run.
type MCPExecutionBinder struct {
mu sync.RWMutex
byToolCall map[string]string
}
@@ -20,12 +24,17 @@ func (b *MCPExecutionBinder) Bind(toolCallID, executionID string) {
if tid == "" || eid == "" {
return
}
b.mu.Lock()
b.byToolCall[tid] = eid
b.mu.Unlock()
}
func (b *MCPExecutionBinder) ExecutionID(toolCallID string) string {
if b == nil {
return ""
}
return b.byToolCall[strings.TrimSpace(toolCallID)]
tid := strings.TrimSpace(toolCallID)
b.mu.RLock()
defer b.mu.RUnlock()
return b.byToolCall[tid]
}