Skip to content

Long streaming model responses cause event loop starvation #89392

Description

@xiaoyaolanyun

Summary

When a model provider with large max output (e.g., DeepSeek v4 Pro, 384K tokens) returns very long streaming responses, the single-threaded Node.js event loop in the gateway gets starved. Stream chunk processing occupies the event loop without yielding, causing cascading delays across all gateway operations.

Diagnostic Evidence

From a session using deepseek-v4-pro on openclaw v2026.5.28 / Windows 10:

Event loop starvation

[diagnostic] liveness warning: eventLoopDelayP99Ms=2447.4 eventLoopDelayMaxMs=6480.2 eventLoopUtilization=0.987

Normal delay < 50ms; here reached 6.5s at 98.7% utilization.

Fetch timeout delayed by stream processing

[fetch-timeout] fetch timeout after 120000ms (elapsed 207325ms) timer delayed 87325ms

The 120s fetch timeout only fired after 207s — an 87-second delay because the timer callback was stuck behind stream chunk processing.

WebSocket response blocked

[ws] ⇄ res ✓ chat.history 215001ms

Returning chat history took 215 seconds.

Sidecar operations stalled

sidecars.session-locks:12577ms
sidecars.acp.runtime-ready:13793ms
sidecars.acp.identity-reconcile:7168ms

Impact

During these episodes the gateway is effectively unresponsive: timers misfire, WebSocket messages queue up, heartbeat/diagnostic events stall, and chat history responses are delayed by minutes.

Suggested Fix

Offload stream chunk processing to a worker thread, or insert periodic setImmediate / process.nextTick yields during long streaming responses to give the event loop breathing room.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions