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, 00:45 UTC
fix(server): opening the branch menu no longer wipes PR status (#33263)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 00:19 UTC
a22068f3711e684b99acfff9f2a0974365046815
2 files changed
+101
-19
apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+97
-2
@@ -375,17 +375,19 @@ describe("VcsStatusBroadcaster", () => {
375
yield* Deferred.await(subscribed);
376
377
state.currentLocalStatus = { ...baseLocalStatus, refName: "main" };
378
+ state.currentRemoteStatus = baseRemoteStatus;
379
const refreshed = yield* broadcaster.refreshStatus("/repo", { localOnly: true });
380
assert.equal(refreshed.refName, "main");
381
assert.isNull(refreshed.pr);
382
assert.equal(state.localInvalidationCalls, 1);
383
assert.equal(state.remoteStatusCalls, 1);
383
- assert.equal(state.remoteInvalidationCalls, 2);
384
+ assert.equal(state.remoteInvalidationCalls, 1);
385
assert.deepStrictEqual((yield* Fiber.join(events)).slice(1), [
386
{ _tag: "remoteUpdated", remote: null },
387
{ _tag: "localUpdated", local: state.currentLocalStatus },
388
]);
389
assert.isNull((yield* broadcaster.getStatus({ cwd: "/repo" })).pr);
390
+ assert.equal(state.remoteStatusCalls, 2);
391
state.currentLocalStatus = { ...state.currentLocalStatus, hasWorkingTreeChanges: true };
392
yield* broadcaster.refreshLocalStatus("/repo");
393
state.currentLocalStatus = { ...baseLocalStatus, refName: "union" };
@@ -433,6 +435,98 @@ describe("VcsStatusBroadcaster", () => {
435
},
436
);
437
438
+ it.effect("a local-only refresh that overlaps the first remote poll keeps its PR", () => {
439
+ const state: Parameters<typeof layerTestFor>[0] = {
440
+ currentLocalStatus: baseLocalStatus,
441
+ currentRemoteStatus: remoteStatusWithPr,
442
+ localStatusCalls: 0,
443
+ remoteStatusCalls: 0,
444
+ localInvalidationCalls: 0,
445
+ remoteInvalidationCalls: 0,
446
+ };
447
+
448
+ return Effect.gen(function* () {
449
+ const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
450
+ const pollStarted = yield* Deferred.make<void>();
451
+ const releasePoll = yield* Deferred.make<void>();
452
+ state.beforeRemoteStatus = Deferred.succeed(pollStarted, undefined).pipe(
453
+ Effect.andThen(Deferred.await(releasePoll)),
454
+ );
455
+ const localSeen = yield* Deferred.make<void>();
456
+ yield* broadcaster.streamStatus({ cwd: "/repo" }).pipe(
457
+ Stream.runForEach((event) =>
458
+ event._tag === "localUpdated" ? Deferred.succeed(localSeen, undefined) : Effect.void,
459
+ ),
460
+ Effect.forkScoped,
461
+ );
462
+ yield* Deferred.await(pollStarted);
463
+ state.beforeRemoteStatus = Effect.void;
464
+
465
+ state.currentLocalStatus = { ...baseLocalStatus, hasWorkingTreeChanges: true };
466
+ const refresh = yield* broadcaster
467
+ .refreshStatus("/repo", { localOnly: true })
468
+ .pipe(Effect.forkScoped);
469
+ yield* Deferred.await(localSeen);
470
+ yield* Deferred.succeed(releasePoll, undefined);
471
+ yield* Fiber.join(refresh);
472
+
473
+ const status = yield* broadcaster.getStatus({ cwd: "/repo" });
474
+ assert.deepStrictEqual(status.pr, remoteStatusWithPr.pr);
475
+ assert.equal(state.remoteStatusCalls, 1);
476
+ }).pipe(Effect.provide(layerTestFor(state)));
477
+ });
478
+
479
+ it.effect(
480
+ "a local-only refresh before any remote read leaves the PR refresh able to read",
481
+ () => {
482
+ const state: Parameters<typeof layerTestFor>[0] = {
483
+ currentLocalStatus: baseLocalStatus,
484
+ currentRemoteStatus: remoteStatusWithPr,
485
+ localStatusCalls: 0,
486
+ remoteStatusCalls: 0,
487
+ localInvalidationCalls: 0,
488
+ remoteInvalidationCalls: 0,
489
+ };
490
+
491
+ return Effect.gen(function* () {
492
+ const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
493
+ yield* broadcaster.refreshStatus("/repo", { localOnly: true });
494
+
495
+ const remote = yield* broadcaster.refreshPullRequestStatus("/repo");
496
+ assert.deepStrictEqual(remote?.pr, remoteStatusWithPr.pr);
497
+ assert.equal(state.remoteStatusCalls, 1);
498
+ }).pipe(Effect.provide(layerTestFor(state)));
499
+ },
500
+ );
501
+
502
+ it.effect("a local-only refresh after a branch switch leaves the PR refresh able to read", () => {
503
+ const state: Parameters<typeof layerTestFor>[0] = {
504
+ currentLocalStatus: baseLocalStatus,
505
+ currentRemoteStatus: remoteStatusWithPr,
506
+ localStatusCalls: 0,
507
+ remoteStatusCalls: 0,
508
+ localInvalidationCalls: 0,
509
+ remoteInvalidationCalls: 0,
510
+ };
511
+
512
+ return Effect.gen(function* () {
513
+ const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
514
+ yield* broadcaster.getStatus({ cwd: "/repo" });
515
+
516
+ state.currentLocalStatus = { ...baseLocalStatus, refName: "feature/next" };
517
+ const nextBranchRemote: VcsStatusRemoteResult = {
518
+ ...baseRemoteStatus,
519
+ pr: { ...remoteStatusWithPr.pr!, number: 3001, headRef: "feature/next" },
520
+ };
521
+ state.currentRemoteStatus = nextBranchRemote;
522
+ yield* broadcaster.refreshStatus("/repo", { localOnly: true });
523
+
524
+ const remote = yield* broadcaster.refreshPullRequestStatus("/repo");
525
+ assert.deepStrictEqual(remote?.pr, nextBranchRemote.pr);
526
+ assert.equal(state.remoteStatusCalls, 2);
527
+ }).pipe(Effect.provide(layerTestFor(state)));
528
+ });
529
+
530
it.effect("clears the previous branch's remote status after an in-flight PR refresh", () => {
531
const remoteReadStarted = Deferred.makeUnsafe<void>();
532
const releaseRemoteRead = Deferred.makeUnsafe<void>();
@@ -463,13 +557,14 @@ describe("VcsStatusBroadcaster", () => {
557
yield* Deferred.succeed(releaseRemoteRead, undefined);
558
yield* Fiber.join(remoteRefresh);
559
yield* Fiber.join(localRefresh);
560
+ state.currentRemoteStatus = baseRemoteStatus;
561
562
const status = yield* broadcaster.getStatus({ cwd: "/repo" });
563
assert.equal(status.refName, "main");
564
assert.isNull(status.pr);
565
assert.equal(status.aheadCount, 0);
566
assert.equal(status.behindCount, 0);
472
- assert.equal(state.remoteStatusCalls, 2);
567
+ assert.equal(state.remoteStatusCalls, 3);
568
}).pipe(Effect.provide(layerTestFor(state)));
569
});
570
apps/server/src/vcs/VcsStatusBroadcaster.ts
+4
-17
@@ -537,24 +537,11 @@ export const make = Effect.gen(function* () {
537
"VcsStatusBroadcaster.refreshStatus",
538
)(function* (rawCwd, options) {
539
const cwd = yield* withFileSystem(normalizeCwd(rawCwd));
540
- const previous = options?.localOnly ? yield* getCachedStatus(cwd) : null;
541
- const local = yield* refreshLocalStatusCore(cwd);
540
+ yield* refreshLocalStatusCore(cwd);
541
if (options?.localOnly) {
543
- return yield* withRemoteWriteLock(
544
- cwd,
545
- Effect.gen(function* () {
546
- if (previous?.local?.value.refName !== local.refName || !previous?.remote) {
547
- yield* workflow.invalidateRemoteStatus(cwd);
548
- yield* updateCachedRemoteStatus(
549
- cwd,
550
- { branch: local.refName, fingerprint: fingerprintStatusPart(null), value: null },
551
- { publish: true },
552
- );
553
- }
554
- const parts = yield* getStatusParts(cwd);
555
- return mergeGitStatusParts(parts.local, parts.remote);
556
- }),
557
- );
542
+ // Never cache a remote here: readers take `value: null` as "read and found no PR".
543
+ const parts = yield* getStatusParts(cwd);
544
+ return mergeGitStatusParts(parts.local, parts.remote);
545
}
546
return yield* withRemoteWriteLock(
547
cwd,