@sema-agent/core
Version:
Stateless, task-oriented AI agent core
17 lines (16 loc) • 938 B
JavaScript
import { isRetryableRemoteErrorCode, RETRYABLE_REMOTE_ERROR_CODES } from "../remote-env.js";
import { withRetry } from "../with-retry.js";
export function remoteEnvFailureNote(op, error, attempts) {
return { op, code: error.code, retryable: isRetryableRemoteErrorCode(error.code), attempts, message: error.message };
}
const REMOTE_RESTORE_MAX_ATTEMPTS = 2;
const REMOTE_RESTORE_BACKOFF_MS = 200;
export async function restoreWorkspaceWithRetry(env, snapshotId, options, onAttempt) {
let attempts = 0;
const outcome = await withRetry(async (attempt) => {
attempts = attempt;
onAttempt?.(attempt);
return env.resumeVM(snapshotId, options);
}, { retryableCodes: RETRYABLE_REMOTE_ERROR_CODES, maxAttempts: REMOTE_RESTORE_MAX_ATTEMPTS, backoffMs: () => REMOTE_RESTORE_BACKOFF_MS }, { ...(options.abortSignal !== undefined ? { signal: options.abortSignal } : {}) });
return { outcome, attempts };
}