@commonlyai/cli 0.1.370 → 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 +1 -1
- package/src/commands/agent.js +12 -0
- package/src/lib/adapters/codex.js +23 -0
- package/src/lib/spawn-retry.js +60 -2
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -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));
|
|
@@ -6023,6 +6030,11 @@ Docs:
|
|
|
6023
6030
|
installedVersion: installedCliVersion(),
|
|
6024
6031
|
log: (line) => console.log(`${stamp()} [${name}] ${line}`),
|
|
6025
6032
|
});
|
|
6033
|
+
// F262: a harness the seat's turns would refuse is named now, not on the
|
|
6034
|
+
// first mention. Fired, not awaited, like the update notice above.
|
|
6035
|
+
Promise.resolve(adapter.startNotice?.({ unconfined: hostUnconfined || codexUnconfined }))
|
|
6036
|
+
.then((notice) => { if (notice) console.warn(`${stamp()} [${name}] ${notice}`); })
|
|
6037
|
+
.catch(() => {});
|
|
6026
6038
|
|
|
6027
6039
|
const { stop } = performRun({
|
|
6028
6040
|
instanceUrl: record.instanceUrl,
|
|
@@ -1506,6 +1506,29 @@ export default {
|
|
|
1506
1506
|
|
|
1507
1507
|
inventory: codexRuntimeInventory,
|
|
1508
1508
|
|
|
1509
|
+
// Read once when `agent run` starts. A Codex below the floor is refused on
|
|
1510
|
+
// every public and private-profile turn, so the person hears it in the seat
|
|
1511
|
+
// log's first lines, not on the first mention (F262). A warning, not a
|
|
1512
|
+
// refusal: the floor skips a cloud-codex pod and an operator-unconfined seat,
|
|
1513
|
+
// exactly as spawn does. A Codex that can't be launched gives no notice here;
|
|
1514
|
+
// the run's detect() has already refused that. The probe is cached, so the
|
|
1515
|
+
// first turn doesn't ask again. `opts` carries spawn's version test seams.
|
|
1516
|
+
async startNotice({ env = process.env, unconfined = false, ...opts } = {}) {
|
|
1517
|
+
if (unconfined || codexTrustedPerimeter(env)) return null;
|
|
1518
|
+
let version;
|
|
1519
|
+
try {
|
|
1520
|
+
version = await readCodexVersion(opts, env);
|
|
1521
|
+
} catch {
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1524
|
+
if (meetsMinimumVersion(version, PUBLIC_CODEX_MIN_VERSION)) return null;
|
|
1525
|
+
return version
|
|
1526
|
+
? `Codex ${version} is older than ${PUBLIC_CODEX_MIN_VERSION}, so every turn will be refused. `
|
|
1527
|
+
+ `Upgrade Codex to at least ${PUBLIC_CODEX_MIN_VERSION} and start the agent again.`
|
|
1528
|
+
: 'could not read the Codex version, so turns may be refused. Check that `codex --version` works '
|
|
1529
|
+
+ `for this agent; this seat needs Codex ${PUBLIC_CODEX_MIN_VERSION} or later.`;
|
|
1530
|
+
},
|
|
1531
|
+
|
|
1509
1532
|
// `opts` is a test seam only: `_commandResolution` overrides the Windows
|
|
1510
1533
|
// resolver's platform/env/fs. Production calls detect() with no argument.
|
|
1511
1534
|
async detect(opts = {}) {
|
package/src/lib/spawn-retry.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
-
|
|
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
|
|