Skip to content

Codex seats in a git worktree: --add-dir <cwd>/.git (a file) breaks the bubblewrap sandbox for every command #121

Closed

Description

@mgall-ibizdigital

Summary

For a Codex seat whose cwd is a linked git worktree, OpenRig launches Codex with --add-dir <cwd>/.git. In a linked worktree <cwd>/.git is a file (gitdir: <common>/.git/worktrees/<name>), not a directory. With Codex's bubblewrap sandbox (-s workspace-write) this makes every sandboxed command fail before it runs, so the seat falls back to approval prompts for everything, including rig whoami.

Environment

  • OpenRig built from source at 4fcf291 (0.5.17)
  • Codex CLI 0.158.0, Ubuntu 24.04, bubblewrap 0.9.0 with the bwrap-userns-restrict AppArmor profile loaded (the sandbox itself works: codex sandbox -- ls succeeds in an ordinary clone)
  • Seat cwd created with git worktree add

Reproduction

With the exact launch shape OpenRig uses (packages/daemon/src/adapters/codex-runtime-adapter.ts, the gitDirArg line):

codex exec -s workspace-write -C <worktree> --add-dir <worktree>/.git "Run: ls -d ."

Result (exit 101):

bwrap: Can't mkdir parents for <worktree>/.git/.git: Not a directory
thread 'main' panicked at linux-sandbox/src/linux_run_main.rs:1271:21:
failed to inspect synthetic bubblewrap mount target <worktree>/.git/.codex: Not a directory (os error 20)

Passing the real git dirs instead works, including a sandboxed git commit in the worktree:

codex exec -s workspace-write -C <worktree> --add-dir <common>/.git/worktrees/<name> --add-dir <common>/.git "..."

Suggested fix

When <cwd>/.git is a file, resolve git -C <cwd> rev-parse --path-format=absolute --git-dir --git-common-dir and add each existing directory; keep the current argument when .git is a directory (or absent). We carry this as a local patch: a small codexGitDirArgs(cwd) helper replacing the one-line gitDirArg, with tests for an ordinary clone, a linked worktree, and an unresolvable .git file. Existing codex-runtime-adapter tests (70) still pass. Happy to open a PR if useful.

Activity

  1. mvschwarz commented on Sep 29, 2026

    @mvschwarz
    Owner

    Thanks for the clear reproduction, the diagnosis and the working alternative. We confirmed the launch code on our side: it always added --add-dir <cwd>/.git, whether .git was a directory or, in a linked worktree, a file.

    A fix based on your report is now merged in #126. When .git is a file, OpenRig now passes the real git directories instead, and it credits you for the report and the approach. It will ship in the next release. We haven't run your Linux bubblewrap setup end to end ourselves, so if you try it after the release, we'd be glad to hear whether sandboxed commands work in your worktree seats.

    — dev-planner@v-openrig-build, on behalf of @mvschwarz

  2. mvschwarz commented on Sep 29, 2026

    @mvschwarz
    Owner

    Thanks for the detailed write-up. #126 fixes this the same way: when a worktree's .git is a file, OpenRig asks git for the worktree's git directory and the common git directory (git rev-parse --git-dir --git-common-dir) and passes those instead. It shipped in 0.6.1 today.

    — dev-planner@v-openrig-build, on behalf of @mvschwarz

  3. mvschwarz commented on Oct 18, 2026

    @mvschwarz
    Owner

    An update, @mgall-ibizdigital: #126 is in OpenRig 0.6.11 (release notes: https://github.com/mvschwarz/openrig/releases/tag/v0.6.11), so we're closing this as completed. If it doesn't cover your case, say so here and we'll reopen it.

  4. bkmcd865 commented on Nov 1, 2026

    @bkmcd865

    We found a follow-up case after the linked-worktree fix in #126. Our installed OpenRig 0.6.14 handles fresh Codex launches. It omits the Git directory arguments when it resumes the same seat.

    The seat is eval-codex-desk1@pbi-eval on Ubuntu. Its working directory is /home/openrig-eval/pbi/trees/eval-codex-desk1. That directory is a linked Git worktree. git rev-parse --path-format=absolute --git-dir --git-common-dir returns:

    /home/openrig-eval/pbi/PBI-Hub/.git/worktrees/eval-codex-desk1
    /home/openrig-eval/pbi/PBI-Hub/.git
    

    At 11:32 AM ET on 2026-11-01, /proc/5924/cwd pointed to that worktree. The process command contained resume and only these two --add-dir values:

    /home/openrig-eval/.openrig/workspace
    /home/openrig-eval/.openrig/shared-docs/rigs/pbi-eval/state/eval
    

    Neither Git directory was present. The sandbox remained workspace-write.

    Our operator also observed this split across both rigs at 11:03 AM ET. Ten freshly launched PBI desks had four --add-dir values, including both Git directories. Resumed eval desks had only the two shared folders. A resumed desk's git add failed at .git/index.lock with Read-only file system. Fresh launches of eval desks 1 and 4 restored prompt-free Git writes. Those last three observations are operator reports; the /proc/5924 check above is our independent confirmation.

    The installed codex-runtime-adapter.js resolves Git directories only when opts.resumeToken is absent. buildResumeCommand also calls resumeCore without Git directories. This appears to leave both normal resume and in-place restart without the directories that fresh launch receives.

    Please extend #126's directory resolution to every managed Codex resume path. Keep the existing sandbox posture. A regression test could compare fresh and resume arguments for a linked worktree. The expected result is both real Git directories in both paths, without --add-dir <worktree>/.git.

    Our temporary operator plan uses rig seat launch --fresh after a handoff. That creates a new conversation, so it is not a substitute for working resume.

  5. mvschwarz commented on Nov 1, 2026

    @mvschwarz
    Owner

    Thanks, @bkmcd865, for the precise follow-up: the worktree path, the git rev-parse output, the resumed process's two --add-dir values, and the comparison with freshly launched agents on both rigs. As you describe it, a fresh Codex launch in a linked worktree gets both Git directories, while a resume of the same agent doesn't. It's with the team now, and we'll come back here.

  6. mvschwarz commented on Nov 1, 2026

    @mvschwarz
    Owner

    Coming back on this as promised, @bkmcd865: a fix for the Codex resume path, #2023, shipped in 0.7.2, which is later than the 0.6.14 you're running. In 0.7.6, both a resume and an in-place restart pass the resolved Git directories when the agent runs on the workspace-write sandbox, as yours does, so it may already cover this. We've read that in the source; we haven't run your case. Could you retest on 0.7.6? If it still happens there, a new issue with the same detail would be welcome, and we'll take it from there.

  7. bkmcd865 commented on Nov 1, 2026

    @bkmcd865

    @mvschwarz, thank you for taking the time to investigate our report. Your clear explanation of the 0.7.2 fix and 0.7.6 behavior helped us plan the upgrade and test. We appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions