fix(api): avoid loading unrelated API resources on first use - #3898
Conversation
Castiron-Internal-PR: openai/openai-python-internal#108 Castiron-Source-SHA: ecd2e7a2d2b785e78791cc704697aa78706f6f0b Castiron-Public-Base-SHA: dcbd6b8
Castiron custom code✅ No new custom-code files detected. 47 mixed files remain; 1 existing customization changed; 1 generated baselines changed. Compared
45 existing customizations unchanged
5 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 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.patchOr 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.patchThis is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ 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. |
jbeckwith-oai
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
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>
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.