Repository navigation
fix(agents): keep phaseless OpenAI WS text buffered until phase resolves - #61968
Conversation
PR SummaryMedium Risk Overview Adds stronger regression coverage in Reviewed by Cursor Bugbot for commit 3b290c5. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryStraightforward, well-scoped fix that gates Confidence Score: 5/5Safe to merge — no logic errors or data-integrity issues found. Only a P2 style note on the changelog PR number reference; the implementation logic is correct, CHANGELOG.md — minor PR number attribution (P2 only) Prompt To Fix All With AIThis is a comment left during a code review.
Path: CHANGELOG.md
Line: 39
Comment:
**Changelog references prior PR instead of this one**
The entry links `#61954` (the original contributor PR) rather than `#61968` (this replacement PR). Since #61968 extends the fix beyond #61954 — adding the flush guard for `output_item.added` — linking the merged PR number keeps the changelog traceable to the actual change.
```suggestion
- Providers/OpenAI: keep WebSocket text buffered until a real assistant phase arrives, even when text deltas land before a phaseless `output_item.added` announcement. (#61968) Thanks @100yenadmin.
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "test(commands): fix session-store import..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2a889dd10
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -1059,7 +1061,7 @@ export function createOpenAIWebSocketStreamFn( | |||
| const key = getOutputTextKey(event.item_id, event.content_index); | |||
| const nextText = `${outputTextByPart.get(key) ?? ""}${event.delta}`; | |||
| outputTextByPart.set(key, nextText); | |||
| if (outputItemPhaseById.has(event.item_id)) { | |||
| if (outputItemPhaseById.get(event.item_id) !== undefined) { | |||
There was a problem hiding this comment.
Emit buffered text when phase metadata never arrives
Gating response.output_text.delta emission on outputItemPhaseById.get(event.item_id) !== undefined means message text is never streamed for items that stay unphased for the entire turn. OutputItem.phase is optional in the WS schema, so when a provider/model omits phase on both response.output_item.added and response.output_item.done, this path now buffers forever and emits no text_delta events until completion, regressing incremental output for those sessions.
Useful? React with 👍 / 👎.
| @@ -37,6 +37,7 @@ Docs: https://docs.openclaw.ai | |||
| - iOS/Watch exec approvals: keep Apple Watch review and approval recovery working while the iPhone is locked or backgrounded, including background-safe reconnects, persisted pending approvals, notification cleanup, and APNs-backed watch refresh recovery. (#61757) Thanks @ngutman. | |||
| - Gateway/status: probe local TLS gateways over `wss://`, forward the local cert fingerprint for self-signed loopback probes, and warn when the local TLS runtime cannot load the configured cert. (#61935) Thanks @ThanhNguyxn07. | |||
| - Agents/history: keep truly legacy unsigned replay text unphased when mixed with phased OpenAI WS assistant blocks, while still inheriting message phase for id-only replay signatures. (#61529) Thanks @100yenadmin. | |||
There was a problem hiding this comment.
Changelog references prior PR instead of this one
The entry links #61954 (the original contributor PR) rather than #61968 (this replacement PR). Since #61968 extends the fix beyond #61954 — adding the flush guard for output_item.added — linking the merged PR number keeps the changelog traceable to the actual change.
| - Agents/history: keep truly legacy unsigned replay text unphased when mixed with phased OpenAI WS assistant blocks, while still inheriting message phase for id-only replay signatures. (#61529) Thanks @100yenadmin. | |
| - Providers/OpenAI: keep WebSocket text buffered until a real assistant phase arrives, even when text deltas land before a phaseless `output_item.added` announcement. (#61968) Thanks @100yenadmin. |
Prompt To Fix With AI
This is a comment left during a code review.
Path: CHANGELOG.md
Line: 39
Comment:
**Changelog references prior PR instead of this one**
The entry links `#61954` (the original contributor PR) rather than `#61968` (this replacement PR). Since #61968 extends the fix beyond #61954 — adding the flush guard for `output_item.added` — linking the merged PR number keeps the changelog traceable to the actual change.
```suggestion
- Providers/OpenAI: keep WebSocket text buffered until a real assistant phase arrives, even when text deltas land before a phaseless `output_item.added` announcement. (#61968) Thanks @100yenadmin.
```
How can I resolve this? If you propose a fix, please make it concise.…p key existence When output_item.added arrives without phase metadata, outputItemPhaseById stores undefined. The previous .has() check returned true for undefined values, bypassing the buffering gate and leaking commentary as unphased visible content. Fix: change .has() to .get() !== undefined on both delta and done handlers. Fixes #61477
605bd37 to
3b290c5
Compare
|
Landed via replacement PR.
Thanks @100yenadmin! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b290c588c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (outputItemPhaseById.get(event.item_id) !== undefined) { | ||
| emitBufferedTextDelta({ | ||
| itemId: event.item_id, | ||
| contentIndex: event.content_index, |
There was a problem hiding this comment.
Restore streaming for permanently phaseless WS items
OutputItem.phase is optional, but this gate only emits when outputItemPhaseById.get(event.item_id) !== undefined. If an item stays phaseless for the whole turn (both response.output_item.added and response.output_item.done omit phase), buffered text is never flushed and users get no text_delta events before completion. Fresh evidence in this commit is that the new tests only exercise paths where a phase eventually appears, so the optional-phase-forever path remains unprotected and regresses incremental output.
Useful? React with 👍 / 👎.
…ves (openclaw#61968) * fix(agents): gate WS text delta emission on valid phase value, not map key existence When output_item.added arrives without phase metadata, outputItemPhaseById stores undefined. The previous .has() check returned true for undefined values, bypassing the buffering gate and leaking commentary as unphased visible content. Fix: change .has() to .get() !== undefined on both delta and done handlers. Fixes openclaw#61477 * docs: note WS phase buffering fix (openclaw#61954) (thanks @100yenadmin) * test(agents): cover phaseless WS output_text.done buffering (openclaw#61954) * test(commands): fix session-store import path for tsgo (openclaw#61968) --------- Co-authored-by: Eva <[email protected]>
…ves (openclaw#61968) * fix(agents): gate WS text delta emission on valid phase value, not map key existence When output_item.added arrives without phase metadata, outputItemPhaseById stores undefined. The previous .has() check returned true for undefined values, bypassing the buffering gate and leaking commentary as unphased visible content. Fix: change .has() to .get() !== undefined on both delta and done handlers. Fixes openclaw#61477 * docs: note WS phase buffering fix (openclaw#61954) (thanks @100yenadmin) * test(agents): cover phaseless WS output_text.done buffering (openclaw#61954) * test(commands): fix session-store import path for tsgo (openclaw#61968) --------- Co-authored-by: Eva <[email protected]>
…ves (openclaw#61968) * fix(agents): gate WS text delta emission on valid phase value, not map key existence When output_item.added arrives without phase metadata, outputItemPhaseById stores undefined. The previous .has() check returned true for undefined values, bypassing the buffering gate and leaking commentary as unphased visible content. Fix: change .has() to .get() !== undefined on both delta and done handlers. Fixes openclaw#61477 * docs: note WS phase buffering fix (openclaw#61954) (thanks @100yenadmin) * test(agents): cover phaseless WS output_text.done buffering (openclaw#61954) * test(commands): fix session-store import path for tsgo (openclaw#61968) --------- Co-authored-by: Eva <[email protected]>
…ves (openclaw#61968) * fix(agents): gate WS text delta emission on valid phase value, not map key existence When output_item.added arrives without phase metadata, outputItemPhaseById stores undefined. The previous .has() check returned true for undefined values, bypassing the buffering gate and leaking commentary as unphased visible content. Fix: change .has() to .get() !== undefined on both delta and done handlers. Fixes openclaw#61477 * docs: note WS phase buffering fix (openclaw#61954) (thanks @100yenadmin) * test(agents): cover phaseless WS output_text.done buffering (openclaw#61954) * test(commands): fix session-store import path for tsgo (openclaw#61968) --------- Co-authored-by: Eva <[email protected]>
…ves (openclaw#61968) * fix(agents): gate WS text delta emission on valid phase value, not map key existence When output_item.added arrives without phase metadata, outputItemPhaseById stores undefined. The previous .has() check returned true for undefined values, bypassing the buffering gate and leaking commentary as unphased visible content. Fix: change .has() to .get() !== undefined on both delta and done handlers. Fixes openclaw#61477 * docs: note WS phase buffering fix (openclaw#61954) (thanks @100yenadmin) * test(agents): cover phaseless WS output_text.done buffering (openclaw#61954) * test(commands): fix session-store import path for tsgo (openclaw#61968) --------- Co-authored-by: Eva <[email protected]>
Fixes #61477.
Replacement for #61954 because the contributor fork would not accept maintainer pushes from this account.
This keeps the original narrow fix and adds the missing flush guard plus stronger regression coverage:
response.output_text.deltaandresponse.output_text.doneon a resolved phase valueoutput_item.added/output_item.donewhile phase is still undefinedoutput_text.delta -> phaseless output_item.added -> output_item.donephaseless output_item.added -> output_text.delta -> output_item.donephaseless output_item.added -> output_text.done -> output_item.doneVerification
pnpm test src/agents/openai-ws-stream.test.ts -t "keeps buffering text deltas until item phase is defined"pnpm test src/agents/openai-ws-stream.test.ts -t "buffers text when output_item.added arrives without phase metadata"pnpm test src/agents/openai-ws-stream.test.ts -t "buffers output_text.done until item phase is defined"pnpm test src/agents/openai-ws-stream.test.tsRepo-wide gate note
Current rebased
mainis already red on unrelated untouched files:pnpm checkfails inextensions/discord/src/monitor/message-utils.tsandextensions/xai/*pnpm buildfails inextensions/acpx/src/runtime.ts