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 21, 23:30 UTC
fix(rewind): allow conversation-only rewind in non-git workspaces (#18379)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Juliann committed
Nov 11, 2026 at 20:08 UTC
31eea883c7f7849ada6eb49265cb11fc64d2ecbd
15 files changed
+328
-45
apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts
+18
-1
@@ -914,7 +914,24 @@ it.layer(layerProjectionStoreTest)("CheckpointCaptureServiceV2", (it) => {
914
DateTime.formatIso(cancelledAt),
915
);
916
assert.equal(projected.rootNode?.status, "cancelled");
917
- assert.deepEqual([...projected.readyCheckpointOrdinals].toSorted(), [0, 1]);
917
+ assert.deepEqual([...projected.preservedCheckpointOrdinals].toSorted(), [0, 1]);
918
+
919
+ // A rewind leaves the run's checkpoint stale; the next capture must rebaseline it.
920
+ yield* projectionStore.apply({
921
+ id: EventId.make("event:checkpoint-capture-cancelled:captured-stale"),
922
+ type: "checkpoint.captured",
923
+ threadId: cancelledThreadId,
924
+ runId: cancelledRunId,
925
+ nodeId: cancelledRootNodeId,
926
+ providerInstanceId,
927
+ occurredAt: cancelledAt,
928
+ payload: { ...captured, status: "stale" },
929
+ });
930
+ const afterRewind = yield* projectionStore.getCheckpointCaptureContext(cancelledThreadId, {
931
+ runId: cancelledRunId,
932
+ scopeId: cancelledScopeId,
933
+ });
934
+ assert.deepEqual(afterRewind.preservedCheckpointOrdinals, [0]);
935
}),
936
);
937
apps/server/src/orchestration-v2/CheckpointCaptureService.ts
+5
-7
@@ -65,7 +65,7 @@ export const layer: Layer.Layer<
65
readonly runId: RunId;
66
readonly scopeId: CheckpointScopeId;
67
}) {
68
- const { run, rootNode, scope, providerThread, readyCheckpointOrdinals, sideChat } =
68
+ const { run, rootNode, scope, providerThread, preservedCheckpointOrdinals, sideChat } =
69
yield* projections.getCheckpointCaptureContext(input.threadId, input);
70
// Stopped runs remain terminal; their checkpoint is the next message's rollback point.
71
const stopped = run?.status === "interrupted" || run?.status === "cancelled";
@@ -101,8 +101,8 @@ export const layer: Layer.Layer<
101
102
const capturedAt = yield* DateTime.now;
103
const baselineOrdinalWithinScope = Math.max(0, run.ordinal - 1);
104
- const hasReadyCheckpoint = (ordinalWithinScope: number) =>
105
- readyCheckpointOrdinals.includes(ordinalWithinScope);
104
+ const isPreserved = (ordinalWithinScope: number) =>
105
+ preservedCheckpointOrdinals.includes(ordinalWithinScope);
106
// The baselines this capture materializes are attributed to the run materializing them. The
107
// thread's scope may already be a later run's: one queued meanwhile, or sent after Stop.
108
const materializeBaseline = (ordinalWithinScope: number) =>
@@ -114,10 +114,8 @@ export const layer: Layer.Layer<
114
forceMissing: sideChat,
115
});
116
const threadStartCheckpoint =
117
- baselineOrdinalWithinScope === 0 || hasReadyCheckpoint(0)
118
- ? null
119
- : yield* materializeBaseline(0);
120
- const baselineCheckpoint = hasReadyCheckpoint(baselineOrdinalWithinScope)
117
+ baselineOrdinalWithinScope === 0 || isPreserved(0) ? null : yield* materializeBaseline(0);
118
+ const baselineCheckpoint = isPreserved(baselineOrdinalWithinScope)
119
? null
120
: yield* materializeBaseline(baselineOrdinalWithinScope);
121
const checkpoint = yield* checkpoints.capture({
apps/server/src/orchestration-v2/CheckpointRollbackService.ts
+3
-1
@@ -152,7 +152,9 @@ export const layer: Layer.Layer<
152
checkpoint === undefined ||
153
scope === undefined ||
154
checkpoint.scopeId !== scope.id ||
155
- checkpoint.status !== "ready"
155
+ // Missing snapshots support conversation rewind only.
156
+ (checkpoint.status !== "ready" &&
157
+ !(input.restoreFiles === false && checkpoint.status === "missing"))
158
) {
159
return yield* new CheckpointRollbackExecutionError({
160
reason: "rollback-target-invalid",
apps/server/src/orchestration-v2/Orchestrator.ts
+10
-2
@@ -12749,7 +12749,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12749
cause: `Checkpoint ${command.checkpointId} was not found.`,
12750
});
12751
}
12752
- if (targetCheckpoint.status !== "ready") {
12752
+ // Missing snapshots support conversation rewind only.
12753
+ if (
12754
+ targetCheckpoint.status !== "ready" &&
12755
+ !(command.restoreFiles === false && targetCheckpoint.status === "missing")
12756
+ ) {
12757
return yield* new OrchestratorDispatchError({
12758
commandId: command.commandId,
12759
commandType: command.type,
@@ -12802,7 +12806,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12806
const targetRun = projection.runs.find((run) => run.ordinal === targetOrdinal);
12807
const targetProviderTurn =
12808
targetRun === undefined ? undefined : providerTurnForRun(projection, targetRun);
12805
- if (targetRun === undefined || targetProviderTurn === undefined) {
12809
+ if (
12810
+ targetRun === undefined ||
12811
+ targetRun.status === "rolled_back" ||
12812
+ targetProviderTurn === undefined
12813
+ ) {
12814
return yield* new OrchestratorDispatchError({
12815
commandId: command.commandId,
12816
commandType: command.type,
apps/server/src/orchestration-v2/ProjectionStore.ts
+11
-6
@@ -262,7 +262,11 @@ export interface ProjectionCheckpointCaptureContext {
262
readonly rootNode: OrchestrationV2ExecutionNode | undefined;
263
readonly scope: OrchestrationV2CheckpointScope | undefined;
264
readonly providerThread: OrchestrationV2ProviderThread | undefined;
265
- readonly readyCheckpointOrdinals: ReadonlyArray<number>;
265
+ /**
266
+ * Ordinals a runless baseline must not overwrite: ready snapshots, and missing checkpoints pinning
267
+ * a run. Without file snapshots that run link is what rewind uses. Stale rows are rebaselined.
268
+ */
269
+ readonly preservedCheckpointOrdinals: ReadonlyArray<number>;
270
/** Side chats share their parent's worktree and never snapshot it. */
271
readonly sideChat: boolean;
272
}
@@ -5427,7 +5431,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5431
runRows[0] === undefined
5432
? undefined
5433
: yield* decodeRunPayload(runRows[0].payload_json);
5430
- const [nodeRows, scopeRows, providerRows, readyRows] = yield* Effect.all([
5434
+ const [nodeRows, scopeRows, providerRows, preservedRows] = yield* Effect.all([
5435
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_nodes
5436
WHERE thread_id = ${threadId} AND node_id = ${run?.rootNodeId ?? null}`,
5437
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_checkpoint_scopes
@@ -5439,7 +5443,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5443
OR provider_thread_id IN (SELECT provider_thread_id FROM orchestration_v2_projection_subagents WHERE thread_id = ${threadId}))`,
5444
sql<{ readonly ordinal: number }>`SELECT ordinal_within_scope AS ordinal
5445
FROM orchestration_v2_projection_checkpoints
5442
- WHERE thread_id = ${threadId} AND scope_id = ${target.scopeId} AND status = 'ready'`,
5446
+ WHERE thread_id = ${threadId} AND scope_id = ${target.scopeId}
5447
+ AND (status = 'ready' OR (status = 'missing' AND run_id IS NOT NULL))`,
5448
]);
5449
return {
5450
run,
@@ -5455,7 +5460,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5460
providerRows[0] === undefined
5461
? undefined
5462
: yield* decodeProviderThreadPayload(providerRows[0].payload_json),
5458
- readyCheckpointOrdinals: readyRows.map(({ ordinal }) => ordinal),
5463
+ preservedCheckpointOrdinals: preservedRows.map(({ ordinal }) => ordinal),
5464
sideChat: threadRows[0].side_chat === 1,
5465
};
5466
}),
@@ -5512,7 +5517,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5517
checkpoint === undefined ||
5518
scope === undefined ||
5519
checkpoint.scopeId !== scope.id ||
5515
- checkpoint.status !== "ready" ||
5520
+ (checkpoint.status !== "ready" && checkpoint.status !== "missing") ||
5521
providerThread.id !== thread.activeProviderThreadId ||
5522
providerThread.providerInstanceId !== thread.modelSelection.instanceId
5523
)
@@ -5526,7 +5531,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5531
JOIN orchestration_v2_projection_runs AS run
5532
ON attempt.attempt_id = json_extract(run.payload_json, '$.activeAttemptId')
5533
WHERE run.thread_id = ${threadId} AND run.ordinal = ${targetOrdinal}
5529
- AND attempt.thread_id = ${threadId}`,
5534
+ AND run.status != 'rolled_back' AND attempt.thread_id = ${threadId}`,
5535
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_runs
5536
WHERE thread_id = ${threadId} AND ordinal > ${targetOrdinal}
5537
AND status IN ('completed', 'interrupted', 'failed', 'cancelled')
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+223
@@ -40,6 +40,7 @@ import * as Effect from "effect/Effect";
40
import * as DateTime from "effect/DateTime";
41
import * as Deferred from "effect/Deferred";
42
import * as Fiber from "effect/Fiber";
43
+import * as FileSystem from "effect/FileSystem";
44
import * as Layer from "effect/Layer";
45
import * as Option from "effect/Option";
46
import * as Path from "effect/Path";
@@ -1011,6 +1012,228 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
1012
}),
1013
);
1014
1015
+ it.effect("captures and repeatedly rewinds non-Git conversations without losing run links", () =>
1016
+ Effect.gen(function* () {
1017
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
1018
+ const eventSink = yield* EventSink.EventSinkV2;
1019
+ const outbox = yield* EffectOutbox.EffectOutboxV2;
1020
+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
1021
+ const sessions = yield* ProviderSessionManager.ProviderSessionManagerV2;
1022
+ const fileSystem = yield* FileSystem.FileSystem;
1023
+ const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-non-git-rewind-" });
1024
+ const threadId = ThreadId.make("runtime-non-git-rewind");
1025
+ const rollbackThread = vi.fn(
1026
+ ({ providerThread }: ProviderAdapter.ProviderAdapterV2RollbackThreadInput) =>
1027
+ Effect.succeed({
1028
+ providerThread: {
1029
+ ...providerThread,
1030
+ nativeThreadRef: {
1031
+ driver,
1032
+ nativeId: "rewound-native-thread",
1033
+ strength: "strong" as const,
1034
+ },
1035
+ },
1036
+ }),
1037
+ );
1038
+ const sessionSpy = vi.spyOn(sessions, "open").mockReturnValue(
1039
+ Effect.succeed({
1040
+ rollbackThread,
1041
+ } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime),
1042
+ );
1043
+ yield* Effect.addFinalizer(() => Effect.sync(() => sessionSpy.mockRestore()));
1044
+ yield* orchestrator.dispatch({
1045
+ type: "thread.create",
1046
+ commandId: CommandId.make("non-git-create"),
1047
+ createdBy: "user",
1048
+ creationSource: "web",
1049
+ threadId,
1050
+ projectId: ProjectId.make("non-git-project"),
1051
+ title: "Non-Git rewind",
1052
+ modelSelection,
1053
+ runtimeMode: "full-access",
1054
+ interactionMode: "default",
1055
+ branch: null,
1056
+ worktreePath: cwd,
1057
+ });
1058
+
1059
+ const completeMessage = (name: string) =>
1060
+ Effect.gen(function* () {
1061
+ yield* orchestrator.dispatch({
1062
+ type: "message.dispatch",
1063
+ commandId: CommandId.make(name),
1064
+ createdBy: "user",
1065
+ creationSource: "web",
1066
+ threadId,
1067
+ messageId: MessageId.make(name),
1068
+ text: name,
1069
+ attachments: [],
1070
+ dispatchMode: { type: "start_immediately" },
1071
+ });
1072
+ const projection = yield* orchestrator.getThreadProjection(threadId);
1073
+ const run = projection.runs.find((candidate) => candidate.userMessageId === name)!;
1074
+ const node = projection.nodes.find((candidate) => candidate.id === run.rootNodeId)!;
1075
+ const providerThread = projection.providerThreads.find(
1076
+ (candidate) => candidate.id === run.providerThreadId,
1077
+ )!;
1078
+ const now = yield* DateTime.now;
1079
+ const commandId = CommandId.make(`${name}-complete`);
1080
+ // The provider completion is the fixture boundary; capture and rollback use real effects.
1081
+ yield* outbox.cancelUnsettled({
1082
+ threadId,
1083
+ effectTypes: ["provider-turn.start"],
1084
+ reason: "provider completion supplied by fixture",
1085
+ });
1086
+ yield* eventSink.writeWithEffects({
1087
+ commandId,
1088
+ events: [
1089
+ {
1090
+ id: EventId.make(`${name}-run`),
1091
+ type: "run.updated",
1092
+ threadId,
1093
+ runId: run.id,
1094
+ occurredAt: now,
1095
+ payload: { ...run, status: "waiting", startedAt: now },
1096
+ },
1097
+ {
1098
+ id: EventId.make(`${name}-node`),
1099
+ type: "node.updated",
1100
+ threadId,
1101
+ runId: run.id,
1102
+ nodeId: node.id,
1103
+ occurredAt: now,
1104
+ payload: { ...node, status: "completed", completedAt: now },
1105
+ },
1106
+ {
1107
+ id: EventId.make(`${name}-turn`),
1108
+ type: "provider-turn.updated",
1109
+ threadId,
1110
+ runId: run.id,
1111
+ occurredAt: now,
1112
+ payload: {
1113
+ id: ProviderTurnId.make(`${name}-turn`),
1114
+ providerThreadId: providerThread.id,
1115
+ nodeId: node.id,
1116
+ runAttemptId: run.activeAttemptId,
1117
+ nativeTurnRef: null,
1118
+ ordinal: run.ordinal,
1119
+ status: "completed",
1120
+ startedAt: now,
1121
+ completedAt: now,
1122
+ },
1123
+ },
1124
+ ],
1125
+ effects: [
1126
+ {
1127
+ id: `${name}-capture`,
1128
+ commandId,
1129
+ threadId,
1130
+ request: {
1131
+ type: "checkpoint.capture",
1132
+ runId: run.id,
1133
+ scopeId: node.checkpointScopeId!,
1134
+ },
1135
+ },
1136
+ ],
1137
+ });
1138
+ yield* worker.drain();
1139
+ const captured = yield* orchestrator.getThreadProjection(threadId);
1140
+ assert.equal(
1141
+ captured.runs.find((candidate) => candidate.id === run.id)?.status,
1142
+ "completed",
1143
+ );
1144
+ const checkpoint = captured.checkpoints.find((candidate) => candidate.runId === run.id)!;
1145
+ assert.equal(checkpoint.status, "missing");
1146
+ return { run, checkpoint };
1147
+ });
1148
+
1149
+ const first = yield* completeMessage("non-git-first");
1150
+ const second = yield* completeMessage("non-git-second");
1151
+ const before = yield* orchestrator.getThreadProjection(threadId);
1152
+ assert.equal(
1153
+ before.checkpoints.find((checkpoint) => checkpoint.id === first.checkpoint.id)?.runId,
1154
+ first.run.id,
1155
+ "capturing a later run must preserve the earlier checkpoint's run link",
1156
+ );
1157
+ const baseline = before.checkpoints.find(
1158
+ (checkpoint) => checkpoint.ordinalWithinScope === 0,
1159
+ )!;
1160
+ assert.equal(baseline.status, "missing");
1161
+ for (const checkpoint of [baseline, first.checkpoint]) {
1162
+ for (const restoreFiles of [undefined, true]) {
1163
+ const commandId = CommandId.make(`non-git-files-${checkpoint.id}-${restoreFiles}`);
1164
+ yield* orchestrator
1165
+ .dispatch({
1166
+ type: "checkpoint.rollback",
1167
+ commandId,
1168
+ threadId,
1169
+ checkpointId: checkpoint.id,
1170
+ scopeId: checkpoint.scopeId,
1171
+ ...(restoreFiles === undefined ? {} : { restoreFiles }),
1172
+ })
1173
+ .pipe(Effect.flip);
1174
+ assert.deepEqual(yield* outbox.listByCommandId(commandId), []);
1175
+ }
1176
+ }
1177
+ assert.equal(rollbackThread.mock.calls.length, 0);
1178
+
1179
+ const rewind = (name: string) =>
1180
+ Effect.gen(function* () {
1181
+ const commandId = CommandId.make(name);
1182
+ yield* orchestrator.dispatch({
1183
+ type: "checkpoint.rollback",
1184
+ commandId,
1185
+ threadId,
1186
+ checkpointId: baseline.id,
1187
+ scopeId: baseline.scopeId,
1188
+ restoreFiles: false,
1189
+ });
1190
+ yield* worker.drain();
1191
+ assert.deepEqual(
1192
+ (yield* outbox.listByCommandId(commandId)).map((effect) => effect.status),
1193
+ ["succeeded"],
1194
+ );
1195
+ const projection = yield* orchestrator.getThreadProjection(threadId);
1196
+ assert.ok(projection.runs.every((run) => run.status === "rolled_back"));
1197
+ assert.isNull(projection.providerThreads[0]!.lastRunOrdinal);
1198
+ assert.equal(
1199
+ projection.providerThreads[0]!.nativeThreadRef?.nativeId,
1200
+ "rewound-native-thread",
1201
+ );
1202
+ assert.isNull(projection.thread.rollbackFailure);
1203
+ });
1204
+
1205
+ yield* rewind("non-git-rewind-first");
1206
+ assert.equal(rollbackThread.mock.calls[0]![0].target.type, "thread_start");
1207
+ assert.deepEqual(
1208
+ rollbackThread.mock.calls[0]![0].providerThreadTurns.map((turn) => turn.id),
1209
+ [ProviderTurnId.make("non-git-first-turn"), ProviderTurnId.make("non-git-second-turn")],
1210
+ );
1211
+ const discardedCommandId = CommandId.make("non-git-discarded-target");
1212
+ yield* orchestrator
1213
+ .dispatch({
1214
+ type: "checkpoint.rollback",
1215
+ commandId: discardedCommandId,
1216
+ threadId,
1217
+ checkpointId: second.checkpoint.id,
1218
+ scopeId: second.checkpoint.scopeId,
1219
+ restoreFiles: false,
1220
+ })
1221
+ .pipe(Effect.flip);
1222
+ assert.deepEqual(yield* outbox.listByCommandId(discardedCommandId), []);
1223
+ assert.equal(rollbackThread.mock.calls.length, 1);
1224
+
1225
+ const resent = yield* completeMessage("non-git-resent");
1226
+ assert.isAbove(resent.run.ordinal, second.run.ordinal);
1227
+ yield* rewind("non-git-rewind-again");
1228
+ assert.equal(rollbackThread.mock.calls.length, 2);
1229
+ assert.equal(rollbackThread.mock.calls[1]![0].target.type, "thread_start");
1230
+ assert.deepEqual(
1231
+ rollbackThread.mock.calls[1]![0].providerThreadTurns.map((turn) => turn.id),
1232
+ [ProviderTurnId.make("non-git-resent-turn")],
1233
+ );
1234
+ }).pipe(Effect.provide(Layer.merge(Layer.fresh(layerTest), NodeServices.layer))),
1235
+ );
1236
+
1237
it.effect("rejects non-ready rollback targets before persisting events or effects", () =>
1238
Effect.gen(function* () {
1239
const orchestrator = yield* Orchestrator.OrchestratorV2;
apps/web/src/components/ChatView.tsx
+7
-3
@@ -1588,7 +1588,7 @@ export default function ChatView(props: ChatViewProps) {
1588
const turnDiffSummaries = useThreadCheckpointSummaries(routeThreadDetailRef);
1589
const availableRevertTurnCounts = deriveAvailableRevertTurnCounts(serverProjection);
1590
// A paged history window cannot identify the first loaded run as the thread start.
1591
- const threadStartCheckpointReady =
1591
+ const threadStartCheckpointAvailable =
1592
!serverThreadHistory.hasMoreHistory &&
1593
findRevertCheckpoint(serverProjection?.checkpoints ?? [], 0) !== undefined;
1594
@@ -3446,7 +3446,7 @@ export default function ChatView(props: ChatViewProps) {
3446
parentThreadLink={parentThreadLink}
3447
workflowOpening={workflowOpening}
3448
supportsConversationRollback={supportsConversationRollback}
3449
- threadStartCheckpointReady={threadStartCheckpointReady}
3449
+ threadStartCheckpointAvailable={threadStartCheckpointAvailable}
3450
availableRevertTurnCounts={availableRevertTurnCounts}
3451
onRevertToTurnCount={onRevertTimelineTurnStable}
3452
onUseArtifactTemplate={insertArtifactTemplateStable}
@@ -3992,7 +3992,11 @@ export default function ChatView(props: ChatViewProps) {
3992
</ChatRightPanel>
3993
) : null}
3994
3995
- <RevertConfirmHost threadKey={routeThreadKey} onConfirm={onConfirmRevertStable} />
3995
+ <RevertConfirmHost
3996
+ threadKey={routeThreadKey}
3997
+ checkpoints={serverProjection?.checkpoints}
3998
+ onConfirm={onConfirmRevertStable}
3999
+ />
4000
{embedded ? null : <LinkPullRequestDialogHost />}
4001
<ThreadVisitWatermark threadRef={routeThreadRef} />
4002
<ExpandedImageDialogHost threadKey={routeThreadKey} />
apps/web/src/components/chat/ChatOverlayHosts.tsx
+12
-2
@@ -2,6 +2,7 @@ import type {
2
DeviceServiceState,
3
EnvironmentId,
4
MessageId,
5
+ OrchestrationV2ThreadProjection,
6
ScopedThreadRef,
7
ThreadId,
8
} from "@t3tools/contracts";
@@ -24,6 +25,7 @@ import {
25
import { Button } from "../ui/button";
26
import { Dialog } from "../ui/dialog";
27
import { WizardPopup } from "../ui/wizard";
28
+import { findRevertCheckpoint } from "../../session-logic";
29
import { registerThreadOverlay } from "./threadOverlayRetention";
30
31
/**
@@ -193,11 +195,15 @@ export function openRevertConfirm(threadKey: string, pending: PendingRevert): vo
195
196
export function RevertConfirmHost(props: {
197
readonly threadKey: string;
198
+ readonly checkpoints: OrchestrationV2ThreadProjection["checkpoints"] | undefined;
199
readonly onConfirm: (turnCount: number, messageId: MessageId, restoreFiles: boolean) => void;
200
}) {
201
const pending = useThreadOverlay(revertConfirmAtom, props.threadKey);
202
+ const canRestoreFiles =
203
+ pending !== null &&
204
+ findRevertCheckpoint(props.checkpoints ?? [], pending.turnCount)?.status === "ready";
205
const confirm = (restoreFiles: boolean) => {
200
- if (pending === null) return;
206
+ if (pending === null || (restoreFiles && !canRestoreFiles)) return;
207
closeThreadOverlay(revertConfirmAtom);
208
props.onConfirm(pending.turnCount, pending.messageId, restoreFiles);
209
};
@@ -218,7 +224,11 @@ export function RevertConfirmHost(props: {
224
</AlertDialogHeader>
225
<AlertDialogFooter>
226
<AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
221
- <Button variant="destructive-outline" onClick={() => confirm(true)}>
227
+ <Button
228
+ variant="destructive-outline"
229
+ disabled={!canRestoreFiles}
230
+ onClick={() => confirm(true)}
231
+ >
232
Revert files too
233
</Button>
234
<Button onClick={() => confirm(false)}>Revert and keep changes</Button>
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+1
-1
@@ -1234,7 +1234,7 @@ describe("MessagesTimeline automation prompts", () => {
1234
],
1235
{
1236
supportsConversationRollback: true,
1237
- threadStartCheckpointReady: true,
1237
+ threadStartCheckpointAvailable: true,
1238
turnDiffSummaries: [
1239
{
1240
runId,
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+1
-1
@@ -1026,7 +1026,7 @@ describe("deriveMessagesTimelineRows", () => {
1026
activeTurnStartedAt: null,
1027
turnDiffSummaries: [assistantTurnDiffSummary],
1028
supportsConversationRollback: true,
1029
- threadStartCheckpointReady: true,
1029
+ threadStartCheckpointAvailable: true,
1030
});
1031
1032
const userRow = rows.find(
apps/web/src/components/chat/MessagesTimeline.logic.ts
+2
-2
@@ -1527,7 +1527,7 @@ export function deriveMessagesTimelineRows(input: {
1527
activeTurnStartedAt?: string | null;
1528
turnDiffSummaries: ReadonlyArray<TurnDiffSummary>;
1529
supportsConversationRollback: boolean;
1530
- threadStartCheckpointReady?: boolean;
1530
+ threadStartCheckpointAvailable?: boolean;
1531
availableRevertTurnCounts?: ReadonlySet<number> | undefined;
1532
worktreeSetup?: WorktreeSetupSnapshot | null;
1533
toolCallVisibility?: ToolCallVisibility;
@@ -1558,7 +1558,7 @@ export function deriveMessagesTimelineRows(input: {
1558
? deriveRevertTurnCountByUserMessageId({
1559
timelineEntries: input.timelineEntries,
1560
checkpoints: input.turnDiffSummaries,
1561
- threadStartCheckpointReady: input.threadStartCheckpointReady === true,
1561
+ threadStartCheckpointAvailable: input.threadStartCheckpointAvailable === true,
1562
unsettledRunId,
1563
availableRevertTurnCounts: input.availableRevertTurnCounts,
1564
})
apps/web/src/components/chat/MessagesTimeline.tsx
+3
-3
@@ -280,7 +280,7 @@ interface MessagesTimelineProps {
280
readonly runId: RunId;
281
}) => Promise<void>;
282
supportsConversationRollback: boolean;
283
- threadStartCheckpointReady?: boolean;
283
+ threadStartCheckpointAvailable?: boolean;
284
availableRevertTurnCounts?: ReadonlySet<number> | undefined;
285
onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
286
onUseArtifactTemplate?: (template: CodexArtifactTemplate) => void;
@@ -379,7 +379,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
379
workflowOpening = null,
380
onForkFromRun,
381
supportsConversationRollback,
382
- threadStartCheckpointReady = false,
382
+ threadStartCheckpointAvailable = false,
383
availableRevertTurnCounts,
384
onRevertToTurnCount,
385
onUseArtifactTemplate = NOOP_USE_ARTIFACT_TEMPLATE,
@@ -737,7 +737,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
737
activeTurnStartedAt,
738
turnDiffSummaries,
739
supportsConversationRollback,
740
- threadStartCheckpointReady,
740
+ threadStartCheckpointAvailable,
741
availableRevertTurnCounts,
742
worktreeSetup,
743
toolCallVisibility,
apps/web/src/session-logic.test.ts
+13
-8
@@ -226,7 +226,7 @@ describe("V2 session presentation", () => {
226
227
const targets = deriveRevertTurnCountByUserMessageId({
228
timelineEntries,
229
- threadStartCheckpointReady: true,
229
+ threadStartCheckpointAvailable: true,
230
checkpoints: [
231
{
232
runId,
@@ -266,7 +266,7 @@ describe("V2 session presentation", () => {
266
},
267
};
268
});
269
- const checkpoint = (ordinal: number, status: "ready" | "stale" = "ready") => ({
269
+ const checkpoint = (ordinal: number, status: "ready" | "missing" | "stale" = "ready") => ({
270
runId: runId(ordinal),
271
checkpointTurnCount: ordinal,
272
checkpointRef: `checkpoint-${ordinal}` as never,
@@ -278,13 +278,13 @@ describe("V2 session presentation", () => {
278
const targets = (
279
ordinals: ReadonlyArray<number>,
280
checkpoints: ReadonlyArray<ReturnType<typeof checkpoint>>,
281
- options: { threadStartCheckpointReady?: boolean; unsettledRunId?: RunId } = {},
281
+ options: { threadStartCheckpointAvailable?: boolean; unsettledRunId?: RunId } = {},
282
) =>
283
Object.fromEntries(
284
deriveRevertTurnCountByUserMessageId({
285
timelineEntries: ordinals.flatMap(turn),
286
checkpoints,
287
- threadStartCheckpointReady: options.threadStartCheckpointReady ?? true,
287
+ threadStartCheckpointAvailable: options.threadStartCheckpointAvailable ?? true,
288
unsettledRunId: options.unsettledRunId ?? null,
289
}),
290
);
@@ -297,6 +297,11 @@ describe("V2 session presentation", () => {
297
"user-5": 4,
298
});
299
expect(targets([2], [checkpoint(1, "stale")])).toEqual({ "user-2": 0 });
300
+ // Without file snapshots, missing checkpoints still pin the conversation.
301
+ expect(targets([1, 2], [checkpoint(1, "missing"), checkpoint(2, "missing")])).toEqual({
302
+ "user-1": 0,
303
+ "user-2": 1,
304
+ });
305
});
306
307
it("preserves a notification-only wake run while ignoring inherited and unrelated work", () => {
@@ -360,7 +365,7 @@ describe("V2 session presentation", () => {
365
checkpoint(7),
366
checkpoint(8),
367
],
363
- threadStartCheckpointReady: true,
368
+ threadStartCheckpointAvailable: true,
369
}),
370
),
371
).toEqual({ "user-1": 0, "user-3": 2 });
@@ -371,7 +376,7 @@ describe("V2 session presentation", () => {
376
expect(targets([1, 2], [checkpoint(1, "stale"), checkpoint(2)])).toEqual({ "user-1": 0 });
377
// Earlier history is paged out, so the first loaded run's predecessor is unknown.
378
expect(
374
- targets([4, 5], [checkpoint(4), checkpoint(5)], { threadStartCheckpointReady: false }),
379
+ targets([4, 5], [checkpoint(4), checkpoint(5)], { threadStartCheckpointAvailable: false }),
380
).toEqual({ "user-5": 4 });
381
expect(targets([1, 2], [checkpoint(1), checkpoint(2)], { unsettledRunId: runId(2) })).toEqual(
382
{ "user-1": 0 },
@@ -384,7 +389,7 @@ describe("V2 session presentation", () => {
389
deriveRevertTurnCountByUserMessageId({
390
timelineEntries: [1, 2, 3].flatMap(turn),
391
checkpoints: [checkpoint(1), checkpoint(2), checkpoint(3)],
387
- threadStartCheckpointReady: true,
392
+ threadStartCheckpointAvailable: true,
393
availableRevertTurnCounts: new Set([0, 1]),
394
}),
395
),
@@ -404,7 +409,7 @@ describe("V2 session presentation", () => {
409
deriveRevertTurnCountByUserMessageId({
410
timelineEntries: [...inheritedEntries, ...turn(2)],
411
checkpoints: [{ ...checkpoint(7), runId: fixture.historyRunId }, checkpoint(2)],
407
- threadStartCheckpointReady: true,
412
+ threadStartCheckpointAvailable: true,
413
}),
414
),
415
).toEqual({ "user-2": 0 });
apps/web/src/session-logic.ts
+13
-7
@@ -992,14 +992,14 @@ export function deriveTimelineEntriesFromVisibleTurnItemsWithState(
992
export function deriveRevertTurnCountByUserMessageId(input: {
993
readonly timelineEntries: ReadonlyArray<TimelineEntry>;
994
readonly checkpoints: ReadonlyArray<ThreadCheckpointSummary>;
995
- readonly threadStartCheckpointReady: boolean;
995
+ readonly threadStartCheckpointAvailable: boolean;
996
readonly availableRevertTurnCounts?: ReadonlySet<number> | undefined;
997
readonly unsettledRunId?: RunId | null;
998
}): Map<ChatMessage["id"], number> {
999
- const readyTurnCountByRunId = new Map<RunId, number>();
999
+ const turnCountByRunId = new Map<RunId, number>();
1000
for (const checkpoint of input.checkpoints) {
1001
- if (checkpoint.status === "ready") {
1002
- readyTurnCountByRunId.set(checkpoint.runId, checkpoint.checkpointTurnCount);
1001
+ if (isRewindableCheckpoint(checkpoint)) {
1002
+ turnCountByRunId.set(checkpoint.runId, checkpoint.checkpointTurnCount);
1003
}
1004
}
1005
const targetByRunId = new Map<RunId, number | undefined>();
@@ -1022,10 +1022,10 @@ export function deriveRevertTurnCountByUserMessageId(input: {
1022
targetByRunId.set(
1023
runId,
1024
previousRunId === null
1025
- ? input.threadStartCheckpointReady
1025
+ ? input.threadStartCheckpointAvailable
1026
? 0
1027
: undefined
1028
- : readyTurnCountByRunId.get(previousRunId),
1028
+ : turnCountByRunId.get(previousRunId),
1029
);
1030
previousRunId = runId;
1031
}
@@ -1043,13 +1043,19 @@ export function deriveRevertTurnCountByUserMessageId(input: {
1043
return byUserMessageId;
1044
}
1045
1046
+// A missing snapshot (no git, or a side chat) still pins a conversation position; only
1047
+// restoring files needs a ready one.
1048
+function isRewindableCheckpoint(checkpoint: Pick<OrchestrationV2Checkpoint, "status">) {
1049
+ return checkpoint.status === "ready" || checkpoint.status === "missing";
1050
+}
1051
+
1052
export function findRevertCheckpoint(
1053
checkpoints: ReadonlyArray<OrchestrationV2Checkpoint>,
1054
turnCount: number,
1055
): OrchestrationV2Checkpoint | undefined {
1056
return checkpoints.findLast(
1057
(checkpoint) =>
1052
- checkpoint.status === "ready" &&
1058
+ isRewindableCheckpoint(checkpoint) &&
1059
(turnCount === 0
1060
? checkpoint.ordinalWithinScope === 0 && checkpoint.appRunOrdinal === null
1061
: checkpoint.appRunOrdinal === turnCount),
packages/client-runtime/src/operations/commands.ts
+6
-1
@@ -941,7 +941,12 @@ export const revertThreadCheckpoint = Effect.fn("EnvironmentCommands.revertThrea
941
? candidate.ordinalWithinScope === 0 && candidate.appRunOrdinal === null
942
: candidate.appRunOrdinal === input.turnCount,
943
);
944
- if (checkpoint === undefined || checkpoint.status !== "ready") {
944
+ if (
945
+ checkpoint === undefined ||
946
+ // Missing snapshots support conversation rewind only.
947
+ (checkpoint.status !== "ready" &&
948
+ !(input.restoreFiles === false && checkpoint.status === "missing"))
949
+ ) {
950
const target =
951
input.checkpointId === undefined
952
? `run ordinal ${input.turnCount ?? "unknown"}`