mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-07-07 13:07:57 +02:00
49a90d03fa
Concurrent tool callbacks in eino_adk_run_loop and the MCP monitor goroutine call Bind/ExecutionID on the same binder. The previous implementation used a plain map[string]string, causing intermittent 'concurrent map read and map write' panics — the same race that TestMCPExecutionBinder_ConcurrentBind was added to guard against. Wrap the map with sync.RWMutex (write lock in Bind, read lock in ExecutionID). The TrimSpace of toolCallID/executionID stays outside the critical section to keep it minimal. go vet ./internal/multiagent/... ✓ go test -race ./internal/multiagent/... -run MCPExecutionBinder ✓
41 lines
826 B
Go
41 lines
826 B
Go
package multiagent
|
|
|
|
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
|
|
}
|
|
|
|
func NewMCPExecutionBinder() *MCPExecutionBinder {
|
|
return &MCPExecutionBinder{byToolCall: make(map[string]string)}
|
|
}
|
|
|
|
func (b *MCPExecutionBinder) Bind(toolCallID, executionID string) {
|
|
if b == nil {
|
|
return
|
|
}
|
|
tid := strings.TrimSpace(toolCallID)
|
|
eid := strings.TrimSpace(executionID)
|
|
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 ""
|
|
}
|
|
tid := strings.TrimSpace(toolCallID)
|
|
b.mu.RLock()
|
|
defer b.mu.RUnlock()
|
|
return b.byToolCall[tid]
|
|
}
|