fix(server): opening the branch menu no longer wipes PR status
Problem
Opening the branch menu sends vcs.refreshStatus with localOnly: true. When no remote status was cached, or the branch had changed, that refresh cached an empty remote entry ({ value: null }) and published remoteUpdated: null. Every reader takes that entry as "the remote was read and has no PR":
- Overlap: if the subscription's first remote read is still running, the refresh overwrites the PR, upstream and ahead/behind counts that read just cached. They stay empty until the next poll, or until a full refresh when automatic fetch is set to 0.
- Before any remote read: the turn-end
refreshPullRequestStatusreturns without reading, because it skips whencached.remote?.value === null. - After a branch switch: the turn-end PR refresh skips in the same way. A subscription that opens afterwards finds a cached remote and waits a full interval before its first read.
Change
The local-only path of VcsStatusBroadcaster.refreshStatus now refreshes local status only and returns the cached parts. It no longer writes a remote entry, invalidates the remote cache, or takes the remote write lock.
- Branch switch:
updateCachedLocalStatusalready drops the old branch's remote and publishesremoteUpdated: null. - Invalidation:
readRemoteStatusalready invalidates the remote cache before every read.
The only caller (the branch menu) ignores the RPC result and gets status from the stream.
Two existing tests used a fake remote that ignores the branch and relied on the empty entry. Their fakes now return the new branch's remote, and their call counts include the remote read getStatus now makes for the new branch. Their assertions are otherwise unchanged.
Scope and approval
Fixes pingdotgg/t3code#33256
Verification
vp test run apps/server/src/vcs/VcsStatusBroadcaster.test.ts: 29/29 pass. Three new tests reproduce the three cases above and fail on main's code:a local-only refresh that overlaps the first remote poll keeps its PR:expected null to deeply equal { number: 2978, … }a local-only refresh before any remote read leaves the PR refresh able to read:expected undefined to deeply equal { number: 2978, … }a local-only refresh after a branch switch leaves the PR refresh able to read:expected undefined to deeply equal { number: 3001, … }
vp run check:changedon456327574c: format, lint, knip, typecheck (3 packages) and the 2 changed test files (31 tests) pass.
Evidence
Server-only change, so the evidence is real-server event logs rather than screenshots. Each row ran each side's own apps/server/src/bin.ts serve on a fresh base dir (T3CODE_DEV_SEED=0), driven over the WebSocket RPC with the same driver and a synthetic repo with a local bare remote. Turn-end rows use the Replay (dev) provider. Overlap rows hold the remote git fetch open with a gate. P1 uses a read-only shallow checkout of this PR's branch, so the server's PR lookup finds the real open PR. Before = main 4c361199f4, after = 456327574c. R1 was recorded at c6ca605630 / 33cb900503, and the fix is unchanged since.
| Row | Scenario | Before 4c361199f4 | After 456327574c | Logs |
|---|---|---|---|---|
| R1 | Cold local-only refresh, then first subscription (30 s interval) | no remote read within 8 s | upstream/ahead 0.45 s later | transcript below |
| R2 | Cold local-only refresh, then a turn ends; automatic fetch 0 | no remote read after the turn; remote stays null | turn-end refresh reads; upstream/ahead published | before · after |
| R3 | Warm cache, same branch (control) | remote kept | remote kept (unchanged) | before · after |
| R4 | Branch A → B, local-only refresh, new subscription | two clears, no B read in window | one clear, B's remote read immediately | before · after |
| R5 | Branch A → B, local-only refresh, turn ends; fetch 0 | turn-end refresh skips; B stays null | B's remote recovered after the turn | before · after |
| R6 | First remote read in flight, local-only refresh overlaps | remote published, then erased to null | remote published and kept | before · after |
| R7 | Branch switch while a remote read is in flight | stale A read discarded; null cached for B, no B read in window | stale A read discarded; B read immediately | before · after |
| R8 | Cold local-only refresh, new subscription; fetch 0 | remote stays null | remote read without a fetch | before · after |
| R9 | Non-repository directory (control) | null | null (unchanged) | before · after |
| P1 | R6 ordering on a checkout of this PR's branch with a real GitHub remote | open PR https://git.cafe/pingdotgg/t3code/pulls/33263 published, then erased | open PR https://git.cafe/pingdotgg/t3code/pulls/33263 kept | before · after |
Environment: Linux 6.8 x64, Node 26; automatic fetch interval 30 s, or 0 s for R2/R5/R8. Index · pass-1 matrix (its "missing" rows were captured afterwards; the index is current) · scripts: capture.ts, capture-hosted.ts, seed.mjs, seed-hosted.mjs, git-wrapper.py, run-matrix.py, R1 driver.
What else changed: the overlapping local-only refresh no longer waits for the remote writer. Branch switches publish one clear instead of two. The immediate refreshStatus result still carries default remote fields while a remote read is in flight, the same as before; the only caller ignores it. Controls R3 and R9 show no change.
Not checked: the web toolbar's PR badge in a browser. P1 shows the real PR payload surviving over the RPC the toolbar subscribes to.
R1 transcript (before c6ca605630, after 33cb900503):
Before (c6ca605630)
[+ 147ms] seeded repo: ## feature/demo...origin/feature/demo [ahead 1]
[+ 165ms] server pid 1070005 checkout c6ca605630
[+ 7814ms] -> vcs.refreshStatus { localOnly: true } (branch menu opened)
[+ 8160ms] <- refreshStatus result: branch feature/demo {"hasUpstream":false,"aheadCount":0,"behindCount":0,"pr":null}
[+ 8160ms] -> subscribeVcsStatus (branch toolbar mounts), watching 8 s
[+ 8198ms] <- snapshot remote: null
[+16171ms] done watching
After (33cb900503)
[+ 144ms] seeded repo: ## feature/demo...origin/feature/demo [ahead 1]
[+ 158ms] server pid 1073114 checkout 33cb900503
[+ 8220ms] -> vcs.refreshStatus { localOnly: true } (branch menu opened)
[+ 8598ms] <- refreshStatus result: branch feature/demo {"hasUpstream":false,"aheadCount":0,"behindCount":0,"pr":null}
[+ 8598ms] -> subscribeVcsStatus (branch toolbar mounts), watching 8 s
[+ 8624ms] <- snapshot remote: null
[+ 9049ms] <- remoteUpdated: {"hasUpstream":true,"aheadCount":1,"behindCount":0,"pr":null}
[+16608ms] done watching
Verification log
- Main merged into the branch with no conflicts (head
456327574c); the fix diff is unchanged. - Review round 1: A found no code bug and asked for runtime evidence of the overlap, turn-end and branch-switch paths with a real PR (captured above as R2–R9 and P1); B: merge.
- Review round 2, with the evidence: A merge, B merge. No open findings.
- Proof audit: pass 1 insufficient (R2, R4–R8 missing); pass 2 sufficient on all 10 rows, with R6 rebuilt independently from the uploaded scripts (32/32 events match).
- Tests: 29/29 in
VcsStatusBroadcaster.test.ts; the 3 new tests fail on main's broadcaster. - CI: all checks green on
456327574c. - Unverified surfaces: none.
AI-assisted; verified with the tests and tools listed above.