Skip to content

Fix WebSocket lifecycle responsiveness#443

Closed
shanselman wants to merge 1 commit into
masterfrom
shanselman/websocket-lifecycle-correctness
Closed

Fix WebSocket lifecycle responsiveness#443
shanselman wants to merge 1 commit into
masterfrom
shanselman/websocket-lifecycle-correctness

Conversation

@shanselman
Copy link
Copy Markdown
Contributor

Summary

  • Serialize outbound WebSocket sends to prevent concurrent ClientWebSocket.SendAsync collisions.
  • Thread connection cancellation from GatewayConnectionManager through GatewayClientFactory into WebSocketClientBase, with captured-socket listen loops and generation guards for stale lifecycle work.
  • Move node invoke capability execution off the WebSocket receive loop using bounded observed dispatch while preserving existing response protocols.

Felt-performance/correctness risk addressed

This prevents receive loops from being blocked by long-running node capabilities, prevents fire-and-forget request sends from colliding, and avoids stale connect/reconnect work updating gateway or node state after cancellation/disconnect.

Validation

  • ./build.ps1
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
  • Additional targeted: dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj

Serialize outbound WebSocket sends, propagate connection cancellation, and move node invoke execution off the receive loop with bounded dispatch. Add regression coverage for send serialization, dispatch responsiveness, and lifecycle cancellation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@shanselman
Copy link
Copy Markdown
Contributor Author

Closing this for now because it is old/dirty against the current connection stack and WebSocket lifecycle changes are high-risk to land as a drive-by during today's stability pass.

The responsiveness concern is valid, but this should come back as a fresh focused PR against current master with a targeted review and local connection lifecycle validation. Thanks for the work here; it helped identify the area that needs a cleaner follow-up.

@shanselman shanselman closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant