Skip to content

fix(ui): refresh transport status labels after a Transport Mode switch settles#48

Open
dehuaichendragonplus wants to merge 1 commit into
FunplayAI:mainfrom
dehuaichendragonplus:fix/transport-status-label-refresh
Open

fix(ui): refresh transport status labels after a Transport Mode switch settles#48
dehuaichendragonplus wants to merge 1 commit into
FunplayAI:mainfrom
dehuaichendragonplus:fix/transport-status-label-refresh

Conversation

@dehuaichendragonplus

Copy link
Copy Markdown
Contributor

Why

Switching the MCP Server window's Transport Mode between Direct HTTP and Broker Mode restarts the server asynchronously (StopAsyncStartAsync, and broker bring-up spawns a process + health-probes + attaches over several frames). But the two status labels were refreshed on a fixed 2-frame delayCall, which fires long before the async restart settles:

EditorApplication.delayCall += () =>
    EditorApplication.delayCall += () => { UpdateBrokerStatus(); InvokeRefreshStatus(); };

So after switching to Broker Mode the header kept showing "Running on …" and the transport line kept showing "Transport: Direct HTTP.", even though the server had already switched (a broker process owning the port, the editor attached to it as a client).

Verified on a live editor: with the server actually in broker mode (IsAttachedToExistingTransport == true, a broker process listening on 8765, the editor connected to it), the labels still read the pre-switch Direct-HTTP text. It's a stale display, not a wrong computation — a fresh refresh produces the correct text.

What changed

FunplayMCPServerControlsPanel now refreshes the labels once the restart has actually settled instead of on a fixed delay: the transport-mode change handler awaits StopAsync/StartAsync, then calls UpdateBrokerStatus() + the header refresh. Awaiting captures the editor main-thread SynchronizationContext, so the refresh runs on the main thread against the final transport state. This also makes the labels correctly show a direct-HTTP fallback when broker mode fails to start (the settled state), which the old racing refresh could miss.

No recurring polling is introduced on purpose: MCPBrokerProcessManager.IsRunning does a synchronous loopback health probe, so polling it every frame/second would risk stalling the editor UI thread when the broker is unreachable — the refresh stays event-driven, just correctly timed.

Testing

  • Compiles clean on Unity 6000.3.13f1.
  • On a live editor in broker mode, confirmed the labels compute the correct text ("Attached to existing server on http://127.0.0.1:8765/ …" + "Transport: Broker running (pid …, port …).") — the fix makes that refresh happen after a Transport Mode switch, not only on a later window rebuild.

Independence

Touches only Editor/MCP/Server/FunplayMCPServerControlsPanel.cs. No overlap with the other open PRs; applies cleanly on current main.

Changelog

Added under ## Unreleased (Fixed).


🤖 Generated with Claude Code

…h settles

Switching to/from Broker Mode restarts the server asynchronously, but the MCP Server
window refreshed its status labels on a fixed 2-frame delayCall that raced the async
broker bring-up. After a switch to broker mode the header kept showing "Running on …"
and the transport line kept showing "Transport: Direct HTTP." even though the server
had already switched (broker process owning the port, editor attached as a client).

The refresh now runs once StopAsync/StartAsync have completed (awaited, so it resumes on
the editor main thread against the settled transport state) instead of on a fixed delay.
It also correctly reflects a direct-HTTP fallback when broker mode fails to start.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant