Skip to content

fix(#1076): pass the git dir as a codex writable root so phases can commit - #1077

Merged
admarble merged 1 commit into
mainfrom
fix/1076-codex-writable-git-dir
Sep 16, 2026
Merged

admarble merged 1 commit into
mainfrom
fix/1076-codex-writable-git-dir

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Fixes #1076.

Summary

Codex's workspace-write sandbox makes the workspace writable but excludes .git/, so every git add / git commit a phase ran was denied:

fatal: Unable to create '…/index.lock': Operation not permitted

The first #1060 gate run hit exactly this — exec produced correct edits across four files and failed with "made no commits" (sequant's #1032 guard auto-committed the work afterwards, which is the only reason it survived).

buildCodexArgs now resolves the repo's git dir and passes it as a writable root when the resolved sandbox mode is workspace-write:

codex exec … -c 'sandbox_workspace_write.writable_roots=["<git-common-dir>"]' …

git rev-parse --git-common-dir is the right question: from inside a worktree it answers the main repo's .git, which is where the index lives; in an ordinary checkout it answers the local .git. One command, both cases. Relative answers are resolved against cwd, because a sandbox policy has no notion of a working directory.

read-only has nothing to write and danger-full-access is already unrestricted, so neither is touched. A non-git cwd leaves the sandbox exactly as codex configured it rather than failing the phase.

Why not danger-full-access

It works, and it was the obvious workaround, but it removes the sandbox entirely. Sequant's guard hooks were designed to run inside a sandbox, not to replace one. This keeps the sandbox and opens one directory.

"Use a clone instead of a worktree" was also considered and measured to not work: a plain clone whose .git sits inside the workspace fails identically, because the exclusion follows .git wherever it is.

Verification

Beyond the unit assertions, the override the driver computes was fed to the real sandbox against the #1064 gate worktree:

$ codex sandbox -c 'sandbox_mode="workspace-write"' -c 'sandbox_workspace_write.writable_roots=["/Users/tony/Projects/sequant/.git"]' \
    -- sh -c 'cd <worktree> && git add probe.txt && echo ADD_OK || echo ADD_FAILED'
ADD_OK

Without the override, the same command prints the index.lock fatal and ADD_FAILED. All of this is $0 — codex sandbox makes no model call. (It does default to read-only, so any probe with it must pass -c 'sandbox_mode="workspace-write"' or it proves nothing; that default is what made my first analysis on #1060 wrong.)

Six tests in a new codex.sandbox.integration.test.ts, against real repos and a real git worktree rather than a stubbed execFileSync — the entire question is which absolute path git keeps the index under, which a mock would only restate.

Mutation-verified: AC — replaced the sandboxMode === "workspace-write" guard with false; exactly 1076 names the repo's own .git for an ordinary checkout and 1076 names the MAIN repo's .git from inside a worktree, where the index lives failed, the other 41 tests in both codex files passed; restored.

Test plan

  • npm run build
  • npm run lint
  • npm test — 319 files, 6439 passed, 0 failed, 1 expected fail, 3 skipped
  • Real-sandbox check above (ADD_FAILED → ADD_OK)
  • Mutation-verified

Unblocks the #1060 gate re-run, which never reached G-4, G-5 or G-6.

…ommit

codex's workspace-write sandbox makes the workspace writable but excludes
.git/, so every git add and git commit a phase ran was denied with
'Unable to create ….index.lock: Operation not permitted'. The first #1060
gate run produced correct edits across four files and ended with 'made no
commits'. Not worktree-specific: a plain clone whose .git sits inside the
workspace fails the same way.

buildCodexArgs now resolves the git dir with rev-parse --git-common-dir,
which answers the main repo's .git from inside a worktree (where the index
lives) and the ordinary .git elsewhere, and passes it as a writable root
under workspace-write only. Verified against the real sandbox: the exact
override the driver computes turns ADD_FAILED into ADD_OK in the #1064 gate
worktree.

Entire-Checkpoint: 5b02f175c9a6
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.

bug(codex): every phase fails to commit — workspace-write excludes .git, so git add/commit are denied

1 participant