MCPcopy Create free account
hub / github.com/cortexkit/magic-context / withRetry

Function withRetry

packages/plugin/scripts/longmemeval/runner.ts:278–306  ·  view source on GitHub ↗
(
    config: RunnerConfig,
    operationName: string,
    run: (attempt: number, signal: AbortSignal) => Promise<T>,
)

Source from the content-addressed store, hash-verified

276}
277
278async function withRetry<T>(
279 config: RunnerConfig,
280 operationName: string,
281 run: (attempt: number, signal: AbortSignal) => Promise<T>,
282): Promise<T> {
283 let lastError: Error | null = null;
284
285 for (let attempt = 1; attempt <= config.maxRequestAttempts; attempt += 1) {
286 const controller = new AbortController();
287 const timeout = setTimeout(() => controller.abort(), config.openCodeRequestTimeoutMs);
288 try {
289 return await run(attempt, controller.signal);
290 } catch (error) {
291 lastError = asError(error);
292 clearTimeout(timeout);
293 if (attempt >= config.maxRequestAttempts) break;
294 const retryDelay = config.retryBaseDelayMs * 2 ** (attempt - 1);
295 logLine(
296 `${operationName} failed on attempt ${attempt}/${config.maxRequestAttempts}: ${lastError.message}; retrying in ${retryDelay}ms`,
297 );
298 await sleep(retryDelay);
299
300 } finally {
301 clearTimeout(timeout);
302 }
303 }
304
305 throw lastError ?? new Error(`${operationName} failed`);
306}
307
308async function createSession(
309 client: OpencodeClient,

Callers 4

createSessionFunction · 0.85
deleteSessionFunction · 0.85
fetchMessagesFunction · 0.85
sendPromptAndCaptureFunction · 0.85

Calls 4

logLineFunction · 0.85
asErrorFunction · 0.70
sleepFunction · 0.70
runFunction · 0.50

Tested by

no test coverage detected