Skip to content

feat(sdk): expose headless patch generation - #774

Open
rohanpoudel2 wants to merge 17 commits into
openai:mainfrom
rohanpoudel2:feat/sdk-headless-patch
Open

feat(sdk): expose headless patch generation#774
rohanpoudel2 wants to merge 17 commits into
openai:mainfrom
rohanpoudel2:feat/sdk-headless-patch

Conversation

@rohanpoudel2

@rohanpoudel2 rohanpoudel2 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #681.

Add CodexSecurity.patch({ repositoryPath, finding }) so applications can generate and verify a patch through the TypeScript SDK. The supplied workspace is mutable; callers retain control of the authoritative diff, approval, commit creation, and delivery.

Changes

  • Export PatchOptions and a discriminated PatchResult with verified, no_change, blocked, and failed outcomes, verification or failure details, relative changed-file metadata, thread identity, and estimated cost.
  • Reuse the existing remediation skill, runtime, authentication, model configuration, cancellation, and observer contracts. Finding strings are literal text; objects are serialized as JSON.
  • Pin the supplied workspace as an untrusted project through raw Codex overrides before thread startup. Repository-local configuration and MCP servers stay disabled; sandboxed commands use workspace writes with approvals, network access, and web search disabled.
  • Merge command-authentication provider overrides with the patch trust overrides. Regression coverage includes both direct and profile-selected providers, including provider IDs containing dots.
  • Reuse the repository's public reasoning-effort type so generated patch declarations do not pull in the underlying SDK's missing MCP type dependency.
  • Document the SDK contract and verify its installed-package types and runtime export. Preserve the newer package-consumer checks from main when resolving merge conflicts.

Authentication defaults to auto; model and reasoning effort inherit constructor configuration unless overridden per call. No public CLI commands, flags, environment variables, accepted values, or defaults change.

Testing

Validation uses Node 24.11.1, pnpm 11.19.0, and Bun 1.3.14.

  • Focused patch, credential, and native CLI trust tests with seed 12345: 30 passed, 0 failed. Both new provider cases failed before the fix and pass afterward.
  • pnpm run types and pnpm run format: passed.
  • pnpm run test:mcp: all 23 test files passed.
  • pnpm pack and archive inspection: passed, 415 entries. The built SDK patch() export check passed.
  • Strict NodeNext compilation of the package-consumer fixture: passed. It initially exposed a missing MCP dependency through the new public type; reusing the existing public reasoning-effort type fixes that failure without adding dependencies.
  • Installed-package smoke was attempted but npm returned ETARGET for the repository's existing @openai/codex@0.149.1 pin. This is not counted as passing validation.
  • pnpm run test --seed 12345 and pnpm run test: both passed, each with 2,421 passed, 43 skipped, and 0 failed tests.
  • Automated code review reported no major issues on 98b9749; its Codex Security Review check passed. Required platform CI still reports action_required and needs maintainer authorization.
  • Portable plugin source compatibility, Ruff lint, and Ruff formatting checks: passed.
  • git diff --check: passed.

Risk and rollout

This adds a public SDK method and types. Existing CLI behavior is unchanged. Failures or cancellation can leave partial workspace edits; callers should use a controlled workspace and inspect or discard its diff. changedFiles is model-reported metadata, not an authoritative diff. Host-configured tools retain their existing host permissions.

Patch-risk assessment remains follow-up SDK work from #681. Commit creation, publication, pull-request delivery, and finding closure remain caller-owned operations.

Public disclosure review

  • No customer, partner, prospect, or user identities, data, or identifying details are included.
  • No credentials, personal data, private source, scan findings, or nonpublic links or tickets are included.
  • I reviewed the branch name, title, description, commits, changes, comments, logs, screenshots, attachments, and links for public disclosure.

The remaining attestation needs maintainer cleanup: an existing automated review comment includes an access-restricted report link. Please remove that link before checking the attestation.

@github-actions github-actions Bot added the enhancement New feature or request label Sep 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T22:26:38.473293Z 98b9749 Manual request
🔒 Security Review Completed 2026-09-05T22:24:38.144870Z 98b9749 New commits

Security findings

Blocking findings (3)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: e071faa9b1

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread sdk/typescript/src/api.ts

@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: 08cdfc9323

ℹ️ 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".

Comment thread sdk/typescript/src/api.ts Outdated

@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: 8f69987795

ℹ️ 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".

Comment thread sdk/typescript/README.md Outdated
Comment thread sdk/typescript/src/api.ts Outdated

@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: 9825b0b7a3

ℹ️ 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".

Comment thread sdk/typescript/src/api.ts Outdated

@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: 55cb677e2a

ℹ️ 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".

Comment thread sdk/typescript/src/api.ts Outdated

@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: e4e77a11af

ℹ️ 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".

Comment thread sdk/typescript/src/api.ts Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Provided git ref 1d9c787670e152f7b0db572a7d6a1b8b96031716 does not exist
ℹ️ 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".

@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: 1d9c787670

ℹ️ 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".

Comment thread sdk/typescript/src/api.ts Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 42d5d2eaf9

ℹ️ 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".

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 42d5d2eaf9

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread sdk/typescript/src/api.ts Outdated
@strbbrn

strbbrn commented Sep 1, 2026

Copy link
Copy Markdown

This API now matches approval-gated remediation use case: patch an isolated workspace, return structured verification, and leave authoritative diff capture, approval, commit creation, PR delivery, and finding closure to the caller.

Before adoption, we need the remaining project-trust issue resolved. An SDK patch operation must fail closed regardless of system-level project_root_markers; an unknown disposable workspace must not activate repository-local MCP servers or other trusted project configuration.

For an embedding-safe default, please consider disabling repository MCP servers for patch() unless the caller explicitly opts in. This would be safer and simpler than relying on exact trust reconstruction across every Codex configuration layer.

assessPatchRisk was included in issue #681's suggested contract but is excluded from this initial API. That is not a blocker for the core patch method, but please track it as a follow-up SDK capability.

@strbbrn

strbbrn commented Sep 1, 2026

Copy link
Copy Markdown

I checked the structured finding path. Object findings are passed through jsonForPrompt() and therefore serialized as JSON text in the Codex turn; this is functionally correct because the thread input is a text prompt, and the tests verify both literal-text and object findings.

One non-blocking SDK contract improvement would help embedding applications: PatchOptions.finding is currently typed as string | object, while the public contract promises a JSON-serializable object. The object type also permits circular values, BigInt, and custom toJSON() results that can fail or disappear only when JSON.stringify() runs.

Please consider exporting a reusable JsonValue/JsonObject type (shared with validate() where appropriate), converting serialization failures into a clear CodexSecurityError, and applying a documented payload-size limit consistent with the CLI. We will pass a canonical finding object containing taxonomy, locations, root cause, code evidence, attack path, remediation guidance, and validation context, so preserving a stable structured-input contract is useful. This is not a blocker for the core patch() API.

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 7a0aaad402

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread sdk/typescript/src/api.ts Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: d69551946b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@sylvesterkaczmarek sylvesterkaczmarek 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.

patch() appears to drop command-authenticated custom provider configuration when it adds the trust overrides.

#createSessionCodex() first conditionally supplies configOverrides: modelProviderConfigOverride(sessionConfig) when commandAuth is true. That raw override is important because the function also deletes model_providers from the structured SDK config. But the later spread for the new configOverrides argument writes the same property again, so patch() replaces the provider override with only project_root_markers=[] and the untrusted-project entry.

A configuration using model_providers.<id>.auth can therefore work for existing SDK operations but lose the provider definition/auth command specifically in patch().

Could these arrays be merged instead of assigning configOverrides twice? I would add a patch test with a command-auth provider and assert that the final Codex options contain both the serialized model_providers=... override and the two trust overrides.

@rohanpoudel2

rohanpoudel2 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the provider-authentication review in c78412e. Provider configuration and patch trust overrides now share one ordered array. Tests cover both direct and profile-selected command authentication, preserve dotted provider IDs, and assert that both trust overrides remain present. Both new cases failed before the fix and pass afterward; the focused patch, credential, and native trust run passes all 30 tests.

The branch is updated with main, including the newer package-consumer checks. Follow-up 98b9749 fixes a strict consumer compilation failure by reusing the existing public reasoning-effort type instead of exposing the underlying SDK declarations. Typechecking, strict NodeNext consumer compilation, formatting, all 23 MCP test files, portable source checks, and package build/archive inspection pass. Both full Bun runs (seed 12345 and default randomized order) pass with 2,421 passed, 43 skipped, and 0 failed tests each. Installed-package smoke remains blocked by npm's ETARGET for the existing Codex dependency pin.

Patch-risk assessment is recorded as follow-up SDK work. Finding input remains consistent with validate(); no new payload-size restriction or CLI surface is introduced.

@mldangelo-oai, could you review the updated implementation and authorize the fork's CI workflows? The older automated comment identified in the disclosure section also needs its access-restricted report link removed. That attestation is intentionally left unchecked until cleanup.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: c78412e3e2

ℹ️ 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".

@rohanpoudel2

Copy link
Copy Markdown
Contributor Author

The current head is 98b9749. It includes the provider-authentication fix and the follow-up that keeps the public patch declarations self-contained. Strict NodeNext consumer compilation now passes, as do the full seeded SDK suite (2,421 passed, 43 skipped, 0 failed), all 23 MCP test files, formatting, typechecking, portable source checks, and the rebuilt 415-entry package archive inspection.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 98b974926f

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: expose headless patch generation through the TypeScript SDK

3 participants