[codex] Fix Windows sandbox git safe.directory for worktrees#21409
Merged
iceweasel-oai merged 1 commit intoMay 6, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Windows sandboxed commands run as a sandbox user, while workspace repositories are usually owned by the real user. The sandbox compensates by injecting a temporary Git
safe.directoryentry into the child environment.That injection was still broken for linked worktrees because the helper followed the
.gitfile'sgitdir:pointer and injected the internal.git/worktrees/...location. Git's dubious-ownership check expects the worktree root instead, so sandboxed Git commands still failed in worktree-based Codex checkouts.What changed
.gitmarker, directory or file, as the worktree root forsafe.directoryinjection.windows-sandbox-rs/src/sandbox_utils.rsand have the one-shot elevated path reuse it..gitdirectories and gitfile-based worktrees.Validation
cargo test -p codex-windows-sandbox sandbox_utils::testscargo test -p codex-windows-sandboxbuilt and ran; the newsandbox_utilstests passed, while two pre-existing legacy sandbox tests failed locally withAccess is denied:session::tests::legacy_non_tty_cmd_emits_outputandspawn_prep::tests::legacy_spawn_env_applies_offline_network_rewrite.