From 69c0e0480e0e13195194d4d63fcf24dcb123ab91 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Thu, 15 Oct 2026 04:46:28 +0000 Subject: [PATCH 01/12] fix(web): edit from here shows how many files a file revert would undo The "Revert files too" button was a solid red button competing with the default. It is now an outline, the dialog says how many files changed since that message, and the file choice is hidden when nothing changed. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatView.tsx | 32 ++++++++++++++++++---------- apps/web/src/session-logic.test.ts | 22 +++++++++++++++++++ apps/web/src/session-logic.ts | 13 +++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index ae891d75193ea..4e923923b45e9 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -198,6 +198,7 @@ import { type TimelineEntriesProjection, deriveActivePlanState, deriveActiveWorkStartedAt, + countFilesChangedAfterTurnCount, deriveCanInterruptRunningThread, findLatestProposedPlan, hasActionableProposedPlan, @@ -8490,6 +8491,10 @@ export default function ChatView(props: ChatViewProps) { if (pendingRevert && pendingRevert.routeThreadKey !== routeThreadKey) { setPendingRevert(null); } + const pendingRevertChangedFileCount = + pendingRevert === null + ? 0 + : countFilesChangedAfterTurnCount(turnDiffSummaries, pendingRevert.turnCount); const onRevertToTurnCount = useCallback( async (turnCount: number, messageId: MessageId, restoreFiles?: boolean) => { @@ -12218,20 +12223,25 @@ export default function ChatView(props: ChatViewProps) { Rewind chat to before this message. Your prompt and attachments return to the composer. + {pendingRevertChangedFileCount > 0 + ? ` ${pendingRevertChangedFileCount} ${pendingRevertChangedFileCount === 1 ? "file" : "files"} changed since then.` + : " No files changed since then."} }>Cancel - + {pendingRevertChangedFileCount > 0 ? ( + + ) : null} diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index f7d61b8f65a70..7d70e70c324d9 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -27,6 +27,7 @@ import { deriveCanInterruptRunningThread, deriveTimelineEntriesFromVisibleTurnItems, deriveTimelineEntriesFromVisibleTurnItemsWithState, + countFilesChangedAfterTurnCount, deriveRevertTurnCountByUserMessageId, derivePhase, findLatestProposedPlan, @@ -301,6 +302,27 @@ describe("V2 session presentation", () => { expect(targets.has(steerMessageId)).toBe(false); }); + it("counts each file changed after the rewind point once", () => { + const checkpoint = (turnCount: number, paths: string[]) => ({ + runId: RunId.make(`run-${turnCount}`), + checkpointTurnCount: turnCount, + checkpointRef: `checkpoint-${turnCount}` as never, + status: "ready" as const, + files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), + assistantMessageId: null, + completedAt: "2026-06-20T00:00:00.000Z", + }); + const checkpoints = [ + checkpoint(1, ["a.ts"]), + checkpoint(2, ["b.ts", "c.ts"]), + checkpoint(3, ["c.ts", "d.ts"]), + ]; + + expect(countFilesChangedAfterTurnCount(checkpoints, 1)).toBe(3); + expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(4); + expect(countFilesChangedAfterTurnCount(checkpoints, 3)).toBe(0); + }); + it("uses visible turn item order and keeps provider errors in the work log", () => { const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); const threadId = ThreadId.make("thread-visible"); diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index a1554683a5648..40f712f1ba251 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1066,6 +1066,19 @@ export function deriveRevertTurnCountByUserMessageId(input: { return byUserMessageId; } +/** Counts distinct files changed by turns a rewind to `turnCount` would undo. */ +export function countFilesChangedAfterTurnCount( + checkpoints: ReadonlyArray, + turnCount: number, +): number { + const paths = new Set(); + for (const checkpoint of checkpoints) { + if (checkpoint.checkpointTurnCount <= turnCount) continue; + for (const file of checkpoint.files) paths.add(file.path); + } + return paths.size; +} + export function derivePhase(runtime: ThreadRuntimeSummary | null): SessionPhase { if (runtime === null) return "disconnected"; if ( From caffcb545d5ff574f5cafe09c3f1b1b3c7c7b254 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Thu, 15 Oct 2026 05:07:01 +0000 Subject: [PATCH 02/12] fix(web): keep the file revert choice and skip discarded turns in the count File restore resets the whole workspace, so a zero agent file count does not mean "Revert files too" is a no-op. The button now always shows and the count only appears when the agent changed files. Stale checkpoints from an earlier rewind no longer inflate the count. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatView.tsx | 28 +++++++++++++--------------- apps/web/src/session-logic.test.ts | 10 ++++++++-- apps/web/src/session-logic.ts | 8 ++++++-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 4e923923b45e9..4a1a77c6adf3c 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -12224,24 +12224,22 @@ export default function ChatView(props: ChatViewProps) { Rewind chat to before this message. Your prompt and attachments return to the composer. {pendingRevertChangedFileCount > 0 - ? ` ${pendingRevertChangedFileCount} ${pendingRevertChangedFileCount === 1 ? "file" : "files"} changed since then.` - : " No files changed since then."} + ? ` The agent changed ${pendingRevertChangedFileCount} ${pendingRevertChangedFileCount === 1 ? "file" : "files"} since then.` + : null} }>Cancel - {pendingRevertChangedFileCount > 0 ? ( - - ) : null} + diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 7d70e70c324d9..86e2063070377 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -303,11 +303,15 @@ describe("V2 session presentation", () => { }); it("counts each file changed after the rewind point once", () => { - const checkpoint = (turnCount: number, paths: string[]) => ({ + const checkpoint = ( + turnCount: number, + paths: string[], + status: "ready" | "stale" = "ready", + ) => ({ runId: RunId.make(`run-${turnCount}`), checkpointTurnCount: turnCount, checkpointRef: `checkpoint-${turnCount}` as never, - status: "ready" as const, + status, files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), assistantMessageId: null, completedAt: "2026-06-20T00:00:00.000Z", @@ -316,6 +320,8 @@ describe("V2 session presentation", () => { checkpoint(1, ["a.ts"]), checkpoint(2, ["b.ts", "c.ts"]), checkpoint(3, ["c.ts", "d.ts"]), + // Discarded by an earlier rewind, so its files are already restored. + checkpoint(4, ["e.ts"], "stale"), ]; expect(countFilesChangedAfterTurnCount(checkpoints, 1)).toBe(3); diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 40f712f1ba251..3cdce1717411e 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1066,14 +1066,18 @@ export function deriveRevertTurnCountByUserMessageId(input: { return byUserMessageId; } -/** Counts distinct files changed by turns a rewind to `turnCount` would undo. */ +/** + * Counts distinct files the agent changed in turns a rewind to `turnCount` would undo. + * Stale checkpoints belong to history an earlier rewind already discarded. File restore + * resets the whole workspace, so a zero here does not mean restoring files is a no-op. + */ export function countFilesChangedAfterTurnCount( checkpoints: ReadonlyArray, turnCount: number, ): number { const paths = new Set(); for (const checkpoint of checkpoints) { - if (checkpoint.checkpointTurnCount <= turnCount) continue; + if (checkpoint.checkpointTurnCount <= turnCount || checkpoint.status === "stale") continue; for (const file of checkpoint.files) paths.add(file.path); } return paths.size; From ddc2a556d8b20660c850bb5b9423cd4569c8ea82 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Thu, 15 Oct 2026 05:10:41 +0000 Subject: [PATCH 03/12] fix(web): count only files in the checkpoint scope the rewind targets Match the rollback command's ordinal-based checkpoint selection so the count never includes turns from another scope. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/session-logic.test.ts | 22 ++++++++++++++++++++++ apps/web/src/session-logic.ts | 11 +++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 86e2063070377..edc5a363d572b 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -302,6 +302,28 @@ describe("V2 session presentation", () => { expect(targets.has(steerMessageId)).toBe(false); }); + it("counts only files in the scope the rewind targets", () => { + const checkpoint = (turnCount: number, scope: string, paths: string[]) => ({ + scopeId: scope as never, + runId: RunId.make(`run-${scope}-${turnCount}`), + checkpointTurnCount: turnCount, + checkpointRef: `checkpoint-${scope}-${turnCount}` as never, + status: "ready" as const, + files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), + assistantMessageId: null, + completedAt: "2026-06-20T00:00:00.000Z", + }); + const checkpoints = [ + checkpoint(1, "root", ["a.ts"]), + checkpoint(2, "root", ["b.ts"]), + checkpoint(2, "other", ["x.ts", "y.ts"]), + checkpoint(3, "root", ["c.ts"]), + ]; + + expect(countFilesChangedAfterTurnCount(checkpoints, 1)).toBe(2); + expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(3); + }); + it("counts each file changed after the rewind point once", () => { const checkpoint = ( turnCount: number, diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 3cdce1717411e..1f90960e21153 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1068,16 +1068,23 @@ export function deriveRevertTurnCountByUserMessageId(input: { /** * Counts distinct files the agent changed in turns a rewind to `turnCount` would undo. - * Stale checkpoints belong to history an earlier rewind already discarded. File restore - * resets the whole workspace, so a zero here does not mean restoring files is a no-op. + * Only the scope of the rollback target counts, matched the way `revertThreadCheckpoint` + * picks it; a rewind to before the first turn targets the first turn's scope. Stale + * checkpoints belong to history an earlier rewind already discarded. File restore resets + * the whole workspace, so a zero here does not mean restoring files is a no-op. */ export function countFilesChangedAfterTurnCount( checkpoints: ReadonlyArray, turnCount: number, ): number { + const scopeId = ( + checkpoints.findLast((checkpoint) => checkpoint.checkpointTurnCount === turnCount) ?? + checkpoints.find((checkpoint) => checkpoint.checkpointTurnCount === turnCount + 1) + )?.scopeId; const paths = new Set(); for (const checkpoint of checkpoints) { if (checkpoint.checkpointTurnCount <= turnCount || checkpoint.status === "stale") continue; + if (checkpoint.scopeId !== scopeId) continue; for (const file of checkpoint.files) paths.add(file.path); } return paths.size; From 11460ef7c35f294db55fcbd0e177df3afd97cbb5 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 09:27:54 +0530 Subject: [PATCH 04/12] fix(web): a rewind to before the first turn counts the latest scope The rewind restores the latest baseline checkpoint, so the fallback picks the latest turn-1 checkpoint's scope, not the oldest. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/session-logic.test.ts | 21 +++++++++++++++++++++ apps/web/src/session-logic.ts | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 257af0dc6ee10..9d96bc1c0d808 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -317,6 +317,27 @@ describe("V2 session presentation", () => { expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(3); }); + it("a rewind to before the first turn counts the latest first turn's scope", () => { + const checkpoint = (turnCount: number, scope: string, paths: string[]) => ({ + scopeId: scope as never, + runId: RunId.make(`run-${scope}-${turnCount}`), + checkpointTurnCount: turnCount, + checkpointRef: `checkpoint-${scope}-${turnCount}` as never, + status: "ready" as const, + files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), + assistantMessageId: null, + completedAt: "2026-06-20T00:00:00.000Z", + }); + // The rewind restores the latest baseline, so the older scope's turn 1 must not win. + const checkpoints = [ + checkpoint(1, "old", ["a.ts"]), + checkpoint(1, "new", ["x.ts", "y.ts"]), + checkpoint(2, "new", ["z.ts"]), + ]; + + expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(3); + }); + it("counts each file changed after the rewind point once", () => { const checkpoint = ( turnCount: number, diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 4e30d50ad6366..2ab4955cb5f1c 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1038,7 +1038,7 @@ export function deriveRevertTurnCountByUserMessageId(input: { /** * Counts distinct files the agent changed in turns a rewind to `turnCount` would undo. * Only the scope of the rollback target counts, matched the way `revertThreadCheckpoint` - * picks it; a rewind to before the first turn targets the first turn's scope. Stale + * picks it; a rewind to before the first turn targets the latest first turn's scope. Stale * checkpoints belong to history an earlier rewind already discarded. File restore resets * the whole workspace, so a zero here does not mean restoring files is a no-op. */ @@ -1048,7 +1048,7 @@ export function countFilesChangedAfterTurnCount( ): number { const scopeId = ( checkpoints.findLast((checkpoint) => checkpoint.checkpointTurnCount === turnCount) ?? - checkpoints.find((checkpoint) => checkpoint.checkpointTurnCount === turnCount + 1) + checkpoints.findLast((checkpoint) => checkpoint.checkpointTurnCount === turnCount + 1) )?.scopeId; const paths = new Set(); for (const checkpoint of checkpoints) { From 9afbf44b6bf1af9544742542fe15097b2880f2b7 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 09:31:07 +0530 Subject: [PATCH 05/12] fix(web): edit from here counts checkpoints captured while it is open The dialog reads the thread's checkpoints while open instead of a count frozen at open time, so a checkpoint captured after Stop still counts. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatView.tsx | 13 ++++--- .../chat/ChatOverlayHosts.browser.test.tsx | 35 ++++++++++++++++--- .../src/components/chat/ChatOverlayHosts.tsx | 13 ++++--- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index e5653e433d707..1cbf598ba4548 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -182,7 +182,6 @@ import { selectHandoffImageResources, deriveActivePlanState, deriveActiveWorkStartedAt, - countFilesChangedAfterTurnCount, deriveCanInterruptRunningThread, findLatestProposedPlan, hasActionableProposedPlan, @@ -5735,11 +5734,7 @@ export default function ChatView(props: ChatViewProps) { return; } if (restoreFiles === undefined) { - openRevertConfirm(routeThreadKey, { - turnCount, - messageId, - changedFileCount: countFilesChangedAfterTurnCount(turnDiffSummaries, turnCount), - }); + openRevertConfirm(routeThreadKey, { turnCount, messageId }); return; } @@ -8615,7 +8610,11 @@ export default function ChatView(props: ChatViewProps) { ) : null} - + diff --git a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx index d042b8ba752d3..16b33c7782cec 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx @@ -1,4 +1,5 @@ -import { MessageId } from "@t3tools/contracts"; +import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; +import { MessageId, RunId } from "@t3tools/contracts"; import { act } from "react"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; @@ -30,15 +31,15 @@ describe("RevertConfirmHost", () => { const onConfirm = vi.fn(); const host = (threadKey: string) => ( - + ); await act(() => root.render(host("env:a"))); - await act(() => openRevertConfirm("env:b", { turnCount: 2, messageId, changedFileCount: 0 })); + await act(() => openRevertConfirm("env:b", { turnCount: 2, messageId })); expect(dialog()).toBeNull(); - await act(() => openRevertConfirm("env:a", { turnCount: 2, messageId, changedFileCount: 0 })); + await act(() => openRevertConfirm("env:a", { turnCount: 2, messageId })); const keep = [...(dialog()?.querySelectorAll("button") ?? [])].find( (button) => button.textContent === "Revert and keep changes", ); @@ -46,9 +47,33 @@ describe("RevertConfirmHost", () => { expect(onConfirm).toHaveBeenCalledExactlyOnceWith(2, messageId, false); await vi.waitFor(() => expect(dialog()).toBeNull()); - await act(() => openRevertConfirm("env:a", { turnCount: 3, messageId, changedFileCount: 0 })); + await act(() => openRevertConfirm("env:a", { turnCount: 3, messageId })); expect(dialog()).not.toBeNull(); await act(() => root.render(host("env:b"))); await vi.waitFor(() => expect(dialog()).toBeNull()); }); + + it("counts a checkpoint captured while the dialog is open", async () => { + const checkpoint = (turnCount: number, paths: string[]): ThreadCheckpointSummary => ({ + runId: RunId.make(`run-${turnCount}`), + checkpointTurnCount: turnCount, + checkpointRef: `checkpoint-${turnCount}` as never, + status: "ready", + files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), + assistantMessageId: null, + completedAt: "2026-06-20T00:00:00.000Z", + }); + const host = (checkpoints: ReadonlyArray) => ( + + + + ); + const first = [checkpoint(1, ["a.ts"]), checkpoint(2, ["b.ts"])]; + await act(() => root.render(host(first))); + await act(() => openRevertConfirm("env:a", { turnCount: 1, messageId })); + expect(dialog()?.textContent).toContain("The agent changed 1 file since then."); + + await act(() => root.render(host([...first, checkpoint(3, ["c.ts", "d.ts"])]))); + expect(dialog()?.textContent).toContain("The agent changed 3 files since then."); + }); }); diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index 1dab1daa4cb85..b475ce75f36a3 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -9,8 +9,11 @@ import { useAtomValue } from "@effect/atom-react"; import { Atom } from "effect/reactivity"; import { useEffect } from "react"; +import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; + import { appAtomRegistry } from "~/rpc/atomRegistry"; import { useRightPanelStore } from "~/rightPanelStore"; +import { countFilesChangedAfterTurnCount } from "~/session-logic"; import { DeviceSetup } from "../device/DeviceSetup"; import { PullRequestThreadDialog } from "../PullRequestThreadDialog"; import { @@ -183,8 +186,6 @@ export function BranchRestoreConfirmHost(props: { interface PendingRevert { readonly turnCount: number; readonly messageId: MessageId; - /** Files the agent changed in checkpoints this rewind would undo. */ - readonly changedFileCount: number; } const revertConfirmAtom = makeThreadOverlayAtom("revert-confirm"); @@ -195,9 +196,13 @@ export function openRevertConfirm(threadKey: string, pending: PendingRevert): vo export function RevertConfirmHost(props: { readonly threadKey: string; + /** Read while open, so a checkpoint captured after opening still counts. */ + readonly checkpoints: ReadonlyArray; readonly onConfirm: (turnCount: number, messageId: MessageId, restoreFiles: boolean) => void; }) { const pending = useThreadOverlay(revertConfirmAtom, props.threadKey); + const changedFileCount = + pending === null ? 0 : countFilesChangedAfterTurnCount(props.checkpoints, pending.turnCount); const confirm = (restoreFiles: boolean) => { if (pending === null) return; closeThreadOverlay(revertConfirmAtom); @@ -215,8 +220,8 @@ export function RevertConfirmHost(props: { Edit from here? Rewind chat to before this message. Your prompt and attachments return to the composer. - {pending !== null && pending.changedFileCount > 0 - ? ` The agent changed ${pending.changedFileCount} ${pending.changedFileCount === 1 ? "file" : "files"} since then.` + {changedFileCount > 0 + ? ` The agent changed ${changedFileCount} ${changedFileCount === 1 ? "file" : "files"} since then.` : null} From f07611731a5c67f9fcf490dd202c250aa64458f9 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 09:36:30 +0530 Subject: [PATCH 06/12] fix(web): edit from here says "at least" when a run left no checkpoint Failed runs are never captured and missing or errored captures have no file list, so the count is a lower bound then. The dialog says so. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatView.tsx | 2 + .../chat/ChatOverlayHosts.browser.test.tsx | 24 +++++++-- .../src/components/chat/ChatOverlayHosts.tsx | 35 ++++++++++--- apps/web/src/session-logic.test.ts | 51 +++++++++++++++++++ apps/web/src/session-logic.ts | 22 ++++++++ 5 files changed, 124 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 1cbf598ba4548..1209f2ccae17a 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -959,6 +959,7 @@ function chatActionErrorMessage(error: unknown): string { const ENVIRONMENT_UNAVAILABLE_SEND_TOAST_TRAIL_SIZE = 3; const EMPTY_HELD_TURN_DIFF_SUMMARIES: readonly never[] = []; +const EMPTY_RUNS: readonly never[] = []; const noopHeldTurnDiff = (_turnId: RunId, _filePath?: string) => {}; const noopHeldRevert = (_targetTurnCount: number) => {}; const noopHeldAttachment = (_attachment: ChatFileAttachment) => {}; @@ -8613,6 +8614,7 @@ export default function ChatView(props: ChatViewProps) { diff --git a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx index 16b33c7782cec..59e55fb0fd59c 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx @@ -31,7 +31,7 @@ describe("RevertConfirmHost", () => { const onConfirm = vi.fn(); const host = (threadKey: string) => ( - + ); await act(() => root.render(host("env:a"))); @@ -53,7 +53,7 @@ describe("RevertConfirmHost", () => { await vi.waitFor(() => expect(dialog()).toBeNull()); }); - it("counts a checkpoint captured while the dialog is open", async () => { + it("counts a checkpoint captured while the dialog is open, and hedges after a failed run", async () => { const checkpoint = (turnCount: number, paths: string[]): ThreadCheckpointSummary => ({ runId: RunId.make(`run-${turnCount}`), checkpointTurnCount: turnCount, @@ -63,9 +63,17 @@ describe("RevertConfirmHost", () => { assistantMessageId: null, completedAt: "2026-06-20T00:00:00.000Z", }); - const host = (checkpoints: ReadonlyArray) => ( + const host = ( + checkpoints: ReadonlyArray, + runs: ReadonlyArray<{ ordinal: number; status: "completed" | "failed" }> = [], + ) => ( - + ); const first = [checkpoint(1, ["a.ts"]), checkpoint(2, ["b.ts"])]; @@ -75,5 +83,13 @@ describe("RevertConfirmHost", () => { await act(() => root.render(host([...first, checkpoint(3, ["c.ts", "d.ts"])]))); expect(dialog()?.textContent).toContain("The agent changed 3 files since then."); + + // A failed run is never captured, so the count becomes a lower bound. + await act(() => + root.render( + host([...first, checkpoint(3, ["c.ts", "d.ts"])], [{ ordinal: 4, status: "failed" }]), + ), + ); + expect(dialog()?.textContent).toContain("The agent changed at least 3 files since then."); }); }); diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index b475ce75f36a3..ba3b7d3f67423 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -2,6 +2,7 @@ import type { DeviceServiceState, EnvironmentId, MessageId, + OrchestrationV2Run, ScopedThreadRef, ThreadId, } from "@t3tools/contracts"; @@ -13,7 +14,10 @@ import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thre import { appAtomRegistry } from "~/rpc/atomRegistry"; import { useRightPanelStore } from "~/rightPanelStore"; -import { countFilesChangedAfterTurnCount } from "~/session-logic"; +import { + countFilesChangedAfterTurnCount, + hasUnrecordedChangesAfterTurnCount, +} from "~/session-logic"; import { DeviceSetup } from "../device/DeviceSetup"; import { PullRequestThreadDialog } from "../PullRequestThreadDialog"; import { @@ -183,6 +187,17 @@ export function BranchRestoreConfirmHost(props: { ); } +/** A failed or uncaptured run makes the checkpoint count a lower bound. */ +function describeChangedFiles(count: number, hasUnrecordedChanges: boolean): string | null { + if (count === 0) { + return hasUnrecordedChanges ? "The agent may have changed files since then." : null; + } + const files = `${count} ${count === 1 ? "file" : "files"}`; + return hasUnrecordedChanges + ? `The agent changed at least ${files} since then.` + : `The agent changed ${files} since then.`; +} + interface PendingRevert { readonly turnCount: number; readonly messageId: MessageId; @@ -198,11 +213,21 @@ export function RevertConfirmHost(props: { readonly threadKey: string; /** Read while open, so a checkpoint captured after opening still counts. */ readonly checkpoints: ReadonlyArray; + readonly runs: ReadonlyArray>; readonly onConfirm: (turnCount: number, messageId: MessageId, restoreFiles: boolean) => void; }) { const pending = useThreadOverlay(revertConfirmAtom, props.threadKey); - const changedFileCount = - pending === null ? 0 : countFilesChangedAfterTurnCount(props.checkpoints, pending.turnCount); + const changedFilesNote = + pending === null + ? null + : describeChangedFiles( + countFilesChangedAfterTurnCount(props.checkpoints, pending.turnCount), + hasUnrecordedChangesAfterTurnCount({ + checkpoints: props.checkpoints, + runs: props.runs, + turnCount: pending.turnCount, + }), + ); const confirm = (restoreFiles: boolean) => { if (pending === null) return; closeThreadOverlay(revertConfirmAtom); @@ -220,9 +245,7 @@ export function RevertConfirmHost(props: { Edit from here? Rewind chat to before this message. Your prompt and attachments return to the composer. - {changedFileCount > 0 - ? ` The agent changed ${changedFileCount} ${changedFileCount === 1 ? "file" : "files"} since then.` - : null} + {changedFilesNote === null ? null : ` ${changedFilesNote}`} diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 9d96bc1c0d808..5dc8c310a6b79 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -28,6 +28,7 @@ import { deriveTimelineEntriesFromVisibleTurnItems, deriveTimelineEntriesFromVisibleTurnItemsWithState, countFilesChangedAfterTurnCount, + hasUnrecordedChangesAfterTurnCount, deriveRevertTurnCountByUserMessageId, derivePhase, findLatestProposedPlan, @@ -365,6 +366,56 @@ describe("V2 session presentation", () => { expect(countFilesChangedAfterTurnCount(checkpoints, 3)).toBe(0); }); + it("flags changes no checkpoint recorded after the rewind point", () => { + const checkpoint = (turnCount: number, status: "ready" | "missing" | "error" | "stale") => ({ + runId: RunId.make(`run-${turnCount}`), + checkpointTurnCount: turnCount, + checkpointRef: `checkpoint-${turnCount}` as never, + status, + files: [], + assistantMessageId: null, + completedAt: "2026-06-20T00:00:00.000Z", + }); + const ready = [checkpoint(1, "ready"), checkpoint(2, "ready")]; + + expect(hasUnrecordedChangesAfterTurnCount({ checkpoints: ready, runs: [], turnCount: 0 })).toBe( + false, + ); + // Failed runs are never captured. + expect( + hasUnrecordedChangesAfterTurnCount({ + checkpoints: ready, + runs: [{ ordinal: 3, status: "failed" }], + turnCount: 1, + }), + ).toBe(true); + // A failed run before the rewind point, or one an earlier rewind discarded, does not count. + expect( + hasUnrecordedChangesAfterTurnCount({ + checkpoints: ready, + runs: [ + { ordinal: 1, status: "failed" }, + { ordinal: 3, status: "rolled_back" }, + ], + turnCount: 1, + }), + ).toBe(false); + expect( + hasUnrecordedChangesAfterTurnCount({ + checkpoints: [...ready, checkpoint(3, "error")], + runs: [], + turnCount: 2, + }), + ).toBe(true); + expect( + hasUnrecordedChangesAfterTurnCount({ + checkpoints: [...ready, checkpoint(3, "stale")], + runs: [], + turnCount: 2, + }), + ).toBe(false); + }); + it("uses visible turn item order and keeps provider errors in the work log", () => { const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); const threadId = ThreadId.make("thread-visible"); diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 2ab4955cb5f1c..42926eb95347b 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1059,6 +1059,28 @@ export function countFilesChangedAfterTurnCount( return paths.size; } +/** + * Whether the agent may have changed files after `turnCount` that no checkpoint recorded, + * so `countFilesChangedAfterTurnCount` is a lower bound. Failed runs are never captured, + * and missing or errored captures carry no file list. + */ +export function hasUnrecordedChangesAfterTurnCount(input: { + readonly checkpoints: ReadonlyArray; + readonly runs: ReadonlyArray< + Pick + >; + readonly turnCount: number; +}): boolean { + return ( + input.runs.some((run) => run.ordinal > input.turnCount && run.status === "failed") || + input.checkpoints.some( + (checkpoint) => + checkpoint.checkpointTurnCount > input.turnCount && + (checkpoint.status === "missing" || checkpoint.status === "error"), + ) + ); +} + export function derivePhase(runtime: ThreadRuntimeSummary | null): SessionPhase { if (runtime === null) return "disconnected"; if ( From 0116092e2c0460702015fed0786b532fbc5aa4e5 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 09:40:30 +0530 Subject: [PATCH 07/12] fix(web): edit from here hedges while a stopped run is still captured Any run after the message that started but has no checkpoint yet makes the count a lower bound, which covers failed runs and a capture still in flight after Stop. Co-Authored-By: Claude Opus 5.5 --- .../chat/ChatOverlayHosts.browser.test.tsx | 11 +++- .../src/components/chat/ChatOverlayHosts.tsx | 4 +- apps/web/src/session-logic.test.ts | 57 +++++++------------ apps/web/src/session-logic.ts | 18 ++++-- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx index 59e55fb0fd59c..090ac5a0ff94d 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx @@ -1,5 +1,6 @@ import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; -import { MessageId, RunId } from "@t3tools/contracts"; +import { MessageId, RunId, type OrchestrationV2Run } from "@t3tools/contracts"; +import * as DateTime from "effect/DateTime"; import { act } from "react"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; @@ -24,6 +25,7 @@ afterEach(async () => { }); const messageId = MessageId.make("message-1"); +const STARTED_AT = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); const dialog = () => document.querySelector('[role="alertdialog"]'); describe("RevertConfirmHost", () => { @@ -65,7 +67,7 @@ describe("RevertConfirmHost", () => { }); const host = ( checkpoints: ReadonlyArray, - runs: ReadonlyArray<{ ordinal: number; status: "completed" | "failed" }> = [], + runs: ReadonlyArray> = [], ) => ( { // A failed run is never captured, so the count becomes a lower bound. await act(() => root.render( - host([...first, checkpoint(3, ["c.ts", "d.ts"])], [{ ordinal: 4, status: "failed" }]), + host( + [...first, checkpoint(3, ["c.ts", "d.ts"])], + [{ ordinal: 4, status: "failed", startedAt: STARTED_AT }], + ), ), ); expect(dialog()?.textContent).toContain("The agent changed at least 3 files since then."); diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index ba3b7d3f67423..a5701a5f97d86 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -187,7 +187,7 @@ export function BranchRestoreConfirmHost(props: { ); } -/** A failed or uncaptured run makes the checkpoint count a lower bound. */ +/** A run with no recorded checkpoint makes the count a lower bound. */ function describeChangedFiles(count: number, hasUnrecordedChanges: boolean): string | null { if (count === 0) { return hasUnrecordedChanges ? "The agent may have changed files since then." : null; @@ -213,7 +213,7 @@ export function RevertConfirmHost(props: { readonly threadKey: string; /** Read while open, so a checkpoint captured after opening still counts. */ readonly checkpoints: ReadonlyArray; - readonly runs: ReadonlyArray>; + readonly runs: ReadonlyArray>; readonly onConfirm: (turnCount: number, messageId: MessageId, restoreFiles: boolean) => void; }) { const pending = useThreadOverlay(revertConfirmAtom, props.threadKey); diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 5dc8c310a6b79..08b8483e44f8d 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -15,6 +15,7 @@ import { type OrchestrationV2ProjectedTurnItem, type OrchestrationV2ExecutionNode, type OrchestrationV2RunAttempt, + type OrchestrationV2RunStatus, type OrchestrationV2TurnItem, } from "@t3tools/contracts"; import type { ThreadRuntimeSummary } from "@t3tools/client-runtime/state/shell"; @@ -376,44 +377,30 @@ describe("V2 session presentation", () => { assistantMessageId: null, completedAt: "2026-06-20T00:00:00.000Z", }); + const startedAt = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); + const run = (ordinal: number, status: OrchestrationV2RunStatus, started = true) => ({ + ordinal, + status, + startedAt: started ? startedAt : null, + }); const ready = [checkpoint(1, "ready"), checkpoint(2, "ready")]; - - expect(hasUnrecordedChangesAfterTurnCount({ checkpoints: ready, runs: [], turnCount: 0 })).toBe( - false, - ); - // Failed runs are never captured. - expect( - hasUnrecordedChangesAfterTurnCount({ - checkpoints: ready, - runs: [{ ordinal: 3, status: "failed" }], - turnCount: 1, - }), - ).toBe(true); - // A failed run before the rewind point, or one an earlier rewind discarded, does not count. - expect( - hasUnrecordedChangesAfterTurnCount({ - checkpoints: ready, - runs: [ - { ordinal: 1, status: "failed" }, - { ordinal: 3, status: "rolled_back" }, - ], - turnCount: 1, - }), - ).toBe(false); - expect( - hasUnrecordedChangesAfterTurnCount({ - checkpoints: [...ready, checkpoint(3, "error")], - runs: [], - turnCount: 2, - }), - ).toBe(true); + const unrecorded = ( + checkpoints: ReadonlyArray>, + runs: ReadonlyArray>, + turnCount: number, + ) => hasUnrecordedChangesAfterTurnCount({ checkpoints, runs, turnCount }); + + expect(unrecorded(ready, [run(1, "completed"), run(2, "completed")], 0)).toBe(false); + // A failed run is never captured. + expect(unrecorded(ready, [run(3, "failed")], 1)).toBe(true); + // A stopped run whose capture has not landed yet. + expect(unrecorded(ready, [run(3, "interrupted")], 2)).toBe(true); + // Runs before the rewind point, discarded by an earlier rewind, or never started do not count. expect( - hasUnrecordedChangesAfterTurnCount({ - checkpoints: [...ready, checkpoint(3, "stale")], - runs: [], - turnCount: 2, - }), + unrecorded(ready, [run(1, "failed"), run(3, "rolled_back"), run(4, "cancelled", false)], 1), ).toBe(false); + expect(unrecorded([...ready, checkpoint(3, "error")], [], 2)).toBe(true); + expect(unrecorded([...ready, checkpoint(3, "stale")], [], 2)).toBe(false); }); it("uses visible turn item order and keeps provider errors in the work log", () => { diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 42926eb95347b..49aa6d7cf95d5 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1061,18 +1061,28 @@ export function countFilesChangedAfterTurnCount( /** * Whether the agent may have changed files after `turnCount` that no checkpoint recorded, - * so `countFilesChangedAfterTurnCount` is a lower bound. Failed runs are never captured, - * and missing or errored captures carry no file list. + * so `countFilesChangedAfterTurnCount` is a lower bound. A run that started but has no + * checkpoint either failed (never captured) or is still being captured after Stop, and + * missing or errored captures carry no file list. */ export function hasUnrecordedChangesAfterTurnCount(input: { readonly checkpoints: ReadonlyArray; readonly runs: ReadonlyArray< - Pick + Pick >; readonly turnCount: number; }): boolean { + const capturedTurnCounts = new Set( + input.checkpoints.map((checkpoint) => checkpoint.checkpointTurnCount), + ); return ( - input.runs.some((run) => run.ordinal > input.turnCount && run.status === "failed") || + input.runs.some( + (run) => + run.ordinal > input.turnCount && + run.status !== "rolled_back" && + run.startedAt !== null && + !capturedTurnCounts.has(run.ordinal), + ) || input.checkpoints.some( (checkpoint) => checkpoint.checkpointTurnCount > input.turnCount && From 0872afeb2015f6610a2c95afa88c6403b5fb8e0f Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 09:44:11 +0530 Subject: [PATCH 08/12] fix(web): edit from here ignores failed captures of discarded runs Co-Authored-By: Claude Opus 5.5 --- .../src/components/chat/ChatOverlayHosts.browser.test.tsx | 4 ++-- apps/web/src/components/chat/ChatOverlayHosts.tsx | 2 +- apps/web/src/session-logic.test.ts | 3 +++ apps/web/src/session-logic.ts | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx index 090ac5a0ff94d..0c1175cd3f70a 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx @@ -67,7 +67,7 @@ describe("RevertConfirmHost", () => { }); const host = ( checkpoints: ReadonlyArray, - runs: ReadonlyArray> = [], + runs: ReadonlyArray> = [], ) => ( { root.render( host( [...first, checkpoint(3, ["c.ts", "d.ts"])], - [{ ordinal: 4, status: "failed", startedAt: STARTED_AT }], + [{ id: RunId.make("run-4"), ordinal: 4, status: "failed", startedAt: STARTED_AT }], ), ), ); diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index a5701a5f97d86..b1a3416fd965f 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -213,7 +213,7 @@ export function RevertConfirmHost(props: { readonly threadKey: string; /** Read while open, so a checkpoint captured after opening still counts. */ readonly checkpoints: ReadonlyArray; - readonly runs: ReadonlyArray>; + readonly runs: ReadonlyArray>; readonly onConfirm: (turnCount: number, messageId: MessageId, restoreFiles: boolean) => void; }) { const pending = useThreadOverlay(revertConfirmAtom, props.threadKey); diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 08b8483e44f8d..7be57d3e2d7a3 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -379,6 +379,7 @@ describe("V2 session presentation", () => { }); const startedAt = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); const run = (ordinal: number, status: OrchestrationV2RunStatus, started = true) => ({ + id: RunId.make(`run-${ordinal}`), ordinal, status, startedAt: started ? startedAt : null, @@ -401,6 +402,8 @@ describe("V2 session presentation", () => { ).toBe(false); expect(unrecorded([...ready, checkpoint(3, "error")], [], 2)).toBe(true); expect(unrecorded([...ready, checkpoint(3, "stale")], [], 2)).toBe(false); + // A failed capture from a run an earlier rewind discarded no longer matters. + expect(unrecorded([...ready, checkpoint(3, "error")], [run(3, "rolled_back")], 2)).toBe(false); }); it("uses visible turn item order and keeps provider errors in the work log", () => { diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 49aa6d7cf95d5..0a4dd5fb97dfc 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1068,13 +1068,17 @@ export function countFilesChangedAfterTurnCount( export function hasUnrecordedChangesAfterTurnCount(input: { readonly checkpoints: ReadonlyArray; readonly runs: ReadonlyArray< - Pick + Pick >; readonly turnCount: number; }): boolean { const capturedTurnCounts = new Set( input.checkpoints.map((checkpoint) => checkpoint.checkpointTurnCount), ); + // An earlier rewind discarded these runs, so their failed captures no longer matter. + const rolledBackRunIds = new Set( + input.runs.filter((run) => run.status === "rolled_back").map((run) => run.id), + ); return ( input.runs.some( (run) => @@ -1086,6 +1090,7 @@ export function hasUnrecordedChangesAfterTurnCount(input: { input.checkpoints.some( (checkpoint) => checkpoint.checkpointTurnCount > input.turnCount && + !rolledBackRunIds.has(checkpoint.runId) && (checkpoint.status === "missing" || checkpoint.status === "error"), ) ); From ffe4d5322cc7983ce356215e97c2118c85271a27 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 14:07:16 +0000 Subject: [PATCH 09/12] fix(web): drop the edit-from-here file count, warn that file revert resets the workspace The count could read low. "Revert and keep changes" also marks checkpoints stale, so their files were skipped even though they were still on disk and a later file revert would undo them. It also only counted the agent's files, while file revert resets the whole workspace with git restore and git clean. Keep the red outline button and say plainly what the revert resets instead. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ChatView.tsx | 8 +- .../chat/ChatOverlayHosts.browser.test.tsx | 50 +------- .../src/components/chat/ChatOverlayHosts.tsx | 35 +----- apps/web/src/session-logic.test.ts | 112 ------------------ apps/web/src/session-logic.ts | 61 ---------- docs/user/composer.md | 3 +- 6 files changed, 7 insertions(+), 262 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 1fdf37b3ef83c..98b3172d0c6e0 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -963,7 +963,6 @@ function chatActionErrorMessage(error: unknown): string { const ENVIRONMENT_UNAVAILABLE_SEND_TOAST_TRAIL_SIZE = 3; const EMPTY_HELD_TURN_DIFF_SUMMARIES: readonly never[] = []; -const EMPTY_RUNS: readonly never[] = []; const noopHeldTurnDiff = (_turnId: RunId, _filePath?: string) => {}; const noopHeldRevert = (_targetTurnCount: number) => {}; const noopHeldAttachment = (_attachment: ChatFileAttachment) => {}; @@ -8622,12 +8621,7 @@ export default function ChatView(props: ChatViewProps) { ) : null} - + diff --git a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx index 0c1175cd3f70a..2e36c714761ac 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.browser.test.tsx @@ -1,6 +1,4 @@ -import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; -import { MessageId, RunId, type OrchestrationV2Run } from "@t3tools/contracts"; -import * as DateTime from "effect/DateTime"; +import { MessageId } from "@t3tools/contracts"; import { act } from "react"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; @@ -25,7 +23,6 @@ afterEach(async () => { }); const messageId = MessageId.make("message-1"); -const STARTED_AT = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); const dialog = () => document.querySelector('[role="alertdialog"]'); describe("RevertConfirmHost", () => { @@ -33,7 +30,7 @@ describe("RevertConfirmHost", () => { const onConfirm = vi.fn(); const host = (threadKey: string) => ( - + ); await act(() => root.render(host("env:a"))); @@ -54,47 +51,4 @@ describe("RevertConfirmHost", () => { await act(() => root.render(host("env:b"))); await vi.waitFor(() => expect(dialog()).toBeNull()); }); - - it("counts a checkpoint captured while the dialog is open, and hedges after a failed run", async () => { - const checkpoint = (turnCount: number, paths: string[]): ThreadCheckpointSummary => ({ - runId: RunId.make(`run-${turnCount}`), - checkpointTurnCount: turnCount, - checkpointRef: `checkpoint-${turnCount}` as never, - status: "ready", - files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), - assistantMessageId: null, - completedAt: "2026-06-20T00:00:00.000Z", - }); - const host = ( - checkpoints: ReadonlyArray, - runs: ReadonlyArray> = [], - ) => ( - - - - ); - const first = [checkpoint(1, ["a.ts"]), checkpoint(2, ["b.ts"])]; - await act(() => root.render(host(first))); - await act(() => openRevertConfirm("env:a", { turnCount: 1, messageId })); - expect(dialog()?.textContent).toContain("The agent changed 1 file since then."); - - await act(() => root.render(host([...first, checkpoint(3, ["c.ts", "d.ts"])]))); - expect(dialog()?.textContent).toContain("The agent changed 3 files since then."); - - // A failed run is never captured, so the count becomes a lower bound. - await act(() => - root.render( - host( - [...first, checkpoint(3, ["c.ts", "d.ts"])], - [{ id: RunId.make("run-4"), ordinal: 4, status: "failed", startedAt: STARTED_AT }], - ), - ), - ); - expect(dialog()?.textContent).toContain("The agent changed at least 3 files since then."); - }); }); diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index b1a3416fd965f..b8fbdad38192d 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -2,7 +2,6 @@ import type { DeviceServiceState, EnvironmentId, MessageId, - OrchestrationV2Run, ScopedThreadRef, ThreadId, } from "@t3tools/contracts"; @@ -10,14 +9,8 @@ import { useAtomValue } from "@effect/atom-react"; import { Atom } from "effect/reactivity"; import { useEffect } from "react"; -import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; - import { appAtomRegistry } from "~/rpc/atomRegistry"; import { useRightPanelStore } from "~/rightPanelStore"; -import { - countFilesChangedAfterTurnCount, - hasUnrecordedChangesAfterTurnCount, -} from "~/session-logic"; import { DeviceSetup } from "../device/DeviceSetup"; import { PullRequestThreadDialog } from "../PullRequestThreadDialog"; import { @@ -187,17 +180,6 @@ export function BranchRestoreConfirmHost(props: { ); } -/** A run with no recorded checkpoint makes the count a lower bound. */ -function describeChangedFiles(count: number, hasUnrecordedChanges: boolean): string | null { - if (count === 0) { - return hasUnrecordedChanges ? "The agent may have changed files since then." : null; - } - const files = `${count} ${count === 1 ? "file" : "files"}`; - return hasUnrecordedChanges - ? `The agent changed at least ${files} since then.` - : `The agent changed ${files} since then.`; -} - interface PendingRevert { readonly turnCount: number; readonly messageId: MessageId; @@ -211,23 +193,9 @@ export function openRevertConfirm(threadKey: string, pending: PendingRevert): vo export function RevertConfirmHost(props: { readonly threadKey: string; - /** Read while open, so a checkpoint captured after opening still counts. */ - readonly checkpoints: ReadonlyArray; - readonly runs: ReadonlyArray>; readonly onConfirm: (turnCount: number, messageId: MessageId, restoreFiles: boolean) => void; }) { const pending = useThreadOverlay(revertConfirmAtom, props.threadKey); - const changedFilesNote = - pending === null - ? null - : describeChangedFiles( - countFilesChangedAfterTurnCount(props.checkpoints, pending.turnCount), - hasUnrecordedChangesAfterTurnCount({ - checkpoints: props.checkpoints, - runs: props.runs, - turnCount: pending.turnCount, - }), - ); const confirm = (restoreFiles: boolean) => { if (pending === null) return; closeThreadOverlay(revertConfirmAtom); @@ -245,7 +213,8 @@ export function RevertConfirmHost(props: { Edit from here? Rewind chat to before this message. Your prompt and attachments return to the composer. - {changedFilesNote === null ? null : ` ${changedFilesNote}`} + “Revert files too” also resets every file in this workspace to how it was then, + including your own edits. diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index 7be57d3e2d7a3..6479438d2bb8f 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -15,7 +15,6 @@ import { type OrchestrationV2ProjectedTurnItem, type OrchestrationV2ExecutionNode, type OrchestrationV2RunAttempt, - type OrchestrationV2RunStatus, type OrchestrationV2TurnItem, } from "@t3tools/contracts"; import type { ThreadRuntimeSummary } from "@t3tools/client-runtime/state/shell"; @@ -28,8 +27,6 @@ import { deriveCanInterruptRunningThread, deriveTimelineEntriesFromVisibleTurnItems, deriveTimelineEntriesFromVisibleTurnItemsWithState, - countFilesChangedAfterTurnCount, - hasUnrecordedChangesAfterTurnCount, deriveRevertTurnCountByUserMessageId, derivePhase, findLatestProposedPlan, @@ -297,115 +294,6 @@ describe("V2 session presentation", () => { expect(targets.has(steerMessageId)).toBe(false); }); - it("counts only files in the scope the rewind targets", () => { - const checkpoint = (turnCount: number, scope: string, paths: string[]) => ({ - scopeId: scope as never, - runId: RunId.make(`run-${scope}-${turnCount}`), - checkpointTurnCount: turnCount, - checkpointRef: `checkpoint-${scope}-${turnCount}` as never, - status: "ready" as const, - files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), - assistantMessageId: null, - completedAt: "2026-06-20T00:00:00.000Z", - }); - const checkpoints = [ - checkpoint(1, "root", ["a.ts"]), - checkpoint(2, "root", ["b.ts"]), - checkpoint(2, "other", ["x.ts", "y.ts"]), - checkpoint(3, "root", ["c.ts"]), - ]; - - expect(countFilesChangedAfterTurnCount(checkpoints, 1)).toBe(2); - expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(3); - }); - - it("a rewind to before the first turn counts the latest first turn's scope", () => { - const checkpoint = (turnCount: number, scope: string, paths: string[]) => ({ - scopeId: scope as never, - runId: RunId.make(`run-${scope}-${turnCount}`), - checkpointTurnCount: turnCount, - checkpointRef: `checkpoint-${scope}-${turnCount}` as never, - status: "ready" as const, - files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), - assistantMessageId: null, - completedAt: "2026-06-20T00:00:00.000Z", - }); - // The rewind restores the latest baseline, so the older scope's turn 1 must not win. - const checkpoints = [ - checkpoint(1, "old", ["a.ts"]), - checkpoint(1, "new", ["x.ts", "y.ts"]), - checkpoint(2, "new", ["z.ts"]), - ]; - - expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(3); - }); - - it("counts each file changed after the rewind point once", () => { - const checkpoint = ( - turnCount: number, - paths: string[], - status: "ready" | "stale" = "ready", - ) => ({ - runId: RunId.make(`run-${turnCount}`), - checkpointTurnCount: turnCount, - checkpointRef: `checkpoint-${turnCount}` as never, - status, - files: paths.map((path) => ({ path, kind: "modified", additions: 1, deletions: 0 })), - assistantMessageId: null, - completedAt: "2026-06-20T00:00:00.000Z", - }); - const checkpoints = [ - checkpoint(1, ["a.ts"]), - checkpoint(2, ["b.ts", "c.ts"]), - checkpoint(3, ["c.ts", "d.ts"]), - // Discarded by an earlier rewind, so its files are already restored. - checkpoint(4, ["e.ts"], "stale"), - ]; - - expect(countFilesChangedAfterTurnCount(checkpoints, 1)).toBe(3); - expect(countFilesChangedAfterTurnCount(checkpoints, 0)).toBe(4); - expect(countFilesChangedAfterTurnCount(checkpoints, 3)).toBe(0); - }); - - it("flags changes no checkpoint recorded after the rewind point", () => { - const checkpoint = (turnCount: number, status: "ready" | "missing" | "error" | "stale") => ({ - runId: RunId.make(`run-${turnCount}`), - checkpointTurnCount: turnCount, - checkpointRef: `checkpoint-${turnCount}` as never, - status, - files: [], - assistantMessageId: null, - completedAt: "2026-06-20T00:00:00.000Z", - }); - const startedAt = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); - const run = (ordinal: number, status: OrchestrationV2RunStatus, started = true) => ({ - id: RunId.make(`run-${ordinal}`), - ordinal, - status, - startedAt: started ? startedAt : null, - }); - const ready = [checkpoint(1, "ready"), checkpoint(2, "ready")]; - const unrecorded = ( - checkpoints: ReadonlyArray>, - runs: ReadonlyArray>, - turnCount: number, - ) => hasUnrecordedChangesAfterTurnCount({ checkpoints, runs, turnCount }); - - expect(unrecorded(ready, [run(1, "completed"), run(2, "completed")], 0)).toBe(false); - // A failed run is never captured. - expect(unrecorded(ready, [run(3, "failed")], 1)).toBe(true); - // A stopped run whose capture has not landed yet. - expect(unrecorded(ready, [run(3, "interrupted")], 2)).toBe(true); - // Runs before the rewind point, discarded by an earlier rewind, or never started do not count. - expect( - unrecorded(ready, [run(1, "failed"), run(3, "rolled_back"), run(4, "cancelled", false)], 1), - ).toBe(false); - expect(unrecorded([...ready, checkpoint(3, "error")], [], 2)).toBe(true); - expect(unrecorded([...ready, checkpoint(3, "stale")], [], 2)).toBe(false); - // A failed capture from a run an earlier rewind discarded no longer matters. - expect(unrecorded([...ready, checkpoint(3, "error")], [run(3, "rolled_back")], 2)).toBe(false); - }); - it("uses visible turn item order and keeps provider errors in the work log", () => { const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"); const threadId = ThreadId.make("thread-visible"); diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index 0a4dd5fb97dfc..7c60d263c025b 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -1035,67 +1035,6 @@ export function deriveRevertTurnCountByUserMessageId(input: { return byUserMessageId; } -/** - * Counts distinct files the agent changed in turns a rewind to `turnCount` would undo. - * Only the scope of the rollback target counts, matched the way `revertThreadCheckpoint` - * picks it; a rewind to before the first turn targets the latest first turn's scope. Stale - * checkpoints belong to history an earlier rewind already discarded. File restore resets - * the whole workspace, so a zero here does not mean restoring files is a no-op. - */ -export function countFilesChangedAfterTurnCount( - checkpoints: ReadonlyArray, - turnCount: number, -): number { - const scopeId = ( - checkpoints.findLast((checkpoint) => checkpoint.checkpointTurnCount === turnCount) ?? - checkpoints.findLast((checkpoint) => checkpoint.checkpointTurnCount === turnCount + 1) - )?.scopeId; - const paths = new Set(); - for (const checkpoint of checkpoints) { - if (checkpoint.checkpointTurnCount <= turnCount || checkpoint.status === "stale") continue; - if (checkpoint.scopeId !== scopeId) continue; - for (const file of checkpoint.files) paths.add(file.path); - } - return paths.size; -} - -/** - * Whether the agent may have changed files after `turnCount` that no checkpoint recorded, - * so `countFilesChangedAfterTurnCount` is a lower bound. A run that started but has no - * checkpoint either failed (never captured) or is still being captured after Stop, and - * missing or errored captures carry no file list. - */ -export function hasUnrecordedChangesAfterTurnCount(input: { - readonly checkpoints: ReadonlyArray; - readonly runs: ReadonlyArray< - Pick - >; - readonly turnCount: number; -}): boolean { - const capturedTurnCounts = new Set( - input.checkpoints.map((checkpoint) => checkpoint.checkpointTurnCount), - ); - // An earlier rewind discarded these runs, so their failed captures no longer matter. - const rolledBackRunIds = new Set( - input.runs.filter((run) => run.status === "rolled_back").map((run) => run.id), - ); - return ( - input.runs.some( - (run) => - run.ordinal > input.turnCount && - run.status !== "rolled_back" && - run.startedAt !== null && - !capturedTurnCounts.has(run.ordinal), - ) || - input.checkpoints.some( - (checkpoint) => - checkpoint.checkpointTurnCount > input.turnCount && - !rolledBackRunIds.has(checkpoint.runId) && - (checkpoint.status === "missing" || checkpoint.status === "error"), - ) - ); -} - export function derivePhase(runtime: ThreadRuntimeSummary | null): SessionPhase { if (runtime === null) return "disconnected"; if ( diff --git a/docs/user/composer.md b/docs/user/composer.md index 66be9fe435712..af7a35ac8da1f 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -149,7 +149,8 @@ into a normal draft. On web and desktop, choose **Edit from here** beneath a sent message to rewind the conversation to before that message. Choose **Revert and keep changes** to -leave workspace files as they are, or **Revert files too** to restore them as well. +leave workspace files as they are, or **Revert files too** to reset every file in +the workspace to how it was before that message, including edits you made yourself. File restore is only offered for threads running in a worktree, and it is refused when another thread or agent session also uses that directory, a folder inside it, or a folder that contains it, since From e034e27c1d5798c383ba0ab17e7e4e97ae0eb7e0 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 14:36:27 +0000 Subject: [PATCH 10/12] fix(web): say file revert restores the saved checkpoint, not every file Ignored files survive a file revert, and it restores the checkpoint saved before the message rather than a fresh snapshot. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/chat/ChatOverlayHosts.tsx | 4 ++-- docs/user/composer.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index b8fbdad38192d..b3f414603e19e 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -213,8 +213,8 @@ export function RevertConfirmHost(props: { Edit from here? Rewind chat to before this message. Your prompt and attachments return to the composer. - “Revert files too” also resets every file in this workspace to how it was then, - including your own edits. + “Revert files too” also puts this workspace back to its checkpoint from before this + message, undoing your own edits too. diff --git a/docs/user/composer.md b/docs/user/composer.md index af7a35ac8da1f..39eb55a8c2848 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -149,8 +149,8 @@ into a normal draft. On web and desktop, choose **Edit from here** beneath a sent message to rewind the conversation to before that message. Choose **Revert and keep changes** to -leave workspace files as they are, or **Revert files too** to reset every file in -the workspace to how it was before that message, including edits you made yourself. +leave workspace files as they are, or **Revert files too** to put the workspace back +to its checkpoint from before that message. That also undoes edits you made yourself. File restore is only offered for threads running in a worktree, and it is refused when another thread or agent session also uses that directory, a folder inside it, or a folder that contains it, since From aa7fa713f32d9f2e181486fae44391f59b2d8087 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Mon, 19 Oct 2026 16:41:39 +0000 Subject: [PATCH 11/12] fix(web): shorten the Edit from here warning Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/chat/ChatOverlayHosts.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/web/src/components/chat/ChatOverlayHosts.tsx b/apps/web/src/components/chat/ChatOverlayHosts.tsx index b3f414603e19e..f2ff3b83a9c4c 100644 --- a/apps/web/src/components/chat/ChatOverlayHosts.tsx +++ b/apps/web/src/components/chat/ChatOverlayHosts.tsx @@ -213,8 +213,7 @@ export function RevertConfirmHost(props: { Edit from here? Rewind chat to before this message. Your prompt and attachments return to the composer. - “Revert files too” also puts this workspace back to its checkpoint from before this - message, undoing your own edits too. + “Revert files too” also undoes your own edits. From 10f9bec5de3def039d34548801905859419ba35e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:47:10 +0000 Subject: [PATCH 12/12] test(web): supply the thread details shortcut flag --- .../web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx b/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx index 60bc23b71e42f..b36dc779935c4 100644 --- a/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx +++ b/apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx @@ -244,6 +244,7 @@ it("keeps workspace controls after expanding and collapsing 70 linked pull reque keybindings={[]} availableEditors={[]} showOpenInPicker + openInShortcutEnabled={false} gitCwd="/tmp/project" isGitRepo envLocked={false}