feat(responses): opt in to incremental WebSocket text and tool snapshots - #3973
Conversation
Castiron custom code✅ No new custom-code files detected. 48 mixed files remain; 0 existing customizations changed. Compared 48 existing customizations unchanged
8 more in the full report. A changed generated baseline means this report cannot reliably identify which handwritten lines changed. Inspect the custom-code diffDownload the exact patch produced by this run (requires repository access): gh run download 36362359910 --repo openai/openai-python \
--name castiron-custom-code-36362359910-1 --dir /tmp/castiron-custom-code-36362359910-1
git apply --stat /tmp/castiron-custom-code-36362359910-1/custom-code.patch
cat /tmp/castiron-custom-code-36362359910-1/custom-code.patchOr reproduce it from an SDK checkout containing the vendored reporter: git fetch --no-tags origin 4ef4129e85e81a285905755e57b392aa9e77f9bd 38f42e91b07db6049f4eae293b255c0b74316bea
python3 scripts/castiron/custom_code_report.py report \
--base 4ef4129e85e81a285905755e57b392aa9e77f9bd \
--head 38f42e91b07db6049f4eae293b255c0b74316bea --fetch --require-head-hash --public \
--out /tmp/castiron-custom-code-38f42e91b07d
cat /tmp/castiron-custom-code-38f42e91b07d/custom-code.patchThis is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12ac7ed8be
ℹ️ 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".
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 12ac7ed8be
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9a072e9ac
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a67024a260
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c86dea9cb
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4446ef16e
ℹ️ 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".
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: a86c8978d0
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
dpiet-oai
left a comment
There was a problem hiding this comment.
One verified medium-severity denial-of-service risk remains in the opt-in accumulator.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80973d71a5
ℹ️ 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".
dpiet-oai
left a comment
There was a problem hiding this comment.
One verified medium-severity partial-snapshot correctness gap remains on the current head.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Reviewed 80973d71a5781dc746a79a6639f46f60086c6c98. I found two remaining snapshot/terminal correctness gaps and left focused inline comments.
I reproduced both using this commit's actual Responses WebSocket decoder and accumulator loaded from the commit archive in memory (Python 3.12 / Pydantic 2). Controls for ordinary text-done replacement, prior text snapshot isolation, explicit empty terminal output, and reset passed. I read the full change and the follow-up sparse-index fix; I did not run the repository's full test suite or contact a live API.
Existing primitive-item replacement and retired-item-ID findings are tracked in #3973 (comment) and #3973 (comment); I have not duplicated those threads. CI was still running on this head, with lint failing, at the last check.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 80973d71a5
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (3)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd3319b8bd
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…etain item IDs linearly
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27bd5b4097
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a3a1e21be
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b38e7cc4f
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d18e1e1705
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Re-reviewed db90e317271737e4425a0449d7fa0afc5a0fd5cc; my two snapshot/terminal blockers are fixed, so I am clearing my changes request.
An authoritative non-text content part now clears only its selected text slot, preserving neighboring content. Malformed non-null lifecycle output is rejected before state replacement or terminal success, and invalid terminal errors remain available through get_final_response(). I also checked the follow-up primitive/metadata validation, retired-ID handling for full and incremental replacements, unknown-type handling, lane/response identity checks, and the corrected progress example. Omitted/null compatibility and exact received terminal responses remain distinct from the partial projection.
Reviewed all three fix-delta files and the complete helper, including sync/async wire regressions and snapshot/raw-event isolation. Exact-head Python 3.10 CI passed 14,102 tests with Pydantic 2 and 14,088 with Pydantic 1; the HTTPX2 job passed the same suites. Python 3.14, lint, build, and compatibility checks are green. This re-review used source inspection and hosted CI, not a local full-suite rerun. No remaining blocking findings.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38f42e91b0
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if getattr(event, "stream_id", None) != expected_stream_id: | ||
| continue | ||
| accumulator.add_event(event) | ||
| event_type = event.type |
There was a problem hiding this comment.
Guard missing event types in the example
Fresh evidence beyond the resolved unhashable-type case: when a default-lane or direct-connection consumer receives a malformed top-level JSON value or object without type, the loose parser can return a value with no .type attribute. add_event() safely ignores it, but this access then raises AttributeError and terminates the documented receive loop; retrieve the type with getattr(event, "type", None) and use that guarded value for all subsequent comparisons.
Useful? React with 👍 / 👎.
| self._error = error | ||
| raise | ||
| self._output = replacement | ||
| self._response_id = response_id or self._response_id |
There was a problem hiding this comment.
Preserve empty response IDs when binding state
When a compatible provider supplies an empty-string response ID, it passes the preceding string validation but this truthiness fallback stores None instead. Besides exposing the wrong snapshot().response_id, that leaves the accumulator unbound to the response identity, so a later lifecycle event with a different nonempty ID bypasses the mismatch check and can replace or finalize the existing projection. Assign the new ID whenever it is not None, rather than only when it is truthy.
Useful? React with 👍 / 👎.
| @pytest.mark.parametrize("field", ["output_index", "content_index"]) | ||
| def test_large_sparse_indices_keep_numeric_order_and_prior_snapshots(field: str) -> None: |
There was a problem hiding this comment.
Reduce the handwritten regression suite
This change adds a 1,132-line handwritten test module with many repeated sync/async socket scripts and state-preservation assertions, despite the repository requirement that handwritten tests remain small. Consolidate the repeated frame-driving and assertion patterns into compact helpers or focused tables so future protocol changes do not require editing a large duplicated matrix.
AGENTS.md reference: AGENTS.md:L5-L8
Useful? React with 👍 / 👎.
WebSocket callers currently cannot inspect cumulative text and tool inputs when a stream omits the scaffolding required by HTTP/SSE accumulation. Adds an optional caller-fed
ResponsesWebSocketAccumulatorwith immutable partial snapshots and a separate exact received terminal response. It handles sync and async connections, failed/incomplete results, empty versus omitted output and item corrections without owning a socket or running tools. Existing lane and SSE methods are unchanged.Known malformed text/tool fields are rejected before they can corrupt a snapshot. Raw events, missing/nullable fields on terminal responses, and unknown variants remain available to the caller.
Validation: 190 WebSocket/accumulator and 23 Responses tests passed on each of Pydantic v1 and v2, full Ruff, mypy on src, Pyright. The nullable-content setup originally hit the environment's unsupported SOCKS proxy and passed using
NO_PROXY=*for the local fixture tests. Cases cover independent interleaved lanes, malformed input, exact terminals and disposal/reuse.