Repository navigation
fix: avoid disconnect warnings during active WebSocket sends - #1023
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 92e601e0-3207-42f8-878a-5fc7efae1479
|
Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 6:15 PM ET / 22:15 UTC. Summary Reproducibility: yes. from source and deterministic coverage: a Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest possible solution: Merge the focused shared-lock fix after ordinary maintainer review and the remaining required checks complete, retaining the two regression tests as the contract for close/send ordering and shutdown cancellation. Do we have a high-confidence way to reproduce the issue? Yes, from source and deterministic coverage: a Is this the best way to solve the issue? Yes. Reusing the existing send semaphore is the narrowest maintainable fix because it preserves the established send serialization contract without adding protocol, configuration, or public API surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9b5ce4bcc4f6. Label changesLabel 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: Copilot App <[email protected]> Copilot-Session: 92e601e0-3207-42f8-878a-5fc7efae1479
Related: #1010
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 users disconnecting a gateway, or a node refreshing its connection after pairing approval, could see a spurious shutdown warning when graceful WebSocket close raced an active send or when disposal canceled a close queued behind that send.
Why This Change Was Made
Graceful close now uses the existing send semaphore, captures the intended socket before waiting, and rechecks that socket's state after entering the critical section. Acquisition mirrors
SendRawAsync: lifetime cancellation or disposal returns quietly before lock ownership, while the releasefinallyis reachable only after a successful acquire.The actual
CloseAsyncretainsCancellationToken.Noneto preserve the existing graceful handshake during normal disconnect. Concurrent disposal still bounds an in-progress close by disposing the captured socket; any resulting mid-close failure remains on the pre-existing caller-contained path rather than broadening this PR into close-operation error policy.User Impact
Gateway disconnect and pairing-refresh shutdown can now finish without
ClientWebSocketrejecting a close that overlaps an active send, and routine disposal no longer turns a queued close-lock wait into a warning/error. No protocol, configuration, or public API changes.Evidence
SendRawAsync, starts graceful close, and proves the close cannot overtake the send. The server must observe a text frame before the close frame.IsCompletedSuccessfully.CloseWebSocketAsync_DisposeCompletesQueuedCloseWithoutExceptionfails withOperationCanceledExceptionfromSemaphoreSlim.WaitAsync; with the guard, both focused tests pass.CODEX_HOME; this is recorded as a tooling blocker rather than a clean autoreview claim.Change Type
Scope
winnodeValidation
.\build.ps1— passed; 5/5 projects built.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --filter "FullyQualifiedName~WebSocketCloseSerializationTests" --no-restore --logger "console;verbosity=minimal"— passed 2, failed 0, skipped 0.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --logger "console;verbosity=minimal"— passed 2,903, failed 0, skipped 31.dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --logger "console;verbosity=minimal"— passed 1,823, failed 0, skipped 0.git diff --check— passed.Real Behavior Proof
HttpListener/WebSockettransport.5059a920abf34bfaa7c29b944d69606f391f3b38.WebSocketCloseSerializationTestscommand listed above.Yes/No/N/A): N/A.CODEX_HOME; no UI, MCP, or gateway runtime proof is applicable to this transport-level race.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