Skip to content

fix: make OpenAI exceptions pickleable - #3733

Open
sylvesterkaczmarek wants to merge 11 commits into
openai:mainfrom
sylvesterkaczmarek:fix/pickle-openai-errors-2629
Open

fix: make OpenAI exceptions pickleable#3733
sylvesterkaczmarek wants to merge 11 commits into
openai:mainfrom
sylvesterkaczmarek:fix/pickle-openai-errors-2629

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Aug 25, 2026

Copy link
Copy Markdown

Summary

  • make OpenAIError subclasses pickleable without retaining live HTTP transport state
  • snapshot only non-sensitive request/response diagnostics and rebuild plain httpx2 objects during unpickling
  • omit request URLs/bodies, raw response bodies, and queued WebSocket payloads from pickle snapshots
  • default-redact request/response header values except a small diagnostic allowlist, covering auth credentials, API keys, cookies, OpenAI-Organization, OpenAI-Project, and arbitrary customer metadata
  • preserve serialisable timeout metadata, response elapsed, and safe protocol metadata (http_version and reason_phrase)
  • support both httpx2 and the SDK's legacy httpx compatibility lane
  • preserve concrete exception subclasses, __dict__ and __slots__ state without replaying custom constructors or subclass __new__ methods

Fixes #2629

Test plan

  • Pre-review: uv run ruff format --check src/openai/_exceptions.py tests/test_exceptions_pickle.py — passed
  • Pre-review: uv run ruff check src/openai/_exceptions.py tests/test_exceptions_pickle.py — passed
  • Pre-review: uv run pytest -o addopts= -q tests/test_exceptions_pickle.py — passed
  • Pre-review: ./scripts/lint and git diff --check — passed
  • Review follow-ups add real sync/async transport regressions, custom-__new__ and slotted-subclass coverage, request/response privacy checks, timeout preservation, response protocol metadata, credential/customer-identifier redaction, WebSocket payload omission, response elapsed preservation, and legacy sync/async httpx compatibility coverage.
  • On the current review-fix head, CI, CodeQL, and Castiron are action_required with no jobs started; the external-contributor workflows are waiting for maintainer approval.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 25, 2026 01:05

@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: 4f2351168d

ℹ️ 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".

Comment thread src/openai/_exceptions.py Outdated
Comment thread src/openai/_exceptions.py Outdated

@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: 65e4756fd7

ℹ️ 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".

Comment thread src/openai/_exceptions.py Outdated
Comment thread src/openai/_exceptions.py
Comment thread src/openai/_exceptions.py Outdated
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

Addressed both review findings: transport-backed request/response state is now snapshotted and rebuilt as plain HTTP objects during unpickling, with regressions through real sync and async client transports. Reconstruction also bypasses subclass new, with coverage for user-defined OpenAIError subclasses.

@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: 470fc2f5eb

ℹ️ 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".

Comment thread src/openai/_exceptions.py Outdated
Comment thread src/openai/_exceptions.py Outdated
Comment thread src/openai/_exceptions.py Outdated
Comment thread src/openai/_exceptions.py Outdated
Comment thread src/openai/_exceptions.py Outdated

@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: 75ee9cdf08

ℹ️ 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".

Comment thread src/openai/_exceptions.py
Comment thread src/openai/_exceptions.py
Comment thread src/openai/_exceptions.py
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

Addressed all five findings from the latest review: request URLs/bodies and raw response bodies are no longer serialized, sensitive response headers are redacted, timeout metadata is preserved, and legacy httpx request/response objects are handled through safe snapshots. Added focused privacy and legacy sync/async regression coverage.

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.

Add __reduce__ method to Exception types

1 participant