Skip to content

fix(local-ai): prevent routing to an unverified managed model - #1212

Merged
karkarl merged 2 commits into
openclaw:mainfrom
joelagnel:fix/1192-managed-model-readiness
Aug 28, 2026
Merged

karkarl merged 2 commits into
openclaw:mainfrom
joelagnel:fix/1192-managed-model-readiness

Conversation

@joelagnel

@joelagnel joelagnel commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1192

What Problem This Solves

Fixes an issue where Local AI could be published to the gateway and reported healthy when llama-server was reachable but the configured managed model was unknown, missing, reported from the wrong path, or no longer served by a proven owned endpoint.

Why This Change Was Made

Managed-model readiness now requires router health, a Verified or Loaded state, and an exact path match. Startup and refresh share that predicate. Every refresh branch that loses endpoint ownership or readiness quiesces the previously published route before returning. If route withdrawal fails or throws, the managed process is stopped and the runtime publishes a fail-closed state. Recovery persists and publishes the freshly verified owned endpoint rather than stale manifest data.

User Impact

The gateway no longer routes Local AI requests to an endpoint that cannot prove it serves the configured managed model. Temporary readiness loss withdraws routing safely and routing recovers automatically only after valid model and endpoint evidence returns.

Evidence

  • Table-driven client coverage rejects timeout, invalid response, missing alias, unknown state, missing path, and wrong path; Verified and Loaded evidence pass.
  • Startup coverage proves unready model evidence does not persist or publish an endpoint.
  • Refresh coverage proves incomplete ownership, ownership conflict, missing endpoint, and readiness loss quiesce routing.
  • Quiesce failure and exception coverage proves the managed process is stopped and runtime ownership is cleared.
  • Recovery coverage proves the freshly observed endpoint is persisted and published, successful republish recovers, and publication failure remains failed.
  • Final rubber-duck review confirmed the route-safety and endpoint-rebinding invariants; its cancellation/exception hardening finding was addressed before publication.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Validation

Environment: Windows 11 ARM64, .NET SDK 10.0.400. OPENCLAW_REPO_ROOT was set to the isolated worktree; Tray tests used an isolated OPENCLAW_TRAY_DATA_DIR.

  • powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\build.ps1: passed. Shared, Cli, WinNodeCli, SetupEngine, and WinUI built successfully for win-arm64.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: passed, 3,819 passed, 0 failed, 32 skipped.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: passed, 2,749 passed, 0 failed, 0 skipped.
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore: passed, 705 passed, 0 failed, 0 skipped.
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore --filter "FullyQualifiedName~LlamaServerClientTests|FullyQualifiedName~LocalAiPortLifecycleTests": passed, 40 passed, 0 failed, 0 skipped.
  • git diff --check: passed.
  • Rubber-duck review: completed. The actionable exception-path finding was fixed and focused tests rerun successfully.

Real behavior proof

  • PR head tested: d3c1b433.
  • Rebase proof: conflict with the b10655 runtime bump was resolved by retaining LlamaRuntimeCatalog-driven manifest data and all readiness lifecycle cases.
  • Refresh_QuiescesPublishedRouteWhenEndpointOwnershipIsLost observes quiesce before returning for incomplete ownership, conflict, and missing endpoint.
  • Refresh_QuiesceFailureStopsUnverifiedManagedProcess observes probe, quiesce, stop and returns Failed with no runtime ownership or process ID.
  • Refresh_QuiesceExceptionStopsManagedProcessBeforePropagating observes quiesce, stop, leaves a fail-closed snapshot, then propagates the lifecycle exception.
  • Refresh_RecoveryRebindsFreshlyVerifiedEndpointBeforePublishing rewrites the persisted receipt to stale port 29999, verifies live port 28777, then observes probe:28777, publish:28777 and confirms the receipt is rebound to 28777.
  • Refresh_UpdatesPublicationWhenManagedModelReadinessChanges observes probe, quiesce followed by probe, publish for successful readiness recovery.
  • Refresh_RecoveryPublishFailureRemainsFailedAndQuiesced proves a failed recovery publication does not report Healthy.
  • Observed focused result: 40 passed, 0 failed, 0 skipped.
  • Screenshot or artifact links verified? N/A.
  • Not verified or blocked: a live managed llama-server plus WSL gateway environment was not exercised locally. Current-head deterministic HTTP and lifecycle tests directly cover the changed route mutation behavior and exact provider checks remain in LocalAiGatewayProviderCoordinator.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? Yes
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation: refresh now withdraws managed gateway routing whenever endpoint ownership or model readiness cannot be proven. Failed route withdrawal stops the managed process, and publication occurs only after the live owned endpoint and exact managed model are verified.

Compatibility and Migration

  • Backward compatible? Yes
  • Config or environment changes? No
  • Migration needed? No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 27, 2026, 8:15 PM ET / August 28, 2026, 00:15 UTC.

ClawSweeper review

What this changes

The PR requires a managed llama-server endpoint to prove the expected model state and path before the Windows companion publishes it to the gateway, and withdraws routing when that proof is lost.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep open. The branch implements the linked Local AI routing fix and addresses the prior quiesce-failure concern, but current main does not contain it and the required real llama-server plus WSL gateway proof is still absent.

Priority: P2
Reviewed head: d3c1b4334ce48dfd3c02d980b0105d5f6c6334c8

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and focused coverage are solid, but merge readiness is capped by the missing real-stack proof.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Needs real behavior proof before merge: current-head unit and lifecycle tests are useful but mock-only, and the PR body confirms that no live managed llama-server plus WSL gateway withdrawal and recovery run was exercised. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Needs real behavior proof before merge: current-head unit and lifecycle tests are useful but mock-only, and the PR body confirms that no live managed llama-server plus WSL gateway withdrawal and recovery run was exercised. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 7 items PR-introduced readiness gate: The verified merge-base-to-head diff changes startup and refresh to require health, a Verified or Loaded model state, and an exact managed-model path before publishing or reporting Healthy.
Fail-closed refresh handling: The introduced refresh branches quiesce the provider when endpoint ownership or model readiness is lost, and stop the managed process if withdrawal fails or throws.
Gateway lifecycle owner: The existing gateway coordinator verifies provider removal after quiescing and cleans up a partially published route, so the runtime's new calls use the established route owner.
Findings None None.
Security None None.

Live Verification

Command: powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "dotnet build .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }; dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore --filter 'FullyQualifiedName~LlamaServerClientTests|FullyQualifiedName~LocalAiPortLifecycleTests'"

Result: FAIL (failed) — execution before step 1 expect_output: sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

Assertions:

  • FAIL expect_output: Passed!

How this fits together

The Windows companion starts a loopback llama-server router and probes its health and managed-model metadata. A verified endpoint is then published to the app-owned WSL gateway so Local AI requests can be routed safely.

flowchart LR
  A[Managed model install] --> B[Windows llama-server router]
  B --> C[Loopback health and model probe]
  C --> D{Owned endpoint and model verified?}
  D -- Yes --> E[Publish provider to WSL gateway]
  D -- No --> F[Withdraw gateway route]
  E --> G[Local AI requests]
  F --> H[Starting or failed runtime state]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Needs real behavior proof before merge: current-head unit and lifecycle tests are useful but mock-only, and the PR body confirms that no live managed llama-server plus WSL gateway withdrawal and recovery run was exercised. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - A transient or malformed model-status response now withdraws Local AI routing, so an upgraded user can temporarily lose Local AI service until the router and gateway prove readiness again.
  • Resolve merge risk (P1) - The deterministic fakes do not establish that an actual managed llama-server and app-owned WSL gateway withdraw and restore the route in the same order.
  • Complete next step (P2) - No repair is queued because the remaining merge blocker is contributor-provided real-stack proof, not a discrete code defect.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +147/-18; tests +379/-7 The route-safety change has more than twice as much focused test growth as production growth across four files.

Merge-risk options

Maintainer options:

  1. Capture real gateway withdrawal and recovery proof (recommended)
    Run the current head with a managed llama-server and app-owned WSL gateway, induce unready model evidence, and show that routing withdraws before recovering only after verified evidence returns.
  2. Accept the temporary fail-closed availability tradeoff
    Merge with explicit acceptance that transient model-status failures temporarily disable Local AI routing rather than preserving the former reachable-but-unverified route.

Technical review

Best possible solution:

Retain the shared verified-model predicate and fail-closed route withdrawal, then demonstrate withdrawal and automatic recovery against a real managed llama-server and WSL gateway before landing.

Do we have a high-confidence way to reproduce the issue?

No for the full real stack. Source and focused tests clearly exercise the route-safety paths, but the PR confirms that a live managed llama-server plus WSL gateway run has not been captured.

Is this the best way to solve the issue?

Yes, with a proof gap. Reusing the existing gateway lifecycle owner while tightening the probe predicate is the narrowest fix for the reported unsafe publication behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f2a96a596c01.

Labels

Label justifications:

  • P2: This is a bounded Local AI routing correctness fix with meaningful but limited user impact.
  • merge-risk: 🚨 compatibility: Existing installations change from continuing on unknown model evidence to withdrawing the gateway provider until verification succeeds.
  • merge-risk: 🚨 availability: The introduced readiness gate can temporarily make Local AI unavailable when model status cannot be proven.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Needs real behavior proof before merge: current-head unit and lifecycle tests are useful but mock-only, and the PR body confirms that no live managed llama-server plus WSL gateway withdrawal and recovery run was exercised. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Joel: Current history attributes both the initial managed llama-server implementation and the later managed-model probe contract to Joel. (role: original Local AI feature author and probe-contract contributor; confidence: high; commits: ccd64bbb7d68, d2fdd70a030a; files: src/OpenClaw.Connection/LocalAi/LlamaServerRuntimeService.cs, src/OpenClaw.Connection/LocalAi/LlamaServerClient.cs)
  • Vitor Cepeda Lopes: Recent main history includes the first-start endpoint lifecycle fix that shares the runtime and gateway-route boundary. (role: recent Local AI lifecycle contributor; confidence: medium; commits: 598a5131bd8d; files: src/OpenClaw.Connection/LocalAi/LlamaServerRuntimeService.cs, src/OpenClaw.Tray.WinUI/Services/LocalAiGatewayProviderCoordinator.cs)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Post redacted terminal output or runtime logs showing a real managed llama-server route withdraw on unready evidence and republish after recovery.
  • Update the PR body with that current-head proof. If a new review does not start automatically, ask a maintainer to comment @clawsweeper re-review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-24T23:45:41.329Z sha e6a9313 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T23:29:19.676Z sha ab038bf :: needs real behavior proof before merge. :: [P1] Publish failure before stopping the managed process

@karkarl karkarl added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 27, 2026
@karkarl
karkarl force-pushed the fix/1192-managed-model-readiness branch from e6a9313 to ab038bf Compare August 27, 2026 23:24
joelagnel and others added 2 commits August 27, 2026 17:02
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 7ef70da5-e94c-4bcf-9cb6-a0acee52c9c4
@karkarl
karkarl force-pushed the fix/1192-managed-model-readiness branch from ab038bf to d3c1b43 Compare August 28, 2026 00:11

@karkarl karkarl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review verdict: SHIP TODAY.

The release-blocking findings are resolved: readiness and exact ownership proof gate routing, every proof-loss path withdraws the published route, quiesce failure hard-stops the managed process, and recovery republishes the freshly verified endpoint rather than stale persisted state. Focused lifecycle coverage exercises ownership loss, missing endpoints, quiesce and publish failures, stale-endpoint recovery, and successful republish.

Dependency/overlap review found no remaining blocker with #1222. The previously observed Axe readiness timeout was a shared test-signalling flake, not an accessibility violation or Local AI regression; the latest rerun is green. Approved at d3c1b43.

@karkarl
karkarl merged commit 1955282 into openclaw:main Aug 28, 2026
29 of 31 checks passed
@karkarl karkarl removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Require verified managed-model evidence before publishing Local AI

2 participants