Skip to content

[deep-review] A10: WindowsNodeClient single-threaded receive loop has no back-pressure (head-of-line blocking) #363

Closed

Description

@codemonkeychris

Summary

WebSocketClientBase.ListenForMessagesAsync calls await ProcessMessageAsync(...) sequentially. For WindowsNodeClient, ProcessMessageAsync calls await capability.ExecuteAsync(request). A slow capability (e.g. screen.record for 5 minutes, system.run of a long-running shell command, stt.transcribe running Whisper on a long clip) blocks every other inbound message on the same WS connection — including health pings, pair events, other invokes.

The slice docs flag this explicitly (docs/architecture/01-shared-protocol.md seams: "Single receive thread … is there back-pressure?"). The answer in the code is "no."

Where

  • src/OpenClaw.Shared/WebSocketClientBase.cs:24 (BackoffMs constants, single receive loop)
  • src/OpenClaw.Shared/WindowsNodeClient.cs:238 (the dispatch site that awaits capability execution)
  • The contrast: McpHttpServer uses a SemaphoreSlim of 16 concurrent handlers — explicit back-pressure with 503 fallback.

Why it matters

Practical consequences:

  1. A slow system.run blocks health pings. The gateway may decide the node is dead and tear down the session.
  2. A long screen.record blocks every other invoke for the duration. A user trying to cancel the recording via canvas.hide or pair-list updates can't get through.
  3. A pair event arriving during a long stt.transcribe is queued indefinitely. Auto-pair flows can stall.

The MCP server got this right (16-deep semaphore). The gateway transport didn't.

Proposed fix

Two-level fix:

  1. Per-capability dispatch isolation: when WindowsNodeClient.ProcessMessageAsync dispatches a node.invoke, don't await it inline on the receive loop. Instead:

    • Launch the capability via Task.Run (or Channel<T> + worker pool).
    • Receive loop returns immediately to read the next frame.
    • Capability completion sends the response when ready.
    • Concurrency cap (suggest 8 — small because some capabilities are heavy).
    • On overflow, reply Error("node busy, retry") rather than queueing unbounded.
  2. Health/ping fast path: route event: connect.challenge, event: health, event: node.pair.*, event: device.pair.* directly on the receive thread without queueing — they're cheap and need low latency.

Add a stress test: dispatch a 10-second-blocking capability, then immediately a health request; assert the health request returns in < 1 second.

Severity

Medium — observable as "gateway thinks node is dead during long captures." Becomes High under multi-tenant load.

Activity

  1. added
    bug
    on May 14, 2026
  2. github-actions commented on May 14, 2026

    @github-actions
  3. github-actions commented on May 17, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    Created a fix PR for this issue: repo-assist/fix-hol-blocking-363 (currently being pushed — PR number to follow). The implementation uses the fire-and-forget approach described in my earlier comment, with a SemaphoreSlim(8) cap.

    Key design decisions in the PR:

    • Both dispatch paths fixed: HandleNodeInvokeAsync (type:req) and HandleNodeInvokeEventAsync (type:event) — both now fire-and-forget.
    • Args cloned before fire-and-forget to prevent use-after-dispose of the parent JsonDocument.
    • Fast path untouched: health, connect.challenge, node.pair.*, device.pair.* are still handled inline.
    • Shutdown-safe: the background Task.Run receives the CancellationToken from WebSocketClientBase and swallows OperationCanceledException on shutdown.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a
    
  4. shanselman commented on May 18, 2026

    @shanselman
    Collaborator

    Closing this one-off deep-review issue as consolidated, not necessarily fixed. The useful signal is preserved in #426 / #372: receive-loop HOL blocking is preserved as the top implementation candidate; #426 is the active draft fix. We will take these one at a time from #372 after verifying against current master instead of keeping the issue list flooded.

  5. locked as resolved and limited conversation to collaborators on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugperformance

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions