Skip to content

The agent that grows with you

fix(desktop): preserve rewinds on older backends

Kevin Rajan7426fb7a5d84
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 dc8a3851353..ea59746a27e 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
@@ -10,6 +10,7 @@
*/
import type { AppendMessage, ThreadMessage } from '@assistant-ui/react'
+import { JsonRpcGatewayError } from '@hermes/shared'
import type { ClientSessionState } from '@/app/types'
import { PROMPT_SUBMIT_REQUEST_TIMEOUT_MS } from '@/hermes'
@@ -343,28 +344,46 @@ export async function runRewindSubmit(
}
}
- const submitFor = (targetId: string) =>
- requestGateway<PromptSubmitResult>(
- 'prompt.submit',
- {
- session_id: targetId,
- text,
- ...truncateSubmitParams(resolvedOrdinal, resolvedMessageId, resolvedRowId, confirmDeepTruncate),
- // A first-turn rewind resolves to an empty transcript, which the
- // gateway additionally gates behind confirm_empty_truncate. In
- // resolved-row-id mode the tail-local ordinal was dropped (see
- // above). The durable target is authoritative, so explicitly allow a
- // first-active-tip cut; the gateway ignores this when the prefix is
- // non-empty.
- ...(resolvedOrdinal === undefined && (resolvedRowId !== undefined || truncateOrdinal === 0)
- ? { confirm_empty_truncate: true }
- : {}),
- ...(rebindRowIds?.length
- ? { rebind_survivor_row_ids: [...new Set(rebindRowIds.filter(Number.isInteger))] }
- : {})
- },
- PROMPT_SUBMIT_REQUEST_TIMEOUT_MS
- )
+ const submitFor = async (targetId: string) => {
+ const params = {
+ session_id: targetId,
+ text,
+ ...truncateSubmitParams(resolvedOrdinal, resolvedMessageId, resolvedRowId, confirmDeepTruncate),
+ // A first-turn rewind resolves to an empty transcript, which the
+ // gateway additionally gates behind confirm_empty_truncate. In
+ // resolved-row-id mode the tail-local ordinal was dropped (see
+ // above). The durable target is authoritative, so explicitly allow a
+ // first-active-tip cut; the gateway ignores this when the prefix is
+ // non-empty.
+ ...(resolvedOrdinal === undefined && (resolvedRowId !== undefined || truncateOrdinal === 0)
+ ? { confirm_empty_truncate: true }
+ : {}),
+ ...(rebindRowIds?.length ? { rebind_survivor_row_ids: [...new Set(rebindRowIds.filter(Number.isInteger))] } : {})
+ }
+
+ try {
+ return await requestGateway<PromptSubmitResult>('prompt.submit', params, PROMPT_SUBMIT_REQUEST_TIMEOUT_MS)
+ } catch (error) {
+ // Desktop and backend can update independently. Backends predating #133716
+ // reject this one new field at contract admission (4000, handler never runs).
+ // The user already confirmed client-side, so retry once without only that
+ // field; never strip any other rejected param.
+ const message = error instanceof Error ? error.message : String(error)
+ const rejectedDeepConfirm =
+ error instanceof JsonRpcGatewayError &&
+ error.code === 4000 &&
+ 'confirm_deep_truncate' in params &&
+ message.includes('invalid params for prompt.submit: confirm_deep_truncate:')
+
+ if (!rejectedDeepConfirm) {
+ throw error
+ }
+
+ const { confirm_deep_truncate: _unsupported, ...compatible } = params
+
+ return requestGateway<PromptSubmitResult>('prompt.submit', compatible, PROMPT_SUBMIT_REQUEST_TIMEOUT_MS)
+ }
+ }
const submit = async () => {
const { result, sessionId: usedId } = await withSessionNotFoundResume(