Skip to content

feat(api): Add obfuscation field to ChatCompletionChunk - #3690

Merged
apcha-oai merged 1 commit into
mainfrom
castiron/promotions/pr-48
Aug 19, 2026
Merged

feat(api): Add obfuscation field to ChatCompletionChunk#3690
apcha-oai merged 1 commit into
mainfrom
castiron/promotions/pr-48

Conversation

@apcha-oai

Copy link
Copy Markdown
Contributor

Summary

Introduce an optional obfuscation field on ChatCompletionChunk to support size-normalized streamed chunks. The new field is optional and omitted when stream_options.include_obfuscation is false.

Changes

  • Add ChatCompletionChunk.obfuscation: Optional[str]. This optional string may be included on streamed moderation chunks to normalize chunk sizes; it is returned by default and omitted when stream_options.include_obfuscation is false.

import subprocess
import tempfile
import textwrap
import unittest
@apcha-oai

Copy link
Copy Markdown
Contributor Author

The Castiron custom-code report is available in the successful CI run: open the job summary or download the castiron-custom-code-32303793534-1 artifact for the full report and patch. I checked the public artifact: the generated baseline hash is verified, and it reports 49 existing customizations unchanged plus the three reporting-tool files customized by this PR.

This PR also introduces the automatic comment publisher. GitHub only starts that workflow_run workflow after it reaches the default branch, so the first rollout PR has a report in Actions but no automatic report comment yet. Once merged, subsequent PR runs will publish/update the report comment automatically, including on ordinary branches and drafts. No branch allowlist is required.

@apcha-oai
apcha-oai marked this pull request as ready for review August 19, 2026 21:33
@apcha-oai
apcha-oai requested a review from a team as a code owner August 19, 2026 21:33
@openai-sdks

openai-sdks Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 13.207s for Python SDK PR #3690.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 268ms
tests/chat-completions-create.test.ts ✅ Passed 326ms
tests/chat-completions-stream.test.ts ✅ Passed 181ms
tests/files-content-binary.test.ts ✅ Passed 275ms
tests/files-create-multipart.test.ts ✅ Passed 178ms
tests/files-list-pagination.test.ts ✅ Passed 221ms
tests/initialize-config.test.ts ✅ Passed 236ms
tests/instance-isolation.test.ts ✅ Passed 210ms
tests/models-list.test.ts ✅ Passed 183ms
tests/responses-background-lifecycle.test.ts ✅ Passed 313ms
tests/responses-body-method-errors.test.ts ✅ Passed 536ms
tests/responses-cancel-timeout.test.ts ✅ Passed 271ms
tests/responses-cancel.test.ts ✅ Passed 351ms
tests/responses-compact-retries.test.ts ✅ Passed 386ms
tests/responses-compact.test.ts ✅ Passed 372ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 193ms
tests/responses-create-advanced.test.ts ✅ Passed 409ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.46s
tests/responses-create-errors.test.ts ✅ Passed 240ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 496ms
tests/responses-create-retries.test.ts ✅ Passed 363ms
tests/responses-create-stream-failures.test.ts ✅ Passed 243ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 216ms
tests/responses-create-stream-wire.test.ts ✅ Passed 3.674s
tests/responses-create-stream.test.ts ✅ Passed 322ms
tests/responses-create-terminal-states.test.ts ✅ Passed 358ms
tests/responses-create-timeout.test.ts ✅ Passed 380ms
tests/responses-create.test.ts ✅ Passed 457ms
tests/responses-delete.test.ts ✅ Passed 282ms
tests/responses-input-items-errors.test.ts ✅ Passed 552ms
tests/responses-input-items-list.test.ts ✅ Passed 332ms
tests/responses-input-items-options.test.ts ✅ Passed 445ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 375ms
tests/responses-input-tokens-count.test.ts ✅ Passed 285ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.83s
tests/responses-not-found-errors.test.ts ✅ Passed 441ms
tests/responses-parse.test.ts ✅ Passed 536ms
tests/responses-retrieve-retries.test.ts ✅ Passed 341ms
tests/responses-retrieve.test.ts ✅ Passed 343ms
tests/responses-stored-method-errors.test.ts ✅ Passed 747ms
tests/retry-behavior.test.ts ✅ Passed 3.174s
tests/sdk-error-shape.test.ts ✅ Passed 504ms

View OkTest run #32308296284

SDK merge (a2076610aa39) · head (36bb83bb3229) · base (2598d530cf68) · OkTest (2b1bdfd25e98)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8eb167039c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


- name: Validate the codegen hash and report custom code
env:
GH_TOKEN: ${{ github.token }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the token from the PR-controlled report step

For fork-originated pull requests, this job checks out the contributor's head and then executes their version of scripts/castiron/custom_code_report.py while GH_TOKEN is present in its environment. A contributor can therefore modify that script to exfiltrate the short-lived repository credential or exercise its contents: read permissions; the token must not be exposed to code taken from the untrusted PR checkout.

AGENTS.md reference: AGENTS.md:L25-L27

Useful? React with 👍 / 👎.

Comment on lines +15 to +16
env:
REPORTER_SHA256: 73ecd6290e9803b0d0a93af4ca4dccdbf8648cbd5c0cce51ea65fce28c7da79f

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Verify the reporter against a trusted checksum

Because this checksum and the reporter are both loaded from the pull-request head, a contributor can modify custom_code_report.py to fabricate a clean status: ok report and update this value so the verification step still passes. The separate trusted publisher then renders that fabricated artifact as a github-actions[bot] comment, so the custom-code check cannot be trusted to detect deliberate customizations; the expected checksum or executable must come from outside the PR-controlled checkout.

Useful? React with 👍 / 👎.

Comment thread scripts/castiron/custom_code_report.py
Comment on lines +5 to +6
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rerun the report when the pull request base changes

When a pull request is retargeted to another base branch, GitHub emits an edited activity rather than any of the activity types listed here. The head SHA can remain unchanged while its merge base and generated baseline change, so no replacement report is produced and the existing bot comment continues to describe the old base; include the base-change event and recompute the report.

Useful? React with 👍 / 👎.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent two-pass review found one Medium compatibility bug: the new stream-chunk-only obfuscation field propagates into completion snapshots and final parsed completions. Preserve it on raw chunks but exclude it when creating completion snapshots.

Present on the moderation chunk when moderated completions are requested.
"""

obfuscation: Optional[str] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] Keep stream-only obfuscation out of final completion objects. Adding this field makes _convert_initial_chunk_into_snapshot copy obfuscation via chunk.to_dict() into ParsedChatCompletionSnapshot; Pydantic allows the extra field, and final parsing carries it into returned completions and their serialized output. That violates the non-streaming completion contract and exposes padding outside raw chunks. Exclude obfuscation while constructing snapshots and cover both the intermediate snapshot and public final completion.

Castiron-Internal-PR: openai/openai-python-internal#48
Castiron-Source-SHA: 1da516e7483ea031e228db8338990b552edbd3a1
Castiron-Public-Base-SHA: 2598d53
@apcha-oai
apcha-oai force-pushed the castiron/promotions/pr-48 branch from 8eb1670 to 36bb83b Compare August 19, 2026 22:19

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent two-pass re-review confirms the prior chunk-only obfuscation leak is fixed: raw chunks retain their padding, copied snapshots and final completions omit it, and regression tests cover absent, empty, and populated values plus serialization. No unrelated runtime changes or new suppressions; substantive CI/CodeQL pass.

@apcha-oai
apcha-oai added this pull request to the merge queue Aug 19, 2026
Merged via the queue into main with commit c7d8e1d Aug 19, 2026
22 checks passed
@apcha-oai
apcha-oai deleted the castiron/promotions/pr-48 branch August 19, 2026 22:41
@openai-sdks openai-sdks Bot mentioned this pull request Aug 19, 2026
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