@commonlyai/cli 0.1.371 → 0.1.372

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.371",
3
+ "version": "0.1.372",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -4975,6 +4975,13 @@ export const performRun = ({
4975
4975
  });
4976
4976
  nextPollDelayMs = retry.delayMs;
4977
4977
  retryScheduled = true;
4978
+ // As in the batch path (F236): an open circuit's wait is walked in
4979
+ // one-minute checks that tell newly waiting pods, never slept
4980
+ // through whole. A stated quota reset can make it hours (F481,
4981
+ // CodeRabbit on #4108).
4982
+ circuitNotice = retry.circuitOpen && cantAnswerNotice(err) && !modelUnavailableFailure(err)
4983
+ ? { error: err, remainingMs: retry.delayMs }
4984
+ : null;
4978
4985
  // Carried to the retry like a failed batch: the event is claimed,
4979
4986
  // so the next poll would not return it.
4980
4987
  tickUnsettled.push(...claimedAfter(groupIndex));
@@ -64,7 +64,7 @@ export const HOST_DEFERRAL_MAX_MS = 2 * 60 * 60 * 1000;
64
64
  export const SPAWN_STALL_RETRY_BASE_MS = 2 * 60 * 1000;
65
65
 
66
66
  export const SPAWN_CIRCUIT_THRESHOLD = 3;
67
- // Base ceiling before the stable per-agent 0–20% anti-herd offset.
67
+ // Fallback ceiling when an error has no usable reset clock.
68
68
  export const SPAWN_RETRY_MAX_MS = 15 * 60 * 1000;
69
69
  export const SPAWN_RETRY_JITTER_MAX_RATIO = 0.2;
70
70
 
@@ -163,6 +163,16 @@ const QUOTA_POSSESSIVE_RE = /you'?ve (?:hit|reached) your (?!rate[ -]?limit)(?:[
163
163
  const THROTTLE_WORDING_RE = /(?:rate[ -]?limit|too many requests|overloaded|capacity)/i;
164
164
  const RATE_LIMIT_RE = /(?:rate[ -]?limit|too many requests|\b429\b|overloaded|capacity)/i;
165
165
  const CONFIGURATION_RE = /(?:ENOENT|command not found|not on PATH|login required|not logged in|invalid api key|authentication failed|unauthori[sz]ed|forbidden|\b40[13]\b)/i;
166
+ // The zone is an IANA name: Area/Location (America/Port-au-Prince, Etc/GMT+5)
167
+ // or a bare UTC/GMT, as a CI box or container seat reports. An unknown name
168
+ // fails Intl below and keeps the fallback.
169
+ const QUOTA_RESET_RE = /\bresets?\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s*\((UTC|GMT|[A-Za-z_]+(?:\/[A-Za-z0-9_+-]+)+)\)/i;
170
+ const QUOTA_RESET_MARGIN_MS = 2 * 60 * 1000;
171
+ // A stated reset is the old account's. A person who hits quota can switch to
172
+ // another account (`/login`), and the seat must notice that within the hour,
173
+ // not at the old account's reset hours later. So a far reset probes hourly,
174
+ // and a near one still waits for it (CTO on #4108).
175
+ export const QUOTA_RESET_MAX_WAIT_MS = 60 * 60 * 1000;
166
176
 
167
177
  const CONNECTION_FAULT_RE = /(?:ECONNRESET|ECONNREFUSED|ETIMEDOUT|EPIPE|socket hang up|fetch failed)/;
168
178
 
@@ -249,6 +259,46 @@ const applyJitter = (delayMs, jitterRatio) => {
249
259
  return Math.round(delayMs * (1 + safeJitter));
250
260
  };
251
261
 
262
+ // Claude names the local reset clock in its quota error. Waiting for that
263
+ // clock avoids repeatedly launching a seat that cannot answer before then.
264
+ // If the hint is absent or malformed, keep the ordinary bounded retry path.
265
+ export const quotaResetDelay = (error, now = Date.now()) => {
266
+ const match = QUOTA_RESET_RE.exec(errorText(error));
267
+ if (!match) return null;
268
+ const hour = Number(match[1]);
269
+ const minute = Number(match[2] || 0);
270
+ if (hour < 1 || hour > 12 || minute > 59) return null;
271
+ const target = ((hour % 12) + (match[3].toLowerCase() === 'pm' ? 12 : 0)) * 60 + minute;
272
+ let formatter;
273
+ try {
274
+ formatter = new Intl.DateTimeFormat('en-US', {
275
+ timeZone: match[4], hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
276
+ });
277
+ } catch {
278
+ return null;
279
+ }
280
+ const localMinute = (instant) => {
281
+ const parts = Object.fromEntries(formatter.formatToParts(instant).map(({ type, value }) => [type, value]));
282
+ return Number(parts.hour) * 60 + Number(parts.minute);
283
+ };
284
+ const nowMinute = localMinute(now);
285
+ const wallMinutes = (target - nowMinute + 1440) % 1440;
286
+ // At or just after the named minute, the message may be a stale failure
287
+ // from the old quota window. Probe on the ordinary cooldown instead of
288
+ // assuming the next reset is nearly 24 hours away.
289
+ if (wallMinutes === 0 || wallMinutes > 1430) return null;
290
+ let resetAt = now - (now % 60000) + wallMinutes * 60 * 1000;
291
+ // Crossing a daylight-saving boundary can shift the initial wall-clock
292
+ // estimate by an hour. Reconcile against the target in the named zone.
293
+ for (let attempt = 0; attempt < 2; attempt += 1) {
294
+ const difference = (target - localMinute(resetAt) + 1440) % 1440;
295
+ if (difference === 0) break;
296
+ resetAt += (difference > 720 ? difference - 1440 : difference) * 60 * 1000;
297
+ }
298
+ if (resetAt <= now || localMinute(resetAt) !== target) return null;
299
+ return resetAt - now + QUOTA_RESET_MARGIN_MS;
300
+ };
301
+
252
302
  /**
253
303
  * Return the next probe delay and whether the circuit is open.
254
304
  *
@@ -294,10 +344,18 @@ export const spawnRetryPolicy = ({
294
344
  failureClass === SPAWN_FAILURE_CLASS.QUOTA
295
345
  || failureClass === SPAWN_FAILURE_CLASS.CONFIGURATION
296
346
  ) {
347
+ const resetDelay = failureClass === SPAWN_FAILURE_CLASS.QUOTA
348
+ ? quotaResetDelay(error)
349
+ : null;
297
350
  return {
298
351
  failureClass,
299
352
  circuitOpen: true,
300
- delayMs: applyJitter(SPAWN_RETRY_MAX_MS, jitterRatio),
353
+ // Spread the reset probe by at most 24 seconds, not a percentage of
354
+ // the entire wait: a six-hour hint must not add an hour of lag.
355
+ delayMs: resetDelay === null
356
+ ? applyJitter(SPAWN_RETRY_MAX_MS, jitterRatio)
357
+ : Math.min(resetDelay, QUOTA_RESET_MAX_WAIT_MS)
358
+ + applyJitter(QUOTA_RESET_MARGIN_MS, jitterRatio) - QUOTA_RESET_MARGIN_MS,
301
359
  };
302
360
  }
303
361