Files
openclaw/src/infra/retry.ts
T
Peter SteinbergerandGitHub d49acffa5e refactor(infra): consolidate retry scheduling (#105789)
* refactor(infra): consolidate retry scheduling

* fix(build): wire shared retry package

* fix(build): resolve retry package in source graphs

* fix(infra): keep retry adapter dependency-free
2026-07-12 19:58:55 -07:00

34 lines
1.2 KiB
TypeScript

// Adapts the dependency-free retry scheduler to core runtime facilities.
import {
createRetryRunner,
resolveRetryConfig,
toRetryError,
type RetryConfig,
type RetryInfo,
type RetryOptions,
} from "../../packages/retry/src/index.js";
import { getRetryAttemptErrors, recordRetryAttemptErrors } from "./retry-attempt-errors.js";
import { generateSecureFraction } from "./secure-random.js";
export { resolveRetryConfig, type RetryConfig, type RetryInfo, type RetryOptions };
function createRetryFailure(rawAttemptErrors: readonly unknown[]): Error {
const attemptErrors = rawAttemptErrors.flatMap((err) => getRetryAttemptErrors(err) ?? [err]);
const failure = toRetryError(
attemptErrors.at(-1) ?? new Error("Retry failed"),
"Non-Error thrown",
);
if (attemptErrors.length > 1) {
// Preserve terminal-error identity while carrying all attempts into
// duplicate-send decisions outside the channel adapter.
recordRetryAttemptErrors(failure, attemptErrors);
}
return failure;
}
/** Runs an async operation until it succeeds, policy stops, or attempts are exhausted. */
export const retryAsync = createRetryRunner({
random: generateSecureFraction,
createFailure: createRetryFailure,
});