Skip to content

activation

Activation-aware retry logic for cold-start tolerance.

When KEDA scales an agent to 0 replicas, the first request may encounter:

  • 503 Service Unavailable (interceptor buffering, no backend yet)
  • Connection refused (pod not started)
  • 504 Gateway Timeout (cold start exceeded upstream timeout)

This module provides configurable retry with exponential backoff and jitter to handle these transient failures transparently.

Use [Client::call_with_activation] for activation-aware A2A calls, or [retry_with_activation] for generic retry over any async callable.

Configuration for activation-aware retries when calling potentially cold agents.

These values drive the SDK-side retry budget. The KEDA HTTP Add-on HTTPScaledObject does NOT have a CRD-level queueDepth — this is the platform’s enforcement layer.

Fields

FieldTypeDescription
max_cold_start_timeoutDurationMax time to wait for a cold agent to respond. Default: 5s.
initial_backoffDurationInitial retry delay. Default: 100ms.
max_backoffDurationMax retry delay cap. Default: 2s.
max_retriesu32Max retries before giving up. Default: 3.
jitterboolAdd jitter to backoff. Default: true.

Methods

fn backoff_for_attempt(&self, attempt: u32) -> Duration

Compute the backoff duration for a given attempt (0-indexed).

Uses exponential backoff: initial * 2^attempt, capped at max_backoff. When jitter is enabled, the result is multiplied by a factor in [0.5, 1.0].

fn is_retriable_status(status: u16) -> bool

Check if an HTTP status code indicates a retriable cold-start scenario.

fn is_retriable_error(error_msg: &str) -> bool

Check if an error message indicates a retriable connection failure.

fn idempotency_key(request_id: &str, attempt: u32) -> String

Generate an idempotency key for safe retries on state-mutating requests.

Format: {request_id}:{attempt} — the server should deduplicate by this key.

async fn activation_delay(duration: Duration)

Async delay for activation retries. Uses tokio::time::sleep on native and std::thread::sleep (WASI monotonic clock) on WASM.

async fn retry_with_activation<T, E, F, Fut>(config: &ActivationConfig, call_fn: F) -> Result<T, E>
where
E: Display,
F: FnMut,
Fut: Future

Execute an async operation with activation-aware retries.

call_fn receives the 0-indexed attempt number and returns Result<T, E>. Errors whose Display output matches [ActivationConfig::is_retriable_error] are retried with exponential backoff; all other errors are returned immediately.

Returns the first Ok, or the last Err when retries are exhausted.