Skip to content

The agent that grows with you

fix(desktop): a replayed /undo or /retry cuts the view by the lost rewind's own count

Tekniumda8015febae4
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx
index 895c27f0f34..e7a4922b939 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.test.tsx
@@ -426,6 +426,27 @@ describe('a repeat after a lost rewind reply on a canonical session', () => {
])
})
+ it('a replayed /undo 2 cuts both turns from a view without row ids', async () => {
+ const owner = lostRewindReply()
+
+ const unbound = THREE_EXCHANGES.map((row, index) => ({
+ id: `u${index}`,
+ parts: [textPart(String(row.content))],
+ role: row.role as 'assistant' | 'user',
+ timestamp: index
+ }))
+
+ const handle = await mountWith(owner.requestGateway, unbound)
+
+ await handle.submitText('/undo 2')
+ await handle.submitText('/undo')
+
+ expect(owner.active()).toEqual(['first question', 'first answer'])
+ expect(renderedText(handle)).toContain('first answer')
+ expect(renderedText(handle)).not.toContain('second question')
+ expect(renderedText(handle)).not.toContain('third question')
+ })
+
it('a view refreshed after the reconnect keeps every exchange the owner still holds', async () => {
const owner = lostRewindReply()
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.ts
index 5811f9fd098..a4a319539f8 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-session-commands.ts
@@ -61,6 +61,10 @@ export interface SessionCommandEnv<C extends { arg: string }> {
const copy = () => runtimeTranslations().promptNotices.sessionCommands
+// The cut (`turnsBack`) of each session's derived rewind still awaiting its reply. A repeat after a
+// lost reply replays THAT request, so an unbound view cuts by its count, not the repeat's own.
+const pendingRewindCuts = new Map<string, number>()
+
/** Clip a queued/steered prompt for the confirmation line (Ink's previewOf). */
const previewOf = (text: string) => `${text.slice(0, PREVIEW_CHARS)}${text.length > PREVIEW_CHARS ? '…' : ''}`
@@ -160,7 +164,10 @@ export function sessionCommandHandlers<C extends { arg: string }>(env: SessionCo
replay_only: true
})
- const receipt = Number(replayed?.rewound_count ?? 0) > 0 ? replayed : await deriveAndRewind(out, turnsBack, intent)
+ const replay = Number(replayed?.rewound_count ?? 0) > 0
+ const receipt = replay ? replayed : await deriveAndRewind(out, turnsBack, intent)
+ const cut = replay ? (pendingRewindCuts.get(sessionId) ?? turnsBack) : turnsBack
+ pendingRewindCuts.delete(sessionId)
if (!receipt) {
return
@@ -179,7 +186,7 @@ export function sessionCommandHandlers<C extends { arg: string }>(env: SessionCo
if (rowId !== undefined) {
updateSessionState(
sessionId,
- state => ({ ...state, messages: truncateRewoundMessages(state.messages, rowId, turnsBack) }),
+ state => ({ ...state, messages: truncateRewoundMessages(state.messages, rowId, cut) }),
storedSessionId
)
}
@@ -218,6 +225,8 @@ export function sessionCommandHandlers<C extends { arg: string }>(env: SessionCo
}
// A derived target: retained by operation alone, so a repeat after a lost reply re-sends it.
+ pendingRewindCuts.set(sessionId, turnsBack)
+
const receipt = await requestGateway<RewindReceipt>('session.rewind', {
session_id: sessionId,
target_message_id: target.row_id,