Skip to content

Files change by running itself from command line with patch file #3953

@konmik

Description

@konmik

What version of Codex is running?

codex-cli 0.38.0

Which model were you using?

gpt-5 high

What platform is your computer?

Windows 11

What steps can reproduce the bug?

Use Codex with model high on Windows, probably mixed newline characters will help to reproduce .

What is the expected behavior?

Use an internal tool to modify files and show diffs.

What do you see instead?

Mutliple patch application output errors. It tries to patch using python, then it tried to run itself with command line, then it fails again and does something weird again. High models (gpt-5 codex high and gpt-5 high) are unusable. Creates a patch file in the root of the project and adds it to git. Does not show any coloration for patches.

Here are some examples:

• I'm trying to figure out why the apply_patch command complains about the final *** End Patch line—suspecting Windows
debugT(): String = '"\"??\""'n fun collectConstraints(constraints: Constraints) { }n fun
substitute(solutions: Solutions): Air = thisn fun refine(context: AnalyzeContext): Air = this@Airn- fun
forEach(action: (Air) -> Unit)n+ fun forEach(action: (Air) -> Unit) {n+ action(this)n+ }n }
`n*** End Patch"'
Invalid patch: The last line of the patch must be '*** End Patch'
incorrect line endings might cause the error; I’m considering running apply_patch via a Python subprocess to control
the input formatting precisely with exact newlines.

• Ran
└ pwsh -NoLogo -Command "python - <<'PY'
import subprocess
patch = "*** Begin Patch\n*** Update File: src/main/kotlin/com/zoffl/rick/analyze/air/Air.kt\n@@\n-interface
Air {\n+interface Air {\n fun debug(): String = \"??\"\n fun debugT(): String = \"??\"\n
fun collectConstraints(constraints: Constraints) { }\n fun substitute(solutions: Solutions): Air = this
\n fun refine(context: AnalyzeContext): Air = this@Air\n- fun forEach(action: (Air) -> Unit)\n+ fun
forEach(action: (Air) -> Unit) {\n+ action(this)\n+ }\n }\n*** End Patch\n"
~~~~~^^^^^^^^^^^^^^^^^^^^^^

• Ran
└ pwsh -NoLogo -Command '$patch = @'"'
*** Begin Patch

    Write-Output $stdout
Write-Error: apply_patch failed
Error: --codex-run-as-apply-patch requires a UTF-8 PATCH argument.

• Ran
└ pwsh -NoLogo -Command "@'
import subprocess, textwrap

def ap(patch: str):
    subprocess.run([
        'C:\\\\Users\\\\elkmo\\\\AppData\\\\Roaming\\\\npm\\\\node_modules\\\\@openai\\\\codex\\\\bin\\\
    \codex-x86_64-pc-windows-msvc.exe',
        '--codex-run-as-apply-patch',
        patch
    ], check=True, text=True, encoding='utf-8')

ap(textwrap.dedent('''
*** Begin Patch

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodel-behaviorIssues related to behaviors exhibited by the modelwindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions