Skip to content

refactor(websocket): add SDK-owned Responses policy helpers - #4219

Open
markstuart-oai wants to merge 2 commits into
mainfrom
codex/responses-websocket-policy-core
Open

markstuart-oai wants to merge 2 commits into
mainfrom
codex/responses-websocket-policy-core

Conversation

@markstuart-oai

Copy link
Copy Markdown
Contributor

Add private SDK-owned helpers for Responses WebSocket setup, iteration, progress tracking, and cleanup. Focused sync and async tests cover prepared headers, argument collisions, generator controls, retry progress, and cleanup error precedence.

Existing public managers do not yet call these helpers. Rollout needs three steps: merge this helper change into public main, land compiler delegation, then regenerate and promote the bindings. The compiler must wait for the merged helper change; an open PR is insufficient. The first dependency needs no package release.

Validation: 585 focused WebSocket tests passed, including the 18 new helper cases. Ruff formatting and lint, plus ty 0.0.87 checks for both changed files, passed.

@markstuart-oai
markstuart-oai requested a review from a team as a code owner October 31, 2026 05:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T05:25:59.045746Z 7813037 PR opened
🔒 Security Review ✅ Completed 2026-10-31T05:26:34.371226Z 7813037 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@aetherxeg-source

Copy link
Copy Markdown

The new entry guards correctly prioritize the initiating exception over failures from connection.close(), and the sync/async symmetry is useful.

There is one adjacent cleanup-failure boundary worth covering before the helpers are wired into the public connection managers.

In both _websocket_entry_guard and _async_websocket_entry_guard, clear_connection() executes outside the protected close-cleanup block. If that callback raises while handling an existing failure, two things follow from the current control flow:

  1. The clearing exception replaces the original failure.
  2. connection.close() is never attempted.

A deterministic regression could inject:

  • An initiating ValueError (and CancelledError in the async case).
  • A clear_connection callback that raises RuntimeError.
  • A socket mock recording whether close() was attempted.

The desired contract, if clearing is not guaranteed to be infallible, would be: attempt connection cleanup, retain the initiating exception, and avoid silently replacing the primary failure with a secondary cleanup error.

A narrowly scoped try/finally or guarded cleanup sequence could enforce that ordering without changing the successful-entry path.

If every production clear_connection implementation is deliberately guaranteed not to raise, documenting or testing that invariant would resolve the concern instead.

This is a source-level failure-path observation, not a reproduced production failure. It is particularly relevant because these private helpers are being qualified before their public-manager rollout.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed exact commit f5c59a0. The shared helpers preserve Responses connection policy, prepared headers/query options, reconnect and unsent-message behavior, progress accounting, and cleanup exception precedence. Existing cleanup comments address the feedback; the BaseException test intentionally checks cancellation/control-flow preservation. Coordinator and independent static review found no actionable issues. Hosted checks are successful or explicitly skipped. No candidate code or tests executed.

This branch has not been deployed

No deployments
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.

4 participants