openclaw - 💡(How to fix) Fix [Bug]: tool and agent websocket events amplify during live tool output [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

During live embedded tool output, the gateway emits overlapping run-scoped agent tool events and session-scoped session.tool mirror events to websocket clients, amplifying event serialization/logging while the gateway is CPU-bound.

Root Cause

The fix should preserve session.tool for session subscribers that did not register for run-scoped tool events, because those clients need to render pending tool cards for in-flight runs discovered after start.

Fix Action

Fixed

Code Example

Command run:
pidstat -h -u -r -d -p [redacted gateway pid] 1 60

Pidstat summary from same window:
rows=60
avg_cpu=83.66
cpu_ge_100_count=42
avg_rd=0.00
write_nonzero_count=21

Gateway log count window:
Window: 2026-05-21T05:07:xxZ through 2026-05-21T05:08:xxZ.

RAW count output:
window_lines=109
total=109
ws=92
agent_event=12
command_output=2
session_tool=7
heartbeat_event=31
fetch_timeout=1
embedded_tool=5
session_message=2
sessions_changed=3

Representative redacted lines:
2026-05-21T05:07:05.820+00:00 gateway/ws event session.tool seq=targeted clients=1 targets=1 dropIfSlow=true
2026-05-21T05:07:23.431+00:00 gateway/ws event session.tool seq=targeted clients=2 targets=1 dropIfSlow=true
2026-05-21T05:07:47.187+00:00 agent/embedded embedded run tool start: runId=[redacted run id] tool=exec toolCallId=REDACTED
2026-05-21T05:08:04.299+00:00 gateway/ws event agent seq=per-client clients=1 run=[redacted run id] agent=main-pr-router session=main stream=command_output aseq=69
2026-05-21T05:08:12.700+00:00 gateway/ws event session.tool seq=targeted clients=1 targets=1 dropIfSlow=true
2026-05-21T05:08:12.709+00:00 gateway/ws event agent seq=per-client clients=1 run=[redacted run id] agent=main-pr-router session=main stream=command_output aseq=73
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

During live embedded tool output, the gateway emits overlapping run-scoped agent tool events and session-scoped session.tool mirror events to websocket clients, amplifying event serialization/logging while the gateway is CPU-bound.

Steps to reproduce

  1. Start the gateway with Control UI attached and websocket event logging enabled.
  2. Run an embedded agent/tool path that starts an exec tool.
  3. Capture gateway websocket logs during the tool run.
  4. Observe both run-scoped agent tool/command output events and session-scoped session.tool events in the same window.

Expected behavior

A websocket connection that already receives run-scoped tool events for a run should not receive a duplicate session-scoped mirror for the same live tool activity. Late-joining session subscribers should still receive session.tool events.

Actual behavior

In the profiled live window, 109 gateway log lines included 92 websocket lines, 12 agent events, 7 session.tool events, 2 command output events, and 31 heartbeat-related lines while pidstat showed the gateway averaged 83.66% CPU with 42/60 samples at or above 100% CPU.

OpenClaw version

Development checkout at 79be9401306f9e6c18937850b32629f0c3029fa4.

Operating system

Linux environment with pidstat; exact distribution/version: NOT_ENOUGH_INFO

Install method

Development gateway; exact launch method: NOT_ENOUGH_INFO

Model

NOT_ENOUGH_INFO

Provider / routing chain

NOT_ENOUGH_INFO

Additional provider/model setup details

NOT_ENOUGH_INFO

Logs, screenshots, and evidence

Command run:
pidstat -h -u -r -d -p [redacted gateway pid] 1 60

Pidstat summary from same window:
rows=60
avg_cpu=83.66
cpu_ge_100_count=42
avg_rd=0.00
write_nonzero_count=21

Gateway log count window:
Window: 2026-05-21T05:07:xxZ through 2026-05-21T05:08:xxZ.

RAW count output:
window_lines=109
total=109
ws=92
agent_event=12
command_output=2
session_tool=7
heartbeat_event=31
fetch_timeout=1
embedded_tool=5
session_message=2
sessions_changed=3

Representative redacted lines:
2026-05-21T05:07:05.820+00:00 gateway/ws event session.tool seq=targeted clients=1 targets=1 dropIfSlow=true
2026-05-21T05:07:23.431+00:00 gateway/ws event session.tool seq=targeted clients=2 targets=1 dropIfSlow=true
2026-05-21T05:07:47.187+00:00 agent/embedded embedded run tool start: runId=[redacted run id] tool=exec toolCallId=REDACTED
2026-05-21T05:08:04.299+00:00 gateway/ws event agent seq=per-client clients=1 run=[redacted run id] agent=main-pr-router session=main stream=command_output aseq=69
2026-05-21T05:08:12.700+00:00 gateway/ws event session.tool seq=targeted clients=1 targets=1 dropIfSlow=true
2026-05-21T05:08:12.709+00:00 gateway/ws event agent seq=per-client clients=1 run=[redacted run id] agent=main-pr-router session=main stream=command_output aseq=73

Impact and severity

Affected: Gateway websocket clients attached to live agent/tool runs. Severity: Medium-high; this adds duplicated websocket event construction, serialization, and logging during periods where the gateway was observed CPU-bound. Frequency: Observed in one 60-second live profile window. Consequence: Extra gateway event work competes with timers, websocket control traffic, and foreground chat latency during tool execution.

Additional information

The fix should preserve session.tool for session subscribers that did not register for run-scoped tool events, because those clients need to render pending tool cards for in-flight runs discovered after start.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

A websocket connection that already receives run-scoped tool events for a run should not receive a duplicate session-scoped mirror for the same live tool activity. Late-joining session subscribers should still receive session.tool events.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING