Skip to content

Support detached HEAD for sandbox operations#399

Merged
robinaugh merged 1 commit intomainfrom
jason/detached-head-support
Mar 5, 2026
Merged

Support detached HEAD for sandbox operations#399
robinaugh merged 1 commit intomainfrom
jason/detached-head-support

Conversation

@robinaugh
Copy link
Contributor

@robinaugh robinaugh commented Mar 5, 2026

Summary

  • When in a detached HEAD state (e.g. Codex's default worktree mode), sandbox operations previously failed because the CLI used a bare "detached" sentinel string that the server couldn't resolve as a git ref, and caused session key collisions across different commits.
  • GetCurrentGitBranch now returns detached@<short-sha>, giving each detached commit a unique session key and a recognizable identifier in sandbox list output.
  • GetCommit now uses the same merge-base logic for detached HEAD as it does for named branches. This means the server clones at the nearest ancestor that exists on the remote, and local-only commits are synced as a patch — matching the existing behavior for unpushed commits on named branches.
  • Added GetShortHead() helper to the git client.

Test plan

  • Unit tests pass for SessionKey, ParseSessionKey, SandboxTitle, IsDetachedBranch, DetachedShortSHA, and GetSessionsForCwdBranch with the new format
  • GetCommit detached-head-diverged test updated to expect merge-base instead of raw HEAD
  • Full ./internal/cli/ and ./internal/git/ test suites pass
  • Lint passes
  • Manual: create a detached HEAD worktree, run rwx sandbox exec, verify it works end-to-end
  • Manual: verify rwx sandbox list shows detached@<sha> in the BRANCH column
  • Manual: make local commits on detached HEAD, start sandbox, verify it clones at remote ancestor and syncs changes

@robinaugh robinaugh self-assigned this Mar 5, 2026
@robinaugh robinaugh force-pushed the jason/detached-head-support branch from e088fee to a5b893e Compare March 5, 2026 19:30
@robinaugh robinaugh marked this pull request as ready for review March 5, 2026 19:44
When the worktree is in a detached HEAD state (e.g. Codex default mode),
sandbox operations now work correctly:

- GetCurrentGitBranch returns "detached@<short-sha>" instead of bare
  "detached", making session keys unique per commit
- SandboxTitle displays "detached <sha>" for readability
- GetCommit now uses merge-base logic for detached HEAD (same as named
  branches), so the server clones at a remote ancestor and local changes
  are synced as a patch
- Added GetShortHead helper to git client
@robinaugh robinaugh force-pushed the jason/detached-head-support branch from a5b893e to 63a1e2a Compare March 5, 2026 19:57
@robinaugh robinaugh requested a review from kylekthompson March 5, 2026 20:10
@robinaugh robinaugh merged commit 405f574 into main Mar 5, 2026
1 check passed
@robinaugh robinaugh deleted the jason/detached-head-support branch March 5, 2026 20:56
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.

2 participants