Skip to content

The agent that grows with you

perf(desktop): an older backend's deep-confirm rejection is remembered for the rest of the submit

kshitijk4poor7828ab375b80
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 4ea371e0cd4..4c675848037 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
@@ -761,6 +761,35 @@ describe('runRewindSubmit durable-address discipline (#87059)', () => {
).rejects.toBe(failure)
expect(request).toHaveBeenCalledTimes(1)
})
+
+ it('a busy retry after the fallback leaves the rejected field out', async () => {
+ const request = vi
+ .fn()
+ .mockRejectedValueOnce(new JsonRpcGatewayError(DEEP_CONFIRM_REJECTED, { code: 4000 }))
+ .mockRejectedValueOnce(new JsonRpcGatewayError('session busy', { code: 4009 }))
+ .mockResolvedValue({ status: 'streaming' })
+
+ await runRewindSubmit(
+ request as never,
+ 'sid',
+ 'fixed prompt',
+ 1,
+ undefined,
+ false,
+ undefined,
+ 13,
+ 'typo prompt',
+ undefined,
+ true
+ )
+
+ // Field rejected, then busy without it, then accepted: no second rejected round trip.
+ const submits = request.mock.calls.filter(([method]) => method === 'prompt.submit').map(([, params]) => params)
+
+ expect(submits).toHaveLength(3)
+ expect(submits[2]).toMatchObject({ confirm_truncate: true, truncate_before_row_id: 13 })
+ expect(submits[2]).not.toHaveProperty('confirm_deep_truncate')
+ })
})
describe('optimistic rewind/reload turn-clock seeding (#86795)', () => {
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 f76fe92858f..b5761de12c3 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
@@ -344,11 +344,20 @@ export async function runRewindSubmit(
}
}
+ // Set once a backend rejected confirm_deep_truncate: the later sends of this submit (busy retries,
+ // a resumed runtime) leave it out instead of paying a rejected round trip each.
+ let deepConfirmUnsupported = false
+
const submitFor = async (targetId: string) => {
const params = {
session_id: targetId,
text,
- ...truncateSubmitParams(resolvedOrdinal, resolvedMessageId, resolvedRowId, confirmDeepTruncate),
+ ...truncateSubmitParams(
+ resolvedOrdinal,
+ resolvedMessageId,
+ resolvedRowId,
+ confirmDeepTruncate && !deepConfirmUnsupported
+ ),
// 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
@@ -369,6 +378,7 @@ export async function runRewindSubmit(
// 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 &&
@@ -379,6 +389,7 @@ export async function runRewindSubmit(
throw error
}
+ deepConfirmUnsupported = true
const { confirm_deep_truncate: _unsupported, ...compatible } = params
return requestGateway<PromptSubmitResult>('prompt.submit', compatible, PROMPT_SUBMIT_REQUEST_TIMEOUT_MS)