Skip to content

Commit ff31e93

Browse files
authored
Merge pull request #2322 from dgageot/board/docker-agent-v7-rag-config-issues-8072140b
fix: resolve duplicate RAG tool names and nil pointer panic in file watcher
2 parents b000ac0 + 3528ab2 commit ff31e93

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

pkg/config/latest/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func (t *Toolset) validate() error {
108108
if t.URL != "" && t.Type != "a2a" && t.Type != "openapi" {
109109
return errors.New("url can only be used with type 'a2a' or 'openapi'")
110110
}
111-
if t.Name != "" && (t.Type != "mcp" && t.Type != "a2a") {
112-
return errors.New("name can only be used with type 'mcp' or 'a2a'")
111+
if t.Name != "" && (t.Type != "mcp" && t.Type != "a2a" && t.Type != "rag") {
112+
return errors.New("name can only be used with type 'mcp', 'a2a', or 'rag'")
113113
}
114114
if t.RAGConfig != nil && t.Type != "rag" {
115115
return errors.New("rag_config can only be used with type 'rag'")

pkg/config/rags.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ func resolveRAGDefinitions(cfg *latest.Config) error {
2424
return fmt.Errorf("agent '%s' references non-existent RAG definition '%s'", agent.Name, ts.Ref)
2525
}
2626

27-
applyRAGDefaults(ts, &def.Toolset)
27+
applyRAGDefaults(ts, &def.Toolset, ts.Ref)
2828
}
2929
}
3030

3131
return nil
3232
}
3333

3434
// applyRAGDefaults fills empty fields in ts from def. Toolset values win.
35-
func applyRAGDefaults(ts, def *latest.Toolset) {
35+
func applyRAGDefaults(ts, def *latest.Toolset, refName string) {
3636
// Clear the ref since it's been resolved
3737
ts.Ref = ""
3838

@@ -51,4 +51,10 @@ func applyRAGDefaults(ts, def *latest.Toolset) {
5151
if ts.Name == "" {
5252
ts.Name = def.Name
5353
}
54+
// If name is still empty after applying defaults from the definition,
55+
// use the ref key (e.g., "rag1") so that multiple RAG tools get unique
56+
// tool names instead of all defaulting to "rag".
57+
if ts.Name == "" {
58+
ts.Name = refName
59+
}
5460
}

pkg/rag/strategy/vector_store.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,15 @@ func (s *VectorStore) addPathToWatcher(ctx context.Context, path string) error {
813813
}
814814

815815
func (s *VectorStore) watchLoop(ctx context.Context, docPaths []string) {
816+
// Capture watcher reference at goroutine start to avoid racing with Close()
817+
// which sets s.watcher = nil under watcherMu.
818+
s.watcherMu.Lock()
819+
watcher := s.watcher
820+
s.watcherMu.Unlock()
821+
if watcher == nil {
822+
return
823+
}
824+
816825
var debounceTimer *time.Timer
817826
debounceDuration := 2 * time.Second
818827
pendingChanges := make(map[string]bool)
@@ -929,7 +938,7 @@ func (s *VectorStore) watchLoop(ctx context.Context, docPaths []string) {
929938
slog.Info("File watcher stopped", "strategy", s.name)
930939
return
931940

932-
case event, ok := <-s.watcher.Events:
941+
case event, ok := <-watcher.Events:
933942
if !ok {
934943
return
935944
}
@@ -940,8 +949,10 @@ func (s *VectorStore) watchLoop(ctx context.Context, docPaths []string) {
940949

941950
if event.Op&fsnotify.Create != 0 {
942951
s.watcherMu.Lock()
943-
if err := s.addPathToWatcher(ctx, event.Name); err != nil {
944-
slog.Debug("Could not watch new path", "path", event.Name, "error", err)
952+
if s.watcher != nil {
953+
if err := s.addPathToWatcher(ctx, event.Name); err != nil {
954+
slog.Debug("Could not watch new path", "path", event.Name, "error", err)
955+
}
945956
}
946957
s.watcherMu.Unlock()
947958
}
@@ -974,7 +985,7 @@ func (s *VectorStore) watchLoop(ctx context.Context, docPaths []string) {
974985
}
975986
debounceTimer = time.AfterFunc(debounceDuration, processChanges)
976987

977-
case err, ok := <-s.watcher.Errors:
988+
case err, ok := <-watcher.Errors:
978989
if !ok {
979990
return
980991
}

0 commit comments

Comments
 (0)