Skip to content

fix(api): avoid loading unrelated API resources on first use - #3898

Merged
marcuswood-oai merged 1 commit into
mainfrom
castiron/promotions/pr-108
Sep 18, 2026
Merged

marcuswood-oai merged 1 commit into
mainfrom
castiron/promotions/pr-108

Conversation

@marcuswood-oai

Copy link
Copy Markdown
Contributor

Importing the SDK or accessing one API resource currently loads unrelated resources, including Assistants. Load resource exports and streaming helpers when first accessed to reduce startup work.

Existing import paths, class identity, static typing, wildcard imports, and discovery are preserved. Code that inspects module dictionaries directly may observe exports appearing later; import work and import errors move to first access.

Regression tests cover import isolation, public exports, runtime annotations, pickling, reloads, sync/async requests and streams, and concurrent first access. Endpoint methods, models, dependencies, and webhook behavior are unchanged.

Validation: 682 focused tests passed (14 skipped), along with Mypy, Pyright, and Ruff. Python 3.10/3.14, HTTPX2, build, lint, and baseline checks passed on the final revision. End-to-end testing also passed.

Castiron-Internal-PR: openai/openai-python-internal#108
Castiron-Source-SHA: ecd2e7a2d2b785e78791cc704697aa78706f6f0b
Castiron-Public-Base-SHA: dcbd6b8
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

47 mixed files remain; 1 existing customization changed; 1 generated baselines changed.

Compared dcbd6b8f5c26 → 9ffc04f5ccfd. Generated baselines verified.

File Result Current custom patch
src/openai/init.py Existing customization changed +169 / −1
src/openai/resources/webhooks/init.py Generated baseline changed +24 / −55
45 existing customizations unchanged
  • api.md
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • src/openai/_client.py
  • src/openai/resources/audio/transcriptions.py
  • src/openai/resources/audio/translations.py
  • src/openai/resources/beta/agents/sessions/sessions.py
  • src/openai/resources/beta/beta.py
  • src/openai/resources/beta/responses/responses.py
  • src/openai/resources/beta/threads/runs/runs.py
  • src/openai/resources/beta/threads/threads.py
  • src/openai/resources/chat/completions/completions.py
  • src/openai/resources/embeddings.py
  • src/openai/resources/files.py
  • src/openai/resources/live/forks.py
  • src/openai/resources/live/live.py
  • src/openai/resources/live/sideband.py
  • src/openai/resources/realtime/api.md
  • src/openai/resources/realtime/realtime.py
  • src/openai/resources/responses/responses.py
  • src/openai/resources/uploads/uploads.py
  • src/openai/resources/vector_stores/file_batches.py
  • src/openai/resources/vector_stores/files.py
  • src/openai/resources/videos.py
  • src/openai/resources/webhooks/webhooks.py
  • src/openai/types/beta/agent_session_message.py
  • src/openai/types/chat/init.py
  • src/openai/types/chat/chat_completion_message_tool_call.py
  • src/openai/types/fine_tuning/fine_tuning_job_integration.py
  • src/openai/types/realtime/conversation_item_input_audio_transcription_delta_event.py
  • src/openai/types/realtime/realtime_error_event.py
  • src/openai/types/responses/init.py
  • src/openai/types/responses/response.py
  • src/openai/types/responses/response_function_web_search.py
  • src/openai/types/responses/response_function_web_search_param.py
  • src/openai/types/responses/responses_client_event.py
  • src/openai/types/responses/responses_client_event_param.py
  • src/openai/types/responses/tool.py
  • src/openai/types/responses/tool_param.py

5 more in the full report.

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 35377518092 --repo openai/openai-python \
  --name castiron-custom-code-35377518092-1 --dir /tmp/castiron-custom-code-35377518092-1
git apply --stat /tmp/castiron-custom-code-35377518092-1/custom-code.patch
cat /tmp/castiron-custom-code-35377518092-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin dcbd6b8f5c26bc09899a584158729b5b67ba7dc6 9ffc04f5ccfdb78685cf942e029a35ae86988865
python3 scripts/castiron/custom_code_report.py report \
  --base dcbd6b8f5c26bc09899a584158729b5b67ba7dc6 \
  --head 9ffc04f5ccfdb78685cf942e029a35ae86988865 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-9ffc04f5ccfd
cat /tmp/castiron-custom-code-9ffc04f5ccfd/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@marcuswood-oai
marcuswood-oai marked this pull request as ready for review September 18, 2026 17:58
@marcuswood-oai
marcuswood-oai requested a review from a team as a code owner September 18, 2026 17:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 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-09-18T18:01:31.396419Z 9ffc04f Draft marked ready
🔒 Security Review ✅ Completed 2026-09-18T18:01:06.772408Z 9ffc04f Draft marked ready
ℹ️ 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.

@openai-sdks

openai-sdks Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 236/236 SDK tests passed in 9.362s for Python SDK PR #3898.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 132ms
tests/chat-completions-create.test.ts ✅ Passed 263ms
tests/chat-completions-stream.test.ts ✅ Passed 199ms
tests/files-content-binary.test.ts ✅ Passed 153ms
tests/files-create-multipart.test.ts ✅ Passed 232ms
tests/files-list-pagination.test.ts ✅ Passed 182ms
tests/initialize-config.test.ts ✅ Passed 136ms
tests/instance-isolation.test.ts ✅ Passed 157ms
tests/models-list.test.ts ✅ Passed 191ms
tests/responses-background-lifecycle.test.ts ✅ Passed 125ms
tests/responses-body-method-errors.test.ts ✅ Passed 263ms
tests/responses-cancel-timeout.test.ts ✅ Passed 198ms
tests/responses-cancel.test.ts ✅ Passed 235ms
tests/responses-compact-retries.test.ts ✅ Passed 263ms
tests/responses-compact.test.ts ✅ Passed 167ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 103ms
tests/responses-create-advanced.test.ts ✅ Passed 263ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.212s
tests/responses-create-errors.test.ts ✅ Passed 175ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 353ms
tests/responses-create-retries.test.ts ✅ Passed 309ms
tests/responses-create-stream-failures.test.ts ✅ Passed 147ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 197ms
tests/responses-create-stream-wire.test.ts ✅ Passed 2.564s
tests/responses-create-stream.test.ts ✅ Passed 281ms
tests/responses-create-terminal-states.test.ts ✅ Passed 208ms
tests/responses-create-timeout.test.ts ✅ Passed 197ms
tests/responses-create.test.ts ✅ Passed 266ms
tests/responses-delete.test.ts ✅ Passed 153ms
tests/responses-input-items-errors.test.ts ✅ Passed 309ms
tests/responses-input-items-list.test.ts ✅ Passed 247ms
tests/responses-input-items-options.test.ts ✅ Passed 238ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 217ms
tests/responses-input-tokens-count.test.ts ✅ Passed 192ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.781s
tests/responses-not-found-errors.test.ts ✅ Passed 228ms
tests/responses-parse.test.ts ✅ Passed 336ms
tests/responses-retrieve-retries.test.ts ✅ Passed 258ms
tests/responses-retrieve.test.ts ✅ Passed 194ms
tests/responses-stored-method-errors.test.ts ✅ Passed 501ms
tests/retry-behavior.test.ts ✅ Passed 3.026s
tests/sdk-error-shape.test.ts ✅ Passed 227ms

View OkTest run #35377485298

SDK merge (a9cbe7d34a0c) · head (9ffc04f5ccfd) · base (dcbd6b8f5c26) · OkTest (cdb90acd46e5)

@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 the exact head across the lazy package export machinery, root streaming exports, client first-access behavior, and compatibility surfaces. I mechanically verified all 40 generated resource packages: every __all__ name has an exact lazy export mapping, every lazy module target exists, every mapped symbol resolves to the canonical object, and the supported submodule set is complete and importable. I also checked wildcard import/discovery, class identity, pickling/reload behavior, concurrent first access, and sync/async request and stream paths. The focused lazy-import suite passed locally (11 tests), Ruff and diff checks passed, OkTest passed 236/236, and exact-head build, Python 3.10/3.14, HTTPX2, lint, baseline, CodeQL, and hosted code/security reviews are green. No blocking findings.

@markstuart-oai markstuart-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 9ffc04f5ccfd against the current main base. The lazy resource initializers preserve the existing __all__ lists; I checked all 40 changed resource packages and resolved 868 exported symbols to their canonical objects. The root streaming handlers and package submodules remain discoverable, while ordinary client imports and first sync/async requests avoid loading Assistants. The generated package files remain below 1,000 lines, and I found no consequential compatibility or structural issue.

Validation: the focused lazy-import suite passed (11/11), including wildcard imports, identity, pickling, reload, concurrent first access, and mocked sync/async request and stream paths. Ruff and git diff --check passed locally; the exact-head CI checks for Python 3.10/3.14, HTTPX2, build, lint, breaking-change detection, and the Castiron budget are green. I did not run live API requests.

Codex task: codex://threads/01a0a21f-84b6-7c21-b7a7-30a1e64ab2f9

@marcuswood-oai
marcuswood-oai added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 68e4317 Sep 18, 2026
28 of 29 checks passed
@marcuswood-oai
marcuswood-oai deleted the castiron/promotions/pr-108 branch September 18, 2026 18:30
@openai-sdks openai-sdks Bot mentioned this pull request Sep 18, 2026
pull Bot pushed a commit to Mattlk13/openai-python that referenced this pull request Sep 18, 2026
Automated Release PR
---


##
[3.16.1](openai/openai-python@v3.16.0...v3.16.1)
(2026-09-18)


### Bug Fixes

* **api:** avoid loading unrelated API resources on first use
([openai#3898](openai#3898))
([68e4317](openai@68e4317))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: openai-sdks[bot] <284451331+openai-sdks[bot]@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.

3 participants