Repository navigation
fix(node): local MCP server can stay running or vanish when toggled during a restart - #2078
Conversation
Start and stop now share one lifecycle lock so a concurrent restart or disable cannot leave a stale listener or null out a live server. Refs openclaw#2072 Co-authored-by: Copilot App <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR serializes local MCP listener publication and removal with one lifecycle lock. Example: Local MCP on port 8765 is disabled while a reconnect starts its listener.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep this collaborator-authored PR open: it addresses a current-main lifecycle defect, and inspection found no definite introduced production bug. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherNodeService hosts the authenticated loopback MCP server, shares registered capabilities with its bridge, and receives lifecycle requests from settings changes and gateway-client attachment. flowchart TD
Settings[Settings toggle] --> Node[NodeService]
Reconnect[Gateway client attachment] --> Node
Node --> Gate[MCP lifecycle lock]
Gate --> Server[Loopback HTTP server]
Server --> Bridge[MCP tool bridge]
Bridge --> Capabilities[Registered capabilities]
Technical reviewBest possible solution: Keep lifecycle synchronization in NodeService, preserve disposal outside the lock, and verify concurrent ownership and revocation through the production transport. Do we have a high-confidence way to reproduce the issue? Main permits startup to pass its enabled check, disable to observe no published server, and startup to publish afterward; competing failed starts can also clear the winning reference. Is this the best way to solve the issue? The dedicated lock is a small repair using the existing owner, and inspection found no unnecessary production machinery; runtime concurrency coverage is still needed to validate its invariant. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e70292487958. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: The patch preserves authentication, but concurrent listener revocation still needs final-effect evidence. EvidenceWhat I checked:
Likely related people:
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 8, 2026, 1:51 AM ET / 06:51 UTC. |
Replace the implementation-shaped ownership check with real NodeService and authenticated HTTP regression cases for competing starts and disable during startup. Co-authored-by: Copilot App <[email protected]>
|
Copilot agent follow-up: b74a343 replaces the source-shaped ownership test with two real NodeService/authenticated-HTTP cases. Both reproduced the original bug: a request after disable still incremented the capability effect counter (2 to 3 for competing starts, 1 to 2 for disable during startup). With the fixed implementation restored and rebuilt, both reject HTTP without another effect, and re-enable accepts the same authenticated client. The full build, Shared (4876 passed, 24 ordinary skips), Tray (5294 passed), and both focused HTTP cases passed. The PR body now includes the before/after evidence and the separate computer-use off/on check. This does not claim every lifecycle interleaving or green hosted CI. |
|
Hi @karkarl! I'm a Copilot triage bot posting for Scott (I'm not Scott). He asked me to assign this PR to you and see if you'd be up for reviewing it and merging it when you're happy with it. This is one of five small fixes from the state machine audit in #2071 (Fix dangerous implicit state machines (audit lanes)). This one makes sure turning the local MCP server on or off during a restart can't leave it running when it should be off, or lose it when it should be on. Start and stop now share one lock. CI note: the UI test job is red. The test host crashed in the known reasoning picker test family before the new MCP tests ran, and there is also a chat fixture timeout whose cause we haven't confirmed. Locally, the build, Shared tests, Tray tests and the two new real HTTP race tests all passed. No rush at all, and please feel free to ask for changes or push back. Thank you so much! |
PR cleanup reviewReviewed head: Source cleanup review at b74a343 against main e59374c: the lifecycle lock and ownership swap are not in main. The latest tests now exercise real NodeService publication and authenticated HTTP calls, so the older review that lacked that coverage is stale. Keep this candidate, but do not land from source review alone: current UI/CI Gate remains failed, and the remaining Gateway/token-rotation/drain overlap proof should be reconciled with the selected proof pools. Action in this cleanup pass: leaving this PR open. No branch changes or runtime-proof waiver. The findings above come from source, discussion and recorded-CI review; Windows validation was not rerun in this pass. |
Co-authored-by: bkudiess <[email protected]>
Closes #2072
Related: #2071
What Problem This Solves
Fixes: the local MCP server could be left running after it was turned off, or a running server could be lost, when it was started and stopped at the same moment (for example, a settings toggle racing a reconnect).
User Impact
User impact: competing starts cannot lose the tracked Local MCP Server, and turning it off during startup prevents later authenticated calls from invoking tools. There is no other visible change.
Why This Change Was Made
Start and stop now share one lifecycle lock. Stop swaps the server references out under the lock and disposes them outside it, so it never waits while holding the lock. A failed start no longer clears a server that a concurrent start created.
Evidence
Two gated regressions exercise real NodeService and authenticated HTTP, replacing the implementation-shaped source test. Both failed on the pre-fix code because a call still caused a capability effect after disable; both pass with the fix, including same-client re-enable. Separately, an isolated app passed
winnodeand computer-use off/on checks, restoring 33 tools without restarting. Independent rubber-duck review found no blocking production defect; test diagnostics and a pending-contender guard were strengthened.Change Type
Scope
winnodeRequired proof pools
windows-winui-interactive: current-head Permissions toggle and local MCP lifecycle proof on an isolated Windows desktop. Manual UI diagnostics and authenticated MCP checks are recorded below; no complete pool/inventory receipt is claimed.Validation
./build.ps1: all builds succeededdotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore: 4876 passed, 24 skippeddotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore: 5294 passed, 0 skippeddotnet test .\tests\OpenClaw.Tray.UITests\OpenClaw.Tray.UITests.csproj -r win-x64 --no-restore --filter 'FullyQualifiedName~NodeServiceMcpLifecycleTests': 2 passed, 0 skipped.ReasoningPicker_UsesOnlyAdvertisedChoices, matching the documenteddocs/CI_FAILURES.mdcrash family; the TRX/sequence confirms the new MCP cases had not executed. Separately,HistoricalFractionalVoiceConversationRendersWithoutLoadingPlaceholdertimed out (80 other fixture cases passed): the app log records working MCP startup/navigation/snapshot, thenChat initial tail navigation did not land at the tail.This points outside the changed lifecycle path, but the chat failure's root cause is not established. Tray/setup/integration and all three WSL E2E jobs passed. No blind rerun or weakened tests; hosted UI remains a merge blocker.Real Behavior Proof
http://127.0.0.1:49995/. No installed Gateway was changed.ce5a6a1c2; the unchanged source was built before committing (embedded base stampe70292487). Source correspondence is manually recorded. App assembly SHA256:78614D9CFC3448B3A3F25F97D708C61F0702355B6A3380DD805DDF10E1DFF22D.winnode --mcp-url http://127.0.0.1:49995/ --list-tools; invokewinnode --mcp-url http://127.0.0.1:49995/ --command app.status --params '{}'; computer-use toggled Permissions > Integrations > Local MCP Server off, then on, repeating both CLI checks. Each CLI call used the same isolated profile and no inherited MCP token.McpToggle=off, CLI exit 1/connection refused, zero listeners and persistedEnableMcpServer=False. On showedMcpToggle=on,Local MCP only,Server enabled: token ready; discovery returned 33 tools,app.statusreturnedReady/fixture-1, one HTTP.sys listener and persistedEnableMcpServer=True.HttpListeneruses HTTP.sys/PID 4. Corrected profile-authenticated/endpoint assertions passed. The earlier MCP-command disable also passed; its reply was cut off by shutting down its own server.b74a343ee694df5f01ba2e16709f38555833c434. Production source remains identical toce5a6a1c2; test source SHA256287E00038B6AF7F05C2FE1896299EFF805D096B8B71CBA425F8ADDBF39BF6EE8was manually associated with the final run before committing unchanged source.Security Impact
Yes, explain the risk and mitigation: N/ACompatibility and Migration
Review Conversations
Opened by a Copilot agent working through the state-machine audit lanes in #2071.