Skip to content

latent.serve.idempotency

Per-process record of answered requests: method + path + Idempotency-Key + body hash.

Studio retries a lifecycle gate, processor or event with the same key. The same key with the same body on the same route gets the recorded answer; the same key with a different body (a re-run with fresh facts) or on another route (two gates of one phase receive the same body) is evaluated anew. Only calls whose one caller is Studio's worker holding K use it, so that caller is the principal; extension routes act for many Studio users and are never replayed. The cache is per process and bounded, so the contract says a pod may return a recorded answer, never that it must (ADR-015 OQ-1: extensions and pods are stateless).

A retry that arrives while the first call with its slot is still running waits for that call and gets the same response, so overlapping retries run the handler once. Only a 200 is recorded: after a failure (timeout, handler error, contract violation) the next sequential retry runs the handler again.

Classes

IdempotencyCache

IdempotencyCache(max_entries: int = DEFAULT_MAX_ENTRIES, ttl_s: float = DEFAULT_TTL_S, clock: Callable[[], float] = time.monotonic)

Bounded LRU of (method, path, key, sha256(body)) -> answer with a TTL.

Methods

IdempotencyCache.get

get(key: str | None, body: bytes, method: str, path: str) -> Any | None

The answer recorded for this call, or None.

IdempotencyCache.put

put(key: str | None, body: bytes, answer: Any, method: str, path: str) -> None

Record answer for this call (no-op without a key).

IdempotencyCache.run

run(key: str | None, body: bytes, compute: Callable[[], Awaitable[Response]], method: str, path: str) -> Response

Answer this call: the recorded answer, the response of the same call already in flight, or compute() (a 200 JSON answer is recorded).

Attributes

DEFAULT_MAX_ENTRIES

DEFAULT_TTL_S

Slot