unity-mcp/MCPForUnity/Editor/Services/Transport/Transports
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
..
StdioBridgeHost.cs Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
StdioBridgeHost.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
StdioTransportClient.cs HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
StdioTransportClient.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
WebSocketTransportClient.cs Fix WebSocket connection reliability and domain reload recovery (#656) 2026-01-30 16:42:39 -08:00
WebSocketTransportClient.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00