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 theRetry-Afterheader), elsereset_at, else the start of the next calendar month (UTC), the reset the contract names; at leastMIN_WAIT_S, at mostMAX_WAIT_S; - Personal slot cool-down (409
registered_instances,cooldown_days): untilreset_at(the web recovery frees it sooner, P7); - policy refusal (403) of a bus publish or a task claim:
POLICY_HOLD_Sper 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_exceededformodel_credit_usd_microsholds like a monthly quota;402 plan_required(keyplan:models, ended by a plan change) and403 policy_deniedholdPOLICY_HOLD_S; the proxy’sleanctxprovider 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_limitedat/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, fromRATE_FIRST_Sup toRATE_MAX_WAIT_S, and never ends before the server’sRetry-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§
- Hold
Kind - 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-Afterwins). - RATE_
FLOOR_ MAX_ S - The longest server
Retry-Afterthe token mint hold honours (a day). - RATE_
MAX_ WAIT_ S - The longest computed token mint wait; a longer
Retry-Afterstill 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
Errwith the throttle’s refusal whilescopeis 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
scopeatnow(the one ending last). - models_
hold_ kind - The kind of the throttle ending last among those holding
Scope::Modelsatnow(a policy hold when none is a quota or plan). - note
- Record the throttle
errorsets onscope(expired ones are dropped on the way) and pass the error on unchanged. - note_on
notefor 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_limitedof the token mint: every process of this machine waitsrate_waitbefore it mints again. Any other error is left alone. Returns the error unchanged. - of_
error - The throttle
errorsets atnow, if it sets one: on the paths its quota resource holds plusscope, 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
scopenow. - quota_
lifted - The quota is back (a successful call, or an answer that shows it):
every quota throttle holding
scopeends. - rate_
wait - The token mint wait after the
strikes-th 429 in a row (strikes >= 1) with the server’sRetry-Afterfloor: doubling fromRATE_FIRST_Sup toRATE_MAX_WAIT_S, never shorter than the floor (which is kept above the cap too, up toRATE_FLOOR_MAX_S: a broken or hostile answer cannot stop every call for weeks). - status_
lines cloud statuslines of every active throttle, sorted by key (stable).- token_
hold - While the token mint is held at
now: the429 rate_limiteda mint answers instead of calling the cloud, with the seconds left asretry_after(so every caller’s backoff waits at least as long). A stale hold (more thanRATE_FLOOR_MAX_Sleft) holds nothing; the next change drops it. - token_
minted - A token was minted: the token mint hold and its backoff step end.