Skip to content

Fix MCP shutdown after timed-out agent runs - #25625

Closed
kamilnowak05 wants to merge 1 commit into
NousResearch:mainfrom
kamilnowak05:fix/neli-linear-timeouts
Closed

Fix MCP shutdown after timed-out agent runs#25625
kamilnowak05 wants to merge 1 commit into
NousResearch:mainfrom
kamilnowak05:fix/neli-linear-timeouts

Conversation

@kamilnowak05

@kamilnowak05 kamilnowak05 commented May 14, 2026

Copy link
Copy Markdown

Summary

  • start the MCP event loop inside its worker thread and wait until it is ready before scheduling work
  • cancel and drain pending MCP-loop tasks before stopping/closing the loop, preventing destroyed pending subprocess pipe tasks after timeouts
  • harden hosted MCP OAuth handling by normalizing confidential client metadata and serializing auth flows across providers

Root cause

A Linear-triggered Hermes agent run hit repeated non-streaming model-call timeouts. During process cleanup, shutdown_mcp_servers() stopped and closed the MCP background loop while stdio MCP subprocess startup/reconnect tasks were still pending. That left asyncio subprocess pipe coroutines half-open and produced the observed BaseSubprocessTransport._connect_pipes / coroutine ignored GeneratorExit warnings.

Tests

  • pytest tests/tools/test_mcp_tool.py::TestShutdown tests/tools/test_mcp_oauth_manager.py -q — 14 passed
  • pytest tests/tools/test_mcp_tool.py::TestShutdown::test_shutdown_cancels_pending_loop_tasks_before_closing_loop -q — 1 passed
  • pytest tests/tools/test_mcp_tool.py -q — 184 passed
  • pytest tests/tools/test_mcp_probe.py tests/tools/test_mcp_oauth.py tests/tools/test_mcp_oauth_manager.py tests/tools/test_mcp_oauth_cold_load_expiry.py tests/tools/test_mcp_oauth_metadata.py tests/tools/test_mcp_oauth_bidirectional.py -q — 80 passed, 1 existing warning
  • python -m py_compile tools/mcp_tool.py tools/mcp_oauth.py tools/mcp_oauth_manager.py tests/tools/test_mcp_tool.py tests/tools/test_mcp_oauth_manager.py
  • git diff --check

Full suite note: pytest -q was also run and reached completion, but the existing repository-wide suite currently reports unrelated failures outside this change area: 100 failed, 22242 passed, 77 skipped, 214 warnings.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth comp/tools Tool registry, model_tools, toolsets labels May 14, 2026
@kamilnowak05
kamilnowak05 deleted the fix/neli-linear-timeouts branch May 14, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets 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.

2 participants