Skip to content

[apply_patch] freeform apply_patch tool - #2576

Merged
dylan-hurd-oai merged 7 commits into
mainfrom
dh--apply-patch-freeform
Aug 22, 2025
Merged

dylan-hurd-oai merged 7 commits into
mainfrom
dh--apply-patch-freeform

Conversation

@dylan-hurd-oai

Copy link
Copy Markdown
Contributor

Summary

GPT-5 introduced the concept of custom tools, which allow the model to send a raw string result back, simplifying json-escape issues. We are migrating gpt-5 to use this by default.

However, gpt-oss models do not support custom tools, only normal functions. So we keep both tool definitions, and provide whichever one the model family supports.

Testing

  • Tested locally with various models
  • Unit tests pass

@github-actions

Copy link
Copy Markdown
Contributor

Summary

  • Adds “custom” freeform tool support for apply_patch and wires streaming/handling of custom tool calls; replaces uses_apply_patch_tool with apply_patch_tool_type across config/model family.
  • Updates tests and logging; moves JSON vs freeform tool definitions into a new tool_apply_patch module.

Review

  • This is a cohesive refactor enabling GPT custom tools with a clear separation of concerns. A few small clarifications and polish items would improve maintainability.

  • codex-rs/core/src/openai_tools.rs @@ -67,0 +87,12

    • Consider documenting why include_apply_patch_tool defaults to Freeform when family is None. If this is a temporary default, a comment or TODO could avoid surprises.
  • codex-rs/core/src/codex.rs @@ -2026,0 +2050,43

    • info!("CustomToolCall: {name} {input}"): logging entire patch contents can be very large/noisy. Suggest truncating or summarizing the input (e.g., first 200 chars).
  • codex-rs/core/src/client_common.rs @@ -51,2 +51,2

    • Comment “(4.1)” might be confusing without context; suggest clarifying or removing the version reference.
  • codex-rs/core/src/tool_apply_patch.rs @@ -0,0 +1,145

    • The Lark grammar is a nice touch. Two suggestions:
      • Enforce relative paths (the older JSON description warned “NEVER ABSOLUTE”). Add a note or validation test for that.
      • Consider covering empty lines/trailing spaces in add_line/change_line cases with tests.
  • codex-rs/core/src/chat_completions.rs @@ -104,0 +105,27

    • Mapping to assistant/tool messages for CustomToolCall/CustomToolCallOutput looks correct; consider adding a focused unit test to prevent regressions.
  • codex-rs/core/src/model_family.rs @@ -98 +101

    • Nice switch to Option<ApplyPatchToolType>; good use of enums. Ensure any downstream serialization expectations are adjusted (looks addressed in ToolsConfig).
  • codex-rs/exec/tests/apply_patch.rs @@ -60 +60, @@ -86 +86

    • Good update to pass raw patch strings for the custom tool. Maybe add a failing case (invalid grammar) to exercise error paths.

Overall, looks solid and thoughtfully modularized. Please ensure just fmt, just fix -p codex-core, and cargo test -p codex-core run clean; given changes in core/common areas, also consider cargo test --all-features.


View workflow run

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

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, or 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 fix this CI failure" or "@codex address that feedback".

Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/core/src/codex.rs Resolved
Comment thread codex-rs/core/src/models.rs Resolved
Comment thread codex-rs/core/src/openai_tools.rs Resolved
SandboxPolicy::ReadOnly,
true,
model_family.uses_apply_patch_tool,
false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In a follow up, perhaps ToolsConfig::new() should take a struct instead of these args because it's not self-documenting this way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed - I have a separate branch in progress that simplifies this so we don't end up with an infinite list of tool booleans floating around our config

Ok(())
}

#[cfg(not(target_os = "windows"))]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why doesn't this test work on Windows?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These tests seem to hang indefinitely on windows for reasons I can't quite figure out. But none of our apply_patch tool logic actually changes this package, the tests just exist in here for convenience (being able to actually invoke the apply_patch binary trick). We should fix but haven't had a chance to investigate deeply yet.

@dylan-hurd-oai
dylan-hurd-oai force-pushed the dh--apply-patch-freeform branch from 25999c1 to 3264e8a Compare August 22, 2025 20:10
@dylan-hurd-oai
dylan-hurd-oai force-pushed the dh--apply-patch-freeform branch from 3264e8a to f775e83 Compare August 22, 2025 20:23
@dylan-hurd-oai
dylan-hurd-oai merged commit 236c4f7 into main Aug 22, 2025
@dylan-hurd-oai
dylan-hurd-oai deleted the dh--apply-patch-freeform branch August 22, 2025 20:42
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants