Repository navigation
fix(setup): prevent Local AI routing ambiguity after rerun - #1282
shanselman merged 8 commits into
Conversation
Clean up every setup-managed record matching the local gateway URL while preserving legacy, remote, and SSH-tunneled entries. This prevents setup reruns from leaving ambiguous Local AI ownership behind. Fixes openclaw#1251.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed September 3, 2026, 3:13 PM ET / 19:13 UTC. ClawSweeper reviewWhat this changesThe PR removes every URL-equivalent gateway record owned by the current setup-managed WSL distro during rerun cleanup, preserves protected records, and adds duplicate and deletion-failure tests. Merge readiness⛔ Blocked before merge - 5 items remain Keep this PR open. It addresses a real setup-rerun defect, but it still needs current-head after-fix gateway proof and a decision on the remaining restoration-save failure that can leave a retained identity without its registry record. Priority: P2 Review scores
Verification
How this fits togetherSetup reruns clean persisted local-gateway records and their per-gateway identities before provisioning a new WSL gateway. The registry determines the active connection route that Local AI uses after setup completes. flowchart LR
A[Setup rerun] --> B[Gateway registry]
B --> C[Classify matching records]
C --> D[Preserve remote and protected records]
C --> E[Remove current-distro duplicates]
E --> F[Persist registry and active route]
F --> G[Delete stale identities]
G --> H[Local AI gateway routing]
Decision needed
Why: The contributor explicitly requests acceptance of this remaining persistence failure mode, while making it fully durable likely requires a transaction or journal design rather than a small local change. Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Use a durable cleanup transaction or recovery journal so a failed identity deletion and any subsequent persistence failure cannot orphan retry state, then attach redacted current-head setup-rerun output showing the first Local AI request reaches the local provider. Do we have a high-confidence way to reproduce the issue? Yes. The focused setup fixture can seed an unmanaged record ahead of multiple current-distro URL-equivalent records and invoke cleanup, though the PR lacks a real current-head WSL setup-rerun trace. Is this the best way to solve the issue? No. The duplicate-removal approach is appropriately narrow, but the claimed retry recovery is not durable if its restoration save fails; current-head after-fix behavior also remains unobserved. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bd7702c5149a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
Adversarial consensus reviewVerdict: No CRITICAL or HIGH-severity defect was found at Both models agree: HIGH consensus
Only one model flagged: LOW consensus
Disputed finding assessment: The partial-failure concern is real but partly pre-existing for one record. PR #1282 materially widens it to repeated deletion/save attempts and permits partial progress across duplicates. Prefer gathering all removable records, persisting one registry update, then deleting identities, with a focused forced-save-failure test. This is an edge-case recovery risk, not a demonstrated common-path failure. Validation scope: Two independent rubber-duck reviews used the same packet with Claude Opus 4.6 and GPT-5.3 Codex. Adjudication covered the complete two-file diff plus registry URL normalization/persistence, setup ownership, pipeline order, rerun and rollback behavior, Local AI manifest/provider routing, distro resolution, cleanup tests, linked issue evidence, and current CI. Collection mutation, unrelated remote/tunnel deletion, manifest staleness, credential precedence, and stable-record compatibility were investigated and not found to regress. Existing setup/recovery E2E shards pass; the remaining CI failure is an unrelated Sandbox page accessibility readiness timeout. No live setup-rerun proof was supplied or run. |
…eway-duplicate-cleanup
Persist removal of all equivalent setup-managed gateway records before deleting their identity directories. Cover mixed protected records, active identity preservation, and multiple managed duplicates. Co-authored-by: Copilot App <[email protected]>
269c370 to
f1399d1
Compare
Clean up every setup-managed record matching the local gateway URL while preserving legacy, remote, and SSH-tunneled entries. This prevents setup reruns from leaving ambiguous Local AI ownership behind. Fixes openclaw#1251. (cherry picked from commit 269c370)
Restore only records whose identity directories could not be removed, including a removed active record, while keeping successful duplicate cleanup durable. Co-authored-by: Copilot App <[email protected]>
f1399d1 to
cdedf07
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…eway-duplicate-cleanup
Preserve the repaired cleanup implementation while connecting the contributor branch history for a non-force fast-forward update. Co-authored-by: Copilot App <[email protected]>
|
Joel: will add proof |
) Root cause: after 31a8c65/16cb6897 gated screen.snapshot/camera.snap/ location.get behind interactive consent, NodeService.EnsureCaptureConsentAsync awaited the RecordingConsentDialog's Task<bool> with no timeout anywhere. An unattended caller (local MCP HTTP client, automated agent, hosted CI) hung forever waiting for a human who would never appear, only "recovering" when the caller's own HttpClient.Timeout (30s in the failing integration tests) fired. This broke McpHttpServerIntegrationTests.CameraSnap_ReturnsImageOr- WellFormedError and ScreenSnapshot_ReturnsImageOrWellFormedError, blocking PRs #1282, #1294, #1295, #1296. Fix: add a fail-closed, configurable consent-prompt timeout (SettingsData.CaptureConsentTimeoutMs, default 120s) enforced by a new pure ConsentPromptTimeoutGate helper. On timeout the prompt is denied (never granted) and the dangling dialog window is force-closed. The bounded task is independent of any single caller's CancellationToken so the shared in-flight prompt (_screen/_camera/_locationConsentInFlight) still resolves for any other concurrent waiter even if the owning caller cancels first. A late Allow click that races the timeout no longer persists a stale grant after the request has already been denied. Interactive UI consent (Allow/Deny, persistence) is unchanged. - Never bypasses or auto-grants consent: timeout always resolves to denied. - TrayAppFixture sets CaptureConsentTimeoutMs=3000 for deterministic CI, not a test/client timeout change - this is a real product settings knob. - New unit tests cover fail-closed timeout, pass-through grant/deny, and the shared-prompt-survives-caller-cancellation case a rubber-duck review found. Co-authored-by: Copilot App <[email protected]>
|
@karkarl @shanselman — for MVP, can we accept the remaining failed-restoration-save case as a bounded recovery risk and treat it as non-blocking? It requires two consecutive failures: Windows first fails to delete a stale managed identity directory, then persistence of the restored retry record also fails. The original duplicate-routing path and the mixed/protected-record cleanup behavior are covered; Karen's review found no Critical or High defect and described this as a lower-consensus edge-case recovery risk rather than a common-path failure. Avoiding this case completely would require adding durable transaction/journal machinery to a focused cleanup repair. I would prefer not to add that complexity for MVP unless you consider it necessary. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4db86e3e-e663-4d36-bb8c-18b4d0b75405
|
Maintainer decision: accept the remaining failed-restoration-save case as a bounded, non-blocking MVP recovery risk. The primary invariant is preserved: the durable registry is updated before identity deletion, so it never references an identity already removed. The residual case requires two consecutive filesystem failures, first deleting the identity and then persisting the restored retry record. Setup surfaces that failure rather than reporting success, but recovery may require manual cleanup. Adding a durable journal would materially expand this focused duplicate-routing repair. Current head |
…enclaw#1300) Root cause: after 31a8c65/16cb6897 gated screen.snapshot/camera.snap/ location.get behind interactive consent, NodeService.EnsureCaptureConsentAsync awaited the RecordingConsentDialog's Task<bool> with no timeout anywhere. An unattended caller (local MCP HTTP client, automated agent, hosted CI) hung forever waiting for a human who would never appear, only "recovering" when the caller's own HttpClient.Timeout (30s in the failing integration tests) fired. This broke McpHttpServerIntegrationTests.CameraSnap_ReturnsImageOr- WellFormedError and ScreenSnapshot_ReturnsImageOrWellFormedError, blocking PRs openclaw#1282, openclaw#1294, openclaw#1295, openclaw#1296. Fix: add a fail-closed, configurable consent-prompt timeout (SettingsData.CaptureConsentTimeoutMs, default 120s) enforced by a new pure ConsentPromptTimeoutGate helper. On timeout the prompt is denied (never granted) and the dangling dialog window is force-closed. The bounded task is independent of any single caller's CancellationToken so the shared in-flight prompt (_screen/_camera/_locationConsentInFlight) still resolves for any other concurrent waiter even if the owning caller cancels first. A late Allow click that races the timeout no longer persists a stale grant after the request has already been denied. Interactive UI consent (Allow/Deny, persistence) is unchanged. - Never bypasses or auto-grants consent: timeout always resolves to denied. - TrayAppFixture sets CaptureConsentTimeoutMs=3000 for deterministic CI, not a test/client timeout change - this is a real product settings knob. - New unit tests cover fail-closed timeout, pass-through grant/deny, and the shared-prompt-survives-caller-cancellation case a rubber-duck review found. Co-authored-by: Copilot App <[email protected]>
…1282) Removes all URL-equivalent setup-managed gateway duplicates while preserving protected records and retrying failed identity cleanup. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4db86e3e-e663-4d36-bb8c-18b4d0b75405

Closes #1251
What Problem This Solves
Rerunning local setup could leave multiple SetupEngine-managed gateway records for the same local URL when an unmanaged or protected record appeared first in registry order. Those duplicates could make Local AI gateway ownership ambiguous.
Why This Change Was Made
Cleanup now examines every URL-equivalent gateway record and removes every record owned by the current SetupEngine-managed distro. It preserves unmanaged and legacy records, records protected by another distro owner, remote records, SSH-tunneled records, and non-equivalent endpoints.
The complete registry and active-ID transition is persisted before identity directories are deleted. If an identity cannot be deleted, only that record is restored, including its active ID when applicable, so setup can retry without resurrecting records that were cleaned successfully.
User Impact
Users can rerun local setup without stale managed duplicates confusing Local AI routing. Existing unrelated gateway records and identities remain intact.
Change Type
Scope
winnodeRequired proof pools
windows-wsl-gateway-e2e: setup rerun cleanup and managed gateway ownership behavior changed.Validation
Validated at
a5867d339a4079b137842523d6cb9f1de4944499after merging currentorigin/mainwithout rebase or force..\build.ps1: passed. All five repository projects built.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: passed, 3,905 passed, 32 skipped, 0 failed.dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: passed on full rerun, 2,833 passed, 0 skipped, 0 failed. The first full run had one unchanged onboarding bootstrap timeout; that exact test then passed 3/3 focused reruns before the clean full rerun.dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj: passed, 709 passed, 0 skipped, 0 failed.dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj: passed, 1,033 passed, 0 skipped, 0 failed.dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter 'FullyQualifiedName~CleanupStaleGateway': passed, 8 passed, 0 skipped, 0 failed.33794747399: passed. Aggregate tests, all three Gateway E2E shards, repo hygiene, and x64/ARM64 builds succeeded.git diff --check: passed.python .agents\skills\autoreview\scripts\autoreview --mode branch --base origin/main --stream-engine-output: clean, no accepted or actionable findings, confidence 0.88.Real behavior proof
Current-head cleanup behavior
The focused current-head run invoked the production
CleanupStaleGatewayStepandGatewayRegistryagainst real temporary filesystem state. All 8 tests passed. The mixed-record regression placed an unmanaged active record before two URL-equivalent setup-managed duplicates and proved that both managed identities and records were removed while unmanaged, other-distro, remote, SSH-tunneled, and non-equivalent records plus identities were preserved. The locked-identity test proved that only the failed record and its active ID are restored, then removed on retry.Current-head Gateway path
All three hosted Gateway E2E shards passed at the refreshed head, including
setup-connect,revocation-recovery, andnetwork-recovery.A local
windows-wsl-gateway-e2eattempt was blocked before the changed cleanup step.wsl.exefailed to mount the proof-owned temporaryswap.vhdxwithWsl/InstallDistro/Service/RegisterDistro/CreateVm/MountDisk/E_ACCESSDENIED. The isolated setup rolled back and removed the proof state. This local host result is recorded as blocked, not passed.Failure reproduction before the fix
The original setup-rerun failure surfaced
No API key found for provider "openai"while Local AI was selected.Screenshot link verified: yes. This is before-fix evidence, not current-head runtime proof.
Maintainer decision
The remaining failed-restoration-save case is accepted as a bounded, non-blocking MVP recovery risk. The primary invariant is preserved: the registry is durably updated before identity deletion, so it never references an identity that was already removed. The residual case requires two consecutive filesystem failures, first identity deletion and then persistence of the restored retry record. Setup reports failure, but recovery may require manual cleanup. A durable transaction journal would materially expand this focused repair.
Security Impact
Yes/No): No.Yes/No): No.Yes/No): No.Yes/No): No.Yes/No): No.Yes, explain the risk and mitigation: N/A.Compatibility and Migration
Yes/No): Yes.Yes/No): No.Yes/No): No.Review Conversations