DocsHarness SDK

BEEOS CLOUD / DEVELOPER REFERENCE

Retry and HTTP errors

Backoff policies, transient-error classification and the Cloud HTTP error type.

Every Cloud control-plane call a harness makes uses one retry vocabulary. Pick a policy instead of writing your own sleep loop.

abortableSleep

TypeScript @beeos-ai/cloud-harness-sdk · TypeScript only

Waits for the given time and rejects as soon as the signal is aborted.

function abortableSleep(ms: number, signal?: AbortSignal): Promise<void>

TypeScript · Parameters

ParameterTypeRequiredDefaultDescription
msnumberyesTime to wait, in milliseconds.
signalAbortSignalnoAborting this signal cancels the wait and rejects with the signal's reason.

Returns Promise<void>

delayForAttempt

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Returns the wait in milliseconds before the next attempt: the initial delay multiplied by the factor for every earlier attempt, capped at the maximum delay.

function delayForAttempt(policy: BackoffPolicy, attempt: number): number

TypeScript · Parameters

ParameterTypeRequiredDefaultDescription
policyBackoffPolicyyesThe backoff policy that supplies the initial delay, factor and cap.
attemptnumberyesNumber of the attempt that just failed, starting at 1.

Returns number

Python · Parameters

ParameterTypeRequiredDefaultDescription
policyBackoffPolicyyesThe backoff policy that supplies the initial delay, factor and cap.
attemptintyesNumber of the attempt that just failed, starting at 1.

Returns int

isTransientError

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Tells whether a failure is worth another attempt: a transient CloudHttpError, or a network failure such as a refused or reset connection, a DNS failure or a timeout. Cancellation is never transient.

function isTransientError(error: unknown): boolean

TypeScript · Parameters

ParameterTypeRequiredDefaultDescription
errorunknownyesThe value thrown by the failed operation.

Returns boolean

Python · Parameters

ParameterTypeRequiredDefaultDescription
errorBaseExceptionyesThe value thrown by the failed operation.

Returns bool

isTransientStatus

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Tells whether an HTTP status is transient: 408, 425, 429, 500, 502, 503 or 504.

function isTransientStatus(status: number): boolean

TypeScript · Parameters

ParameterTypeRequiredDefaultDescription
statusnumberyesHTTP status code of the response.

Returns boolean

Python · Parameters

ParameterTypeRequiredDefaultDescription
statusintyesHTTP status code of the response.

Returns bool

retryWithBackoff

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Runs an operation until it succeeds, a non-retryable error occurs, or the policy is exhausted.

async function retryWithBackoff<T>(operation: (attempt: number) => Promise<T>, options: RetryOptions): Promise<T>

TypeScript · Parameters

ParameterTypeRequiredDefaultDescription
operation(attempt: number) => Promise<T>yesThe call to run. It receives the attempt number, starting at 1.
optionsRetryOptionsyesRetry settings: the policy, an optional retry predicate, an abort signal, a retry callback and replaceable sleep and clock functions.

Returns Promise<T>

Python · Parameters

ParameterTypeRequiredDefaultDescription
operationCallable[[int], Awaitable[T]]yesThe call to run. It receives the attempt number, starting at 1.
policyBackoffPolicyyesThe backoff policy: number of attempts, delays and wall-clock budget.
is_retryableCallable[[BaseException], bool]nois_transient_errorPredicate that decides whether an exception is retried. Defaults to is_transient_error.
on_retryCallable[[int, int, BaseException], None] | NonenoNoneCalled before every wait with the attempt number, the delay in milliseconds and the error.
sleepCallable[[float], Awaitable[None]]noasyncio.sleepReplaceable sleep function that takes seconds. Defaults to asyncio.sleep; mainly useful in tests.
nowCallable[[], float]notime.monotonicReplaceable monotonic clock that returns seconds. Defaults to time.monotonic.

Returns T

STARTUP_BACKOFF

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Policy for a control plane that is not ready yet: unlimited attempts within a two-minute budget, waiting 1 s growing to 15 s.

const STARTUP_BACKOFF: BackoffPolicy

Entries

NameTypeDescription
maxAttemptsnumberUnlimited attempts; the budget and cancellation end the retrying.
initialDelayMs1000First wait: 1000 ms.
maxDelayMs15000Longest wait: 15000 ms.
factor2Each wait is twice the previous one.
budgetMs120000Total budget: 120000 ms (two minutes).

TRANSIENT_BACKOFF

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Policy for short gateway interruptions on ordinary calls: 3 attempts, waiting 200 ms then 500 ms.

const TRANSIENT_BACKOFF: BackoffPolicy

Entries

NameTypeDescription
maxAttempts3Three attempts in total, including the first.
initialDelayMs200First wait: 200 ms.
maxDelayMs500Longest wait: 500 ms.
factor2.5Each wait is 2.5 times the previous one, subject to the cap.

TRANSIENT_STATUSES

Python beeos_cloud_harness_sdk.retry · Python only

The set of HTTP statuses treated as transient: 408, 425, 429, 500, 502, 503 and 504.

TRANSIENT_STATUSES = frozenset({408, 425, 429, 500, 502, 503, 504})

CloudHttpError

TypeScript @beeos-ai/cloud-harness-sdk · Python beeos_cloud_harness_sdk.retry

Error for any non-2xx answer from Cloud. body is truncated and never contains credentials.

class CloudHttpError extends Error
new CloudHttpError(readonly method: string, readonly path: string, status: number, body: string)

TypeScript · Constructor

ParameterTypeRequiredDefaultDescription
methodstringyesHTTP method of the failed request.
pathstringyesRequest path of the failed request.
statusnumberyesHTTP status code of the answer.
bodystringyesResponse body; it is truncated to 2048 characters.

Python · Constructor

ParameterTypeRequiredDefaultDescription
methodstryesHTTP method of the failed request.
pathstryesRequest path of the failed request.
statusintyesHTTP status code of the answer.
bodystryesResponse body; it is truncated to 2048 characters.

Properties

NameTypeDescription
readonly statusnumberHTTP status code of the answer.
readonly bodystringResponse body, truncated to 2048 characters.
readonly code?stringError code taken from the JSON error body (error.code or code), when present.
readonly transientboolean / booltrue when the status is one of the transient statuses.
readonly methodstringHTTP method of the failed request.
readonly pathstringRequest path of the failed request.

Errors and exceptions

Error types that this module defines. The description of each method says when it raises one.

ErrorsLanguageDescription
CloudHttpErrorTypeScript, PythonError for any non-2xx answer from Cloud. body is truncated and never contains credentials.