mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 16:43:43 +00:00
fix(agents): cap embedded runner retry loop
This commit is contained in:
@@ -102,6 +102,9 @@ function createCompactionDiagId(): string {
|
||||
return `ovf-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
|
||||
// Defensive guard for the outer run loop across all retry branches.
|
||||
const MAX_RUN_RETRY_ITERATIONS = 24;
|
||||
|
||||
const hasUsageValues = (
|
||||
usage: ReturnType<typeof normalizeUsage>,
|
||||
): usage is NonNullable<ReturnType<typeof normalizeUsage>> =>
|
||||
@@ -475,13 +478,42 @@ export async function runEmbeddedPiAgent(
|
||||
}
|
||||
|
||||
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
||||
const MAX_RUN_LOOP_ITERATIONS = MAX_RUN_RETRY_ITERATIONS;
|
||||
let overflowCompactionAttempts = 0;
|
||||
let toolResultTruncationAttempted = false;
|
||||
const usageAccumulator = createUsageAccumulator();
|
||||
let lastRunPromptUsage: ReturnType<typeof normalizeUsage> | undefined;
|
||||
let autoCompactionCount = 0;
|
||||
let runLoopIterations = 0;
|
||||
try {
|
||||
while (true) {
|
||||
if (runLoopIterations >= MAX_RUN_LOOP_ITERATIONS) {
|
||||
const message = `Exceeded retry limit after ${runLoopIterations} attempts.`;
|
||||
log.error(
|
||||
`[run-retry-limit] sessionKey=${params.sessionKey ?? params.sessionId} ` +
|
||||
`provider=${provider}/${modelId} attempts=${runLoopIterations}`,
|
||||
);
|
||||
return {
|
||||
payloads: [
|
||||
{
|
||||
text:
|
||||
"Request failed after repeated internal retries. " +
|
||||
"Please try again, or use /new to start a fresh session.",
|
||||
isError: true,
|
||||
},
|
||||
],
|
||||
meta: {
|
||||
durationMs: Date.now() - started,
|
||||
agentMeta: {
|
||||
sessionId: params.sessionId,
|
||||
provider,
|
||||
model: model.id,
|
||||
},
|
||||
error: { kind: "retry_limit", message },
|
||||
},
|
||||
};
|
||||
}
|
||||
runLoopIterations += 1;
|
||||
attemptedThinking.add(thinkLevel);
|
||||
await fs.mkdir(resolvedWorkspace, { recursive: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user