Skip to content

Conversation

@davidgilbertson
Copy link
Contributor

Currently apply_patch will fail on Windows if the file contents happen to have a multi-byte character at the point where the preview function truncates.

I've used the existing take_bytes_at_char_boundary helper and added a regression test (that fails without the fix).

This is related to #4013 but doesn't fix it.

Avoid panicking when the command preview truncates multi-byte characters.
Use a char-boundary truncation helper and add a regression test.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@davidgilbertson
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@etraut-openai
Copy link
Collaborator

@davidgilbertson, thanks for the contribution. I'm a bit confused by the commit comment. You mention that this fix relates to apply_patch, but the fix seems to target windows sandbox logging. I'm not sure how the two are connected. Can you elaborate?

@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 7, 2026
@davidgilbertson
Copy link
Contributor Author

Sure, it's a long and winding road from apply_patch to preview:

In codex-rs\core\src\tools\handlers\apply_patch.rs

Apply patch tool handler: ApplyPatchHandler::handle parses the tool payload and, when it needs to actually execute, delegates to the runtime via ToolOrchestrator and ApplyPatchRuntime.

In codex-rs\core\src\tools\runtimes\apply_patch.rs

Apply patch runtime: ApplyPatchRuntime::run builds a CommandSpec that invokes the current codex binary with the CODEX_APPLY_PATCH_ARG1 arg, then calls execute_env.

In codex-rs\core\src\sandboxing\mod.rs and codex-rs\core\src\exec.rs

Sandbox execution pipeline: execute_env is a thin wrapper that calls execute_exec_env, which chooses the Windows sandbox path when SandboxType::WindowsRestrictedToken is active.

In codex-rs\core\src\exec.rs

Windows sandbox entry: exec_windows_sandbox calls into the Windows sandbox crate, choosing run_windows_sandbox_capture or the elevated variant based on is_windows_elevated_sandbox_enabled().

In codex-rs\windows-sandbox-rs\src\lib.rs, codex-rs\windows-sandbox-rs\src\elevated_impl.rs, codex-rs\windows-sandbox-rs\src\logging.rs

Windows sandbox logging: both the non‑elevated and elevated run_windows_sandbox_capture log the command at start/end via log_start/log_success/log_failure. These functions call preview internally to truncate and format the command.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 9, 2026
@davidgilbertson
Copy link
Contributor Author

Has this fallen through the cracks?

@etraut-openai
Copy link
Collaborator

@davidgilbertson, it's in the queue for review. Apologies for the slow response. The Codex Team has been very busy lately.

Copy link
Collaborator

@iceweasel-oai iceweasel-oai left a comment

Choose a reason for hiding this comment

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

sorry this took so long! Thanks for fixing this

@etraut-openai etraut-openai merged commit 313ee30 into openai:main Jan 26, 2026
26 of 27 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2026
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.

3 participants