# Review opus r3: final whole-PR audit for [#20825](https://github.com/pingdotgg/t3code/pull/20825)

Head: [1b3b634297](https://github.com/shivamhwp/t3code/commit/1b3b634297c4f12ead8d0325e6ba1e14c5e9b852). Base: [e3e89f4b2e](https://github.com/pingdotgg/t3code/commit/e3e89f4b2ec21020f380fdba4a79207e3d5fcd56). Read-only.

## Verdict: no blockers. Merge once the PR body is refreshed.

## What I checked (whole diff, not only the last fix)
- **contracts/git.ts**: `upstreamRef` on VcsRef and `isAtRepositoryRoot` on VcsListRefsResult are both optional. Older clients and servers still decode.
- **GitVcsDriverCore**: `%(upstream)` is appended as the 4th tab field and only set when it is non-empty. `isAtRepositoryRoot` compares realPath(cwd) with the physical toplevel using `path.relative === ""`. A realPath error becomes `undefined`, which the client then refuses visibly. That is one cached syscall per repository-paths resolution, so the performance cost is negligible.
- **client-runtime readRefs**: uncached RPC command on the existing `vcsListRefs` tag. No new server method and no scope change.
- **checkout-new-task-branch.ts**:
  - Worktree mode is unchanged.
  - The current branch yields `worktreePath: null`, which keeps the nested cwd.
  - The query is bounded to 256 characters, which matches the contract's `isMaxLength(256)`. The full name is compared on every page, and pagination stops at `nextCursor === null` or at the first exact match.
  - A remote ref requires `upstreamRef === refs/remotes/<full remote ref>`. With slash remotes, the local name comes from the `remoteName` prefix.
  - An occupied worktree is refused when the server omits metadata, and refused when the project is not at the repository root.
  - A free branch goes to switchRef, which now explicitly sets `worktreePath: null`. That fixes the stale-path issue from Macroscope and Sol r2.
- **Picker and draft route**: both callers pass `readRefs`. The draft route now carries the resolved `worktreePath` through `resolveNewTaskBranchWorktreePath`, which collapses a path equal to `projectCwd` to null. The picker's `flow.selectBranch` already used the same helper.

## Evidence
- Ran at HEAD: `vp test run checkout-new-task-branch.test.ts new-task-context-presentation.test.ts` gave 28/28 passing. The parent's 41/41 run includes a third neighbor file.
- `stale-path-before.log` shows the updated baseline test failing before the fix with a non-null stale path. The test uses real git: a linked worktree holds `feature/a`, then moves to `other-branch`. It now asserts the actual checkout and the null override.
- Server tests, runtime tests and package typechecks come from the parent's logs. I did not rerun them; the last commit does not touch them.

## Non-blocking notes (no action needed)
- In the picker, a ref with a stale non-null `worktreePath` skips the `canWriteSourceControl` gate. If readRefs then finds the branch free, switchRef runs. The server still enforces scope, and a failure surfaces through the existing "Could not switch branch" dialog. This behavior predates the PR.
- A remote ref whose local branch has a different upstream falls through to switchRef with the remote ref name. That matches the pre-PR checkout behavior.

## Limits
No native device pass was run (devices unavailable; accepted per the brief). Proof is headless with real git.
