Tolerate missing Responses output when aggregating text#3315
Conversation
671245e to
2666857
Compare
|
Related downstream canonical Hermes PR that motivated and validates this SDK invariant issue: NousResearch/hermes-agent#32884 That Hermes PR recovers already-streamed Codex output when the final Responses object has This SDK PR is narrower: it prevents the SDK parser/accessor layer from leaking the raw Python iteration error for a Responses object with missing/null |
|
Update on downstream status: the canonical Hermes-side fix was merged via NousResearch/hermes-agent#32963, while the earlier linked #32884 was closed as a duplicate after the fix was cherry-picked/merged. Current downstream evidence link: NousResearch/hermes-agent#32963 That merged PR still demonstrates the same SDK-layer invariant issue: Hermes has to recover from streamed Codex Responses where the terminal/final Responses object has missing/null or empty So the relationship is now:
|
|
Duplicate check update: I compared the newer duplicate PRs #3316 and #3317.
#3315 already includes the parser guard/regression and additionally covers |
Responses objects can be constructed from malformed or partial payloads where output is None. Avoid leaking a raw Python TypeError from parser and output_text convenience paths; treat a missing output list as empty so callers receive stable SDK behavior.\n\nConstraint: observed downstream Hermes/Codex integrations received terminal Responses snapshots with output=None.\nRejected: Leaving applications to catch TypeError | the SDK owns the Responses object invariant and can handle the missing list at the iteration boundary.\nConfidence: medium\nScope-risk: narrow\nDirective: If maintainers prefer a typed validation error, preserve the invariant that raw 'NoneType' iteration never escapes.\nTested: uv run pytest -q tests/lib/responses/test_responses.py -> 7 passed\nNot-tested: Full repository test suite
2666857 to
eed893c
Compare
|
Update: the automated Codex review on duplicate PRs #3316/#3317 caught one useful missing behavior, and I pulled it into this PR. New coverage/fix in #3315:
Validation: So #3315 now covers:
Thanks to the review signal on #3316/#3317 for pointing out the stream-state data-loss risk. |
|
Duplicate check update: new PR #3320 is another minimal #3315 already includes the parser guard plus |
Summary
Guard Responses parsing and the
Response.output_textconvenience accessor when aResponseinstance hasoutput=None.Today these paths can leak a raw Python error:
Observed iteration sites:
openai/lib/_parsing/_responses.py:for output in response.outputopenai/types/responses/response.py:for output in self.outputOntology / boundary
outputis absent/null on a Responses object.output_textis useful, but they should not need to reverse-engineer aNoneTypeiterable failure.This PR takes the minimal compatibility-preserving approach: treat missing output as an empty list at the iteration boundary.
If maintainers prefer a stricter policy, the alternative would be a typed validation/API-response error that identifies
response.output; either is preferable to leaking rawTypeError.Verification