mirror of
https://github.com/openai/codex.git
synced 2026-04-29 00:55:38 +00:00
2.7 KiB
2.7 KiB
PR #2186: [apply-patch] Support applypatch command string
- URL: https://github.com/openai/codex/pull/2186
- Author: dylan-hurd-oai
- Created: 2025-08-11 17:50:25 UTC
- Updated: 2025-08-11 21:32:24 UTC
- Changes: +27/-1, Files changed: 1, Commits: 2
Description
Summary
GPT-OSS and gpt-5-mini have training artifacts that cause the models to occasionally use applypatch instead of apply_patch. I think long-term we'll want to provide apply_patch as a first class tool, but for now let's silently handle this case to avoid hurting model performance
Testing
- Added unit test
Full Diff
diff --git a/codex-rs/apply-patch/src/lib.rs b/codex-rs/apply-patch/src/lib.rs
index 61b1b68f9e..262d219d6d 100644
--- a/codex-rs/apply-patch/src/lib.rs
+++ b/codex-rs/apply-patch/src/lib.rs
@@ -82,8 +82,9 @@ pub struct ApplyPatchArgs {
}
pub fn maybe_parse_apply_patch(argv: &[String]) -> MaybeApplyPatch {
+ const APPLY_PATCH_COMMANDS: [&str; 2] = ["apply_patch", "applypatch"];
match argv {
- [cmd, body] if cmd == "apply_patch" => match parse_patch(body) {
+ [cmd, body] if APPLY_PATCH_COMMANDS.contains(&cmd.as_str()) => match parse_patch(body) {
Ok(source) => MaybeApplyPatch::Body(source),
Err(e) => MaybeApplyPatch::PatchParseError(e),
},
@@ -722,6 +723,31 @@ mod tests {
}
}
+ #[test]
+ fn test_literal_applypatch() {
+ let args = strs_to_strings(&[
+ "applypatch",
+ r#"*** Begin Patch
+*** Add File: foo
++hi
+*** End Patch
+"#,
+ ]);
+
+ match maybe_parse_apply_patch(&args) {
+ MaybeApplyPatch::Body(ApplyPatchArgs { hunks, patch: _ }) => {
+ assert_eq!(
+ hunks,
+ vec![Hunk::AddFile {
+ path: PathBuf::from("foo"),
+ contents: "hi\n".to_string()
+ }]
+ );
+ }
+ result => panic!("expected MaybeApplyPatch::Body got {result:?}"),
+ }
+ }
+
#[test]
fn test_heredoc() {
let args = strs_to_strings(&[
Review Comments
codex-rs/apply-patch/src/lib.rs
- Created: 2025-08-11 21:32:24 UTC | Link: https://github.com/openai/codex/pull/2186#discussion_r2268071503
@@ -82,8 +82,9 @@ pub struct ApplyPatchArgs {
}
pub fn maybe_parse_apply_patch(argv: &[String]) -> MaybeApplyPatch {
+ const APPLY_PATCH_COMMANDS: [&str; 2] = ["apply_patch", "applypatch"];
This should have a comment (and ideally to link to a GitHub issue or something with more information) that explains why we are accepting
applypatch. Ideally, it would also provide guidance about criteria for when we should stop recognizingapplypatch.