Support detached HEAD for sandbox operations#399
Merged
Conversation
e088fee to
a5b893e
Compare
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
a5b893e to
63a1e2a
Compare
kylekthompson
approved these changes
Mar 5, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
"detached"sentinel string that the server couldn't resolve as a git ref, and caused session key collisions across different commits.GetCurrentGitBranchnow returnsdetached@<short-sha>, giving each detached commit a unique session key and a recognizable identifier insandbox listoutput.GetCommitnow 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.GetShortHead()helper to the git client.Test plan
SessionKey,ParseSessionKey,SandboxTitle,IsDetachedBranch,DetachedShortSHA, andGetSessionsForCwdBranchwith the new formatGetCommitdetached-head-diverged test updated to expect merge-base instead of raw HEAD./internal/cli/and./internal/git/test suites passrwx sandbox exec, verify it works end-to-endrwx sandbox listshowsdetached@<sha>in the BRANCH column