Skip to content

Run tools off the event loop so one stuck call can't stall the server - #8

Merged
Erfouni merged 1 commit into
mainfrom
fix/tools-off-event-loop
Oct 1, 2026
Merged

Erfouni merged 1 commit into
mainfrom
fix/tools-off-event-loop

Conversation

@Erfouni

@Erfouni Erfouni commented Oct 1, 2026

Copy link
Copy Markdown
Owner

FastMCP runs sync tools straight on the event loop, and every tool here is sync and waits on the COM bridge. So while one call sat behind an AutoCAD dialog (up to the 120-300 s timeout), the server answered nothing else, /health included. The logging wrapper is now async and runs the tool on a worker thread with anyio; the COM bridge still serialises the AutoCAD work on its own thread, so how AutoCAD is called doesn't change.

The new test in test_assembled_server holds a call inside bridge.run and checks /health answers meanwhile. It fails on main and passes here (5 runs), full suite 49 OK locally. Error results still come back with their message. Not tested against a live AutoCAD.

FastMCP calls a plain (sync) tool directly on the event loop. Every tool
here is sync and waits on the COM bridge, which can take minutes when
AutoCAD sits at a dialog, so during that time the server answered
nothing else: not /health, not another client, not a retry.

The logging wrapper the tools already go through is now async and runs
the tool with anyio.to_thread.run_sync. The COM bridge still serialises
the AutoCAD work on its own thread, so nothing changes about how
AutoCAD is called. New test in test_assembled_server holds a tool call
inside bridge.run and checks /health answers meanwhile; it fails on main
and passes here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Erfouni
Erfouni merged commit 6082aa5 into main Oct 1, 2026
2 checks passed
@Erfouni
Erfouni deleted the fix/tools-off-event-loop branch October 1, 2026 06:37
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.

1 participant