Repository navigation
fix(ai): unify Responses stream processing - #114263
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 12:22 AM ET / 04:22 UTC. ClawSweeper reviewWhat this changesThe branch replaces separate private OpenAI Responses stream processors with one transport-owned indexed processor, updating OpenAI, Azure, and ChatGPT/Codex callers plus regression coverage for terminal, reasoning, text, and tool-call state. Merge readinessThis PR remains necessary: it is the implementation follow-up to the merged parity-fixture baseline and consolidates private Responses stream handling across OpenAI, Azure, and ChatGPT/Codex callers. The supplied diff and prior review cycles show no discrete patch defect, and the contributor has now posted real OpenAI provider-stream evidence; keep it open for the protected maintainer review path and refresh the current-base proof before merge. Priority: P2 Review scores
Verification
How this fits togetherResponses-based providers emit streamed OpenAI-compatible events into OpenClaw’s AI transport layer. The transport validates and observes those events, converts them into assistant content and tool-call events, and returns finalized replayable output to the agent runtime. flowchart LR
A[OpenAI Azure and ChatGPT streams] --> B[Responses transport callers]
B --> C[Stream observer and validation]
C --> D[Canonical Responses processor]
D --> E[Indexed text reasoning and tool slots]
E --> F[Terminal usage and failure handling]
F --> G[Assistant events and replayable result]
G --> H[Agent runtime]
Decision needed
Why: The patch intentionally changes common runtime behavior for three provider surfaces, while available real-provider proof directly covers OpenAI and the other two surfaces are covered through shared tests and caller-specific suites. Before merge
Agent review detailsSecurityNone. PR surfaceSource -387, Tests -63, Other -1. Total -451 across 14 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase or otherwise validate the clean merge result against current Do we have a high-confidence way to reproduce the issue? Yes, at source level: the branch supplies focused fixtures for interleaving, missing terminal events, encrypted reasoning recovery, and tool scratch cleanup, and the contributor reports a real OpenAI Responses live run. I did not independently execute that provider path in this read-only review. Is this the best way to solve the issue? Yes, with a final current-base validation: centralizing the two private processors avoids preserving divergent state machines while keeping transport-specific timing, service-tier, and alias adaptation at their callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b699a93c8710. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
dab46ef to
c93725c
Compare
c93725c to
b8386fc
Compare
|
Live provider-stream gate passed on the rebased exact head In response to the ClawSweeper gate comment: #114263 (comment)
No dedicated |
|
Maintainer decision for the latest ClawSweeper review: accept the scoped provider proof set for landing.
This addresses both Rank-up moves in #114263 (comment). No ClawSweeper code finding remains. |
|
Merged via squash.
|
* refactor(ai): unify Responses stream processing * fix(ai): preserve unindexed output boundaries * refactor(ai): remove obsolete Responses helpers * refactor(ai): trim canonical stream surface
Related: #114230
What Problem This Solves
OpenClaw had two private OpenAI Responses stream processors with different state models and observable correctness gaps. Interleaved output items could be misrouted, raw reasoning deltas could disappear, unterminated streams could report success, terminal encrypted reasoning and compatible-provider output could be lost, and finalized tool calls could retain streaming-only scratch state.
Why This Change Was Made
This replaces both legacy processors with one indexed canonical processor owned by the private Responses transport module. The OpenAI, Azure, ChatGPT SSE, and ChatGPT WebSocket callers now converge on that implementation;
mapCodexEventsremains the only Codex alias/error adapter. Transport timing/debug/cooperative scheduling stays in an iterator wrapper, while terminal recovery, usage, signatures, slot routing, and failure validation settle once in the canonical machine.The provider-side processor and its forwarding surface are deleted. The private structural event union is not exported from any public
@openclaw/aientrypoint.text_delta.partialis omitted globally, matching the llm-core optional-field memory contract.AI-assisted: implemented and reviewed with Codex under maintainer direction.
User Impact
Responses-based OpenAI, Azure, and ChatGPT/Codex streams now preserve interleaved reasoning/text/tool output, fail closed on malformed or unterminated streams, recover compatible terminal-only output safely, and persist replayable reasoning/tool results without streaming scratch fields.
Evidence
node scripts/run-vitest.mjs packages/ai/src/transports/openai-responses-stream-parity.test.ts packages/ai/src/providers/openai-responses-shared.test.ts packages/ai/src/providers/openai-responses.test.ts packages/ai/src/providers/azure-openai-responses.test.ts packages/ai/src/providers/openai-chatgpt-responses.test.ts packages/ai/src/providers/openai-chatgpt-responses.retry.test.ts packages/ai/src/providers/openai-responses-terminal-usage.test.ts— 152 passed on the rebased headnode scripts/run-vitest.mjs src/agents/openai-transport-stream.base.test.ts src/agents/openai-transport-stream.streaming.test.ts src/agents/openai-transport-stream.incomplete-output.test.ts src/agents/openai-transport-stream.replay-and-tools.test.ts— 139 passed on the rebased head/Users/steipete/.claude/skills/autoreview/scripts/autoreview --mode branch --base origin/main— clean, no accepted/actionable findingsgit diff --check— pass after the final splitc93725c5ab8b81869aa353a11927e7462e8ab8bf— success, including build artifacts, prod/test types, lint, dead-code dependencies/exports, package boundaries, all selected Node shards, andopenclaw/ci-gate; the unrelated TUI PTY flake passed on its targeted rerunClawSweeper reports no code findings and asks the landing orchestrator to add or explicitly waive live OpenAI/Azure/ChatGPT provider-stream proof before merge. This worker stopped at the batch-authorized exact-head CI boundary and did not start credentialed live-provider traffic.
Divergence Fix Checklist
indexed interleaved reasoning itemsraw reasoning delta with empty summarystream close without terminal responseterminal encrypted reasoning backfillnull completed message content preserves streamed textfinalized tool call drops streaming scratchreused indexed output slot fails closedAdditional canonical fixtures cover terminal-only compatible output, deltas without content-part events, terminal failures, nullable terminal recovery, and deferred text materialization across an unindexed tool boundary.