From 5a6696b233a9b582fc778e6946deb1099a9f50ad Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Feb 2026 08:43:24 +0000 Subject: [PATCH] Fix revert checkpoint ordering and checkpoint hydration retry loop - Swap filesystem restore and thread rollback order in revertToCheckpoint so a filesystem restore failure doesn't leave the thread irreversibly rolled back while the UI still shows pre-revert state. - Stop deleting the dedup ref key on ensureSession failure in the checkpoint hydration effect, preventing an unbounded retry loop when the backend is unreachable. --- apps/server/src/providerManager.ts | 15 +++++++++------ apps/web/src/components/ChatView.tsx | 11 ++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/server/src/providerManager.ts b/apps/server/src/providerManager.ts index 5e55f0b1ce..7f7f344123 100644 --- a/apps/server/src/providerManager.ts +++ b/apps/server/src/providerManager.ts @@ -330,12 +330,6 @@ export class ProviderManager extends EventEmitter { } } - const requestedRollbackTurns = currentTurnCount - input.turnCount; - const afterSnapshot = - requestedRollbackTurns > 0 - ? await this.codex.rollbackThread(input.sessionId, requestedRollbackTurns) - : beforeSnapshot; - if (checkpointCwd) { const restored = await this.filesystemCheckpointStore.restoreCheckpoint({ cwd: checkpointCwd, @@ -347,6 +341,15 @@ export class ProviderManager extends EventEmitter { `Filesystem checkpoint is unavailable for turn ${input.turnCount} in thread ${beforeSnapshot.threadId}.`, ); } + } + + const requestedRollbackTurns = currentTurnCount - input.turnCount; + const afterSnapshot = + requestedRollbackTurns > 0 + ? await this.codex.rollbackThread(input.sessionId, requestedRollbackTurns) + : beforeSnapshot; + + if (checkpointCwd) { await this.filesystemCheckpointStore.pruneAfterTurn({ cwd: checkpointCwd, threadId: afterSnapshot.threadId, diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 9a518c0c92..a47d8e229b 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -960,9 +960,14 @@ export default function ChatView() { } checkpointHydrationSessionRequestRef.current.add(requestKey); setThreadError(activeThreadId, null); - void ensureSession().finally(() => { - checkpointHydrationSessionRequestRef.current.delete(requestKey); - }); + void ensureSession().then( + () => { + checkpointHydrationSessionRequestRef.current.delete(requestKey); + }, + () => { + // Keep the ref key so the effect does not retry indefinitely on failure. + }, + ); }, [ activeThreadId, activeThreadRuntimeId,