unity-mcp/MCPForUnity/Editor/Services
dsarno 4d969419d4
Fix WebSocket connection reliability and domain reload recovery (#656)
* Add server-side ping/pong heartbeat to detect dead WebSocket connections

On Windows, WebSocket connections can die silently (OSError 64) without
either side being notified. This causes commands to fail with "Unity
session not available" until Unity eventually detects the dead connection.

Changes:
- Add PingMessage model for server->client pings
- Add ping loop in PluginHub that sends pings every 10 seconds
- Track last pong time per session; close connection if no pong within 20s
- Include session_id in pong messages from Unity for server-side tracking
- Clean up debug/timing logs from Issue #654 investigation

The server will now proactively detect dead connections within 20 seconds
instead of waiting indefinitely for the next command to fail.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix connection recovery after Unity domain reloads (#654)

When Unity performs a domain reload (after script changes, test runs,
or large payload transfers), the MCP connection drops and needs to
reconnect. The previous reconnection timeout (2s) was too short for
domain reloads which can take 10-30s.

Changes:
- Increase UNITY_MCP_RELOAD_MAX_WAIT_S default from 2s to 30s
- Increase backoff cap when reloading from 0.8s to 5.0s
- Skip PluginHub session resolution for stdio transport (was causing
  unnecessary waits on every command)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix ping/pong heartbeat, reduce timeout to 20s, fix test flakiness

- Add server-side ping loop to detect dead WebSocket connections
- Include session_id in pong messages for tracking
- Reduce domain reload timeout from 30s to 20s
- Add ClassVar annotations for mutable class attributes
- Add lock protection for _last_pong access
- Change debug stack trace log from Warn to Debug level
- Remove unused TIMING-STDIO variable
- Fix flaky async duration test (allow 20% timer variance)
- Fix Python test that cleared HOME env var on Windows
- Skip Unix-path test on Windows (path separator difference)
- Add LogAssert.Expect to PropertyConversion tests

Fixes #654, #643

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 16:42:39 -08:00
..
Server Remote server auth (#644) 2026-01-30 18:39:21 -04:00
Transport Fix WebSocket connection reliability and domain reload recovery (#656) 2026-01-30 16:42:39 -08:00
BridgeControlService.cs Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
BridgeControlService.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
ClientConfigurationService.cs Fix HTTP/Stdio Transport UX and Test Bug (#530) 2026-01-07 23:33:22 -04:00
ClientConfigurationService.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
EditorConfigurationCache.cs Remote server auth (#644) 2026-01-30 18:39:21 -04:00
EditorConfigurationCache.cs.meta Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
EditorPrefsWindowService.cs Add EditorPrefs management window for MCP configuration debugging (#491) 2025-12-29 13:30:45 -04:00
EditorPrefsWindowService.cs.meta Add EditorPrefs management window for MCP configuration debugging (#491) 2025-12-29 13:30:45 -04:00
EditorStateCache.cs fix: comprehensive performance optimizations, claude code config, and stability improvements (issue #577) (#595) 2026-01-20 18:11:25 -08:00
EditorStateCache.cs.meta Async Test Infrastructure & Editor Readiness Status + new refresh_unity tool (#507) 2026-01-03 12:42:32 -08:00
HttpBridgeReloadHandler.cs Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
HttpBridgeReloadHandler.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
IBridgeControlService.cs HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
IBridgeControlService.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
IClientConfigurationService.cs Simplify MCP client configs (#401) 2025-11-27 18:18:44 -04:00
IClientConfigurationService.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
IPackageDeploymentService.cs [FEATURE] Deployment of local source code to Unity (#450) 2025-12-09 20:17:18 -05:00
IPackageDeploymentService.cs.meta [FEATURE] Deployment of local source code to Unity (#450) 2025-12-09 20:17:18 -05:00
IPackageUpdateService.cs HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
IPackageUpdateService.cs.meta Notify users when there's a new version (#329) 2025-10-18 20:42:18 -04:00
IPathResolverService.cs fix: resolve Claude Code HTTP Remote UV path override not being detected in System Requirements .#550 2026-01-17 18:34:40 -05:00
IPathResolverService.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
IPlatformService.cs Remove old UI and do lots of cleanup (#340) 2025-10-24 00:50:29 -04:00
IPlatformService.cs.meta Remove old UI and do lots of cleanup (#340) 2025-10-24 00:50:29 -04:00
IResourceDiscoveryService.cs Display resources (#658) 2026-01-30 20:31:35 -04:00
IResourceDiscoveryService.cs.meta Display resources (#658) 2026-01-30 20:31:35 -04:00
IServerManagementService.cs Fix local HTTP server UI check (#556) 2026-01-14 19:57:17 -08:00
IServerManagementService.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
ITestRunnerService.cs Add test filtering to run_tests tool (#462) 2025-12-17 16:59:21 -04:00
ITestRunnerService.cs.meta Add testing and move menu items to resources (#316) 2025-10-13 11:16:43 -04:00
IToolDiscoveryService.cs Optimise so startup is fast again (#494) 2025-12-29 18:39:03 -04:00
IToolDiscoveryService.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
MCPServiceLocator.cs Display resources (#658) 2026-01-30 20:31:35 -04:00
MCPServiceLocator.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
McpEditorShutdownCleanup.cs Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
McpEditorShutdownCleanup.cs.meta HTTP setup overhaul: transport selection (HTTP local/remote vs stdio), safer lifecycle, cleaner UI, better Claude Code integration (#499) 2026-01-01 17:08:51 -08:00
PackageDeploymentService.cs Fixes Windows installation failures caused by long path issues when cloning the full repository via git URL (MAX_PATH 260 char limit exceeded by files in TestProjects/). (#534) 2026-01-08 07:14:44 -08:00
PackageDeploymentService.cs.meta [FEATURE] Deployment of local source code to Unity (#450) 2025-12-09 20:17:18 -05:00
PackageUpdateService.cs Fix manage prefabs (#405) 2025-11-28 18:47:11 -04:00
PackageUpdateService.cs.meta Notify users when there's a new version (#329) 2025-10-18 20:42:18 -04:00
PathResolverService.cs fix: resolve Claude Code HTTP Remote UV path override not being detected in System Requirements .#550 2026-01-17 18:34:40 -05:00
PathResolverService.cs.meta New UI and work without MCP server embedded (#313) 2025-10-11 03:08:16 -04:00
PlatformService.cs Remove old UI and do lots of cleanup (#340) 2025-10-24 00:50:29 -04:00
PlatformService.cs.meta Remove old UI and do lots of cleanup (#340) 2025-10-24 00:50:29 -04:00
ResourceDiscoveryService.cs Display resources (#658) 2026-01-30 20:31:35 -04:00
ResourceDiscoveryService.cs.meta Display resources (#658) 2026-01-30 20:31:35 -04:00
Server.meta Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
ServerManagementService.cs Remote server auth (#644) 2026-01-30 18:39:21 -04:00
ServerManagementService.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
StdioBridgeReloadHandler.cs Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
StdioBridgeReloadHandler.cs.meta Fix stdio reloads (#402) 2025-11-27 19:33:26 -04:00
TestJobManager.cs Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
TestJobManager.cs.meta Async Test Infrastructure & Editor Readiness Status + new refresh_unity tool (#507) 2026-01-03 12:42:32 -08:00
TestRunStatus.cs Async Test Infrastructure & Editor Readiness Status + new refresh_unity tool (#507) 2026-01-03 12:42:32 -08:00
TestRunStatus.cs.meta Async Test Infrastructure & Editor Readiness Status + new refresh_unity tool (#507) 2026-01-03 12:42:32 -08:00
TestRunnerNoThrottle.cs Fix PlayMode tests stalling when unfocused (python refresh utility), improve domain reload recovery and refresh tool (#554) 2026-01-14 15:02:40 -08:00
TestRunnerNoThrottle.cs.meta Async Test Infrastructure & Editor Readiness Status + new refresh_unity tool (#507) 2026-01-03 12:42:32 -08:00
TestRunnerService.cs Fix PlayMode tests stalling when unfocused (python refresh utility), improve domain reload recovery and refresh tool (#554) 2026-01-14 15:02:40 -08:00
TestRunnerService.cs.meta Add testing and move menu items to resources (#316) 2025-10-13 11:16:43 -04:00
ToolDiscoveryService.cs Display resources (#658) 2026-01-30 20:31:35 -04:00
ToolDiscoveryService.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
Transport.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00