Skip to content

fix: wizard shutdown no longer reports a timeout - #1018

Merged
shanselman merged 2 commits into
mainfrom
shanselman-fix-wizard-request-cancellation
Jul 18, 2026
Merged

shanselman merged 2 commits into
mainfrom
shanselman-fix-wizard-request-cancellation

Conversation

@shanselman

@shanselman shanselman commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #1010

What Problem This Solves

Fixes an issue where users running the gateway setup wizard could see a timeout when the client was actually shutting down or being disposed.

Why This Change Was Made

The wizard request wait now uses the framework timeout-and-cancellation primitive so deadline expiry and client-lifetime cancellation remain distinct. Request completion and method tracking are cleaned in one terminal finally path without changing gateway response or error propagation.

User Impact

Wizard shutdown and connection teardown now report cancellation rather than a misleading timeout. Real gateway deadlines still report TimeoutException.

Evidence

Five loopback WebSocket behavioral tests exercise real request serialization, transport response handling, timeout, disposal ordering, and a late response after timeout. They prove response payloads and gateway errors propagate unchanged, timeout remains a timeout with the compatible message, disposal surfaces OperationCanceledException, late responses cannot replace a completed timeout, and both pending trackers are empty on every terminal path.

Rubber-duck closeout: clean; no blocking or non-blocking findings.

Structured autoreview was attempted with Codex (gpt-5.6-sol, high) and Claude. It was blocked before review by local reviewer tooling: Codex 0.137.0 refused helper binaries in the isolated temporary runtime, and Claude Code 2.1.156 is older than the helper's required 2.1.169 safe-mode version. No autoreview findings were produced.

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

  • ./build.ps1 - passed; 5/5 projects built
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore - passed; 2,906 passed, 31 skipped, 0 failed
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore - passed; 1,823 passed, 0 skipped, 0 failed
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore --filter "FullyQualifiedName~OpenClawGatewayClientTests.SendWizardRequestAsync" --logger "console;verbosity=normal" - passed; 5 passed, 0 failed

Real Behavior Proof

  • Environment tested: Windows 11, .NET SDK 10.0.302, in-process loopback WebSocket server
  • PR head or commit tested: 1558aaaa
  • Exact steps or command run: focused OpenClawGatewayClientTests.SendWizardRequestAsync* filter above
  • Evidence after fix: response-before-dispose returned the exact payload and observed both trackers empty before disposal; gateway ok:false preserved InvalidOperationException("wizard rejected"); a 250 ms unfulfilled request threw TimeoutException("Timed out waiting for wizard.status response"); dispose-before-response threw OperationCanceledException; a late response after timeout was processed ahead of a successful probe response but left the original task on the same timeout exception and both trackers empty
  • Observed result: terminal classification, timeout compatibility, late-response ordering, and cleanup match the contract on the real WebSocket request/response path
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A
  • Not verified or blocked: No live external gateway was used; protocol behavior is covered by the repository loopback WebSocket transport. Structured autoreview blocked as described above.

Security Impact

  • New permissions or capabilities? (Yes/No): No
  • Secrets or tokens handling changed? (Yes/No): No
  • New or changed network calls? (Yes/No): No
  • Command or tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes
  • Config or environment changes? (Yes/No): No
  • Migration needed? (Yes/No): 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.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: ef1a489e-d0db-416e-a8da-ac6184e5f6af
@clawsweeper clawsweeper Bot added 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. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 5:41 PM ET / 21:41 UTC.

Summary
The PR replaces the wizard-request timeout race with Task.WaitAsync cancellation support, centralizes pending-request cleanup in finally, and adds loopback WebSocket tests for responses, errors, timeouts, disposal, and late frames.

Reproducibility: no. executed current-main reproduction was established in this read-only review, but the source path is clear: cancellation of the delay task in the current Task.WhenAny branch is classified as a timeout during disposal.

Review metrics: 2 noteworthy metrics.

  • Changed surface: 4 files affected; 210 added, 10 removed. Most of the change is focused regression coverage around one shared gateway-client method.
  • Focused scenarios: 5 loopback WebSocket cases. The PR exercises the terminal response, error, timeout, disposal, and late-frame paths that define the proposed behavior.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Attach redacted current-head proof from a real gateway/setup-wizard shutdown or disposal run.
  • Update the PR body with that artifact or transcript; if review does not refresh, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The reported loopback WebSocket tests are useful behavioral coverage, but they are automated test evidence rather than after-fix proof from a real gateway/setup runtime; attach redacted live output, logs, or a recording from the current head. 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.

Risk before merge

  • [P1] Existing callers that currently handle TimeoutException during shutdown will instead receive OperationCanceledException; that is the intended correction but is a compatibility-visible error-classification change.
  • [P1] The supplied proof is limited to an in-process loopback WebSocket test run, so the real setup/gateway shutdown path remains unobserved on the PR head.

Maintainer options:

  1. Add real shutdown proof before merge (recommended)
    Run the current head through a real gateway/setup-wizard shutdown or disposal flow and attach redacted terminal output, logs, or a recording that shows cancellation while a genuine deadline still reports the compatible timeout.
  2. Accept the classification change on test evidence
    Maintainers may accept the intentional OperationCanceledException behavior for shutdown based on the focused loopback coverage, acknowledging that live gateway proof was not collected.

Next step before merge

  • [P1] The remaining merge gate is contributor-supplied real gateway/setup proof and maintainer acceptance of the compatibility-visible exception classification, not a safe automated code repair.

Security
Cleared: The diff changes local request waiting and test infrastructure only; it adds no permissions, dependencies, secrets handling, artifact execution, or network destination changes.

Review details

Best possible solution:

Keep the narrow WaitAsync plus finally cleanup design, preserve the established timeout message for real deadlines, and add a redacted current-head gateway/setup shutdown transcript showing cancellation rather than a timeout before merge.

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

No executed current-main reproduction was established in this read-only review, but the source path is clear: cancellation of the delay task in the current Task.WhenAny branch is classified as a timeout during disposal.

Is this the best way to solve the issue?

Yes. Using the framework timeout-and-cancellation wait while retaining the compatible deadline message is the narrowest maintainable fix; the remaining need is live gateway/setup proof, not a different implementation direction.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a bounded setup/gateway error-classification fix with limited blast radius rather than an availability or security emergency.
  • merge-risk: 🚨 compatibility: The patch intentionally changes shutdown-facing failures from TimeoutException to OperationCanceledException, which can affect callers that branch on exception type.
  • 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: The reported loopback WebSocket tests are useful behavioral coverage, but they are automated test evidence rather than after-fix proof from a real gateway/setup runtime; attach redacted live output, logs, or a recording from the current head. 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

What I checked:

  • Current-main behavior: Current main waits with Task.WhenAny(completion.Task, Task.Delay(timeoutMs, CancellationToken)); when the client-lifetime token cancels the delay, that branch is treated as a timeout rather than preserving cancellation. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:621, ee4817d2c2e7)
  • Patch mechanism: The proposed method instead awaits the completion task with both a timeout and the client cancellation token, converts only actual deadline expiration to the compatible timeout message, and removes both trackers in one terminal finally path. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:621, 1558aaaa342c)
  • Focused behavioral coverage: The branch adds five loopback WebSocket cases covering success, gateway errors, deadline timeout, disposal cancellation, and a late response after timeout, including pending-tracker cleanup assertions. (tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs:488, 1558aaaa342c)
  • Related report: The linked umbrella report identifies this exact client-lifetime-token race as a lower-severity wizard-request hazard, while also covering separate concurrency topics; it supports a partial overlap rather than a duplicate close.
  • Repository proof policy: The repository policy requires gateway-mediated changes to show the real gateway path when available and requires direct current-head real-behavior proof for PRs; the PR explicitly reports no live external gateway run. (AGENTS.md, ee4817d2c2e7)

Likely related people:

  • anagnorisis2peripeteia: The linked concurrency report traced the wizard-request cancellation race through OpenClawGatewayClient and documented the expected distinction between shutdown cancellation and a real timeout; local history access was unavailable for stronger ownership attribution. (role: related behavior investigator; confidence: low; files: src/OpenClaw.Shared/OpenClawGatewayClient.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-18T21:29:21.424Z sha e3dbbf8 :: needs real behavior proof before merge. :: none

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: ef1a489e-d0db-416e-a8da-ac6184e5f6af
@shanselman

Copy link
Copy Markdown
Collaborator Author

Addressed the paired test-quality findings in 1558aaaa:

  • Success-path cleanup is now asserted before client.Dispose() (and again after disposal).
  • The deadline test asserts the exact compatibility message: Timed out waiting for wizard.status response.
  • Added a deterministic late-response test: the timed-out response is sent before a second probe response on the same WebSocket. The successful probe proves the late frame was consumed first; the original task retains the same TimeoutException, and both pending trackers remain empty.

Current-head validation:

  • ./build.ps1 — passed (5/5 projects)
  • Shared tests — 2,906 passed, 31 skipped, 0 failed
  • Tray tests — 1,823 passed, 0 failed
  • Focused wizard request tests — 5 passed, 0 failed

@shanselman
shanselman merged commit 9b5ce4b into main Jul 18, 2026
19 checks passed
@shanselman
shanselman deleted the shanselman-fix-wizard-request-cancellation branch July 18, 2026 21:59
anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/openclaw-windows-node that referenced this pull request Jul 18, 2026
… timeouts

A chat.send or exec.approval.resolve response wait races its timeout delay
against the client-lifetime token. A cancelled delay completes Task.WhenAny
exactly like an elapsed one, so client shutdown mid-request surfaced as
'Timed out waiting for ... response from gateway' instead of a cancellation.
Classify the cancelled-token case before throwing TimeoutException at both
sites, mirroring the wizard-request fix in openclaw#1018.

Fixes the two sibling sites of openclaw#1021.
anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/openclaw-windows-node that referenced this pull request Jul 18, 2026
… timeouts

A chat.send or exec.approval.resolve response wait races its timeout delay
against the client-lifetime token. A cancelled delay completes Task.WhenAny
exactly like an elapsed one, so client shutdown mid-request surfaced as
'Timed out waiting for ... response from gateway' instead of a cancellation.
Classify the cancelled-token case before throwing TimeoutException at both
sites, mirroring the wizard-request fix in openclaw#1018.

Fixes the two sibling sites of openclaw#1021.
steipete added a commit that referenced this pull request Jul 19, 2026
…al timeouts (#1026)

* fix: report gateway shutdown as cancellation instead of chat/approval timeouts

A chat.send or exec.approval.resolve response wait races its timeout delay
against the client-lifetime token. A cancelled delay completes Task.WhenAny
exactly like an elapsed one, so client shutdown mid-request surfaced as
'Timed out waiting for ... response from gateway' instead of a cancellation.
Classify the cancelled-token case before throwing TimeoutException at both
sites, mirroring the wizard-request fix in #1018.

Fixes the two sibling sites of #1021.

* fix: report gateway shutdown as cancellation instead of chat/approval timeouts

A chat.send or exec.approval.resolve response wait races its timeout delay
against the client-lifetime token. A cancelled delay completes Task.WhenAny
exactly like an elapsed one, so client shutdown mid-request surfaced as
'Timed out waiting for ... response from gateway' instead of a cancellation.
Classify the cancelled-token case before throwing TimeoutException at both
sites, mirroring the wizard-request fix in #1018.

Fixes the two sibling sites of #1021.

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant