[codex] Skip parsing incomplete response text
Summary
- avoid structured-output parsing for response message text unless the message is completed
- preserve incomplete output text while leaving
parsedasNone - add a regression test for incomplete JSON output in
parse_response
Fixes #2486.
Root cause
parse_response attempted to parse every message.output_text item with the requested structured output type. For incomplete responses, that text can contain partial JSON, so Pydantic raises a validation error instead of returning the incomplete response payload.
Validation
PYTHONPATH=src uv run --frozen --python 3.9 --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest tests/lib/responses/test_responses.py::test_parse_incomplete_output_text -q -o addopts=""(1 passed)env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy PYTHONPATH=src uv run --frozen --python 3.9 --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest tests/lib/responses/test_responses.py -q -o addopts=""(8 passed)uv run --frozen --python 3.9 --with ruff ruff format --check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.pyuv run --frozen --python 3.9 --with ruff ruff check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.pyuv run --frozen --python 3.9 --with pyright==1.1.399 --with pytest --with pytest-asyncio --with respx --with inline-snapshot pyright src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py(0 errors)
Rebased this fix onto current main (f16fbbd) and resolved the test insertion conflict while preserving the upstream program-item coverage. The refreshed head is 387108b.
Validation on Python 3.9: focused regression 1 passed, full tests/lib/responses/test_responses.py 8 passed, Ruff format/check clean, Pyright 0 errors, and the incomplete-JSON reproduction now returns the response with parsed=None.