In batch-mode sessions, every script-recompiling refresh triggers a domain reload that kills the stdio bridge listener. The editor side handles this well: StdioBridgeHost retries the old port for BusyPortFallbackWindowSeconds (3 s), can't rebind because the socket is in TIME_WAIT (~30 s on macOS, and ExclusiveAddressUse = true is deliberate per #1173), walks to the next port, and immediately announces the new port via the status file — exactly as its own warning log says: "clients follow via the status file."
The Python server doesn't follow promptly. Two compounding delays:
port_registry_ttl (5.0, core/config.py, no override available) — after the reload, the client keeps dialing the dead cached port until the TTL expires, even though the status file already names the live port.
- Exponential reconnect backoff — by the time the editor is back (~4 s of real reload work), the client is sleeping and overshoots.
Measured on macOS / Unity 2022.3.62f2 / mcpforunityserver 10.1.2, batch mode: ~12–15 s of reconnect latency per reload against ~4 s of actual reload work, deterministically on every reload (an automated pipeline of ours pays it 1–3 times per job; the editor walked 6400 → 6401 → 6402 across two reloads in one session, recovery always correct, just slow).
Proposed fix
On connection refused/reset, treat the cached discovery as invalid immediately — re-read the status registry before entering backoff. The fresh port is already on disk at that moment; the current code just doesn't look.
Alternatively (or additionally): make port_registry_ttl and BusyPortFallbackWindowSeconds configurable via environment variables so automated hosts can tune them.
Happy to provide editor logs / timings from the runs where we measured this.
In batch-mode sessions, every script-recompiling refresh triggers a domain reload that kills the stdio bridge listener. The editor side handles this well:
StdioBridgeHostretries the old port forBusyPortFallbackWindowSeconds(3 s), can't rebind because the socket is in TIME_WAIT (~30 s on macOS, andExclusiveAddressUse = trueis deliberate per #1173), walks to the next port, and immediately announces the new port via the status file — exactly as its own warning log says: "clients follow via the status file."The Python server doesn't follow promptly. Two compounding delays:
port_registry_ttl(5.0,core/config.py, no override available) — after the reload, the client keeps dialing the dead cached port until the TTL expires, even though the status file already names the live port.Measured on macOS / Unity 2022.3.62f2 / mcpforunityserver 10.1.2, batch mode: ~12–15 s of reconnect latency per reload against ~4 s of actual reload work, deterministically on every reload (an automated pipeline of ours pays it 1–3 times per job; the editor walked 6400 → 6401 → 6402 across two reloads in one session, recovery always correct, just slow).
Proposed fix
On connection refused/reset, treat the cached discovery as invalid immediately — re-read the status registry before entering backoff. The fresh port is already on disk at that moment; the current code just doesn't look.
Alternatively (or additionally): make
port_registry_ttlandBusyPortFallbackWindowSecondsconfigurable via environment variables so automated hosts can tune them.Happy to provide editor logs / timings from the runs where we measured this.