Files
archived-orca/src/cli/runtime/client-error-recovery.ts
gsxdsmandNeil 219dca09d0 fix(cli): refuse oversized local requests before dispatch (#37734)
The CLI now measures the serialized runtime request against the shared
1 MiB local transport limit before writing any bytes. Oversized requests
fail with invalid_argument and requestSent=false instead of being cut off
by the server mid-frame, and the client skips mutation recovery for these
unsent requests so it never suggests resending the same payload.

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-11-05 18:08:51 -08:00

42 lines
1.2 KiB
TypeScript

import { RuntimeClientError, RuntimeRpcFailureError } from './types'
export function attachMutationRecovery(
error: unknown,
requestId: string | undefined,
originalCommand?: string[],
unsent = false
): unknown {
if (!requestId || !(error instanceof RuntimeClientError)) {
return error
}
const data = {
...(error.data && typeof error.data === 'object' ? error.data : {}),
orchestrationRequestId: requestId,
...(originalCommand ? { originalCommand } : {}),
...(unsent ? { requestSent: false } : {})
}
if (error instanceof RuntimeRpcFailureError) {
return new RuntimeRpcFailureError({
...error.response,
error: {
...error.response.error,
message: `${error.message} Orchestration mutation request ID: ${requestId}.`,
data
}
})
}
return new RuntimeClientError(
error.code,
`${error.message} Orchestration mutation request ID: ${requestId}.`,
data
)
}
/** True when this invocation never sent the request. */
export function isRequestUnsent(error: unknown): boolean {
const data: unknown = error instanceof RuntimeClientError ? error.data : undefined
return (
typeof data === 'object' && data !== null && 'requestSent' in data && data.requestSent === false
)
}