bullswarm 0.40.2 → 0.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/docs/guide/concepts.md +1 -1
- package/docs/guide/routing.md +1 -1
- package/docs/guide/workflows.md +1 -1
- package/docs/reference/cli.md +1 -1
- package/docs/reference/program.md +1 -1
- package/package.json +1 -1
- package/skill/references/recovery.md +1 -1
- package/src/lib/quota.js +39 -6
- package/src/providers/_schema.json +1 -1
- package/src/workflow/cli-capabilities.js +1 -1
- package/src/workflow/v2-dispatch.js +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.40.3 — Cloudflare rate limit waits on the same pool
|
|
6
|
+
|
|
7
|
+
- Cloudflare Workers AI's per-model rate limit (code 3021, `rate limiting: inference request per min rate reached`, HTTP 429) is now a `throttle`: the step backs off on the same pool and keeps its one retry. Before, it read as a provider failure, so each hit spent the retry on another pool (one step went Inkling, DeepSeek, then gpt-oss-120b). A notice line that opens with HTTP 429's reason phrase (`Too Many Requests: {...}`) now counts as a provider notice.
|
|
8
|
+
- The throttle backoff is jittered: 20-30 s, then 60-90 s, instead of exactly 20 s and 60 s, so parallel workers that hit one per-minute limit do not all retry in the same second. A wait the provider names is kept as named.
|
|
9
|
+
- A long limit notice (a 429 JSON body) is quoted in `why` from the matched phrase, so the line stays short.
|
|
10
|
+
|
|
5
11
|
## 0.40.2 — Routing fixes for lane-limited and pay-per-token pools
|
|
6
12
|
|
|
7
13
|
- `strategy set-lanes <pool> analyze` no longer empties the pool's medium and low rungs at the next `strategy apply`. A lane limit decides which work a pool takes, not which effort tiers it keeps. Before, grok (limited to analyze on 17 Nov) took no work at all after the nightly apply, not even analyze at medium.
|
package/docs/guide/concepts.md
CHANGED
|
@@ -49,7 +49,7 @@ A run ends with one **verdict** object. A run is a one-step workflow, so `runId`
|
|
|
49
49
|
|
|
50
50
|
Bullswarm never remembers a spent or dead pool from one step to the next: nothing pauses or benches a pool. Each step, and each `bullswarm run`, routes on the live meters, so a window at its limit (5-hour at 99% or more, weekly or monthly at 100%) keeps a pool out until that window resets, and a pool that failed one step is a candidate for the next whenever its meters allow it.
|
|
51
51
|
|
|
52
|
-
A **usage limit** is a limit notice that says a usage window, a quota or a balance is spent (with or without a reset named), or a meter showing the window full. It goes to the caller: in a workflow started by this version the step comes back to you at once, with no wait, no move to another pool and no retry, and a single `bullswarm run` exits 1. The pool's meter is then read again at once, so the next pick sees a window it shows at its limit (5-hour at 99% or more, weekly or monthly at 100%); when it cannot be read, the pool counts as full until its reset only when the provider named that reset or an earlier meter reading gave it. A **throttle** (too many requests, no usage window spent) backs off on the same pool at most twice (20 s, then 60 s, or a named wait of at most 2 minutes) before it comes back to you too. Neither ever moves to another pool, for a step, the dispatched planner or the preflight scout. Only a workflow started by an earlier version gives them a short bounded same-pool retry, then another pool for that attempt only.
|
|
52
|
+
A **usage limit** is a limit notice that says a usage window, a quota or a balance is spent (with or without a reset named), or a meter showing the window full. It goes to the caller: in a workflow started by this version the step comes back to you at once, with no wait, no move to another pool and no retry, and a single `bullswarm run` exits 1. The pool's meter is then read again at once, so the next pick sees a window it shows at its limit (5-hour at 99% or more, weekly or monthly at 100%); when it cannot be read, the pool counts as full until its reset only when the provider named that reset or an earlier meter reading gave it. A **throttle** (too many requests, no usage window spent) backs off on the same pool at most twice (20-30 s, then 60-90 s with random jitter, or a named wait of at most 2 minutes) before it comes back to you too. Neither ever moves to another pool, for a step, the dispatched planner or the preflight scout. Only a workflow started by an earlier version gives them a short bounded same-pool retry, then another pool for that attempt only.
|
|
53
53
|
|
|
54
54
|
A **sign-in failure** (failure kind `auth`) gets the step's one automatic retry on a pool that does not share the dead credential: every pool in the same credential group is skipped for the rest of that step. Nothing is stored, so a later step can pick that pool again.
|
|
55
55
|
|
package/docs/guide/routing.md
CHANGED
|
@@ -235,7 +235,7 @@ CLI would otherwise hang, and the pool's meter is read again as above. In a
|
|
|
235
235
|
workflow started by this version the step then comes back to you; in one
|
|
236
236
|
started by an earlier version the action moves elsewhere.
|
|
237
237
|
|
|
238
|
-
Every other limit notice — `Rate limit exceeded. Please wait a moment and try again.`, `429 Too Many Requests`, an overload — is failure kind `throttle`. In a workflow started by an earlier version the dispatcher retries the same pool up to twice, after 20 s and then 60 s (or after the wait the provider named), without a mechanical-retry charge; after that the attempt moves to another pool. A throttle that names a wait longer than 15 minutes skips the same-pool retry and moves at once. In a workflow started by this version a window phrase with no reset is a usage limit instead (`quota`), and a throttle never moves: it backs off at most twice,
|
|
238
|
+
Every other limit notice — `Rate limit exceeded. Please wait a moment and try again.`, `429 Too Many Requests`, Cloudflare Workers AI's `rate limiting: inference request per min rate reached` (code 3021), an overload — is failure kind `throttle`. In a workflow started by an earlier version the dispatcher retries the same pool up to twice, after 20 s and then 60 s (or after the wait the provider named), without a mechanical-retry charge; after that the attempt moves to another pool. A throttle that names a wait longer than 15 minutes skips the same-pool retry and moves at once. In a workflow started by this version a window phrase with no reset is a usage limit instead (`quota`), and a throttle never moves: it backs off at most twice on the same pool (20-30 s, then 60-90 s: a random share is added so parallel workers that hit one per-minute limit do not all return together; or the wait the provider named, at most 2 minutes), and then comes back to you (see above). The backoff does not use the step's one retry. A single `bullswarm run` is a one-step workflow and backs off the same way. Detection is shape-gated to provider notices, so an agent writing *about* rate limits does not trigger either path.
|
|
239
239
|
|
|
240
240
|
## A sign-in failure upstream
|
|
241
241
|
|
package/docs/guide/workflows.md
CHANGED
|
@@ -467,7 +467,7 @@ Your choices after a usage limit, or with no pool free:
|
|
|
467
467
|
- cancel the run: `bullswarm workflow cancel <id>`.
|
|
468
468
|
|
|
469
469
|
A short "too many requests" rate limit is not a usage limit. It backs off on
|
|
470
|
-
the same pool at most twice (20 s, then 60 s, or the wait it names when that
|
|
470
|
+
the same pool at most twice (20-30 s, then 60-90 s with random jitter, or the wait it names when that
|
|
471
471
|
is at most 2 minutes), then comes back to you. Its header reads `rate limited · backed off twice` (`once` after one
|
|
472
472
|
backoff; a backoff is never counted as the retry), and a try after a backoff
|
|
473
473
|
reads `· after a rate-limit backoff`. One that names a longer wait comes back to you
|
package/docs/reference/cli.md
CHANGED
|
@@ -344,7 +344,7 @@ Either way the pool's meter is read again at once, and a window it shows at its
|
|
|
344
344
|
|
|
345
345
|
Any other rate limit — `Error: Rate limit exceeded. Please wait a moment and try again.`,
|
|
346
346
|
`429 Too Many Requests`, an overload — backs off on the same pool at most twice
|
|
347
|
-
(20 s, then 60 s, or the wait it names when that is at most 2 minutes) and then
|
|
347
|
+
(20-30 s, then 60-90 s with random jitter, or the wait it names when that is at most 2 minutes) and then
|
|
348
348
|
comes back to you; one that names a longer wait comes back to you at once, with
|
|
349
349
|
`back at` at the end of that wait. Nothing moves to another pool, and a single
|
|
350
350
|
`bullswarm run` exits 1 on it. In a workflow started by an earlier version the
|
|
@@ -199,7 +199,7 @@ Any other field is rejected. Resolution per field: the action's own `lane` or `e
|
|
|
199
199
|
|---|---|---|
|
|
200
200
|
| `process` | `auth`, `provider`, `process`, `interrupted`, `stalled`, `model-not-in-plan`: one retry on another eligible pool; the same pool if it is the only candidate (except `auth`, whose retry also skips every pool that shares its credential, and `model-not-in-plan`, whose retry never goes back to the pool whose plan refused the model) | You decide |
|
|
201
201
|
| `gate` | `not-produced`, `failed-evidence`, `schema`, `semantic`: one retry on the same pool with the failure attached, except `not-produced` on a build or chore step (no file changed), which gets no automatic retry | You decide |
|
|
202
|
-
| `wait` | `quota`: none. A usage limit (a spent 5-hour or weekly window, or no credit left) ends the step at once. `throttle`: at most two short backoffs on the same pool (20 s, then 60 s, or a named wait of at most 2 minutes), without spending the retry | You decide; the block shows `back at <time>` when the pool's return time is known |
|
|
202
|
+
| `wait` | `quota`: none. A usage limit (a spent 5-hour or weekly window, or no credit left) ends the step at once. `throttle`: at most two short backoffs on the same pool (20-30 s, then 60-90 s with random jitter, or a named wait of at most 2 minutes), without spending the retry | You decide; the block shows `back at <time>` when the pool's return time is known |
|
|
203
203
|
| `caller` | `ownership`, `ownership-conflict`, `runtime`, `unavailable`, or any unknown kind: no automatic retry | You decide |
|
|
204
204
|
| `stop` | `cancelled`, `paused`, `restarted`, `superseded`: no failure retry | The caller controls what runs next |
|
|
205
205
|
|
package/package.json
CHANGED
|
@@ -97,7 +97,7 @@ run out before its window resets is never given a step it would push over;
|
|
|
97
97
|
when another capable pool is free, routing picks it as usual.
|
|
98
98
|
|
|
99
99
|
A short "too many requests" rate limit is not a usage limit (failure kind
|
|
100
|
-
`throttle`). It backs off on the same pool at most twice (20 s, then 60 s, or
|
|
100
|
+
`throttle`). It backs off on the same pool at most twice (20-30 s, then 60-90 s with random jitter, or
|
|
101
101
|
the wait it names when that is at most 2 minutes), then comes back to you (`✗
|
|
102
102
|
<step> needs you · rate limited · backed off twice`). A try after a backoff
|
|
103
103
|
reads `· after a rate-limit backoff`, and the block's header counts the
|
package/src/lib/quota.js
CHANGED
|
@@ -61,6 +61,10 @@ const QUOTA_SIGNATURE_TABLE = Object.freeze([
|
|
|
61
61
|
{ phrase: 'rate_limit_exceeded', generic: true, limit: 'throttle' },
|
|
62
62
|
{ phrase: 'rate limited', generic: true, limit: 'throttle' },
|
|
63
63
|
{ phrase: 'too many requests', generic: true, limit: 'throttle' },
|
|
64
|
+
// Cloudflare Workers AI per-model request rate (error code 3021; Paid
|
|
65
|
+
// models allow 20 requests a minute per account). Its own wording, so not
|
|
66
|
+
// generic; it sits inside the 429 body, past the head of the line.
|
|
67
|
+
{ phrase: 'inference request per min rate reached', limit: 'throttle' },
|
|
64
68
|
{ phrase: 'quota exceeded', generic: true },
|
|
65
69
|
{ phrase: 'exceeded your current quota' },
|
|
66
70
|
{ phrase: 'insufficient_quota' },
|
|
@@ -151,10 +155,12 @@ const DAY_MS = 24 * 60 * 60_000;
|
|
|
151
155
|
* Shared with `matchLikelyAuthFailure` in watch.js so both gates agree on what
|
|
152
156
|
* "error-shaped" means. HTTP 402 (Payment Required) is how a spent prepaid
|
|
153
157
|
* balance arrives (grok, 2026-09-25): the limit phrase sits past the head
|
|
154
|
-
* window of that line, so only its error shape admits it.
|
|
158
|
+
* window of that line, so only its error shape admits it. A line that opens
|
|
159
|
+
* with HTTP 429's reason phrase (`Too Many Requests: {...}`, how an
|
|
160
|
+
* OpenAI-compatible SDK reports Workers AI 3021, 2026-11-24) is one too.
|
|
155
161
|
*/
|
|
156
162
|
export const ERROR_SHAPED_LINE =
|
|
157
|
-
/^(?:error|fatal)(?:\b|:)|^(?:authentication failed|failed to authenticate|not authenticated|invalid api key|rate limit(?:ed| exceeded)?|cmd login)(?:[.!:]|$)|\b(?:http\s*(?:401|402|403|429)|status\s*(?:401|402|403|429)|payment required|login required|please login|access denied|quota exceeded)\b/i;
|
|
163
|
+
/^(?:error|fatal)(?:\b|:)|^(?:authentication failed|failed to authenticate|not authenticated|invalid api key|rate limit(?:ed| exceeded)?|cmd login|too many requests)(?:[.!:]|$)|\b(?:http\s*(?:401|402|403|429)|status\s*(?:401|402|403|429)|payment required|login required|please login|access denied|quota exceeded)\b/i;
|
|
158
164
|
|
|
159
165
|
function declaredList(connector, key) {
|
|
160
166
|
return Array.isArray(connector?.[key]) ? connector[key] : [];
|
|
@@ -224,16 +230,25 @@ export function classifyQuotaLimit(connector, { line = '', context = '' } = {},
|
|
|
224
230
|
return { limit, waitMs, resetAt, explicit: windowWording && resetAt != null };
|
|
225
231
|
}
|
|
226
232
|
|
|
233
|
+
/** Jitter adds up to this share of a fixed backoff step (20 s -> 20-30 s). */
|
|
234
|
+
export const THROTTLE_JITTER_SHARE = 0.5;
|
|
235
|
+
|
|
227
236
|
/**
|
|
228
237
|
* How long to wait before same-pool retry number `retry` (1-based) of a
|
|
229
238
|
* throttled attempt: the wait the provider named when it named one (never
|
|
230
|
-
* shorter than a second), else the fixed short schedule
|
|
239
|
+
* shorter than a second), else the fixed short schedule plus `jitter` (a
|
|
240
|
+
* number in [0, 1), clamped) times THROTTLE_JITTER_SHARE of the step, so
|
|
241
|
+
* workers that hit one per-minute limit together do not all come back in the
|
|
242
|
+
* same second (Workers AI 3021, 2026-11-24).
|
|
231
243
|
*/
|
|
232
|
-
export function throttleBackoffMs(retry = 1, { waitMs = null } = {}) {
|
|
244
|
+
export function throttleBackoffMs(retry = 1, { waitMs = null, jitter = 0 } = {}) {
|
|
233
245
|
const named = Number(waitMs);
|
|
234
246
|
if (Number.isFinite(named) && named > 0) return Math.max(1000, Math.min(named, THROTTLE_MAX_WAIT_MS));
|
|
235
247
|
const index = Math.max(0, Math.min(THROTTLE_BACKOFF_MS.length - 1, Math.floor(Number(retry) || 1) - 1));
|
|
236
|
-
|
|
248
|
+
const step = THROTTLE_BACKOFF_MS[index];
|
|
249
|
+
const span = Math.round(step * THROTTLE_JITTER_SHARE);
|
|
250
|
+
const share = Number.isFinite(Number(jitter)) ? Math.min(Math.max(Number(jitter), 0), 1) : 0;
|
|
251
|
+
return step + Math.min(span - 1, Math.floor(share * span));
|
|
237
252
|
}
|
|
238
253
|
|
|
239
254
|
/**
|
|
@@ -598,6 +613,24 @@ function quoted(line, max = 160) {
|
|
|
598
613
|
return `"${text.length > max ? `${text.slice(0, max - 1)}…` : text}"`;
|
|
599
614
|
}
|
|
600
615
|
|
|
616
|
+
/** A notice line longer than this is quoted from its phrase, this long. */
|
|
617
|
+
const NOTICE_LINE_CHARS = 160;
|
|
618
|
+
const NOTICE_QUOTE_CHARS = 60;
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* The notice as a `why` quotes it: the whole line (as before) up to
|
|
622
|
+
* NOTICE_LINE_CHARS, else the part that starts at the matched phrase (a 429
|
|
623
|
+
* body arrives as one long JSON line, Workers AI 3021, 2026-11-24), so the
|
|
624
|
+
* `why` stays one readable line.
|
|
625
|
+
*/
|
|
626
|
+
function quotedNotice(line, signature) {
|
|
627
|
+
const text = String(line ?? '').replace(/\s+/g, ' ').trim();
|
|
628
|
+
if (text.length <= NOTICE_LINE_CHARS) return quoted(text);
|
|
629
|
+
const at = signature ? text.toLowerCase().indexOf(String(signature).toLowerCase()) : -1;
|
|
630
|
+
if (at <= 0) return quoted(text, NOTICE_QUOTE_CHARS);
|
|
631
|
+
return quoted(`…${text.slice(at)}`, NOTICE_QUOTE_CHARS);
|
|
632
|
+
}
|
|
633
|
+
|
|
601
634
|
/**
|
|
602
635
|
* What a limit notice says about the pool's usage window: the one place the
|
|
603
636
|
* Q6 rule lives. Nothing here is stored or remembered (Q7).
|
|
@@ -633,7 +666,7 @@ export function decideUsageLimit({
|
|
|
633
666
|
? classifyQuotaLimit(connector, notice, { now: nowMs, timeZone })
|
|
634
667
|
: { limit: 'throttle', waitMs: null, resetAt: null, explicit: false };
|
|
635
668
|
const reading = meterReadingOf(meter !== undefined ? meter : readMeterSnapshot(bullswarmDir, pool), { now: nowMs });
|
|
636
|
-
const said =
|
|
669
|
+
const said = quotedNotice(line, notice?.signature) ?? 'a limit notice';
|
|
637
670
|
const summary = meterSummary(reading);
|
|
638
671
|
const clockOpts = { now: nowMs, timeZone };
|
|
639
672
|
const base = {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"throttleSignatures": [
|
|
52
52
|
"strings in output that mean a momentary request throttle (please wait a moment and try again)"
|
|
53
53
|
],
|
|
54
|
-
"$comment-throttleSignatures": "Optional. Transient-throttle wording, merged on top of DEFAULT_THROTTLE_SIGNATURES (src/lib/quota.js) under the same quota-shaped gate. A throttle is NOT a spent window: in a workflow the attempt is retried on the same pool after a short backoff (THROTTLE_BACKOFF_MS: 20 s, then 60 s); a single bullswarm run makes one attempt. A named wait is sat out on the same pool up to a cap: in a run started by this version the cap is 2 minutes, and a longer wait goes back to the caller with the time the provider named; in a run started by an earlier version the cap is THROTTLE_MAX_WAIT_MS (15 minutes), and a longer wait skips the same-pool retry and moves the attempt to another pool. A throttle becomes a usage limit only when the pool's own meter reads >= 95% on a running window (Q6).",
|
|
54
|
+
"$comment-throttleSignatures": "Optional. Transient-throttle wording, merged on top of DEFAULT_THROTTLE_SIGNATURES (src/lib/quota.js) under the same quota-shaped gate. A throttle is NOT a spent window: in a workflow the attempt is retried on the same pool after a short backoff (THROTTLE_BACKOFF_MS: 20-30 s, then 60-90 s with random jitter); a single bullswarm run makes one attempt. A named wait is sat out on the same pool up to a cap: in a run started by this version the cap is 2 minutes, and a longer wait goes back to the caller with the time the provider named; in a run started by an earlier version the cap is THROTTLE_MAX_WAIT_MS (15 minutes), and a longer wait skips the same-pool retry and moves the attempt to another pool. A throttle becomes a usage limit only when the pool's own meter reads >= 95% on a running window (Q6).",
|
|
55
55
|
"outputExtraction": {
|
|
56
56
|
"$comment": "how to get the real answer out of stdout+stderr+files",
|
|
57
57
|
"strategy": "stdout|stdout-tail|json-field|file|event-stream",
|
|
@@ -100,7 +100,7 @@ export async function wfCapabilities(opts, { ensureHome } = {}) {
|
|
|
100
100
|
processFailure: 'retry once on another eligible pool; the same pool when it is the only candidate (except auth)',
|
|
101
101
|
gateFailure: 'retry once on the same pool with the failure attached; a build or chore step that changed no file (not-produced) comes back at once with no automatic retry, every other not-produced keeps it',
|
|
102
102
|
quota: 'a usage limit (a spent 5-hour or weekly window, or no credit left: a notice that says so, with or without a reset, or a full meter) ends the step and goes to the caller at once, never waited out, moved or retried; retryAfter is the reset when it is known, else the earliest known return when no capable pool is free',
|
|
103
|
-
throttle: 'a transient rate limit (too many requests, no usage window spent) backs off on the same pool at most twice without spending the retry (20 s, then 60 s, or a named wait of at most 2 minutes), then goes to the caller; a longer named wait goes to the caller at once, with retryAfter at its end; a backoff whose pool is no longer free goes to the caller at once, as quota when that pool is out on a usage limit, with retryAfter its known return',
|
|
103
|
+
throttle: 'a transient rate limit (too many requests, no usage window spent) backs off on the same pool at most twice without spending the retry (20-30 s, then 60-90 s with random jitter, or a named wait of at most 2 minutes), then goes to the caller; a longer named wait goes to the caller at once, with retryAfter at its end; a backoff whose pool is no longer free goes to the caller at once, as quota when that pool is out on a usage limit, with retryAfter its known return',
|
|
104
104
|
noFreePool: 'no capable pool free at the first pick (nearly spent, or a 5-hour, weekly or monthly window at its limit): the step goes to the caller, as quota when every reason is a usage limit, else unavailable; why names each pool and its reason; retryAfter is the earliest known return; a promised retry that finds no free pool keeps the last failure\'s kind and its why ends "· no retry: <pool> <reason>; …"',
|
|
105
105
|
then: 'caller; only dependents wait',
|
|
106
106
|
savedRuns: 'keep their original retry and review rules',
|
|
@@ -1334,7 +1334,10 @@ async function dispatchUncapped({
|
|
|
1334
1334
|
} else if (next.sameBackoff) {
|
|
1335
1335
|
throttleRetries += 1;
|
|
1336
1336
|
replayPool = pool;
|
|
1337
|
-
await backoff(throttleBackoffMs(throttleRetries, {
|
|
1337
|
+
await backoff(throttleBackoffMs(throttleRetries, {
|
|
1338
|
+
waitMs: verdict.throttleWaitMs,
|
|
1339
|
+
jitter: (dependencies.random ?? Math.random)(),
|
|
1340
|
+
}));
|
|
1338
1341
|
} else if (kind === 'stalled') {
|
|
1339
1342
|
fallbackWhy = verdict?.meta?.stalledBy === 'no-progress'
|
|
1340
1343
|
? `fallback from ${pool.name} after no file change for ${Math.round(noProgressSec)}s`
|