Skip to content

fix: improve apply_patch command detection for path prefixes and variants - #9498

Closed
yuvrajangadsingh wants to merge 13 commits into
openai:mainfrom
yuvrajangadsingh:fix/apply-patch-detection
Closed

yuvrajangadsingh wants to merge 13 commits into
openai:mainfrom
yuvrajangadsingh:fix/apply-patch-detection

Conversation

@yuvrajangadsingh

Copy link
Copy Markdown
Contributor

Summary

Fixes #2235

The apply_patch command detection was failing for certain edge cases reported by users:

  • /usr/bin/apply_patch (absolute path prefix)
  • ./apply_patch (relative path prefix)
  • apply-patch (hyphenated variant)

Changes

apply-patch/src/invocation.rs

  • Added is_apply_patch_command() helper that extracts the filename from path-prefixed commands
  • Added apply-patch to the APPLY_PATCH_COMMANDS array
  • Updated Tree-sitter query to match apply-patch in heredoc scripts
  • Added 5 new tests covering the edge cases

arg0/src/lib.rs

  • Added HYPHENATED_APPLY_PATCH_ARG0 constant
  • Updated arg0 dispatch to handle apply-patch invocations
  • Added symlink creation for apply-patch in PATH

Test plan

  • All 54 existing tests pass
  • 5 new tests for edge cases pass
  • Clippy clean

…ants

- Add is_apply_patch_command() helper to extract filename from paths
  (handles /usr/bin/apply_patch, ./apply_patch)
- Add apply-patch (hyphenated) to recognized command variants
- Update Tree-sitter query to match apply-patch in heredoc scripts
- Add symlink for apply-patch in PATH setup (arg0/src/lib.rs)
- Add 5 new tests for edge cases

Fixes openai#2235
@etraut-openai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

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

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

@yuvrajangadsingh

Copy link
Copy Markdown
Contributor Author

Hi @etraut-openai, this PR has been open for a couple weeks. Would you be able to take a look when you have a chance? It improves the apply_patch command detection to handle path prefixes and variants.

@yuvrajangadsingh

Copy link
Copy Markdown
Contributor Author

@bolinfest Since you commented on issue #2235, would you mind taking a look at this fix as well?

@bolinfest

Copy link
Copy Markdown
Collaborator

While this has historically been a problem (certainly when #2235 was originally opened), reports have died down considerably. Accepting this change would paper over errors and potentially result in incorrect behavior if, for some reason, you had your own /usr/bin/apply_patch that you wanted the model to use.

We have also refined the custom apply_patch tool (originally introduced in #2576, I believe), reducing the reliance on the CLI, which also appears to be helping.

@bolinfest

Copy link
Copy Markdown
Collaborator

As such, thank you for your submission, but we are not going to take this solution.

@bolinfest bolinfest closed this Jan 30, 2026
@yuvrajangadsingh
yuvrajangadsingh deleted the fix/apply-patch-detection branch January 30, 2026 22:33
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.

apply_patch sometimes invoked as shell command -> 'apply_patch: command not found'

3 participants