Skip to main content

Module throttle

Module throttle 

Source
Expand description

Quota and policy throttles (Release B, Cloud API §7.2 and §8.1).

When Cloud answers 429 quota_exceeded (monthly transfer or bus messages), 409 quota_exceeded for a cooling-down Personal engine slot, or 403 policy_denied, the engine records a throttle in <data_dir>/throttles.json and every path it applies to waits instead of asking again: sync and pushes, bus publishes, task claims, connect. The local work stays where it is (the replica’s pending events, the bus queue, the outbox) and goes once the throttle ends.

Backoff rules (deterministic, never a busy loop):

  • monthly quota (429): until now + retry_after_s (the body’s value, or the Retry-After header), else reset_at, else the start of the next calendar month (UTC), the reset the contract names; at least MIN_WAIT_S, at most MAX_WAIT_S;
  • Personal slot cool-down (409 registered_instances, cooldown_days): until reset_at (the web recovery frees it sooner, P7);
  • policy refusal (403) of a bus publish or a task claim: POLICY_HOLD_S per member and path, then one try (an admin may have changed the policy meanwhile), and at once when a newer policy is installed (policy_changed); a sync refusal holds only its draft (outbox, same wait, also ended by a newer policy) or its vault sync, never the other vaults;
  • the subscription models gateway (mz6, Scope::Models): 429 quota_exceeded for model_credit_usd_micros holds like a monthly quota; 402 plan_required (key plan:models, ended by a plan change) and 403 policy_denied hold POLICY_HOLD_S; the proxy’s leanctx provider answers locally meanwhile (models_hold_kind);
  • other counted quotas (409 private_vaults, a slot without cool-down): no throttle; the refusal is shown and nothing retries it by itself;
  • token mint rate limit (429 rate_limited at /instances/{id}/token): one hold for every process of this machine (they all mint with the same instance key, on the same server budget). It grows exponentially with each 429 in a row, from RATE_FIRST_S up to RATE_MAX_WAIT_S, and never ends before the server’s Retry-After (the floor, also above the cap). No caller passes it, a person’s manual sync neither: the server counts refused attempts too. A minted token ends it.

lean-ctx cloud status lists the active throttles (status_lines).

Structs§

Throttle
One recorded throttle.

Enums§

HoldKind
What holds the models path (mz6), for the local answer’s status.
Scope
The engine paths a throttle can hold.

Constants§

MAX_WAIT_S
The longest wait (a reset further out is shortened to this).
MIN_WAIT_S
The shortest wait of a throttle: one tick of a loop is never a retry.
POLICY_HOLD_S
How long a policy refusal holds its path.
QUOTA_PROBE_S
A quota throttle lets one call through this often before it ends, so a quota that was raised or lowered in Cloud is noticed (E2E-FINAL: sync waited for the month’s end after usage was lowered).
RATE_FIRST_S
The first wait after a token mint 429 (a longer Retry-After wins).
RATE_FLOOR_MAX_S
The longest server Retry-After the token mint hold honours (a day).
RATE_MAX_WAIT_S
The longest computed token mint wait; a longer Retry-After still wins.
RATE_MEMORY_S
How long an ended token mint hold is remembered, so that the next 429 within it doubles the wait instead of starting again at the first.
TOKEN_SCOPE
The scope name the token mint hold shows in cloud status.

Functions§

check
Err with the throttle’s refusal while scope is held. When only quota throttles hold it and their probe is due, one call passes (the next probe is an hour later): a success ends them (passed), a new refusal records them again.
clear_connect
A new enrolment starts without the old connect throttle.
holding
The active throttle holding scope at now (the one ending last).
models_hold_kind
The kind of the throttle ending last among those holding Scope::Models at now (a policy hold when none is a quota or plan).
note
Record the throttle error sets on scope (expired ones are dropped on the way) and pass the error on unchanged.
note_on
note for an answer of any engine route: a quota holds the paths its resource names (every authenticated call passes here, Session).
note_token_limit
Record a 429 rate_limited of the token mint: every process of this machine waits rate_wait before it mints again. Any other error is left alone. Returns the error unchanged.
of_error
The throttle error sets at now, if it sets one: on the paths its quota resource holds plus scope, the path that met it (None: an HTTP call of unknown path, so only the resource’s paths; a policy refusal then sets nothing).
passed
A successful call on scope: its policy holds and quota throttles are over (a probe that passed, or a quota raised in Cloud meanwhile).
plan_changed
The workspace’s plan changed (a newer lease): every quota throttle was the old plan’s answer and ends, and so does a plan hold of the models path; policy holds stay.
policy_changed
A newer policy is in force: every policy hold is over, on every path (each was the old policy’s answer), and so is every outbox item’s policy wait (a refused knowledge draft); quota throttles stay.
quota_holds
Whether a quota throttle (not only a policy hold) holds scope now.
quota_lifted
The quota is back (a successful call, or an answer that shows it): every quota throttle holding scope ends.
rate_wait
The token mint wait after the strikes-th 429 in a row (strikes >= 1) with the server’s Retry-After floor: doubling from RATE_FIRST_S up to RATE_MAX_WAIT_S, never shorter than the floor (which is kept above the cap too, up to RATE_FLOOR_MAX_S: a broken or hostile answer cannot stop every call for weeks).
status_lines
cloud status lines of every active throttle, sorted by key (stable).
token_hold
While the token mint is held at now: the 429 rate_limited a mint answers instead of calling the cloud, with the seconds left as retry_after (so every caller’s backoff waits at least as long). A stale hold (more than RATE_FLOOR_MAX_S left) holds nothing; the next change drops it.
token_minted
A token was minted: the token mint hold and its backoff step end.