Add per-call timeout parameter to execute_code - #6
Open
jasoncbraatz wants to merge 1 commit into
Open
Conversation
Long-running Maya operations (Arnold renders, large simulations, heavy
mesh ops) currently hit the client default timeout (60s set in
SessionManager) and raise MayaExecutionError("Timeout waiting for Maya
response") even though Maya is still happily processing.
This change adds an optional `timeout: float | None = None` parameter to
the execute_code MCP tool and threads it through the client all the way
down to asyncio.wait_for. When supplied, it overrides self.timeout for
that single call; when None, the existing behavior is preserved.
Both MayaClient (native commandPort) and MayaQtClient (Qt server) are
updated. Both _send_receive paths now use:
effective_timeout = timeout if timeout is not None else self.timeout
Tests:
- two existing tests updated to assert timeout=None in call args
- added test_execute_code_passes_timeout_override (verifies 600s passes
through)
- added test_execute_code_default_timeout_is_none
All 131 tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First off — thanks for putting this server together. It's been load-bearing in my pre-CNC validation workflow (I render Maya previews of CNC'd parts before committing physical fabrication time), and the multi-session + Qt-server-on-demand design is really nice to work with. The zero-Maya-side-setup story in particular is excellent. ❤️
The problem
Long-running operations in Maya (Arnold renders, large simulations, heavy mesh ops, batch processes) currently hit the client default timeout —
60.0set inSessionManager._add_session— and raise:This happens inside
_send_receive, whereasyncio.wait_for(reader.read, timeout=self.timeout)aborts after 60 s even though Maya itself is happily processing the command. The work completes in Maya, but the client connection is lost, so the result is unreachable.Repro (in a Maya session connected via this server):
For a typical Arnold scene of moderate complexity, this is 60–180 s and reliably trips the timeout.
The fix
Add an optional per-call
timeout: float | None = Noneparameter to theexecute_codeMCP tool, thread it throughBaseMayaClient.execute_codeand_send_receive, and use it as theasyncio.wait_fordeadline when provided. Default behavior is unchanged.Both
MayaClient(native commandPort) andMayaQtClient(Qt server) are updated. Inside each_send_receive:Files changed
src/maya_mcp_server/server.py— newtimeoutparameter on theexecute_codeMCP tool, passed toclient.execute_code. Docstring updated.src/maya_mcp_server/client.py— abstract_send_receivesignature, both concrete_send_receiveimplementations, andBaseMayaClient.execute_codeupdated. Bothasyncio.wait_forcalls now useeffective_timeout.tests/test_client.py— two existing tests updated to asserttimeout=Noneis present in call args; two new tests added:test_execute_code_passes_timeout_overrideandtest_execute_code_default_timeout_is_none.Tests
All 131 tests pass:
Caveats / future work
wait_fortriggers. Users with very long operations may also need to bump their MCP client's request timeout, or we can layer inContext.report_progress(...)notifications in a follow-up to keep the connection alive over long renders. Happy to do that as a separate PR if you'd like.self.timeoutas before.Discovered this while building a walnut CNC enclosure where I use Maya/Arnold for pre-fabrication visual validation. Glad to chip back to a tool that's already saved me a lot of CNC hours. Let me know if you'd like me to adjust anything — happy to iterate.