Skip to content

fix: avoid triggering toolset startup from emitToolsChanged callback#2323

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/emittoolschanged-timeout-races-with-rag-2061feeb
Apr 6, 2026
Merged

fix: avoid triggering toolset startup from emitToolsChanged callback#2323
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/emittoolschanged-timeout-races-with-rag-2061feeb

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 4, 2026

Problem

When the TUI starts, RAG and MCP toolsets initialize concurrently. If an MCP server connects and fires OnToolsChanged before RAG finishes file indexing, emitToolsChanged() creates a 5-second timeout context and calls CurrentAgentTools(), which triggers ensureToolSetsAreStarted(). For projects with many files, RAG initialization exceeds 5 seconds, causing a spurious "context deadline exceeded" warning in the TUI.

Fix

Add Agent.StartedTools() that lists tools only from already-started toolsets without triggering initialization. Use it in emitToolsChanged() so the MCP callback never starts slow toolsets under a tight deadline. RAG continues to initialize normally through the startup path with a proper long-lived context.

emitToolsChanged uses a 5-second timeout context that races with slow
toolset initialization (e.g. RAG file indexing). When an MCP server
connects and fires OnToolsChanged before RAG finishes, the timeout
causes a context deadline exceeded error and a spurious warning.

Add Agent.StartedTools() that lists tools only from already-started
toolsets without calling ensureToolSetsAreStarted(), and use it in
emitToolsChanged so the callback never triggers initialization.

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner April 4, 2026 17:51
@dgageot dgageot merged commit b000ac0 into docker:main Apr 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants