@devries-cameron20 / t3code Mirror · read-only / commits / 5b35402623
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 17:00 UTC

fix(web): refresh the current branch when opening the picker (#22807)

Utkarsh Patil committed Oct 25, 2026 at 19:35 UTC 5b35402623d7d1d88eaa472807272a6c2e78012a
5 files changed +146 -4
apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+113
@@ -156,6 +156,119 @@ function layerBackgroundPolicy(shouldRunScopeWork: (scope: BackgroundScope) => b
156 }
157
158 describe("VcsStatusBroadcaster", () => {
159 + it.effect("publishes a terminal branch switch without reading remote status", () => {
160 + const state = {
161 + currentLocalStatus: baseLocalStatus,
162 + currentRemoteStatus: remoteStatusWithPr,
163 + localStatusCalls: 0,
164 + remoteStatusCalls: 0,
165 + localInvalidationCalls: 0,
166 + remoteInvalidationCalls: 0,
167 + };
168 +
169 + return Effect.gen(function* () {
170 + const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
171 + yield* broadcaster.getStatus({ cwd: "/repo" });
172 + const subscribed = yield* Deferred.make<void>();
173 + const events = yield* broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }).pipe(
174 + Stream.tap((event) =>
175 + event._tag === "snapshot" ? Deferred.succeed(subscribed, undefined) : Effect.void,
176 + ),
177 + Stream.take(2),
178 + Stream.runCollect,
179 + Effect.forkScoped,
180 + );
181 + yield* Deferred.await(subscribed);
182 +
183 + state.currentLocalStatus = { ...baseLocalStatus, refName: "main" };
184 + const refreshed = yield* broadcaster.refreshStatus("/repo", { localOnly: true });
185 + assert.equal(refreshed.refName, "main");
186 + assert.isNull(refreshed.pr);
187 + assert.equal(state.localInvalidationCalls, 1);
188 + assert.equal(state.remoteStatusCalls, 1);
189 + assert.equal(state.remoteInvalidationCalls, 1);
190 + assert.deepStrictEqual((yield* Fiber.join(events))[1], {
191 + _tag: "snapshot",
192 + local: state.currentLocalStatus,
193 + remote: null,
194 + });
195 + assert.isNull((yield* broadcaster.getStatus({ cwd: "/repo" })).pr);
196 + const snapshot = yield* broadcaster
197 + .streamStatus({ cwd: "/repo", includeRemote: false })
198 + .pipe(Stream.take(1), Stream.runCollect);
199 + assert.deepStrictEqual(snapshot[0], {
200 + _tag: "snapshot",
201 + local: state.currentLocalStatus,
202 + remote: null,
203 + });
204 + }).pipe(Effect.provide(layerTestFor(state)));
205 + });
206 +
207 + it.effect(
208 + "preserves cached remote status when a local-only refresh stays on the same branch",
209 + () => {
210 + const state = {
211 + currentLocalStatus: baseLocalStatus,
212 + currentRemoteStatus: { ...remoteStatusWithPr, aheadCount: 2, behindCount: 3 },
213 + localStatusCalls: 0,
214 + remoteStatusCalls: 0,
215 + localInvalidationCalls: 0,
216 + remoteInvalidationCalls: 0,
217 + };
218 +
219 + return Effect.gen(function* () {
220 + const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
221 + const initial = yield* broadcaster.getStatus({ cwd: "/repo" });
222 + const refreshed = yield* broadcaster.refreshStatus("/repo", { localOnly: true });
223 + assert.deepStrictEqual(refreshed, initial);
224 + assert.deepStrictEqual(yield* broadcaster.getStatus({ cwd: "/repo" }), refreshed);
225 + assert.equal(state.localInvalidationCalls, 1);
226 + assert.equal(state.remoteInvalidationCalls, 0);
227 + assert.equal(state.remoteStatusCalls, 1);
228 + }).pipe(Effect.provide(layerTestFor(state)));
229 + },
230 + );
231 +
232 + it.effect("clears the previous branch's remote status after an in-flight PR refresh", () => {
233 + const remoteReadStarted = Deferred.makeUnsafe<void>();
234 + const releaseRemoteRead = Deferred.makeUnsafe<void>();
235 + const state = {
236 + currentLocalStatus: baseLocalStatus,
237 + currentRemoteStatus: remoteStatusWithPr,
238 + localStatusCalls: 0,
239 + remoteStatusCalls: 0,
240 + localInvalidationCalls: 0,
241 + remoteInvalidationCalls: 0,
242 + beforeRemoteStatus: Effect.void,
243 + };
244 +
245 + return Effect.gen(function* () {
246 + const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
247 + yield* broadcaster.getStatus({ cwd: "/repo" });
248 + state.beforeRemoteStatus = Deferred.succeed(remoteReadStarted, undefined).pipe(
249 + Effect.andThen(Deferred.await(releaseRemoteRead)),
250 + );
251 + const remoteRefresh = yield* broadcaster
252 + .refreshPullRequestStatus("/repo")
253 + .pipe(Effect.forkScoped);
254 + yield* Deferred.await(remoteReadStarted);
255 + state.currentLocalStatus = { ...baseLocalStatus, refName: "main" };
256 + const localRefresh = yield* broadcaster
257 + .refreshStatus("/repo", { localOnly: true })
258 + .pipe(Effect.forkScoped);
259 + yield* Deferred.succeed(releaseRemoteRead, undefined);
260 + yield* Fiber.join(remoteRefresh);
261 + yield* Fiber.join(localRefresh);
262 +
263 + const status = yield* broadcaster.getStatus({ cwd: "/repo" });
264 + assert.equal(status.refName, "main");
265 + assert.isNull(status.pr);
266 + assert.equal(status.aheadCount, 0);
267 + assert.equal(status.behindCount, 0);
268 + assert.equal(state.remoteStatusCalls, 2);
269 + }).pipe(Effect.provide(layerTestFor(state)));
270 + });
271 +
272 it.effect.skipIf(!symlinksSupported)(
273 "automatically pulls an enabled clean default branch when status detects it is behind",
274 () => {
apps/server/src/vcs/VcsStatusBroadcaster.ts
+21 -2
@@ -207,7 +207,10 @@ export class VcsStatusBroadcaster extends Context.Service<
207 readonly refreshLocalStatus: (
208 cwd: string,
209 ) => Effect.Effect<VcsStatusLocalResult, GitManagerServiceError>;
210 - readonly refreshStatus: (cwd: string) => Effect.Effect<VcsStatusResult, GitManagerServiceError>;
210 + readonly refreshStatus: (
211 + cwd: string,
212 + options?: { readonly localOnly?: boolean },
213 + ) => Effect.Effect<VcsStatusResult, GitManagerServiceError>;
214 readonly refreshPullRequestStatus: (
215 cwd: string,
216 ) => Effect.Effect<VcsStatusRemoteResult | null, GitManagerServiceError>;
@@ -506,8 +509,24 @@ export const make = Effect.gen(function* () {
509
510 const refreshStatus: VcsStatusBroadcaster["Service"]["refreshStatus"] = Effect.fn(
511 "VcsStatusBroadcaster.refreshStatus",
509 - )(function* (rawCwd) {
512 + )(function* (rawCwd, options) {
513 const cwd = yield* withFileSystem(normalizeCwd(rawCwd));
514 + if (options?.localOnly) {
515 + return yield* withRemoteWriteLock(
516 + cwd,
517 + Effect.gen(function* () {
518 + yield* workflow.invalidateLocalStatus(cwd);
519 + const local = yield* workflow.localStatus({ cwd });
520 + const previous = yield* getCachedStatus(cwd);
521 + if (previous?.local?.value.refName !== local.refName) {
522 + yield* workflow.invalidateRemoteStatus(cwd);
523 + return yield* updateCachedStatus(cwd, local, null, { publish: true });
524 + }
525 + yield* updateCachedLocalStatus(cwd, local, { publish: true });
526 + return mergeGitStatusParts(local, previous?.remote?.value ?? null);
527 + }),
528 + );
529 + }
530 // Full invalidation also bypasses GitManager's slow PR cache.
531 return yield* withRemoteWriteLock(
532 cwd,
apps/server/src/ws.ts
+2 -1
@@ -2932,7 +2932,8 @@ export const layerWsRpc = (
2932 worktreeSetupTracker
2933 .cancel(input.threadId)
2934 .pipe(Effect.map((cancelled) => ({ cancelled }))),
2935 - [WS_METHODS.vcsRefreshStatus]: (input) => vcsStatusBroadcaster.refreshStatus(input.cwd),
2935 + [WS_METHODS.vcsRefreshStatus]: (input) =>
2936 + vcsStatusBroadcaster.refreshStatus(input.cwd, { localOnly: input.localOnly ?? false }),
2937 [WS_METHODS.vcsPull]: (input) =>
2938 gitWorkflow.pullCurrentBranch(input.cwd).pipe(
2939 Effect.matchCauseEffect({
apps/web/src/components/BranchToolbarBranchSelector.tsx
+6
@@ -126,6 +126,9 @@ export function BranchToolbarBranchSelector({
126 const switchRef = useAtomCommand(vcsEnvironment.switchRef, {
127 reportFailure: false,
128 });
129 + const refreshStatus = useAtomCommand(vcsEnvironment.refreshStatus, {
130 + reportFailure: false,
131 + });
132 const createRefMutation = useAtomCommand(vcsEnvironment.createRef, {
133 reportFailure: false,
134 });
@@ -503,6 +506,9 @@ export function BranchToolbarBranchSelector({
506
507 const handleOpenChange = (open: boolean) => {
508 setIsBranchMenuOpen(open);
509 + if (open && !isBranchMenuOpen && branchCwd !== null) {
510 + void refreshStatus({ environmentId, input: { cwd: branchCwd, localOnly: true } });
511 + }
512 if (!open) {
513 setBranchQuery("");
514 }
packages/contracts/src/rpc.ts
+4 -1
@@ -1361,7 +1361,10 @@ const WsVcsPullRpc = Rpc.make(WS_METHODS.vcsPull, {
1361 });
1362
1363 const WsVcsRefreshStatusRpc = Rpc.make(WS_METHODS.vcsRefreshStatus, {
1364 - payload: VcsStatusInput,
1364 + payload: Schema.Struct({
1365 + ...VcsStatusInput.fields,
1366 + localOnly: Schema.optional(Schema.Boolean),
1367 + }),
1368 success: VcsStatusResult,
1369 error: Schema.Union([GitManagerServiceError, EnvironmentAuthorizationError]),
1370 });