Skip to content

fix(mcp): move t.cancel() inside try block to prevent RuntimeError on /exit - #60287

Closed
AIalliAI wants to merge 1 commit into
NousResearch:mainfrom
AIalliAI:cherry-pick/60213
Closed

fix(mcp): move t.cancel() inside try block to prevent RuntimeError on /exit#60287
AIalliAI wants to merge 1 commit into
NousResearch:mainfrom
AIalliAI:cherry-pick/60213

Conversation

@AIalliAI

@AIalliAI AIalliAI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick of PR #60213 by webtecnica.

During shutdown, the event loop is closed before MCP tasks finish, so t.cancel() raises RuntimeError("Event loop is closed"). Moved t.cancel() inside the try block at both locations in tools/mcp_tool.py.

(cherry picked from commit 8c7afb4)
Co-authored-by: webtecnica 75556242+webtecnica@users.noreply.github.com
Closes #60197

… /exit

During shutdown, the event loop is closed before MCP tasks finish, so
t.cancel() → call_soon() raises RuntimeError('Event loop is closed').
Moved t.cancel() inside the try block at both locations (keepalive
loop and _wait_for_reconnect_or_shutdown).

Closes NousResearch#60197

(cherry picked from commit 8c7afb4)
Co-authored-by: AIalliAI <285906080+AIalliAI@users.noreply.github.com>
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/mcp MCP client and OAuth duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #60032 — this is a cherry-pick of #60213, and all three (#60032, #60213, this) move t.cancel() inside the try block and catch RuntimeError at the same two _wait_for_reconnect_or_shutdown shutdown sites to suppress the 'Event loop is closed' noise on /exit (#60197). #60032 is the earliest open canonical fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] RuntimeError: Event loop is closed during /exit (MCPServerTask.shutdown)

3 participants