mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
fix(acp): address CodeRabbit review on transient retry
Re-check operation currency after the backoff sleep so a cancelled or rotated probe never issues another request, cap retries at three attempts total (two backoffs), document the helpers, and cover the abort-during-backoff case with a test.
This commit is contained in:
committed by
Kelvin Amoaba
parent
40894a41f8
commit
aff9575de0
@@ -192,11 +192,12 @@ const folderlessListing = (spec: AcpLaunchSpec) =>
|
||||
|
||||
// Agents (notably opencode) answer session/new with a transient -32603 while
|
||||
// their providers still open; without a retry one probe failure degrades the picker.
|
||||
const TRANSIENT_AGENT_RETRY_DELAYS_MS = [250, 500, 1_000] as const
|
||||
const TRANSIENT_AGENT_RETRY_DELAYS_MS = [250, 500] as const
|
||||
|
||||
const isTransientAgentFailure = (error: unknown): boolean =>
|
||||
error instanceof AcpAgentError && error.code === -32603
|
||||
|
||||
/** Retries transient -32603 agent answers at most three attempts total, stopping on abort or agent switch. */
|
||||
async function retryTransientAgentFailure<T>(
|
||||
run: () => Promise<T>,
|
||||
operation?: StructuredAgentResolutionOperation
|
||||
@@ -208,12 +209,13 @@ async function retryTransientAgentFailure<T>(
|
||||
if (attempt >= TRANSIENT_AGENT_RETRY_DELAYS_MS.length || !isTransientAgentFailure(error)) {
|
||||
throw error
|
||||
}
|
||||
assertStructuredAgentResolutionCurrent(operation)
|
||||
await sleep(TRANSIENT_AGENT_RETRY_DELAYS_MS[attempt], operation?.signal)
|
||||
assertStructuredAgentResolutionCurrent(operation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolves on timeout or abort; the caller must re-check operation currency afterwards. */
|
||||
async function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
||||
if (signal?.aborted) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user