Skip to content

Preserve snapshots when resuming response streams#1984

Open
koriyoshi2041 wants to merge 2 commits into
openai:mainfrom
koriyoshi2041:fix-response-stream-starting-after
Open

Preserve snapshots when resuming response streams#1984
koriyoshi2041 wants to merge 2 commits into
openai:mainfrom
koriyoshi2041:fix-response-stream-starting-after

Conversation

@koriyoshi2041

@koriyoshi2041 koriyoshi2041 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

responses.stream({ response_id, starting_after }) needs the replayed event prefix to build complete event snapshots and finalResponse(). Passing starting_after through to responses.retrieve makes the API omit that prefix, including response.created, so the accumulator can fail before yielding resumed events.

Fix

  • Keep the full replay for the by-ID stream helper and continue filtering emitted events locally.
  • Clarify the starting_after docs so the snapshot-building behavior is explicit.
  • Add a regression test that emulates the API's truncated suffix behavior and verifies resumed streams still build a final response.

Test

  • pnpm test tests/lib/ResponseStream.test.ts
  • pnpm lint

Related to #1983.

@koriyoshi2041 koriyoshi2041 requested a review from a team as a code owner July 7, 2026 02:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0bf5e75bf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/lib/responses/ResponseStream.ts Outdated
@HAYDEN-OAI HAYDEN-OAI changed the title Pass starting_after when resuming response streams Preserve snapshots when resuming response streams Jul 9, 2026

Copy link
Copy Markdown
Contributor

updated this in 9fe6084b. we kept the full replay for responses.stream({ response_id, starting_after }) so the accumulator still sees response.created, clarified that starting_after filters emitted events locally, and replaced the url-only test with a regression test that simulates a server-truncated suffix and verifies finalResponse() still succeeds. verified with pnpm test tests/lib/ResponseStream.test.ts and pnpm lint.

@koriyoshi2041

Copy link
Copy Markdown
Contributor Author

Thanks, this version looks right to me. I pulled 9fe6084b locally and re-ran:

  • pnpm test tests/lib/ResponseStream.test.ts
  • pnpm lint

Both pass. The new regression is a better fit than my original URL-only test since it checks the truncated replay case directly.

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.

2 participants