Skip to content

[PR] fix: parse and rewrite complete core-loop SSE payloads - #6619

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_loop-multiline-sse
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_loop-multiline-sse

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #6614

Problem

Core-loop SSE readers and rewriters disagree about the event boundary. OpenAI and Gemini parse only the first data: field. Anthropic already reads the complete event, but its index, usage and prose rewrites parse each data line independently. A legal multiline JSON payload therefore loses replies, retains stale start usage, or reuses a client content-block index across continuation rounds.

A real loopback upstream exercised through startServer reproduces all three failures on master: OpenAI emits an empty successful stop, Gemini reports a truncated stream, and Anthropic emits three content-block starts with only two distinct indices during a signed-thinking/status/continuation exchange. All equivalent single-line exchanges pass.

Change

Read all data fields as one LF-joined payload. For existing rewrites, replace the complete payload while preserving event/id/retry/comment fields and the terminal blank line. Unedited frames retain their original data lines. OpenAI and Gemini buffered real-tool replay prefix each physical payload line with data: so accepted multiline calls remain valid SSE. The Gemini JSON-array reader applies the same framing when synthesizing SSE from formatted JSON elements.

The change covers the three affected standard compression-loop adapters together. Responses remains a passing control. No compression policy, retry budget, tool argument string, or signed thinking text/signature is changed.

Validation

Base: e1f31ad9d5b47500362699a9867819b861c7de96 (0.1.213), Node v24.22.1.

  • 24 new cases: 18 failures / 6 passing controls on unchanged master; 24 pass with this change.
  • Six real HTTP proxy cases cover multiline and single-line exchanges for OpenAI, Gemini and Anthropic. On both signed wires, the tests compare thinking text and signatures on the client stream and on the actual continuation request. Tool-call signature preservation is also checked for Gemini.
  • Unit guards cover LF/CRLF/CR under one-byte UTF-8 splits, byte-identical decoded tool arguments, unedited event formatting, complete-event rejection of malformed data, usage accounting, text filtering, content-block remapping, finish suppression and terminal frame boundaries.
  • 106 targeted tests pass across the new files and existing adapter, cross-round, signed-thinking, hold/retry, reasoning and standalone-signature suites.
  • Root typecheck, production build, unused-export gate, test-import-graph gate and git diff --check: pass.

The HTTP tests use a hermetic upstream speaking supported wire formats; they do not claim live-provider coverage. The local Codex prerequisite probe found no reachable upstream at 127.0.0.1:8199, so the real-client four-phase E2E remains a hosted/integration gate. Full regression is the GitHub CI verdict on this head.

Related work and scope

All-state searches and file-diff checks distinguished #260 (plugin passthrough / Responses), #6102 (summary readers) and #6603 (CloudCode v1 envelopes). None repairs these standard core-loop readers and rewriters. The source protocol requirement is the SSE event interpretation algorithm.

Topic N, cross-client; suggested bug, p1, scope/wiring, as recorded in #6614.

@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6677 (merged as 3858b6956, 2026-11-14).

Landed into master via the real merge commit 66c99c45b9b (Merge Afloat16/2026-11-13_loop-multiline-sse (PR #6619)), so your original commits are preserved verbatim in master history — only hashes of the batch wrapper changed, your authorship and commit messages are intact.

The fix for #6614 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiline SSE data breaks core-loop replies and Anthropic continuation indices

2 participants