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 23, 01:45 UTC
fix(web): a closed proactive diff stays closed when you return to a thread (#14705)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
IlyaL committed
Oct 19, 2026 at 11:23 UTC
7400bc574851fea53655e6e481993fe0ac655311
5 files changed
+182
-35
apps/web/src/components/ChatView.logic.test.ts
+5
-11
@@ -1744,7 +1744,6 @@ describe("proactive completed diff guard", () => {
1744
resolveProactiveTurnDiffAction({
1745
checkpoint: changedCheckpoint,
1746
isGitRepo: true,
1747
- activeSurfaceKind: null,
1747
}),
1748
).toBe(action);
1749
},
@@ -1764,41 +1763,37 @@ describe("proactive completed diff guard", () => {
1763
resolveProactiveTurnDiffAction({
1764
checkpoint: undefined,
1765
isGitRepo: true,
1767
- activeSurfaceKind: null,
1766
}),
1767
).toBe("defer");
1768
expect(
1769
resolveProactiveTurnDiffAction({
1770
checkpoint: missingCheckpoint,
1771
isGitRepo: true,
1774
- activeSurfaceKind: null,
1772
}),
1773
).toBe("defer");
1774
expect(
1775
resolveProactiveTurnDiffAction({
1776
checkpoint: changedCheckpoint,
1777
isGitRepo: undefined,
1781
- activeSurfaceKind: null,
1778
}),
1779
).toBe("defer");
1780
});
1781
1786
- it("keeps an active pull request above a completed turn diff", () => {
1782
+ it("delegates a qualifying completed diff to the store while a pull request is active", () => {
1783
const changedCheckpoint = {
1784
status: "ready",
1789
- files: [{ path: "src/app.ts", kind: "modified", additions: 1, deletions: 0 }],
1785
+ files: [{ path: "src/app.ts", kind: "modified", additions: 50, deletions: 0 }],
1786
} satisfies Pick<TurnDiffSummary, "status" | "files">;
1787
1788
expect(
1789
resolveProactiveTurnDiffAction({
1790
checkpoint: changedCheckpoint,
1791
isGitRepo: true,
1796
- activeSurfaceKind: "pull-request",
1792
}),
1798
- ).toBe("ignore");
1793
+ ).toBe("open");
1794
});
1795
1801
- it("leaves an already open diff and its chosen scope alone", () => {
1796
+ it("delegates a qualifying completion to the store while a diff is already open", () => {
1797
const largeCheckpoint = {
1798
status: "ready",
1799
files: Array.from({ length: 3 }, (_, index) => ({
@@ -1813,9 +1808,8 @@ describe("proactive completed diff guard", () => {
1808
resolveProactiveTurnDiffAction({
1809
checkpoint: largeCheckpoint,
1810
isGitRepo: true,
1816
- activeSurfaceKind: "diff",
1811
}),
1818
- ).toBe("ignore");
1812
+ ).toBe("open");
1813
});
1814
});
1815
apps/web/src/components/ChatView.logic.ts
-5
@@ -181,12 +181,7 @@ export function shouldOpenProactiveTurnDiff(input: {
181
export function resolveProactiveTurnDiffAction(input: {
182
checkpoint: Pick<TurnDiffSummary, "status" | "files"> | undefined;
183
isGitRepo: boolean | undefined;
184
- activeSurfaceKind: RightPanelSurface["kind"] | null;
184
}): "defer" | "ignore" | "open" {
186
- // An open diff already shows the work; reopening it would reset the chosen scope.
187
- if (input.activeSurfaceKind === "pull-request" || input.activeSurfaceKind === "diff") {
188
- return "ignore";
189
- }
185
if (input.checkpoint === undefined || input.checkpoint.status === "missing") return "defer";
186
if (input.isGitRepo === undefined) return "defer";
187
if (
apps/web/src/hooks/useProactivePanels.ts
+7
-2
@@ -169,7 +169,6 @@ export function useProactivePanels(input: {
169
? resolveProactiveTurnDiffAction({
170
checkpoint: completedCheckpoint,
171
isGitRepo,
172
- activeSurfaceKind: openSurface?.kind ?? null,
172
})
173
: "ignore";
174
proactivePanelObservationRef.current = {
@@ -179,7 +178,13 @@ export function useProactivePanels(input: {
178
diffAction === "defer" || shouldDeferLink ? previousRunningTurnId : activeRunningTurnId,
179
};
180
if (diffAction !== "open" || newlyCompletedTurnId === null) return;
182
- if (!panels.openProactive(threadRef, { id: "diff", kind: "diff" }, userActionRevision)) {
181
+ if (
182
+ !panels.openProactive(
183
+ threadRef,
184
+ { kind: "diff", turnId: newlyCompletedTurnId },
185
+ userActionRevision,
186
+ )
187
+ ) {
188
return;
189
}
190
useDiffPanelStore.getState().selectGitScope(threadRef, "branch");
apps/web/src/rightPanelStore.test.ts
+141
-5
@@ -1,5 +1,5 @@
1
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2
-import { type EnvironmentId, ThreadId } from "@t3tools/contracts";
2
+import { type EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
3
import { beforeEach, describe, expect, it } from "vite-plus/test";
4
5
import { useClosedViewStore } from "./closedViewStore";
@@ -29,6 +29,16 @@ beforeEach(() => {
29
});
30
});
31
32
+async function reloadRightPanelStore() {
33
+ const { storage, name } = useRightPanelStore.persist.getOptions();
34
+ const persisted = await storage!.getItem(name!);
35
+ expect(persisted).not.toBeNull();
36
+ useRightPanelStore.setState(useRightPanelStore.getInitialState());
37
+ await storage!.setItem(name!, persisted!);
38
+ await useRightPanelStore.persist.rehydrate();
39
+ expect(useRightPanelStore.persist.hasHydrated()).toBe(true);
40
+}
41
+
42
describe("rightPanelStore", () => {
43
it("records single and bulk tab closes, newest first", () => {
44
const store = useRightPanelStore.getState();
@@ -208,7 +218,7 @@ describe("rightPanelStore", () => {
218
},
219
);
220
211
- const completedDiff = { id: "diff", kind: "diff" } as const;
221
+ const completedDiff = { kind: "diff", turnId: RunId.make("turn-1") } as const;
222
const linkedPullRequest = pullRequestSurface({
223
projectId: "project-a",
224
repository: "pingdotgg/t3code",
@@ -281,9 +291,15 @@ describe("rightPanelStore", () => {
291
expect(
292
store.openProactive(refA, { id: "pull-requests", kind: "pull-requests" }, revision),
293
).toBe(false);
284
- expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toBe(
285
- chosen,
294
+ const { isOpen, activeSurfaceId, surfaces } = selectThreadRightPanelState(
295
+ useRightPanelStore.getState().byThreadKey,
296
+ refA,
297
);
298
+ expect({ isOpen, activeSurfaceId, surfaces }).toEqual({
299
+ isOpen: chosen.isOpen,
300
+ activeSurfaceId: chosen.activeSurfaceId,
301
+ surfaces: chosen.surfaces,
302
+ });
303
});
304
305
it("allows automatic panels for a later turn after a manual choice", () => {
@@ -293,7 +309,127 @@ describe("rightPanelStore", () => {
309
expect(store.openProactive(refA, completedDiff, firstTurnRevision)).toBe(false);
310
311
const nextTurnRevision = store.getUserActionRevision(refA);
296
- expect(store.openProactive(refA, completedDiff, nextTurnRevision)).toBe(true);
312
+ expect(
313
+ store.openProactive(
314
+ refA,
315
+ { ...completedDiff, turnId: RunId.make("turn-2") },
316
+ nextTurnRevision,
317
+ ),
318
+ ).toBe(true);
319
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
320
+ });
321
+
322
+ it("offers each completed diff once across dismissal, panel changes, and reload", async () => {
323
+ const store = useRightPanelStore.getState();
324
+ expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(true);
325
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
326
+
327
+ store.close(refA);
328
+ await reloadRightPanelStore();
329
+ expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
330
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
331
+
332
+ store.open(refA, "files");
333
+ store.openFile(refA, "src/app.ts");
334
+ await reloadRightPanelStore();
335
+ expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
336
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("file");
337
+
338
+ store.closeAllSurfaces(refA);
339
+ await reloadRightPanelStore();
340
+ expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
341
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
342
+
343
+ const otherEnvironment = scopeThreadRef("env-2" as EnvironmentId, refA.threadId);
344
+ for (const ref of [refB, otherEnvironment]) {
345
+ expect(store.openProactive(ref, completedDiff, store.getUserActionRevision(ref))).toBe(true);
346
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, ref)).toBe("diff");
347
+ }
348
+
349
+ const nextTurn = { ...completedDiff, turnId: RunId.make("turn-2") };
350
+ expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(true);
351
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
352
+
353
+ const completedWhileOpen = { ...completedDiff, turnId: RunId.make("turn-3") };
354
+ const existingDiff = selectActiveRightPanelSurface(
355
+ useRightPanelStore.getState().byThreadKey,
356
+ refA,
357
+ );
358
+ expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
359
+ false,
360
+ );
361
+ expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
362
+ existingDiff,
363
+ );
364
+ store.closeSurface(refA, "diff");
365
+ await reloadRightPanelStore();
366
+ expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
367
+ false,
368
+ );
369
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
370
+
371
+ // A later storage migration must preserve the dismissal, just like an ordinary reload.
372
+ const { storage, name, version } = useRightPanelStore.persist.getOptions();
373
+ const persisted = await storage!.getItem(name!);
374
+ await storage!.setItem(name!, { ...persisted!, version: version! - 1 });
375
+ await reloadRightPanelStore();
376
+ expect(store.openProactive(refA, completedWhileOpen, store.getUserActionRevision(refA))).toBe(
377
+ false,
378
+ );
379
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
380
+
381
+ expect(
382
+ store.openProactive(
383
+ refA,
384
+ { ...completedDiff, turnId: RunId.make("turn-4") },
385
+ store.getUserActionRevision(refA),
386
+ ),
387
+ ).toBe(true);
388
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
389
+ store.closeSurface(refA, "diff");
390
+ store.open(refA, "diff");
391
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
392
+ });
393
+
394
+ it("does not retry declined diff offers after manual choices or PR priority clear", async () => {
395
+ const store = useRightPanelStore.getState();
396
+ const revision = store.getUserActionRevision(refA);
397
+ store.openFile(refA, "src/app.ts");
398
+ expect(store.openProactive(refA, completedDiff, revision)).toBe(false);
399
+ await reloadRightPanelStore();
400
+ expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
401
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("file");
402
+
403
+ store.closeAllSurfaces(refA);
404
+ expect(store.openProactive(refA, completedDiff, store.getUserActionRevision(refA))).toBe(false);
405
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
406
+
407
+ const nextTurn = { ...completedDiff, turnId: RunId.make("turn-2") };
408
+ store.openPullRequest(refA, linkedPullRequest);
409
+ expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(false);
410
+ expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
411
+ linkedPullRequest,
412
+ );
413
+ expect(
414
+ selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA).surfaces,
415
+ ).toEqual([linkedPullRequest]);
416
+ await reloadRightPanelStore();
417
+ expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(false);
418
+ expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)).toEqual(
419
+ linkedPullRequest,
420
+ );
421
+ store.closeSurface(refA, linkedPullRequest.id);
422
+ await reloadRightPanelStore();
423
+ expect(store.openProactive(refA, nextTurn, store.getUserActionRevision(refA))).toBe(false);
424
+ expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
425
+
426
+ expect(
427
+ store.openProactive(
428
+ refA,
429
+ { ...completedDiff, turnId: RunId.make("turn-3") },
430
+ store.getUserActionRevision(refA),
431
+ ),
432
+ ).toBe(true);
433
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
434
});
435
apps/web/src/rightPanelStore.ts
+29
-12
@@ -3,7 +3,7 @@ import {
3
scopedThreadKey,
4
scopeThreadRef,
5
} from "@t3tools/client-runtime/environment";
6
-import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
6
+import { EnvironmentId, RunId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
7
import { create } from "zustand";
8
import { createJSONStorage, persist } from "zustand/middleware";
9
@@ -95,6 +95,7 @@ export interface ThreadRightPanelState {
95
surfaces: RightPanelSurface[];
96
dismissedDeviceSurfaceIds?: string[];
97
maximized?: true;
98
+ proactiveDiffTurnId?: RunId;
99
}
100
101
export interface ThreadPanelVisibility {
@@ -117,7 +118,9 @@ interface RightPanelStoreState {
118
*/
119
openProactive: (
120
ref: ScopedThreadRef,
120
- surface: Extract<RightPanelSurface, { kind: "diff" | "pull-request" | "pull-requests" }>,
121
+ request:
122
+ | Extract<RightPanelSurface, { kind: "pull-request" | "pull-requests" }>
123
+ | { kind: "diff"; turnId: RunId },
124
expectedUserActionRevision: number,
125
) => boolean;
126
open: (
@@ -310,7 +313,8 @@ const updateThreadStateMap = (
313
!next.isOpen &&
314
next.activeSurfaceId === null &&
315
next.surfaces.length === 0 &&
313
- !next.dismissedDeviceSurfaceIds?.length
316
+ !next.dismissedDeviceSurfaceIds?.length &&
317
+ next.proactiveDiffTurnId === undefined
318
) {
319
if (!(threadKey in byThreadKey)) return byThreadKey;
320
const { [threadKey]: _removed, ...rest } = byThreadKey;
@@ -545,6 +549,9 @@ export function migratePersistedRightPanelState(persistedState: unknown): {
549
isOpen,
550
surfaces,
551
activeSurfaceId,
552
+ ...(typeof validThreadState?.proactiveDiffTurnId === "string"
553
+ ? { proactiveDiffTurnId: RunId.make(validThreadState.proactiveDiffTurnId) }
554
+ : {}),
555
...(Array.isArray(validThreadState?.dismissedDeviceSurfaceIds)
556
? {
557
dismissedDeviceSurfaceIds:
@@ -593,24 +600,34 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
600
closeRevisionByThreadKey: {},
601
getUserActionRevision: (ref) =>
602
get().userActionRevisionByThreadKey[scopedThreadKey(ref)] ?? 0,
596
- openProactive: (ref, surface, expectedUserActionRevision) => {
603
+ openProactive: (ref, request, expectedUserActionRevision) => {
604
let opened = false;
605
set((state) => {
606
const threadKey = scopedThreadKey(ref);
600
- if (
601
- (state.userActionRevisionByThreadKey[threadKey] ?? 0) !== expectedUserActionRevision
602
- ) {
603
- return state;
607
+ if (request.kind === "diff") {
608
+ const current = selectThreadRightPanelState(state.byThreadKey, ref);
609
+ if (current.proactiveDiffTurnId === request.turnId) return state;
610
+ const activePanel = selectActiveRightPanel(state.byThreadKey, ref);
611
+ const pullRequestActive =
612
+ activePanel === "pull-request" || activePanel === "pull-requests";
613
+ opened =
614
+ (state.userActionRevisionByThreadKey[threadKey] ?? 0) ===
615
+ expectedUserActionRevision &&
616
+ activePanel !== "diff" &&
617
+ !pullRequestActive;
618
+ // Record the offer even when refused, so a revisit does not retry this turn.
619
+ return automaticUpdate(state, threadKey, (thread) => ({
620
+ ...(opened ? upsertSurface(thread, singletonSurface("diff")) : thread),
621
+ proactiveDiffTurnId: request.turnId,
622
+ }));
623
}
624
if (
606
- surface.kind === "diff" &&
607
- (selectActiveRightPanel(state.byThreadKey, ref) === "pull-request" ||
608
- selectActiveRightPanel(state.byThreadKey, ref) === "pull-requests")
625
+ (state.userActionRevisionByThreadKey[threadKey] ?? 0) !== expectedUserActionRevision
626
) {
627
return state;
628
}
629
opened = true;
613
- return automaticUpdate(state, threadKey, (current) => upsertSurface(current, surface));
630
+ return automaticUpdate(state, threadKey, (current) => upsertSurface(current, request));
631
});
632
return opened;
633
},