Skip to content

fix(provider): retain Responses text baselines across output items - #501

Open
haohaomin wants to merge 1 commit into
leookun:mainfrom
haohaomin:codex/upstream-responses-text
Open

haohaomin wants to merge 1 commit into
leookun:mainfrom
haohaomin:codex/upstream-responses-text

Conversation

@haohaomin

Copy link
Copy Markdown

Responses text completion events describe one output item, but the existing reconciliation baseline accumulates text for the whole response. As a result, later items can lose their entire text or a missing delta suffix. This change retains a baseline per output_index for the lifetime of the response and uses it for both response.output_text.done and message response.output_item.done.

This addresses the issue identified by @kevin9327 in #421 and adds coverage for item indices that return after another item has already emitted text. Clearing one buffer whenever the index changes fixes sequential items but loses the previous item's baseline: interleaved events and late duplicate completion events can then replay text. The first explicit index can also arrive after an unindexed prefix; that prefix is adopted by the newly identified item instead of being emitted twice. Events without an index continue to use the current item.

The implementation retains per-item cumulative text in a map. It leaves function-call handling and the existing prefix-only text reconciliation behavior unchanged.

Validation:

  • Nine integration tests exercise actual HTTP/SSE → OpenAiResponsesProvider → consume_model_cycle, checking final text, finish reason, usage, and tool-call results.
  • Earlier comparison with these tests: upstream base passed 5/9, the proposed fix(provider): scope OpenAI Responses text reconciliation to one output item #421 patch passed 6/9, and this implementation passed 9/9. The additional failures in fix(provider): scope OpenAI Responses text reconciliation to one output item #421 were interleaved items, late completion of an earlier item, and first-index adoption of an unindexed prefix.
  • Earlier real Cursor checks confirmed suffix completion, no duplicate terminal text, a live Responses conversation/follow-up, and actual shell execution/result delivery. A separately discovered tool-card presentation problem was fixed independently and is outside this PR.

Only the provider change and its integration tests are included. This PR is independent of #487 and the Anthropic refusal fix, with no fork customization or release changes. Related: #421; it does not require that PR to be merged first.

Revalidated on current upstream main (9a8fde2): cargo test -p cursor-server --all-targets passed all 264 tests, including all nine Responses integration tests; server all-targets Clippy with -D warnings, cargo fmt --all -- --check, and git diff --check passed. This upstream-only branch contains one production file and one integration-test file.

Address the text reconciliation issue identified in leookun#421. Retain baselines across interleaved or late terminal events and adopt an initial unindexed prefix. Cover the provider through HTTP/SSE model-cycle integration tests.

Co-authored-by: kevin9327 <kevin9327@users.noreply.github.com>
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.

1 participant