Skip to content

The agent that grows with you

fix(desktop): re-confirm expanded edit retries

Kevin Rajan05af6caef0e6
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
index ed79cc74fb2..a33ab9d23c4 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
@@ -67,6 +67,7 @@ import {
durableRowIdsForRebind,
type EditPlan,
finalizeStoppedMessages,
+ laterVisibleUserTurns,
planConfirmedReload,
planEdit,
planEditAfterConfirm,
@@ -1108,7 +1109,7 @@ export function usePromptActions({
// The confirm is a wait of user length: a turn that started or output that landed meanwhile
// makes the plan (and the rollback snapshot) stale, so drop it rather than cut a live turn.
- if (!plan || isStaleAfterConfirm(sessionId, messages)) {
+ if (!plan || activeSessionIdRef.current !== sessionId || isStaleAfterConfirm(sessionId, messages)) {
return
}
@@ -1308,7 +1309,7 @@ export function usePromptActions({
edited: AppendMessage,
plan: EditPlan & { confirmDeepTruncate: boolean },
messages: ChatMessage[]
- ): Promise<'sent' | { surfaced?: unknown; surfacedConfirmed?: boolean; unavailable: boolean }> => {
+ ): Promise<'cancelled' | 'sent' | { surfaced?: unknown; surfacedConfirmed?: boolean; unavailable: boolean }> => {
let surfacedConfirmed: boolean | undefined
try {
@@ -1327,6 +1328,23 @@ export function usePromptActions({
surfacedConfirmed = retryKeepsDeepConfirm(plan, messages, retryPlan, refreshed)
+ // A refreshed 4018 retry can reveal later user turns the first plan did
+ // not cover. During the warn-only rollout the backend still allows an
+ // unconfirmed deep cut, so the client must ask again before sending it.
+ if (laterVisibleUserTurns(refreshed, retryPlan.sourceIndex) > 0 && !surfacedConfirmed) {
+ const accepted = await confirm(deepCutConfirmRequest(t.assistant.thread))
+
+ if (
+ !accepted ||
+ activeSessionIdRef.current !== sessionId ||
+ currentMessages(sessionId) !== refreshed
+ ) {
+ return 'cancelled'
+ }
+
+ surfacedConfirmed = true
+ }
+
const survivorRowIds = await submitRewindPrompt(
sessionId,
retryPlan.text,
@@ -1350,7 +1368,7 @@ export function usePromptActions({
}
}
},
- [applySurvivorRowIds, resumeStoredSession, selectedStoredSessionIdRef, submitRewindPrompt]
+ [activeSessionIdRef, applySurvivorRowIds, resumeStoredSession, selectedStoredSessionIdRef, submitRewindPrompt, t]
)
// Roll an optimistic edit/truncation back to the original history so the UI stays in sync with
@@ -1455,6 +1473,12 @@ export function usePromptActions({
return
}
+ if (retried === 'cancelled') {
+ rollBackEdit(sessionId, messages)
+
+ return
+ }
+
unavailable = retried.unavailable
if (retried.surfaced !== undefined) {