Skip to content

fix(client-runtime): checking out a pull request refreshes cached branch lists - #29161

Open
saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:fix/pr-checkout-refreshes-refs
Open

saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:fix/pr-checkout-refreshes-refs

Conversation

@saphid

@saphid saphid commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Problem

When you check out a pull request (the PR thread dialog in Local or Worktree mode, or a mobile new task started from a PR), the server creates or switches a local branch or adds a worktree. The branch lists the client already has open don't refresh: the worktree base picker, the diff panel ref lists, and the mobile branch lists keep the pre-checkout refs. They are missing the PR branch, they show the old current branch, and they lack the new branch's worktree path. The persisted branch list keeps the old snapshot too. The lists stay stale until something else invalidates refs, the session changes, or the atom idles out.

#4727 replaced ref-list polling with explicit invalidation. Every ref-changing VCS command in state/vcs.ts (pull, refreshStatus, createWorktree, removeWorktree, createRef, switchRef, init) has onSettled: invalidateRefs, and so do gitRunStackedAction and clone/publish. preparePullRequestThread in state/git.ts uses the same VCS scheduler, and the server handles it like createWorktree/switchRef, but it was left without the hook.

Change

preparePullRequestThread now calls invalidateCachedVcsRefs from onSettled, the same way its siblings in state/vcs.ts do. The runtime type of createGitEnvironmentAtoms widens to include Persistence.EnvironmentCacheStore, matching createVcsEnvironmentAtoms. Web and mobile already pass the same connectionAtomRuntime to both, so neither client needs a change.

Scope and approval

This is a very small, focused fix for an obvious bug, so there is no prior issue. It is one command #4727 missed when it added invalidation to every other ref-changing command: 6 lines in git.ts plus one assertion block in an existing test. There are no contract, server, or UI changes.

Overlap search: #27438 (open) adds refresh: true to rebuilt listRefs requests in state/vcs.ts. It complements this fix, because it depends on the revision bump that this PR adds for PR checkouts, and the lines don't overlap. Other preparePullRequestThread PRs (#24674, #23368, #27658, …) change server checkout behavior or mobile new-task files, not client cache invalidation.

Verification

  • Extended the existing invalidates persisted refs when ref-affecting commands settle case in packages/client-runtime/src/state/vcs.test.ts. It now runs preparePullRequestThread (local mode) and asserts that the persisted refs are cleared and the refs revision is bumped.
  • On main it fails: AssertionError: expected 2 to be 3 at vcs.test.ts:293 (1 failed | 9 passed).
  • With the fix: vp test run src/state/vcs.test.ts → 10 passed (10).
  • vp run check:changed: format, lint, knip, typecheck (7 packages, including web, mobile, and desktop) and tests all pass.
  • Not checked: a manual PR checkout in a running client. The change only adds the existing invalidation hook, and the test covers that hook.

Reviewed with sol-loop: 1 round with GPT-6.1 Sol on high. Sol verdict: approved.

Created with Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

…nch lists

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 2, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 15dcad3

Macroscope's review found this PR approvable — Pull-request checkout now refreshes cached branch lists using the existing cache-invalidation mechanism. The change is limited to disposable cache state and preserves existing Git command behavior.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d01b92c and 15dcad3.

Files selected for processing: 2
  • packages/client-runtime/src/state/git.ts
  • packages/client-runtime/src/state/vcs.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

createGitEnvironmentAtoms now accepts runtimes that include EnvironmentCacheStore. When preparePullRequestThread settles, it invalidates cached VCS refs for the environment and command working directory.

Changes: Pull-request thread cache invalidation

Layer / File(s) Summary
Command runtime and cache invalidation
packages/client-runtime/src/state/git.ts, packages/client-runtime/src/state/vcs.test.ts
The runtime type includes EnvironmentCacheStore. The command invalidates cached VCS refs when it settles. The test checks for a successful result, an additional cache clear, and a cache revision increase.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: t3dotgg

Merge Risk: Minimal · up to 15dca

The cache invalidation change is consistent across supported callers and is covered by the updated test.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title names the fix and its scope: checking out a pull request now refreshes cached branch lists. The raw summary shows the change adds cache invalidation to preparePullRequestThread, and the obje…
Description check Passed The description follows the template. It has Problem, Change, Scope and approval, and Verification sections. The Problem section explains the stale ref lists and reproduction contexts. The Change sect…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its scope: checking out a pull request now refreshes cached branch lists. The raw summary shows the change adds cache invalidation to preparePullRequestThread, and the objectives describe the same stale branch list problem. The title is specific and follows the conventional commit format from the template.

Full details: Description check

Explanation

The description follows the template. It has Problem, Change, Scope and approval, and Verification sections. The Problem section explains the stale ref lists and reproduction contexts. The Change section explains the hook addition and the runtime type widening. The Scope section explains why no prior issue exists and gives an overlap search. The Verification section gives a failing-before and passing-after test result, the check run, and a note on what was not checked. The model and harness are named at the end, as the template requests. Minor gap: the Scope section cites a small fix without a linked issue or maintainer approval, which the template allows when the fix is obviously small and the reasoning is given. The description is complete enough to pass.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@maria-rcks

maria-rcks commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Written by gpt-6.1-sol on behalf of Maria

Verified in a real dev environment

verified unchanged head 15dcad367c66729d1e262303daf5e6308288fa21 on linux using the real dev web app, repository playwright, and /usr/bin/google-chrome. projects and threads were created through the app. codex gpt-6.1-sol turns ran through the local proxy with real git commands. no mocks or demo data.

  • reproduced on github/main at 84537c4dd9 in a separate worktree: local pr checkout switched git to the pr head, but the branch picker still marked main as current.
  • repeated on this head: the picker refreshed after local checkout, marked the pr branch current, and marked main default.
  • worktree checkout created a real worktree at the same pr commit. its branch appeared in the picker, and the root picker subsequently showed its worktree badge. a codex turn confirmed the worktree directory, branch, and commit.
  • nearby behavior: switched back to local main through the picker and confirmed that its current marker refreshed. repeated local checkout also worked.
  • blacksmith: existing vcs.test.ts passed, 10/10. vp run check:changed FETCH_HEAD^ passed format, lint, both knip checks, typecheck for 7 packages, and the affected tests. the worker first fetched the pr's history because its snapshot lacked the default comparison merge base. all 31 reported pr checks were successful.

runtime transcript from real codex turns:

main app, before checkout:
branch: main
head: 84537c4dd9

pr app, local checkout:
branch: fix/pr-checkout-refreshes-refs
head: 15dcad367c66729d1e262303daf5e6308288fa21

pr app, worktree checkout:
pwd: /home/user/t3code/.t3/worktrees/pr-checkout-scenario/t3code-pr-29161-fix-pr--d063fa6066d46601
branch: t3code/pr-29161/fix/pr-checkout-refreshes-refs
HEAD: 15dcad367c66729d1e262303daf5e6308288fa21

before, main still marked current after pr checkout:

main branch picker retains the stale current marker

after, pr branch current and main default:

pr branch picker refreshes its current and default markers

local checkout and switching back to main, with the worktree badge visible:

real pr checkout refreshes refs and ordinary switching still works

real codex turn confirms the local pr branch and exact commit

real codex turn confirms the dedicated worktree path and pr commit

Not verified

native ios/android and electron shells were not exercised on this linux vm. other providers, remote/relay connections, the separate diff ref selector, failure-path invalidation, and persistent cache storage across a client restart were not directly exercised. the existing unit test covers persisted refs clearing and the revision bump. no source changes were needed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants