Skip to content

[PR] fix: preserve literal buffered SSE field semantics - #6654

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-14_buffered-sse-field-semantics
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-14_buffered-sse-field-semantics

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #6652.

Problem

The buffered summary parser treats whitespace-only lines as blank event boundaries. A legal unknown field containing one space or tab therefore splits a multiline JSON event, and preflight/external summaries can fail even though the upstream response is valid. Colon-free fields are also dropped, and event names are over-trimmed.

Change

Parse a field at its first colon, remove only one optional leading space from its value, and recognize colon-free fields with empty values. Only an actually empty line dispatches an event. This follows the SSE interpretation rules. Caller-owned terminal and residual validation remain unchanged.

Validation

  • Seven new regression cases fail against upstream e5e1647ba0f92dfc36a96220f3e5c0d454218e2f; 34 controls pass.
  • After rebasing onto current master 1ff89e878522f3e4d4147067973e2dc26e648923, all 211 targeted tests pass: the original 130 SSE cases plus 81 broader summary-path cases, including preflight compression, stream summaries, empty/incomplete summaries, Google/Responses summary handling, external summaries, and terminal detection.
  • The regressions verify real summary extraction on Responses, Anthropic, OpenAI and Google, plus colon-free values, event whitespace and genuine blank-line boundaries.
  • npm run typecheck, npm run build, and git diff --check pass. Full-suite status remains the upstream CI result.

Both compression modes share this summary parser. No outgoing message shape, kernel, configuration, or persisted format changes.

Base after rebase: 1ff89e878522f3e4d4147067973e2dc26e648923. Current head: dadbcd35475b451cd2d8207c1f1cee23cecfbded. Published tree 87ff0c9ebe626bb7b0ccb92c2df9e387e0a029ac matches the tested tree. The rebase changes the base only; the three-file patch is unchanged. The local targeted tests, full typecheck and build above were rerun on this rebased tree.

Hosted CI follow-up

The branch has been rebased onto the current master after the maintainer review. CI run 43571794127 for the new head dadbcd35475b451cd2d8207c1f1cee23cecfbded has been queued; no full-suite green result is claimed for it.

For the previous head 4ed6fed50668c58b11679ac7531efa5f0e70c1f9, the maintainer reran CI run 43564467766 (attempt 2). It finished with 25 successful jobs, two failed Windows test jobs and one skipped job. All Linux test shards and both Windows/Ubuntu static gates passed. That historical run remains red and is not a verdict on the rebased head.

The two previous-head failures were:

  • Windows 22 shard 3: three persist-metadata-fold-gate cases fail while removing open index.db files (EBUSY); the automatic retry repeats them.
  • Windows 22 shard 5: ten persist-zstd cases fail on the same open-file cleanup; the automatic retry repeats them.

The exact suites and teardown cause are already covered by upstream issue #6547 and open fix PR #6561. This PR does not duplicate that work. No failure in those previous-head logs belongs to this PR's new regression cases.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 Searched open PRs/issues for this parser: #6654 is the only one fixing the bufferedSseEvents whitespace-boundary bug. The other open SSE PRs target different mechanisms — #6603 (CloudCode payloads), #6619 (core-loop payloads), #6579 (native-compaction perf), #4979 (emergency-shrink) — none touch src/sse-util.ts. Source issue #6652 is the only matching issue.

Independent verification (checked out head 4ed6fed, installed deps, built the in-repo kernel):

  • The 5 targeted SSE suites (buffered-sse-fields, preflight-sse-extraction, external-summary-http, terminal-sse-framing, issue2323-sse-crlf-cross-chunk) → 130/130 pass.
  • A broader batch of 81 summary-path tests (preflight-stream-summary, preflight-empty-summary, preflight-incomplete-json, preflight-google-summary, preflight-responses-reasoning-extract, preflight-compress[-responses], external-summary, stream-terminal) → 81/81 pass.
  • Reverted src/sse-util.ts to base and re-ran the new tests → 3/4 in buffered-sse-fields + 4/4 protocol cases in preflight-sse-extraction FAIL on base, pass on the fix. They are real regression tests, not tautologies.
  • The exact issue repro (openai, whitespace-only line inside a multiline JSON, LF and CRLF) → returns "summary".
  • npm run typecheck + kernel build pass; git diff --check clean.

Key correctness finding: the fix aligns the summary parser with the SSE spec and with the streaming adapters (loop/adapter-*.ts), which already split on indexOf("\n\n") (empty-line-only) and skip whitespace-only events (raw.trim().length > 0). The old bufferedSseEvents was the inconsistent one — a producer using whitespace-only boundaries would already break the streaming relay, so the regression surface is minimal.

Behavior changes (old → new), all spec-aligned:

  1. Event boundary: line.trim() === "" (any whitespace-only line dispatches) → line === "" (only a truly empty line dispatches). WHY: SSE spec — only an empty line is a boundary; a whitespace-only line is an unknown field.
  2. Event name: line.slice(6).trim() (trim all whitespace) → strip only one optional leading space. WHY: the SSE spec strips exactly one leading space.
  3. Colon-free fields: previously ignored → now contribute an empty value (data → empty data line; event → reset name to ""). WHY: SSE spec — a colon-free line has field = the line, value = "".

Action items before merge (I will not merge — human-only):

  1. Rebase onto current master. The PR is behind (master tip is now 1ff89e8, 2 commits ahead: the updater fix [PR] In-place auto-update 100% failure fix: Backup must not exist prior to atomic swap (Gate Lane X repro) | 就地自动更新 100% 失败修复:备份不能先于原子交换存在(门禁 Lane X 复现) #6643). Neither commit touches sse-util.ts/preflight.ts/external-summary-http.ts/the two test files, so the rebase is conflict-free with no semantic interaction.
  2. Re-trigger CI. Every check-run on head 4ed6fed is cancelled — there is no green verdict yet. After the rebase, the full-suite CI on the new head is the authoritative gate.

Per §7.4 this is auto-merge-eligible (single-module fix:, real regression test, no wire/config/persistence/kernel/message-id changes, clean diff, references #6652).


结构化八问:

  1. 是什么问题:缓冲式摘要 SSE 解析器 bufferedSseEvents 把「只含空白(空格/Tab)的行」当成事件边界,使跨多行的合法 JSON 事件被从空白行处切成两个畸形片段,JSON.parse 失败 → 摘要提取返回 "" → 压缩失败、落入重试/[Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726 减半退避;同时它丢弃无冒号字段、并把事件名整体 trim(而非只去一个可选前导空格)。
  2. 什么原因导致的:边界判定用 line.trim() === ""(任意空白行=边界)而非 line === ""(仅真正空行=边界,符合 SSE 规范);字段解析用 startsWith("event:")/startsWith("data:") + .trim(),而非按「第一个冒号」切分 + 只去一个前导空格。根因:解析器偏离了 SSE 事件流解释规则。
  3. 影响范围与严重程度:影响摘要提取路径(preflight.extractSummaryFromSse + external-summary-http),两种压缩模式共用。触发条件:上游合法摘要流的跨行 JSON 中含空白行(或无冒号字段)。严重度:合法流提取失败 → 压缩降级为重试/减半;并非「完全不可用」(多数单行 JSON 流不受影响),但属解析器真实正确性缺陷。issue 作者建议 p1/scope-wiring(最终标签由 owner 定,我未给本 PR 打标)。
  4. 怎么修复的:按第一个冒号切分字段(无冒号→空值)、只去一个可选前导空格、仅在真正空行派发事件。使摘要解析器对齐 SSE 规范,且与流式适配器(loop/adapter-*.ts,已按 indexOf("\n\n") 只按空行切分、跳过空白事件)保持一致——摘要路径向既有流式路径看齐,而非反向。
  5. 是否有回归问题:低。已核:①行为差异仅 3 处(空白行不再派发 / 事件名保留尾部与多余空白 / 无冒号 data/event 行现贡献空值),三处均符合规范;②5 个定向 SSE 套件 130 全绿 + 81 个摘要路径测试全绿;③新测试为真回归(base 上 3/4 + 4/4 协议用例失败,修复后通过);④issue 原始复现(openai,L/CRLF)返回 "summary";⑤未触碰配置 schema、持久化、wire/消息形状、kernel、message-ref/id 逻辑;⑥PR 落后 master 2 个提交([PR] In-place auto-update 100% failure fix: Backup must not exist prior to atomic swap (Gate Lane X repro) | 就地自动更新 100% 失败修复:备份不能先于原子交换存在(门禁 Lane X 复现) #6643 更新器修复),均不触碰本 PR 文件,无语义交互、可干净 rebase。
  6. 是否破坏缓存:否。仅改 bili 如何解析上游摘要响应,不影响缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:否。属对齐 SSE 规范的 bug 修复,无架构转向。
  8. 是否引入了新的配置:否。

判定:修复正确、符合规范、测试有牙、回归风险低,符合 §7.4 自动合并条件。合并前需:rebase 到当前 master + 重触发 CI(当前 head 的 check 全为 cancelled,尚无绿)。我不合并(人工专属)。

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.

[Bug] Buffered SSE parsing splits summary events on whitespace-only lines

2 participants