Repository navigation
fix(platform): treat an embedding 429 as a rate limit, pace and retry it - #4071
Conversation
DashScope's tokens-per-minute limit (Throttling.AllocationQuota) reaches the OpenAI-compatible client as code `insufficient_quota`, OpenAI's billing code, so it read as a spent balance: unretried, the scan ended on its first 429 and the dialog sent the admin to the account. The code no longer decides; the wording does, and a 429 outside it is `throttled`. A throttled batch pauses its whole lane and comes back on the minute scale (10/20/40/60/60 s); a search query keeps the short schedule. Two optional embedding.json keys, maxTokensPerMinute and maxRequestsPerMinute, pace what a lane sends per minute so a crawl is held under the provider's limit instead of refused.
Alibaba Cloud support confirmed that a model's RPM and TPM are enforced per second as well, each divided by sixty: a minute's worth sent in one second is refused while the minute is nearly empty, which is what three in-flight batches of twenty-five chunks do. Under maxTokensPerMinute and maxRequestsPerMinute the lane now also keeps every second under a sixtieth of the limit, and sizes each request to fit that second, so no single request can be the burst the per-second rule refuses.
|
Follow-up after Alibaba Cloud support confirmed the limits are enforced per second too (RPM ÷ 60, TPM ÷ 60): with the per-minute window alone, a docs.tale.dev scan at 6 pages/min uses ~4 % of 1,000,000 TPM and still got the So, under
Tests: three requests of 4 tokens under 600 TPM (10/s) — the third waits a second, not a minute; four texts under the same limit go as two requests a second apart; two requests a minute now go one second apart. |
A 300-page crawl on Alibaba Cloud Model Studio ended on its first
429—Allocated quota exceeded, please increase your quota limit— recorded as[credit], unretried, with the dialog telling the admin to check the account's balance. The account was fine: that429isThrottling.AllocationQuota, DashScope's tokens-per-minute limit, which its OpenAI-compatible mode sends under OpenAI's billing codeinsufficient_quota.CREDIT_REFUSAL_CODESheld that code, soisCreditRefusal→credit→isRetryablefalse → the scan died. And nothing paced what three in-flight batches of up to 25 texts send per minute, so a fast crawl bursts past 1,000,000 TPM.What changed
core/knowledge/embedding.ts): the bareinsufficient_quotacode no longer means the account; the wording does (OpenAI's "exceeded your current quota … plan and billing" still reads ascredit). A429outside the billing wording is a new class,throttled, and is retryable. Carried through: the crawl reason[throttled](scan_scheduling.ts), the dialog hintscanDetail.throttled(en/de/fr: the next scan continues on its own; pace requests under Data residency), the query path (EMBEDDING_UPSTREAM_ERRORwith its own prose), document indexing (embedding_upstream, the job retries).429pauses its whole lane (every slot, every waiting batch) and comes back after 10 s, 20 s, 40 s, 60 s, 60 s — six attempts,retry-afterhonoured as before — instead of 1 s / 2 s / 4 s for three. A search query keeps the short schedule and skips the pause: a refusal in seconds serves a chat turn better than a vector after a minute.embedding.jsonkeys,maxTokensPerMinuteandmaxRequestsPerMinute, kept like the other operator-only settings (schema, write schema,KNOWLEDGE_EMBEDDING_KEPT_KEYS, CLI pass-through). The lane meters the last minute (tokens estimated from characters, as the timeout already does) and holds a batch until enough has aged out; a single request larger than the limit goes when the minute is empty. The lane's memory outlives its queue, which a crawl drops between pages.maxConcurrentRequestsis untouched.Proof
embedding.test.ts: the sameinsufficient_quotacode told apart by its words; the billing refusal still unretried; a limited batch retried after 10 s with a second batch held by the lane meanwhile; a query answered at once during the pause; six attempts then give up;maxRequestsPerMinuteholds the third request until the minute turns;maxTokensPerMinuteholds the second batch and lets an oversized lone request through — 80 pass.crawl_action.vectors.test.ts: a throttled page ends the scan under[throttled].scan-error.test.ts, locale parity, CLI config tests (51),tsc --noEmit,oxlint --type-aware,format:check,lint:links,lint:manual.maxTokensPerMinute: 1000000.