fix(gateway): guard Codex null output and provider SDK errors - #33103
Closed
trymhaak wants to merge 2 commits into
Closed
fix(gateway): guard Codex null output and provider SDK errors#33103trymhaak wants to merge 2 commits into
trymhaak wants to merge 2 commits into
Conversation
chatgpt.com's backend-api/codex emits early streaming snapshots where ``response.output`` is ``null``. openai 2.24.0 iterates that field without a None-guard at lib/_parsing/_responses.py:61 (called from lib/streaming/responses/_responses.py:360 via accumulate_event), which raises ``TypeError: 'NoneType' object is not iterable`` mid ``for event in stream`` — aborting every codex turn before our existing guards in run_codex_stream / _normalize_codex_response can normalize the snapshot. We can't move the openai pin (pyproject documents that other releases segfault pydantic-core), so install a surgical, idempotent shim at codex_runtime import time. The shim wraps ``parse_response`` in BOTH namespaces it's bound in (origin + the streaming module's re-import) and coerces ``response.output`` to ``[]`` before delegating, leaving all other behaviour untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When openai 2.24.0's accumulate_event iterates a streaming snapshot
whose response.output is null, it raises a bare
``TypeError("'NoneType' object is not iterable")`` mid-``for event in
stream``. Commit a0c90a190 installs an SDK-level shim to prevent the
crash, but the agent's outer retry loop still needs to be hardened
against future provider/SDK leaks of the same shape: after max retries
the user-facing reply was ``"API call failed after 5 retries: 'NoneType'
object is not iterable"`` — gibberish in a Telegram bubble and worse on
CLI/Slack/web paths that skip the Telegram-only sanitizer.
Wrap bare TypeError/AttributeError whose ``str(error)`` matches Python's
stock ``"'<TypeName>' object …"`` shape (a signature that real provider
HTTP bodies do not emit) in a ``Provider SDK streaming bug`` envelope
inside ``AIAgent._summarize_api_error``. Only fires when
``status_code`` is unset, so errors that carry real provider HTTP
context still flow through the existing body/HTTP fallback paths
unchanged.
Extend ``_gateway_provider_error_reply`` with a targeted Telegram reply
for the new envelope so users get "malformed streaming response" rather
than the generic provider-failed-after-retries fallback. The composed
final reply ``"API call failed after N retries: Provider SDK streaming
bug …"`` still triggers ``_looks_like_gateway_provider_error``'s shape
regex, so the Telegram sanitizer remains the second line of defence.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Closing as obsolete. PR #33042 (merged commit cb38ce2) removes the OpenAI SDK's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Response.output=Nonesnapshots by normalizing the value beforeparse_responseconsumes it.TypeError/AttributeErrorfailures into a user-visible provider error envelope instead of letting raw Python exceptions surface in Telegram.Test plan
python -m pytest tests/run_agent/test_codex_stream_null_output_guard.py tests/run_agent/test_provider_sdk_error_envelope.py -q -o 'addopts='Operational notes
origin/mainand cherry-picked from the earlier local incident branch.