Handle Unity editor offline reconnects#1183
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds editor-offline detection and bounded reconnect waiting to the legacy Unity transport: connection acquisition can be retried (with optional discovery cache bypass) within a configurable window, and when offline it returns a structured ChangesEditor Lifecycle Recovery
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b7da729 to
2f50043
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Server/tests/test_editor_lifecycle_recovery.py (1)
26-66: 💤 Low valueCoverage note: this test patches
get_unity_connectiondirectly, so it bypassesdiscover_all_instances' 5s cache. It validates the retry mechanics but won't catch the no-instances reconnect gap flagged inunity_connection.py. Worth adding a case that exercises the real discovery path once that gap is addressed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Server/tests/test_editor_lifecycle_recovery.py` around lines 26 - 66, Add a new test that exercises the real discovery path instead of patching get_unity_connection directly: simulate discover_all_instances returning an empty list initially and then returning the instance after the discovery cache expires so send_command_with_retry goes through the discovery -> reconnect gap; patch transport.legacy.unity_connection.discover_all_instances, transport.legacy.unity_connection.time.monotonic and time.sleep to control timing, set UNITY_MCP_EDITOR_RECONNECT_MAX_WAIT_S via monkeypatch, and assert send_command_with_retry (the send_command_with_retry function) eventually calls get_unity_connection and succeeds, verifying retries across the discovery cache gap.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Server/src/transport/legacy/unity_connection.py`:
- Around line 824-862: The reconnect loop in
_get_connection_with_editor_reconnect retries get_unity_connection() but
discovery is cached, so add a force-refresh plumbing: extend
get_unity_connection(...)/UnityConnectionPool.get_connection(...) to accept a
force_refresh: bool flag and pass it to
discover_all_instances(force_refresh=True) inside UnityConnectionPool, and then
modify _get_connection_with_editor_reconnect to set force_refresh=True for
subsequent reconnect attempts (e.g., when _resolve_instance_id raises the “No
Unity Editor instances found” error or after the first failed attempt) so
instance discovery is re-scanned within the
UNITY_MCP_EDITOR_RECONNECT_MAX_WAIT_S window.
---
Nitpick comments:
In `@Server/tests/test_editor_lifecycle_recovery.py`:
- Around line 26-66: Add a new test that exercises the real discovery path
instead of patching get_unity_connection directly: simulate
discover_all_instances returning an empty list initially and then returning the
instance after the discovery cache expires so send_command_with_retry goes
through the discovery -> reconnect gap; patch
transport.legacy.unity_connection.discover_all_instances,
transport.legacy.unity_connection.time.monotonic and time.sleep to control
timing, set UNITY_MCP_EDITOR_RECONNECT_MAX_WAIT_S via monkeypatch, and assert
send_command_with_retry (the send_command_with_retry function) eventually calls
get_unity_connection and succeeds, verifying retries across the discovery cache
gap.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 03fa78e4-798c-4909-9591-0477d80e498b
📒 Files selected for processing (3)
Server/src/transport/legacy/unity_connection.pyServer/tests/test_editor_lifecycle_recovery.pydocs/plans/2026-05-31-editor-lifecycle-recovery-spec.md
Summary
Handle the common window where the Unity Editor is closed or still starting while MCP tools are called.
editor_offlineresponse withhint=retryinstead of an unhandled connection failureWhy
When the Editor is closed or not ready, agents currently see transport failures and often retry the wrong layer. A retryable MCP response gives clients a clear signal to back off and try again after Unity is ready.
Validation
uv run --extra dev python -m pytest tests/test_editor_lifecycle_recovery.py tests/integration/test_domain_reload_resilience.py -qgit diff --checkSummary by CodeRabbit
New Features
Documentation
Tests