From eba445b402bc11feaf063c2c28e310f32e9f6805 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 6 Oct 2026 13:11:36 +0530 Subject: [PATCH] refactor(desktop): make the deep-truncate confirm explicit at every rewind site Gate C18 r1 quality [Low]: runRewindSubmit defaulted confirmDeepTruncate to true while truncateSubmitParams defaulted it to false, so regenerate had to write `?? false` and restore/edit opted into a destructive server bypass by omitting a trailing argument. An omitted flag now means not confirmed; restore/edit and their stale-target retries pass true explicitly, and ReloadPlan.confirmDeepTruncate is a plain boolean (planReload false, planConfirmedReload true after the confirm). The parameter stays optional rather than required: it trails other optional parameters, which TypeScript forbids for a required one. --- apps/desktop/src/app/chat/session-tile-actions.ts | 11 +++++++---- .../app/session/hooks/use-prompt-actions/index.ts | 14 +++++++++----- .../hooks/use-prompt-actions/rewind.test.ts | 2 +- .../app/session/hooks/use-prompt-actions/rewind.ts | 11 ++++++----- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.ts index c3b60d784b..19bafc82ee 100644 --- a/apps/desktop/src/app/chat/session-tile-actions.ts +++ b/apps/desktop/src/app/chat/session-tile-actions.ts @@ -581,7 +581,7 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored plan.truncateRowId, plan.sourceText, durableRowIdsForRebind(messages), - plan.confirmDeepTruncate ?? false + plan.confirmDeepTruncate ) ) } catch (err) { @@ -627,7 +627,8 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored plan.truncateMessageId, plan.truncateRowId, plan.sourceText, - durableRowIdsForRebind(messages) + durableRowIdsForRebind(messages), + true ) ) } catch (err) { @@ -662,7 +663,8 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored retryPlan.truncateMessageId, retryPlan.truncateRowId, retryPlan.sourceText, - durableRowIdsForRebind(freshMessages) + durableRowIdsForRebind(freshMessages), + true ) ) @@ -719,7 +721,8 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored plan.truncateMessageId, plan.truncateRowId, plan.sourceText, - durableRowIdsForRebind(messages) + durableRowIdsForRebind(messages), + true ) ) } catch (err) { 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 b025d86b10..63b1e66963 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 @@ -1029,7 +1029,7 @@ export function usePromptActions({ plan.truncateRowId, plan.sourceText, durableRowIdsForRebind(messages), - plan.confirmDeepTruncate ?? false + plan.confirmDeepTruncate ) applySurvivorRowIds(sessionId, survivorRowIds) @@ -1104,7 +1104,8 @@ export function usePromptActions({ interruptFirst, plan.truncateRowId, plan.sourceText, - durableRowIdsForRebind(messages) + durableRowIdsForRebind(messages), + true ) applySurvivorRowIds(sessionId, survivorRowIds) @@ -1140,7 +1141,8 @@ export function usePromptActions({ false, retryPlan.truncateRowId, retryPlan.sourceText, - durableRowIdsForRebind(refreshed) + durableRowIdsForRebind(refreshed), + true ) applySurvivorRowIds(sessionId, survivorRowIds) @@ -1241,7 +1243,8 @@ export function usePromptActions({ interruptFirst, plan.truncateRowId, plan.sourceText, - durableRowIdsForRebind(messages) + durableRowIdsForRebind(messages), + true ) applySurvivorRowIds(sessionId, survivorRowIds) @@ -1275,7 +1278,8 @@ export function usePromptActions({ false, retryPlan.truncateRowId, retryPlan.sourceText, - durableRowIdsForRebind(refreshed) + durableRowIdsForRebind(refreshed), + true ) applySurvivorRowIds(sessionId, survivorRowIds) diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts index 1a9490bdf0..ab4b2f1d34 100644 --- a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts +++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts @@ -738,7 +738,7 @@ describe('planConfirmedReload (#133716)', () => { plan.truncateRowId, plan.sourceText, undefined, - plan.confirmDeepTruncate ?? false + plan.confirmDeepTruncate ) } diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts index c8e19177cd..7a9fd08cdb 100644 --- a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts +++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts @@ -281,9 +281,9 @@ export async function runRewindSubmit( truncateRowId?: number, sourceText?: string, rebindRowIds?: readonly number[], - // Restore/edit name their target explicitly; only regenerate (implicit - // target) passes false unless the user confirmed a deep cut (#133716). - confirmDeepTruncate = true + // Omitted never means confirmed: restore/edit (explicit target) and a + // confirmed deep regenerate pass true; tail regenerate passes false (#133716). + confirmDeepTruncate?: boolean ): Promise { // Recovery may rebind the live id mid-flight; interrupt/submit must both // follow it rather than pinning the dead one. @@ -492,8 +492,8 @@ export function appendMidTurnUserMessage< export interface ReloadPlan { branchGroupId: string - /** Set only after the user confirmed a reload that archives later user turns. */ - confirmDeepTruncate?: boolean + /** True only after the user confirmed a reload that archives later user turns. */ + confirmDeepTruncate: boolean /** Original persisted text of the turn — the durable-row-id content key. */ sourceText: string text: string @@ -533,6 +533,7 @@ export function planReload(messages: ChatMessage[], parentId: null | string): nu return { branchGroupId: targetAssistant?.branchGroupId ?? branchGroupForUser(userMessage), + confirmDeepTruncate: false, sourceText: text, text, truncateOrdinal: isFailedTurn ? undefined : visibleUserOrdinal(messages, userIndex),