Skip to content

fix(native): resolve missing Git worktree refs - #6364

Merged
tlgimenes merged 3 commits into
mainfrom
codex/fix-native-git-ref-resolution
Aug 20, 2026
Merged

fix(native): resolve missing Git worktree refs#6364
tlgimenes merged 3 commits into
mainfrom
codex/fix-native-git-ref-resolution

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace version-specific Git stderr matching with structural ref resolution
  • resolve worktree start points to immutable SHA-1 or SHA-256 commit OIDs
  • repair missing or dangling origin/HEAD and prevent nonempty remotes from silently becoming orphan branches
  • preserve upstream configuration, cancellation, and collision handling
  • make sandbox setup failures neutral across repository access, branch selection, and local Git configuration
  • document the incident, invariants, implementation, and verification plan

Root cause

The missing-branch fallback depended on two human-readable errors from git worktree add. The reporter Git version emitted Not a valid object name instead, so Studio returned immediately and never tried origin/HEAD even though clone and fetch had succeeded.

Testing

  • bun run fmt
  • cargo fmt --all -- --check
  • cargo test -p local-api setup::clone::tests:: -- --test-threads=1 (18 passed)
  • cargo test -p local-api sandbox::manager::tests:: -- --test-threads=1 (29 passed)
  • cargo clippy -p local-api --all-targets -- -D warnings
  • cargo test --workspace (1,085 passed; 2 ignored)
  • pre-commit formatting and workspace clippy hooks

Summary by cubic

Resolve Git worktree start points structurally and pin them to immutable commit OIDs. This restores missing-branch fallback across Git versions, prevents orphan branches on nonempty remotes, and makes worktree creation robust to concurrent fetch/prune.

  • Resolve refs/remotes/origin/* via rev-parse^{commit}; confirm absence with show-ref; repair origin/HEAD using remote set-head -a; allow no start point only when rev-list --max-count=1 --remotes=origin is empty. Always pass the resolved OID to git worktree add.
  • Handle collisions: if canonical holds the branch, detach and retry with the same OID; if a sibling worktree holds it, create a detached worktree at that OID. Preserve branch.<name>.{remote,merge}.
  • Change behavior: a nonempty remote without a resolvable default now fails with guidance instead of creating an orphan; cancellations remain cancellations.
  • Update UX: neutralize failure copy in SandboxManager and tweak the completion trace.
  • Expand real-Git tests: SHA-1/256 OID parsing; requested-branch precedence over origin/HEAD; missing/dangling origin/HEAD repair; sibling-held branch fallback reusing the same OID; nonempty-remote-without-default failing early; cancellation classification; orphan behavior guarded by rev-list.
  • Maintenance: satisfy Rust 1.98 clippy in log_store with as_chunks::<2>(); remove the implementation plan doc.

Written for commit 880f985. Summary will update on new commits.

Review in cubic

@tlgimenes
tlgimenes force-pushed the codex/fix-native-git-ref-resolution branch from 1ef1b58 to 880f985 Compare August 20, 2026 20:03
@tlgimenes
tlgimenes enabled auto-merge (squash) August 20, 2026 20:13
@tlgimenes
tlgimenes merged commit f30b0df into main Aug 20, 2026
36 checks passed
@tlgimenes
tlgimenes deleted the codex/fix-native-git-ref-resolution branch August 20, 2026 20:13
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.

1 participant