JuliusBrussee/caveman · error · RetryLoopError
retry loop interrupted: tool call
Error message
retry loop interrupted: tool call ${JSON.stringify(signature)} repeated ${repeats} times (threshold ${threshold}) What it means
RetryLoopGuard detects the model (or caller) repeating the same tool call with identical arguments beyond a threshold and throws RetryLoopError to break runaway loops. `guard(name, args, fn)` records each call and refuses execution once the same signature repeats too many times.
Solutions
- Fix the underlying tool failure or make its output informative so the model changes strategy
- Raise the guard threshold for tools where repeats are legitimate
- Catch RetryLoopError and inject a corrective prompt/tool result telling the model to try a different approach
Example fix
// before
const result = await guard.guard("search", args, () => search(args)); // throws after N repeats
// after
try {
const result = await guard.guard("search", args, () => search(args));
} catch (e) {
if (e instanceof RetryLoopError) {
return instructModelToTryDifferentApproach(e.message);
}
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
let lastSig = null, repeats = 0;
if (JSON.stringify([name, args]) === lastSig && ++repeats > threshold) {
throw new Error("would exceed retry threshold");
} Try / catch
try {
return await guard.guard(name, args, fn);
} catch (e) {
if (e instanceof RetryLoopError) {
console.warn(`retry loop on ${e.signature}; nudging model`);
return correctiveResponse(e.message);
}
throw e;
} Prevention
- Make tool outputs explicit about failure causes so the model varies strategy
- Set thresholds appropriate to tools where repeated idempotent calls are valid
- Monitor RetryLoopError rates to find looping prompts
When it happens
Trigger: The LLM keeps issuing the same tool call with identical name+args (e.g. a search tool returning results that don't change the model's next attempt) more than `threshold` times through `guard`.
Common situations: Model loops retrying a failing search/read; a tool whose output doesn't give the model enough signal to change strategy; a threshold set too low for legitimately repeated idempotent calls.
Related errors
- retry loop interrupted: tool call
- artifactId is required
- assemble requires model and sessionId
- cave artifact response missing artifact_id
- cave_async_jobs_unavailable
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/dc379e7c9831dd0c.
Report an issue: GitHub.
Appendix: source
Thrown at packages/sdk/typescript/src/index.ts:694
serialized = String(args);
}
return `${name}(${serialized})`;
}
/**
* Record a tool call. Throws {@link RetryLoopError} once an identical call has
* repeated past the threshold. A different call resets the streak.
*/
record(name: string, args: unknown): void {
const sig = this.signature(name, args);
if (sig === this.lastSignature) {
this.repeats += 1;
} else {
this.lastSignature = sig;
this.repeats = 1;
}
if (this.repeats > this.threshold) {
throw new RetryLoopError(sig, this.repeats, this.threshold);
}
}
/** Record the call (may throw) then invoke `fn`. */
async guard<T>(name: string, args: unknown, fn: () => Promise<T> | T): Promise<T> {
this.record(name, args);
return fn();
}
/** Clear the streak (e.g. when starting a new task). */
reset(): void {
this.lastSignature = null;
this.repeats = 0;
}
}
// ─── Async job client ─────────────────────────────────────────────────────────
View on GitHub (pinned to 3ee70a1026)