Support sandbox session lookup after commits on detached HEAD#414
Merged
Support sandbox session lookup after commits on detached HEAD#414
Conversation
Adds git merge-base --is-ancestor support, which will be used for ancestry-based sandbox session lookup on detached HEADs.
When a detached HEAD advances (e.g. Codex making commits in a worktree), the session key no longer matches. GetSessionByAncestry and GetSessionsForCwdBranchByAncestry fall back to git ancestor checks, and re-key matching sessions to the current SHA to avoid repeated misses.
When on a detached HEAD and an exact session lookup misses, fall back to ancestry-based matching. This handles the case where tools like Codex commit on a detached HEAD, advancing the SHA while the sandbox is still running. Applied to CheckExistingSandbox, ExecSandbox (both specific-config and no-config paths, plus remote recovery), StopSandbox, and ResetSandbox.
kylekthompson
approved these changes
Mar 11, 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@<short-sha>, so the CLI could no longer find the running sandbox.IsAncestorto the git client, wrappinggit merge-base --is-ancestor.GetSessionByAncestryandGetSessionsForCwdBranchByAncestrytoSandboxStorage, which fall back to ancestry-based lookup when an exact key match fails on a detached HEAD. Matching sessions are re-keyed to the current SHA to avoid repeated misses.CheckExistingSandbox,ExecSandbox(specific-config, no-config, and remote recovery paths),StopSandbox, andResetSandbox.Test plan
IsAncestor(ancestor, descendant, unrelated, equal, non-repo)GetSessionByAncestry(match + re-key, no match, wrong cwd/config, named branch, bare detached)GetSessionsForCwdBranchByAncestry(multi-config match, non-ancestor filtered, empty)./internal/cli/and./internal/git/test suites passrwx sandbox execandrwx sandbox stopstill find the sandbox