Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openai/openai-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.16.1
Choose a base ref
...
head repository: openai/openai-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.16.2
Choose a head ref
  • 2 commits
  • 9 files changed
  • 3 contributors

Commits on Sep 18, 2026

  1. fix(parsing): drop TextFormatT parameterization in parse_response to …

    …fix memory leak (#3084) (#3088)
    
    ## Why
    
    Closes #3084.
    
    `AsyncResponses.parse()` leaks pydantic schema objects without bound.
    The issue author captured it with a flame graph — every call allocates a
    fresh Rust-backed `SchemaValidator`/`SchemaSerializer` that never gets
    freed.
    
    ## Root cause
    
    `parse_response()` called `construct_type_unchecked` with three types
    parameterized by a free module-level `TypeVar`:
    
    ```python
    construct_type_unchecked(type_=ParsedResponseOutputText[TextFormatT], ...)
    construct_type_unchecked(type_=ParsedResponseOutputMessage[TextFormatT], ...)
    construct_type_unchecked(type_=ParsedResponse[TextFormatT], ...)
    ```
    
    Pydantic can't resolve a free `TypeVar`, so
    `model_rebuild(raise_errors=False)` returns `False`.
    `MockCoreSchema._built_memo` only caches the rebuilt schema when
    `model_rebuild` succeeds — so the cache is never populated and a new
    schema is allocated on every call.
    
    ## Fix
    
    Drop the `[TextFormatT]` parameterization at the `type_=` argument. At
    runtime Python's generics are erased anyway — the constructed object's
    type is identical either way. Only the pydantic schema rebuild path
    differs:
    
    | | Before | After |
    |---|---|---|
    | `type_` arg | `ParsedResponse[TextFormatT]` | `ParsedResponse` |
    | `model_rebuild` | always returns `False` | succeeds |
    | `_built_memo` | never populated | populated once, reused |
    | Per-call allocation | heavy Rust objects | cache hit |
    
    This is exactly what the issue author diagnosed.
    
    ## Verification
    
    - Ran the existing `tests/lib/responses/test_responses.py` suite
    locally: **5/5 passing** — no functional regression.
    - The change is purely about schema caching behavior. Callers see no
    difference in returned objects or their types.
    
    ## Scope
    
    Minimal — 3 sites in one file, inline comments pointing back to #3084
    for maintainability. No public API change, no test changes needed
    (existing tests cover the parse path).
    
    ---------
    
    Signed-off-by: Mukunda Katta <[email protected]>
    Co-authored-by: Marcus Wood <[email protected]>
    MukundaKatta and marcuswood-oai authored Sep 18, 2026
    Configuration menu
    Copy the full SHA
    009b7f6 View commit details
    Browse the repository at this point in the history
  2. release: 3.16.2 (#3903)

    Automated Release PR
    ---
    
    
    ##
    [3.16.2](v3.16.1...v3.16.2)
    (2026-09-18)
    
    
    ### Bug Fixes
    
    * **parsing:** drop TextFormatT parameterization in parse_response to
    fix memory leak
    ([#3084](#3084))
    ([#3088](#3088))
    ([009b7f6](009b7f6))
    
    ---
    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>
    openai-sdks[bot] authored Sep 18, 2026
    Configuration menu
    Copy the full SHA
    c9c3e69 View commit details
    Browse the repository at this point in the history
Loading