Repository navigation
fix: report gateway shutdown as a cancellation instead of chat/approval timeouts - #1026
Conversation
… 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.
… 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.
|
Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 10:45 PM ET / July 19, 2026, 02:45 UTC. Summary Reproducibility: yes. the PR provides a concrete loopback WebSocket path that parks each real client request, cancels the lifetime token, and distinguishes an immediate cancellation from the five- or fifteen-second genuine timeout budget. Review metrics: 2 noteworthy metrics.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge the narrow shared outcome-classification path once required CI completes and repository-required build coverage is confirmed, preserving TimeoutException only for genuine elapsed gateway deadlines. Do we have a high-confidence way to reproduce the issue? Yes: the PR provides a concrete loopback WebSocket path that parks each real client request, cancels the lifetime token, and distinguishes an immediate cancellation from the five- or fifteen-second genuine timeout budget. Is this the best way to solve the issue? Yes: factoring the already-established gateway response-wait classification into one helper is narrower and less drift-prone than retaining two separate Task.WhenAny implementations, while the tests preserve genuine-timeout behavior as the key invariant. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 93174b274dff. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (1 earlier review cycle)
|
Co-authored-by: Cameron Beeley <[email protected]>
Closes #1021
Related: #1010, #1018
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where shutting down or disposing the gateway client while a chat message send or an exec-approval resolve was still awaiting its response logged a gateway timeout that never happened — "Timed out waiting for chat.send response from gateway" / "Timed out waiting for exec.approval.resolve response from gateway" — instead of a cancellation. #1018 fixed this misclassification for wizard requests; these are the two remaining sites named in #1021.
Why This Change Was Made
Both sites race the pending response against
Task.Delay(timeoutMs, CancellationToken)on the client-lifetime token, and a cancelled delay completesTask.WhenAnyexactly like an elapsed one. The fix classifies the cancelled-token case (CancellationToken.ThrowIfCancellationRequested()) immediately before eachTimeoutExceptionthrow, the same disambiguation idiom as #1011/#1018. The exec-approval site's TryRemove-first and same-tickIsCompletedmachinery is deliberately left untouched rather than restructured to #1018'sWaitAsyncshape — smallest reviewable diff, identical classification outcome; pending-map cleanup is unchanged on both exits.User Impact
Disconnect or shutdown during an in-flight chat send or approval resolve now surfaces as a cancellation, so diagnostics no longer report a phantom gateway timeout and callers that branch on
TimeoutExceptionare not misled. Genuine timeouts behave exactly as before (the added check is a no-op on an uncancelled token). Callers already catch broadly per theClearPendingRequestscaller contract, so the approval-banner retry path is preserved.Evidence
GatewayRequestShutdownClassificationTests): each classification test starts a real request against a loopback WebSocket gateway that never responds, waits until the server observes the request frame on the wire (so all connectivity guards have passed and the request is parked on its response wait), then cancels the lifetime token. Base: both fail withTimeoutExceptionin under 100 ms — impossible for a real timeout (budgets are 5 s / 15 s), proving the misclassification. Head: both surfaceOperationCanceledExceptionimmediately. Test identities use the repository's disposableOpenClaw.TestSupport.TempDirectoryfixture.client.Dispose()shutdown path during the parked wait and proves it surfaces a cancellation, never a fabricated timeout. It is green on base and head by design:Disposefaults pending completions viaClearPendingRequestsbefore cancelling the lifetime token, which is exactly why a realDisposecannot deterministically reproduce the racy register-after-clear window — the reflection-modeled pair above pins that window, theDisposetest guards the real entry point.dotnet-concconcurrency gate over the diff: verdict clean, with lane liveness proven (planted sync-over-async and deadlock fixtures caught).Change Type
Scope
winnodeValidation
Windows box at dff33f7 (
dotnet restore+ builds ofOpenClaw.Shared,OpenClaw.Shared.Tests,OpenClaw.Tray.Tests -r win-x64all succeeded first):dotnet test tests/OpenClaw.Shared.Tests --no-build -c Debug(withOPENCLAW_RUN_INTEGRATION=1) — passed 2,971, failed 0, skipped 0, total 2,971.dotnet test tests/OpenClaw.Tray.Tests --no-build -c Debug -r win-x64— passed 1,823, failed 0, skipped 0, total 1,823.dotnet test tests/OpenClaw.Shared.Tests --filter "FullyQualifiedName~GatewayRequestShutdownClassificationTests"— passed 3, failed 0 (and repeated stability reruns).Real Behavior Proof
Interleaving-class defect: the misclassification (a cancelled delay indistinguishable from an elapsed one inside
Task.WhenAny) has no deterministically observable live surface, so the deterministic demonstration is the real-behavior proof — with the real shutdown entry point additionally exercised by theDisposetest above.Before (base 9b5ce4b — shutdown misreported as gateway timeout, in milliseconds; the real-Dispose invariant passes as expected):
After (head dff33f7 — shutdown classified as cancellation, same scenario, all three tests):
A recorded proof manifest (base/head revisions, identical before/after commands, SHA-256-hashed console artifacts) backs this in the local gate ledger.
Review history
https://gist.github.com/anagnorisis2peripeteia/54cb9e32326a9e3bcc8239c3e63fb4a9