Skip to content

Make domain reload detection more deterministic (reduce 20s timeout) #657

@dsarno

Description

@dsarno

Summary

Currently, when Unity performs a domain reload (e.g., after running tests or compiling scripts), the MCP connection drops. The server waits up to 20 seconds for Unity to reconnect before failing commands.

This 20-second timeout handles most domain reloads, but it could cause unnecessary delays in agentic workflows where domain reloads happen frequently.

Current Behavior

  • UNITY_MCP_SESSION_RESOLVE_MAX_WAIT_S defaults to 20 seconds
  • UNITY_MCP_RELOAD_MAX_WAIT_S defaults to 20 seconds
  • Server blindly waits up to 20s when no Unity session is available

Proposed Improvement

Make detection more deterministic by:

  1. Detecting Unity's actual reload state rather than blindly waiting

    • Check the status file for "reloading" state
    • Monitor for connection attempts during the wait period
    • Use exponential backoff with early exit when connection is established
  2. Shorter default with smart detection

    • Default to ~5-10 seconds for normal operations
    • Extend only when domain reload is detected (via status file or heuristics)
  3. Different timeouts for different contexts

    • Post-test-suite: longer timeout expected
    • Normal commands: shorter timeout preferred

Related

Files Involved

  • Server/src/transport/plugin_hub.py - UNITY_MCP_SESSION_RESOLVE_MAX_WAIT_S
  • Server/src/transport/legacy/unity_connection.py - UNITY_MCP_RELOAD_MAX_WAIT_S

Notes

See TODO comment in unity_connection.py around line 786 for context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions