openclaw - ✅(Solved) Fix bug(agents): output_item.added/done handler flushes buffered text without valid phase — commentary leaks on OpenAI Responses stream [1 pull requests, 1 comments, 2 participants]

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…
GitHub stats
openclaw/openclaw#61814Fetched 2026-04-08 02:54:12
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
cross-referenced ×3closed ×1commented ×1

When the OpenAI Responses adapter receives output_item.added or output_item.done events, the handler flushes any buffered text content without checking whether the current phase is user-visible. This means commentary/work-note text accumulated during tool-calling phases gets emitted to user-facing channels.

Root Cause

The flush path in the output_item event handlers does not consult currentPhase before forwarding buffered text blocks. The phase-gate check only exists on the response.text.delta / response.text.done paths but not on the item-level flush.

Fix Action

Fixed

PR fix notes

PR #61528: fix(agents): OpenAI WS stream — gate buffered text delta on valid phase value, not just outputItemPhaseById key existence

Description (problem / solution / changelog)

What this fixes (plain English)

The WebSocket streaming code was supposed to hold back text until it knew the phase (commentary vs. visible), but a subtle bug meant it released text as soon as the item was registered — even if the phase was still unknown. This caused internal commentary to leak into user-visible output.

Technical details

Root cause: outputItemPhaseById.has(event.item_id) returns true even when the stored value is undefined (set by an output_item.added event before phase metadata arrives). This defeats the buffering protection entirely.

Fix: Changed both emission gates (.delta and .done handlers) from .has(id) to .get(id) !== undefined so text stays buffered until a valid phase value arrives.

Files changed:

  • src/agents/openai-ws-stream.ts — 2-line gate fix (.has() -> .get() !== undefined)

Related

  • Fixes #61477
  • Parent fix: #59643
  • Companion PRs: #61529, #61463, #61478

Test plan

  • 92/92 existing tests pass
  • 2-line change, minimal blast radius
  • No scope creep — single file, single fix

Changed files

  • src/agents/openai-ws-stream.ts (modified, +2/-2)
RAW_BUFFERClick to expand / collapse

Description

When the OpenAI Responses adapter receives output_item.added or output_item.done events, the handler flushes any buffered text content without checking whether the current phase is user-visible. This means commentary/work-note text accumulated during tool-calling phases gets emitted to user-facing channels.

Root cause

The flush path in the output_item event handlers does not consult currentPhase before forwarding buffered text blocks. The phase-gate check only exists on the response.text.delta / response.text.done paths but not on the item-level flush.

Impact

  • Internal commentary text leaks to end users on messaging channels (Telegram, Feishu, etc.)
  • Affects OpenAI Responses API stream adapter specifically
  • Intermittent — only triggers when text is buffered before an output_item boundary

Related

  • PR #61528 (fix in progress)
  • #61734, #25592, #59536 (broader commentary leak family)

Reproduction

  1. Configure an agent with openai-responses provider and a messaging channel
  2. Trigger a multi-tool-call response where the model emits text between tool calls
  3. Observe that buffered text flushes to the channel on output_item.added

extent analysis

TL;DR

Check the currentPhase before flushing buffered text content in the OpenAI Responses adapter to prevent commentary text from leaking to user-facing channels.

Guidance

  • Verify that the issue is indeed caused by the missing phase check in the output_item event handlers by reproducing the problem using the steps provided.
  • Consider adding a phase-gate check in the flush path of the output_item event handlers to prevent buffered text from being emitted during non-user-visible phases.
  • Review the related PR #61528 for a potential fix and consider applying it if available.
  • Test the adapter with different scenarios to ensure the fix does not introduce any regressions.

Example

No explicit code example is provided due to the lack of specific code details in the issue.

Notes

The provided guidance assumes that the issue is specific to the OpenAI Responses adapter and may not apply to other adapters or components.

Recommendation

Apply the workaround by adding a phase-gate check in the flush path of the output_item event handlers, as this is a targeted fix for the identified root cause.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING