Skip to content

[codex] Fix Windows sandbox git safe.directory for worktrees#21409

Merged
iceweasel-oai merged 1 commit into
mainfrom
codex/windows-sandbox-safe-directory-worktrees
May 6, 2026
Merged

[codex] Fix Windows sandbox git safe.directory for worktrees#21409
iceweasel-oai merged 1 commit into
mainfrom
codex/windows-sandbox-safe-directory-worktrees

Conversation

@iceweasel-oai
Copy link
Copy Markdown
Collaborator

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.directory entry into the child environment.

That injection was still broken for linked worktrees because the helper followed the .git file's gitdir: 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

  • Treat any .git marker, directory or file, as the worktree root for safe.directory injection.
  • Keep the safe-directory logic in windows-sandbox-rs/src/sandbox_utils.rs and have the one-shot elevated path reuse it.
  • Add regression coverage for both normal .git directories and gitfile-based worktrees.

Validation

  • cargo test -p codex-windows-sandbox sandbox_utils::tests
  • cargo test -p codex-windows-sandbox built and ran; the new sandbox_utils tests passed, while two pre-existing legacy sandbox tests failed locally with Access is denied: session::tests::legacy_non_tty_cmd_emits_output and spawn_prep::tests::legacy_spawn_env_applies_offline_network_rewrite.

@iceweasel-oai iceweasel-oai marked this pull request as ready for review May 6, 2026 20:46
Copy link
Copy Markdown

@bschoepke-openai bschoepke-openai left a comment

Choose a reason for hiding this comment

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

ty!

@iceweasel-oai iceweasel-oai merged commit 123e78b into main May 6, 2026
26 checks passed
@iceweasel-oai iceweasel-oai deleted the codex/windows-sandbox-safe-directory-worktrees branch May 6, 2026 21:08
@github-actions github-actions Bot locked and limited conversation to collaborators May 6, 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.

2 participants