Skip to content

[PR] fix(responses): preserve content indices in synthesized streams - #7402

Closed
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_preserve-responses-content-indices
Closed

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_preserve-responses-content-indices

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7401

Problem

Responses text events are addressed by both output_index and content_index. Several synthesized frames retain the item address but omit the part address, causing the official OpenAI Node SDK to throw missing content at index undefined.

This affects generated text/ACP markers, legacy stream-error completions, and filtered text tails in both proxy and plugin modes. An ordinary answer ending in Length: 10 m reproduces it: the final m is buffered, then flushed in a newly constructed delta that loses its content index.

Change

  • Set content_index: 0 on the four content/text lifecycle frames for messages containing one generated text part.
  • Preserve the source content index in proxy and plugin tail metadata, including plugin retry reframing.
  • Add WC-026, matching fake enforcement, and regressions which feed the actual emitted bytes into the official OpenAI SDK already present in the development dependencies.

The fix retains the existing text/filtering policy, item/output remapping and protocol-native error default. Source part indices are preserved without guessing a replacement for malformed upstream frames.

Validation

Tested base: 1e357bf2d6632bfbd2a74ffb70ecee1af1ec7cc3.

  • Restoring all three production files to that unchanged base: 10 failures / 10 passing controls, with the original fixed files restored byte-for-byte afterward.
  • Fixed branch: 193/193 passed, zero skipped, across responses-content-index, proxy-stream-error, wire-contract, loop-adapters, tag-echo, plugin-passthrough-tag-strip, and plugin-empty-turn-retry.
  • Nine real SDK-consumption cases cover generated text/markers, legacy completion, native-error rejection, part indices 0/1 in both modes, preservation of an earlier part, and retry-tail flushing.
  • npm run typecheck, npm run build, npm run check:unused-exports, npm run check:test-import-graph, and git diff --check pass.
  • Codex preflight finds CLI 0.169.0 and the built artifact. Its local upstream probe is unavailable, so live four-phase coverage remains pending; the preflight is not counted as that run. Full-suite verification is the remote CI on this head.

The consumer contract is visible in OpenAI's ResponseStream v6.26.0. No dependency or golden snapshot changes are needed.

Related history

All-author/all-state duplicate screening found no equivalent change. #2691 repaired the Anthropic legacy lifecycle, #1464 introduced the native error policy, and #5057 handles a different preflight failure body.

Set content_index=0 on the single-part text and marker lifecycles and
legacy stream-error completions. Retain the source content index when
proxy and plugin filters flush pending text, including plugin retry
reframing. This prevents official SDK consumers from rejecting valid
answers such as text ending in a buffered "m" as a missing content part.

Record WC-026, enforce it in the matching fake and exercise actual OpenAI
SDK consumption. The unchanged production fails ten focused regressions
with ten controls passing; the fixed relevant suites pass all 193 tests.
Typecheck, build, unused-export and test-import-graph gates also pass.
@ranxianglei

Copy link
Copy Markdown
Owner

已收编进 batch-B PR #7445(已合并,2026-11-21)。本 PR 的 Responses 合成流 content_index 修复已 cherry-pick 进 #7445 并保留原作者署名,Fixes #7401 已随合并自动关单。本 PR 关闭。

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Synthesized Responses text events lose content_index and crash SDK consumers

2 participants