Skip to content

refactor(api): move file processing polling into SDK-owned helpers - #3712

Merged
apcha-oai merged 3 commits into
mainfrom
apcha/castiron-python-file-processing-public
Aug 21, 2026
Merged

refactor(api): move file processing polling into SDK-owned helpers#3712
apcha-oai merged 3 commits into
mainfrom
apcha/castiron-python-file-processing-public

Conversation

@apcha-oai

@apcha-oai apcha-oai commented Aug 21, 2026

Copy link
Copy Markdown
Contributor
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Move the existing sync and async file-processing polling bodies into SDK-owned lib/_files.py. Files.wait_for_processing and AsyncFiles.wait_for_processing keep their public signatures, defaults, docstrings, and return types, and delegate to the helpers. No schema, compiler, dependency, or generation-metadata changes are needed.

The polling bodies are unchanged apart from renaming the receiver from self to files. This preserves the processed/error/deleted terminal states, wall-clock timing, dynamic retrieve and _sleep hooks, return identity, and exact errors. In particular, the strict > timeout check still happens after a repeated retrieval, even if that retrieval returns a terminal state. This does not introduce a generic polling framework or change existing timeout behavior.

Review pointers:

Following the review discussion, the new handwritten suite is limited to 87 lines rather than an exhaustive matrix of clock, timeout, and event-order details. Existing Files API tests are unchanged. The review revision changes only this new test file; runtime source remains byte-identical to the original PR head.

Additional context & links

Validation:

  • Commands: TEST_API_BASE_URL=http://127.0.0.1:4141 .venv/bin/python -m pytest tests/lib/test_file_processing.py tests/api_resources/test_files.py -q -n 0 and the same command using .venv-pydantic-v1/bin/python: 130 passed, 3 skipped in each Pydantic mode. The skips are the existing aiohttp/respx2-incompatible test_method_content, test_raw_response_content, and test_streaming_response_content cases.
  • Commands: .venv/bin/ruff format tests/lib/test_file_processing.py and ./scripts/lint passed on the review revision, including Ruff, Pyright, mypy, and import checks. The initial full ./scripts/format also passed; unrelated reporter-formatting changes were excluded.
  • Command: ./scripts/build passed. Both the wheel and source distribution contain openai/lib/_files.py; importing the helper and resource classes from the built wheel also passed.
  • Exact source/AST comparison against the base verified both polling bodies, all other resource statements, public signatures, exports, request construction, and response wrappers.

The verified custom-code report keeps 36 mixed files and changes only the Files resource customization, shrinking it from +47/-0 to +26/-0. The other 35 customizations are unchanged. Reproduction command:

python3 scripts/castiron/custom_code_report.py report \
  --base bedb9a7b8839e193107e88b92f7cc166f08ac83d \
  --head 3dfdf85e4d33a3274270aadccda6278c41ac8ede \
  --fetch --require-head-hash --public \
  --out /tmp/castiron-file-processing

@apcha-oai
apcha-oai requested a review from a team as a code owner August 21, 2026 13:44
@apcha-oai apcha-oai added the custom-code-burndown Behavior-preserving cleanup of custom code in generated SDK files label Aug 21, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 21, 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-08-21T15:35:02.966086Z c708fbd New commits
🔒 Security Review Completed 2026-08-21T15:35:22.669765Z c708fbd New commits
ℹ️ 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 Aug 21, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 11.425s for Python SDK PR #3712.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 187ms
tests/chat-completions-create.test.ts ✅ Passed 278ms
tests/chat-completions-stream.test.ts ✅ Passed 128ms
tests/files-content-binary.test.ts ✅ Passed 212ms
tests/files-create-multipart.test.ts ✅ Passed 242ms
tests/files-list-pagination.test.ts ✅ Passed 147ms
tests/initialize-config.test.ts ✅ Passed 240ms
tests/instance-isolation.test.ts ✅ Passed 251ms
tests/models-list.test.ts ✅ Passed 147ms
tests/responses-background-lifecycle.test.ts ✅ Passed 251ms
tests/responses-body-method-errors.test.ts ✅ Passed 353ms
tests/responses-cancel-timeout.test.ts ✅ Passed 217ms
tests/responses-cancel.test.ts ✅ Passed 303ms
tests/responses-compact-retries.test.ts ✅ Passed 307ms
tests/responses-compact.test.ts ✅ Passed 241ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 155ms
tests/responses-create-advanced.test.ts ✅ Passed 260ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.108s
tests/responses-create-errors.test.ts ✅ Passed 198ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 254ms
tests/responses-create-retries.test.ts ✅ Passed 355ms
tests/responses-create-stream-failures.test.ts ✅ Passed 135ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 236ms
tests/responses-create-stream-wire.test.ts ✅ Passed 3.907s
tests/responses-create-stream.test.ts ✅ Passed 81ms
tests/responses-create-terminal-states.test.ts ✅ Passed 253ms
tests/responses-create-timeout.test.ts ✅ Passed 225ms
tests/responses-create.test.ts ✅ Passed 335ms
tests/responses-delete.test.ts ✅ Passed 194ms
tests/responses-input-items-errors.test.ts ✅ Passed 389ms
tests/responses-input-items-list.test.ts ✅ Passed 341ms
tests/responses-input-items-options.test.ts ✅ Passed 365ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 266ms
tests/responses-input-tokens-count.test.ts ✅ Passed 208ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.981s
tests/responses-not-found-errors.test.ts ✅ Passed 264ms
tests/responses-parse.test.ts ✅ Passed 454ms
tests/responses-retrieve-retries.test.ts ✅ Passed 310ms
tests/responses-retrieve.test.ts ✅ Passed 216ms
tests/responses-stored-method-errors.test.ts ✅ Passed 570ms
tests/retry-behavior.test.ts ✅ Passed 3.045s
tests/sdk-error-shape.test.ts ✅ Passed 304ms

View OkTest run #32498273101

SDK merge (f33a81c79c82) · head (c708fbd05d19) · base (a002ef3c7d22) · OkTest (2b1bdfd25e98)

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

36 mixed files remain; 1 existing customization changed.

Compared a002ef3c7d22c708fbd05d19. Generated baselines verified.

File Result Current custom patch
src/openai/resources/files.py Existing customization changed +26 / −0
35 existing customizations unchanged
  • api.md
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • src/openai/init.py
  • src/openai/_client.py
  • src/openai/resources/audio/transcriptions.py
  • src/openai/resources/audio/translations.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/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/init.py
  • src/openai/resources/webhooks/webhooks.py
  • src/openai/types/init.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/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/tool.py
  • src/openai/types/responses/tool_param.py
  • src/openai/types/webhooks/init.py
  • src/openai/types/websocket_connection_options.py
  • tests/api_resources/test_videos.py

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 32498300373 --repo openai/openai-python \
  --name castiron-custom-code-32498300373-1 --dir /tmp/castiron-custom-code-32498300373-1
git apply --stat /tmp/castiron-custom-code-32498300373-1/custom-code.patch
cat /tmp/castiron-custom-code-32498300373-1/custom-code.patch

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

git fetch --no-tags origin a002ef3c7d2276fb63deeea58d920d87da61b1e5 c708fbd05d196493874aed3970c314792442b0c8
python3 scripts/castiron/custom_code_report.py report \
  --base a002ef3c7d2276fb63deeea58d920d87da61b1e5 \
  --head c708fbd05d196493874aed3970c314792442b0c8 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-c708fbd05d19
cat /tmp/castiron-custom-code-c708fbd05d19/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

@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: 18d4b16498

ℹ️ 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 tests/lib/test_file_processing.py Outdated
Comment on lines +90 to +91
@pytest.mark.parametrize("status", ["processed", "error", "deleted"])
@pytest.mark.parametrize("max_wait_seconds", [-1.0, 0.0, 1800.0])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Pare down the exhaustive handwritten polling suite

This 358-line suite adds roughly 80 cases for a 57-line extraction whose behavior is otherwise unchanged, including combinatorial checks for incidental implementation details such as negative and non-finite timeouts, backward wall clocks, and exact internal event ordering. That makes future polling fixes unnecessarily expensive and conflicts with the repository requirement that handwritten tests remain small; retain focused sync/async coverage for terminal results, polling, and timeout propagation instead.

AGENTS.md reference: AGENTS.md:L5-L8

Useful? React with 👍 / 👎.

@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.

Please address the existing discussion on the new handwritten test suite: repository AGENTS.md requires handwritten tests to remain small, but this behavior-preserving extraction adds a 358-line suite with broad combinations that lock in incidental clock, timeout, and event-order details. Keep focused sync/async coverage for terminal states, polling, timeout, cancellation, and error propagation. Treat this as a maintainability issue, not a runtime/security defect; no duplicate inline thread needed.

@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.

Thanks for addressing the maintainability feedback. The handwritten polling suite is now a focused 87 lines covering terminal states, polling, timeout boundaries, transport errors, and cancellation across sync/async paths; the production extraction remains behavior- and API-preserving. Looks good.

@apcha-oai
apcha-oai added this pull request to the merge queue Aug 21, 2026
@apcha-oai
apcha-oai removed this pull request from the merge queue due to a manual request Aug 21, 2026
@apcha-oai
apcha-oai enabled auto-merge August 21, 2026 15:35
@apcha-oai
apcha-oai added this pull request to the merge queue Aug 21, 2026
Merged via the queue into main with commit 5f20c51 Aug 21, 2026
25 checks passed
@apcha-oai
apcha-oai deleted the apcha/castiron-python-file-processing-public branch August 21, 2026 15:39
@openai-sdks openai-sdks Bot mentioned this pull request Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

custom-code-burndown Behavior-preserving cleanup of custom code in generated SDK files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants