Skip to content

Fix false results for whitespace-padded true responses - #3854

Merged
marcuswood-oai merged 2 commits into
openai:mainfrom
1fanwang:1fannnw/fix-boolean-response-whitespace
Sep 29, 2026
Merged

marcuswood-oai merged 2 commits into
openai:mainfrom
1fanwang:1fannnw/fix-boolean-response-whitespace

Conversation

@1fanwang

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

Changes being requested

A JSON true with a trailing newline is parsed as False. Both response parsers now trim whitespace and keep case-insensitive parsing.

Additional context & links

# Scenario Command Result
1 Local file download Program below true\n: False before, True after
Reproducer and raw logs
PYTHONPATH=src python - <<'PY'
from http import HTTPStatus
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from threading import Thread

import httpx2
from openai import OpenAI

FILES: dict[str, bytes] = {"file_false": b"false\n", "file_true": b"true\n"}

class Handler(BaseHTTPRequestHandler):
    def do_GET(self) -> None:
        body = FILES[self.path.split("/")[3]]
        self.send_response(HTTPStatus.OK)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)

    def log_message(self, format: str, *args: object) -> None:
        pass

server = ThreadingHTTPServer(server_address=("127.0.0.1", 0), RequestHandlerClass=Handler)
thread = Thread(target=server.serve_forever)
thread.start()
try:
    with OpenAI(api_key="local", base_url=f"http://127.0.0.1:{server.server_port}/v1",
                http_client=httpx2.Client(trust_env=False)) as client:
        for file_id in FILES:
            raw = client.files.with_raw_response.content(file_id=file_id)
            with client.files.with_streaming_response.content(file_id=file_id) as streamed:
                values = (raw.parse(to=bool), streamed.parse(to=bool))
            print(file_id, raw.status_code, values, flush=True)
            expected = file_id == "file_true"
            assert values == (expected, expected), "Incorrect boolean result"
finally:
    server.shutdown()
    server.server_close()
    thread.join()
PY

Before:

file_false 200 (False, False)
file_true 200 (False, False)
Traceback (most recent call last):
  File "<stdin>", line 34, in <module>
AssertionError: Incorrect boolean result
exit=1

After:

file_false 200 (False, False)
file_true 200 (True, True)
exit=0

Both parser modules hit the same existing AttributeError: module 'rich' has no attribute 'console' in the display helper before and after this change.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang requested a review from a team as a code owner September 14, 2026 10:49
@github-actions

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

48 mixed files remain; 0 existing customizations changed.

Compared 49e436684751 → 0015fc6848bd. Generated baselines verified.

48 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/agents/sessions/sessions.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/files.py
  • src/openai/resources/live/forks.py
  • src/openai/resources/live/live.py
  • src/openai/resources/live/sideband.py
  • src/openai/resources/realtime/api.md
  • 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/beta/agent_session_message.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/realtime/conversation_item_input_audio_transcription_delta_event.py
  • src/openai/types/realtime/realtime_error_event.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/responses_client_event.py
  • src/openai/types/responses/responses_client_event_param.py

8 more in the full report.

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

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

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

@marcuswood-oai
marcuswood-oai added this pull request to the merge queue Sep 29, 2026
Merged via the queue into openai:main with commit 5a4bb96 Sep 29, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants