Skip to main content

Module retry

Module retry 

Source
Expand description

Explicit HTTP retry policy for crates.io / docs.rs (Rules Rust — retry/backoff).

§Workload and policy scope

  • Dependency: public HTTPS hosts only (crates.io, docs.rs, static.docs.rs, doc.rust-lang.org).
  • Operations: product surface is GET-only (idempotent by HTTP semantics). No POST/PUT/DELETE; no Idempotency-Key required.
  • Default: retries on for transient failures (agent reliability). Kill switch: --disable-retry / DOCSRS_CLI_DISABLE_RETRY=1 / TOML disable_retry = true / max_retries = 0.
  • Layer: single retry loop inside crate::http::HttpClient only — no middleware stack, no nested client retries, no agent-level auto-retry of permanent kinds.

§Delay formula

cap(n)  = min(base_ms * 2^min(n, 16), max_delay_ms)
delay   = uniform(0..=cap)   // full jitter (AWS architecture blog)

Relógio monotônico: sleeps usam tokio::time::sleep (não SystemTime). Retry-After delta-seconds overrides the formula for 429/503 when present. HTTP-date Retry-After is not parsed (no chrono dep); falls back to formula.

§Out of scope (one-shot agent CLI)

Circuit breaker, retry budget token-bucket, hedged requests, gRPC, OAuth refresh, outbox/saga, multi-host sticky sessions.

Structs§

RetryConfig
Named retry policy for the product HTTP client (one dependency class).

Enums§

RetryClass
Classification of an HTTP status for the retry gate.

Constants§

DEFAULT_MAX_RETRIES
Default maximum retries after the first attempt (total attempts = N+1).
DEFAULT_RETRY_BASE_MS
Default base backoff in milliseconds (also minimum floor for formula).
DEFAULT_RETRY_MAX_DELAY_MS
Default ceiling for a single backoff sleep (milliseconds).
HARD_MAX_DELAY_MS
Hard ceiling for a single delay (milliseconds).
HARD_MAX_RETRIES
Hard cap on configured retries (prevents accidental retry storms).

Functions§

backoff_full_jitter
Full jitter: uniform(0..=min(base*2^attempt, max_delay)).
classify_http_status
Classify HTTP status for in-process retry (GET-only product).
parse_retry_after
Parse Retry-After as delta-seconds only.
politeness_delay
Per-host politeness delay with additive jitter (never below the configured floor).
wait_for_retry
Prefer server Retry-After when present; otherwise full-jitter formula.