Repository navigation
fix(local-ai): keep routing safe across endpoint restarts - #1390
Conversation
On every companion start, EnsureStartedCoreAsync quiesced the gateway
route, started llama-server, probed it, and only then republished. With
no prior model to restore, quiesce unset agents.defaults.model.primary
outright -- and an absent primary is not "no routing", it is the
gateway's built-in default:
parseModelRef(... ?? "gpt-5.6-sol", "openai", ...)
So any prompt sent during that window was dispatched to openai and
failed with ProviderAuthError / missing-provider-auth on a Local
AI-only install. The window was ~10s and reproduced on every launch,
because requestedPort is 0 and the OS-assigned port made the previously
published baseUrl stale by construction.
Retain the managed primary across an endpoint cycle. QuiesceAsync now
takes a LocalAiQuiesceReason: EndpointCycle keeps llamacpp/<alias> in
place so a mid-cycle request fails as Local AI rather than as an
unrelated provider, while Teardown (stop, shutdown, failed publish)
still restores whatever preceded Local AI.
Reuse the last verified port when it is free, and skip the quiesce
entirely when the published route already names the port about to be
bound. The normal restart now performs zero config writes; PublishAsync
re-verifies and no-ops. A route is only withdrawn when the endpoint
genuinely moves.
Deciding the port before touching routing exposed a latent bug: the
port-conflict and ownership-unknown paths returned Conflict without
withdrawing the published route, leaving the gateway aimed at a port a
foreign process owns. FailStartupAsync now takes a route to withdraw,
and every startup-failure path passes it when one was left standing.
Refs #1293
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ClawSweeper review of PR #1321 identified two terminal lifecycle paths that could leave the gateway configured for a Local AI provider nothing would serve: 1. With a retained route (last-verified port reuse), a process-launch exception, immediate child exit, probe failure, or cancellation hit the catch handlers in EnsureStartedCoreAsync, which only disposed the child. The gateway kept routing to the retained port with no listener. Both catch paths now withdraw the retained route with teardown semantics before the child's listener disappears. 2. HandleManagedProcessExitedAsync always quiesced with EndpointCycle semantics even when automatic restart attempts were exhausted, so the managed primary stayed selected with its provider absent and no republish to follow. The exit handler now picks the quiesce reason from whether a restart will actually run: EndpointCycle for a pending restart, Teardown once the retry budget is spent. FailStartupAsync also now withdraws a retained route before disposing the child (previously after), matching the lifecycle contract that managed routing is removed before a listener can disappear. Tests: three new regression tests cover launch exception, retry exhaustion, and cancellation with a retained route; the publish-failure and startup-timeout tests were updated for the withdraw-before-stop ordering. Validation: build.ps1 clean; OpenClaw.Connection.Tests 724/724, OpenClaw.Tray.Tests 2864/2864, OpenClaw.SetupEngine.Tests LocalAiGpu 8/8 pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Copilot App <[email protected]> Copilot-Session: d0dbb47f-7bb0-4294-bda6-60b2a8b5fc55
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Bound post-cancellation route recovery, publish retryable ownership when process shutdown fails, and cover teardown failure after retry exhaustion. Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
Make endpoint-cycle recovery state explicit and drive the manifest-lock cancellation test causally. Co-authored-by: Copilot App <[email protected]> Copilot-Session: fe99977b-465c-4796-a6ae-436b4b11f6fa
|
🦞👀 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: blocked before merge. Reviewed September 10, 2026, 4:40 AM ET / 08:40 UTC. ClawSweeper reviewWhat this changesKeeps Local AI selected while its endpoint restarts, strengthens interrupted cleanup and fallback restoration, and exposes Stop for failed cleanup states. Merge readiness⛔ Blocked before merge - 3 items remain This remains necessary, and the earlier cleanup findings are addressed. No definite introduced defect was found, but the maintainer-requested real restart evidence remains outstanding. Priority: P1 Review scores
Verification
How this fits togetherThe Windows companion manages the local llama-server process and configures the WSL Gateway to send requests to its verified endpoint. Runtime transitions update Gateway routing and the Local AI settings page. flowchart TD
A[Startup or restart] --> B[Withdraw local provider]
B --> C[Keep Local AI selected]
C --> D[Start and verify endpoint]
D -->|Ready| E[Publish Gateway route]
D -->|Terminal failure| F[Restore prior routing]
F --> G[Show cleanup status and Stop]
E --> H[Gateway inference requests]
Before merge
Agent review detailsSecurityNone. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve local selection through recoverable cycles and terminal fallback restoration, with real Gateway verification on fresh and upgraded installations. Do we have a high-confidence way to reproduce the issue? Yes, from source and the linked configuration-audit reproduction: main removes the managed primary during startup, exposing the Gateway default before republishing. This review did not execute that path. Is this the best way to solve the issue? Yes in direction: the existing lifecycle and coordinator are the appropriate owners, and the patch covers the previously reported cleanup gaps without introducing a parallel routing implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3ce56b8902d5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Supersedes #1321 (fix(local-ai): stop routing to OpenAI while the endpoint restarts).
What Problem This Solves
Fixes an issue where Local AI-only users could have a prompt routed toward the Gateway's built-in OpenAI default while the managed llama.cpp endpoint was restarting or being rebound.
Why This Change Was Made
Endpoint cycles now withdraw the
llamacppprovider while retaining the managed Local AI primary, so requests fail locally instead of falling through to OpenAI. Terminal stop, startup failure, cancellation, retry exhaustion, and disposal paths restore the recorded fallback or unset the managed primary, and process-shutdown failures remain visible and retryable.Ownership transfer: none. Runtime sequencing remains in
LlamaServerRuntimeServiceandLocalAiEndpointLifecycle; Gateway route mutation remains inLocalAiGatewayProviderCoordinator; setup repair/rollback remains inLocalAiGatewayConfiguration; UI action policy remains inLocalAiPageViewModel.App.xaml.csis unchanged.User Impact
Local AI users keep privacy-safe routing while the endpoint cycles. If restart or cleanup cannot complete, the app reports an actionable failed state and exposes Stop when a managed listener still needs cleanup.
Evidence
EndpointCycleretains the managed primary and terminalTeardownrestores fallback or unsets it.Change Type
Scope
winnodeRequired proof pools
windows-wsl-dgx-blackwell: validate a real managed Local AI restart and fixed-prompt inference without cloud fallback.windows-wsl-gateway-e2e: validate Gateway prompt routing while the local provider is temporarily withdrawn.windows-winui-interactive: validate visible Stop recovery actions for failed/conflict Local AI cleanup states.Validation
Exact head:
8d1553395c70fa358c78584dc4b03de2b200b36d.\build.ps1: passed.dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore --filter "FullyQualifiedName~LocalAiPortLifecycleTests": 79 passed, 0 failed, repeated 3 times.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,991 passed, 32 skipped, 0 failed.dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,897 passed, 0 failed.dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore: 790 passed, 1 skipped, 0 failed.dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore: 1,136 passed, 0 failed.8d155339reported no actionable findings.Real Behavior Proof
main(3ce56b89).8d1553395c70fa358c78584dc4b03de2b200b36d.Failed/CompanionManaged; exhausted retries do not remain in endpoint-cycle routing state.Security Impact
Yes, explain the risk and mitigation: Gateway model routing during Local AI endpoint cycles is intentionally changed to retain the managed local primary and prevent unintended fallback toward OpenAI. Terminal cleanup restores the recorded prior route or unsets the managed primary.Compatibility and Migration
Review Conversations