@commonlyai/cli 0.1.369 → 0.1.371

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.
@@ -143,6 +143,15 @@ class Commonly:
143
143
  newest message (409 unseen_messages). Reading first is the contract."""
144
144
  return self._request("GET", f"/api/agents/runtime/pods/{pod_id}/context")
145
145
 
146
+ def catch_up(self, pod_id: str) -> dict:
147
+ """Read the newest messages and mark the older ones read. A read marks
148
+ messages read only when it returns every unseen one, so a pod with more
149
+ unseen than one context read returns stays held after get_pod_context;
150
+ the 409 then names this route. It skips history unread, so call it
151
+ before you write a reply, not after, and reply to what it returns."""
152
+ return self._request("POST", f"/api/agents/runtime/pods/{pod_id}/catch-up",
153
+ {"confirmSkipHistory": True})
154
+
146
155
  def _post_reply(self, pod_id: str, content: str) -> dict:
147
156
  """Read the pod, then post. If a message lands between the read and the
148
157
  post, read once more and retry; a second 409 propagates with its reason."""
@@ -406,6 +406,21 @@ export const markExternalSignal = (error, { code = null, signal = null } = {}) =
406
406
  return error;
407
407
  };
408
408
 
409
+ // F491: EX_TEMPFAIL (sysexits.h 75). A host-side gate in front of the CLI exits
410
+ // 75 to say "not now, try again later" without running the turn: the seat's
411
+ // memory gate during a host memory hold, or a full slot pool. The provider was
412
+ // never asked, so the run loop defers the event instead of counting a failure.
413
+ export const HOST_DEFERRAL_EXIT_CODE = 75;
414
+
415
+ /**
416
+ * Mark `error` as a host-side deferral (F491). Like markExternalSignal, call it
417
+ * only on a bare non-zero exit, never over a cause the failure named.
418
+ */
419
+ export const markHostDeferral = (error, { code = null } = {}) => {
420
+ if (code === HOST_DEFERRAL_EXIT_CODE) error.hostDeferred = true;
421
+ return error;
422
+ };
423
+
409
424
  /**
410
425
  * Whether the failure text names a cause: an upstream status or a provider
411
426
  * code. Such a failure keeps its own class and is never marked as an outside
@@ -429,6 +444,7 @@ export const adapterFailure = (label, text, {
429
444
  // cause (a stream's error, the adapter's own kill) never gets the mark, and
430
445
  // never over a status or provider code the text named: that is a cause too.
431
446
  if (signal === undefined || status !== null || providerCode !== null) return error;
447
+ markHostDeferral(error, { code: exitCode });
432
448
  return markExternalSignal(error, { code: exitCode, signal });
433
449
  };
434
450
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.369",
3
+ "version": "0.1.371",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -135,8 +135,11 @@ import {
135
135
  } from '../lib/hooks-config.js';
136
136
  import {
137
137
  EXTERNAL_SIGNAL_GRACE,
138
+ HOST_DEFERRAL_MAX_MS,
139
+ SPAWN_RETRY_MAX_MS,
138
140
  formatRetryDelay,
139
141
  isExternalSignal,
142
+ isHostDeferral,
140
143
  spawnRetryJitter,
141
144
  spawnRetryPolicy,
142
145
  } from '../lib/spawn-retry.js';
@@ -2325,11 +2328,40 @@ export const performRun = ({
2325
2328
  // first EXTERNAL_SIGNAL_GRACE of them retry without counting as failures, so
2326
2329
  // a walk that kills three turns doesn't open the circuit on the fourth ask.
2327
2330
  let externalSignalStreak = 0;
2331
+ // F491: host deferrals (a gate in front of the CLI exited 75) since the last
2332
+ // good spawn, and when the first of them came. Inside HOST_DEFERRAL_MAX_MS
2333
+ // they don't count, strike no event and keep the circuit shut, and the retry
2334
+ // backs off by this streak. Past it, they count like any failure.
2335
+ let hostDeferralStreak = 0;
2336
+ let hostDeferralSince = null;
2337
+ let lastHostDeferralAt = null;
2338
+ // `graced`: this failure doesn't count, and the carried events take no strike.
2328
2339
  const countSpawnFailure = (err) => {
2329
- const graced = isExternalSignal(err) && externalSignalStreak < EXTERNAL_SIGNAL_GRACE;
2340
+ if (isHostDeferral(err)) {
2341
+ // A run with no deferral for longer than the longest retry wait ended
2342
+ // without a good spawn (claims lost, events released): a new hold starts
2343
+ // a new run, so it isn't charged for the last one's time.
2344
+ if (lastHostDeferralAt !== null && Date.now() - lastHostDeferralAt > 2 * SPAWN_RETRY_MAX_MS) {
2345
+ hostDeferralStreak = 0;
2346
+ hostDeferralSince = null;
2347
+ }
2348
+ lastHostDeferralAt = Date.now();
2349
+ if (hostDeferralSince === null) hostDeferralSince = Date.now();
2350
+ if (Date.now() - hostDeferralSince < HOST_DEFERRAL_MAX_MS) {
2351
+ hostDeferralStreak += 1;
2352
+ return { graced: true, externalSignal: false, hostDeferrals: hostDeferralStreak };
2353
+ }
2354
+ }
2355
+ const externalSignal = isExternalSignal(err) && externalSignalStreak < EXTERNAL_SIGNAL_GRACE;
2330
2356
  if (isExternalSignal(err)) externalSignalStreak += 1;
2331
- if (!graced) consecutiveSpawnFailures += 1;
2332
- return graced;
2357
+ if (!externalSignal) consecutiveSpawnFailures += 1;
2358
+ return { graced: externalSignal, externalSignal, hostDeferrals: 0 };
2359
+ };
2360
+ const resetFailureStreaks = () => {
2361
+ externalSignalStreak = 0;
2362
+ hostDeferralStreak = 0;
2363
+ hostDeferralSince = null;
2364
+ lastHostDeferralAt = null;
2333
2365
  };
2334
2366
  let pollStalled = false;
2335
2367
  const pollLiveness = createPollLiveness({
@@ -3891,8 +3923,11 @@ export const performRun = ({
3891
3923
  const inboxQuery = ({ inOutage = false } = {}) => {
3892
3924
  const carried = [...heldRetry, ...heldGreeting];
3893
3925
  const carriedCount = carried.filter((event) => event.deliveryMode !== 'digest').length;
3926
+ // A host hold (F491) counts as an outage here: with the carry full, a
3927
+ // deferred retry claims nothing new, or each one would claim a row past
3928
+ // the prompt cap and spend its attempts on hand-backs.
3894
3929
  const full = carriedCount >= batchLimit
3895
- && (inOutage || consecutiveSpawnFailures >= FULL_CARRY_CLAIM_FAILURES);
3930
+ && (inOutage || hostDeferralStreak > 0 || consecutiveSpawnFailures >= FULL_CARRY_CLAIM_FAILURES);
3896
3931
  return {
3897
3932
  agentName,
3898
3933
  instanceId,
@@ -3911,7 +3946,9 @@ export const performRun = ({
3911
3946
  // inside its grace (F293) is no failure of the event's either: `strike: false`
3912
3947
  // carries it without one, or the third kill would release it to the server's
3913
3948
  // requeue and the answer would wait 10–20 minutes. The grace bounds this.
3914
- const holdForRetry = async (failedEvents, untriedEvents = [], pastCap = [], { strike = true } = {}) => {
3949
+ // `passOver: false` (F491): no turn ran at all (a host deferral), so the
3950
+ // past-cap items weren't passed over by one and keep their carry budget.
3951
+ const holdForRetry = async (failedEvents, untriedEvents = [], pastCap = [], { strike = true, passOver = true } = {}) => {
3915
3952
  const released = [];
3916
3953
  let part = null;
3917
3954
  const carry = [];
@@ -3944,7 +3981,7 @@ export const performRun = ({
3944
3981
  const id = String(event._id);
3945
3982
  if (!seen.has(id)) {
3946
3983
  seen.add(id);
3947
- const carries = (pastCapCarries.get(id) || 0) + 1;
3984
+ const carries = (pastCapCarries.get(id) || 0) + (passOver ? 1 : 0);
3948
3985
  // As above: a stop hands the item back rather than leave it to the sweep.
3949
3986
  if (running && carries >= PAST_CAP_MAX_CARRIES) passedOver.push(event);
3950
3987
  else {
@@ -4783,13 +4820,14 @@ export const performRun = ({
4783
4820
  // The unacked items are carried to the retry, not left to the
4784
4821
  // requeue sweep, so the delay below is when they run again.
4785
4822
  const scheduleBatchRetry = async (err, failedEvents) => {
4786
- const externalSignal = countSpawnFailure(err);
4823
+ const { graced, externalSignal, hostDeferrals } = countSpawnFailure(err);
4787
4824
  const retry = spawnRetryPolicy({
4788
4825
  error: err,
4789
4826
  consecutiveFailures: consecutiveSpawnFailures,
4790
4827
  intervalMs,
4791
4828
  jitterRatio: spawnJitterRatio,
4792
4829
  externalSignal,
4830
+ hostDeferrals,
4793
4831
  });
4794
4832
  nextPollDelayMs = retry.delayMs;
4795
4833
  retryScheduled = true;
@@ -4803,7 +4841,7 @@ export const performRun = ({
4803
4841
  attempted,
4804
4842
  untriedAfter(groupIndex),
4805
4843
  pastCapEvents,
4806
- { strike: !externalSignal },
4844
+ { strike: !graced, passOver: hostDeferrals === 0 },
4807
4845
  );
4808
4846
  keepHeldLeases(retry.delayMs);
4809
4847
  const event = group[0];
@@ -4856,7 +4894,7 @@ export const performRun = ({
4856
4894
  ));
4857
4895
  if (batchSpawned) {
4858
4896
  consecutiveSpawnFailures = 0;
4859
- externalSignalStreak = 0;
4897
+ resetFailureStreaks();
4860
4898
  // Notices arriving mid-turn get one bounded collection window.
4861
4899
  // Idle polls and batches with no model turn keep their cadence.
4862
4900
  completedModelTurn = true;
@@ -4926,13 +4964,14 @@ export const performRun = ({
4926
4964
  // at-least-once delivery. Stop this fetched batch immediately —
4927
4965
  // continuing could launch every one of the 10 returned events
4928
4966
  // into the same provider outage before the next poll (#782).
4929
- const externalSignal = countSpawnFailure(err);
4967
+ const { graced, externalSignal, hostDeferrals } = countSpawnFailure(err);
4930
4968
  const retry = spawnRetryPolicy({
4931
4969
  error: err,
4932
4970
  consecutiveFailures: consecutiveSpawnFailures,
4933
4971
  intervalMs,
4934
4972
  jitterRatio: spawnJitterRatio,
4935
4973
  externalSignal,
4974
+ hostDeferrals,
4936
4975
  });
4937
4976
  nextPollDelayMs = retry.delayMs;
4938
4977
  retryScheduled = true;
@@ -4944,7 +4983,7 @@ export const performRun = ({
4944
4983
  // eslint-disable-next-line no-await-in-loop
4945
4984
  if (failedTurn?.event === event) await noteFailedTurnPart([event]);
4946
4985
  // eslint-disable-next-line no-await-in-loop
4947
- const hold = await holdForRetry([event], untriedAfter(groupIndex), [], { strike: !externalSignal });
4986
+ const hold = await holdForRetry([event], untriedAfter(groupIndex), [], { strike: !graced });
4948
4987
  keepHeldLeases(retry.delayMs);
4949
4988
  const wrapped = new Error(
4950
4989
  `${event.type} processing failed (${retry.failureClass}; `
@@ -5003,7 +5042,7 @@ export const performRun = ({
5003
5042
  const stoodDown = result?.reason === 'cascade-cap' || result?.reason === 'claim-held';
5004
5043
  if (eventWillSpawn && !stoodDown) {
5005
5044
  consecutiveSpawnFailures = 0;
5006
- externalSignalStreak = 0;
5045
+ resetFailureStreaks();
5007
5046
  }
5008
5047
  // Record after successful processing but before ack. If the ack
5009
5048
  // fails, the next delivery is skipped and re-acked instead of
@@ -5984,6 +6023,11 @@ Docs:
5984
6023
  installedVersion: installedCliVersion(),
5985
6024
  log: (line) => console.log(`${stamp()} [${name}] ${line}`),
5986
6025
  });
6026
+ // F262: a harness the seat's turns would refuse is named now, not on the
6027
+ // first mention. Fired, not awaited, like the update notice above.
6028
+ Promise.resolve(adapter.startNotice?.({ unconfined: hostUnconfined || codexUnconfined }))
6029
+ .then((notice) => { if (notice) console.warn(`${stamp()} [${name}] ${notice}`); })
6030
+ .catch(() => {});
5987
6031
 
5988
6032
  const { stop } = performRun({
5989
6033
  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 = {}) {
@@ -28,6 +28,10 @@ export const SPAWN_FAILURE_CLASS = Object.freeze({
28
28
  // supervisor, a walk). The provider never refused anything, so the retry
29
29
  // comes at the normal poll interval and the circuit stays shut.
30
30
  SIGNALED: 'signaled',
31
+ // F491: a host-side gate exited 75 (EX_TEMPFAIL) without running the turn,
32
+ // e.g. the memory gate during a host hold. Not a failure: the event is kept
33
+ // with no strike, the circuit stays shut, and the retry backs off.
34
+ HOST_DEFERRED: 'host_deferred',
31
35
  });
32
36
 
33
37
  // How many outside signals in a row go uncounted before they count again. A
@@ -39,6 +43,22 @@ export const EXTERNAL_SIGNAL_GRACE = 3;
39
43
  // its own: a stream's error or the adapter's own kill never carries it.
40
44
  export const isExternalSignal = (error) => error?.externalSignal === true;
41
45
 
46
+ // Set by adapterFailure (`markHostDeferral`) on a bare exit 75.
47
+ export const isHostDeferral = (error) => error?.hostDeferred === true;
48
+
49
+ // A host hold can last an hour or more (the 11-13 memory hold ran 96 minutes),
50
+ // so the deferred retry starts at a minute and doubles to the usual ceiling:
51
+ // 1, 2, 4, 8, then 15 minutes, and a long hold claims rarely.
52
+ export const HOST_DEFERRAL_RETRY_BASE_MS = 60 * 1000;
53
+ // How long a run of deferrals with no good spawn goes uncounted. Past it, an
54
+ // adapter that exits 75 on every spawn is a fault (a gate stuck shut, a
55
+ // misconfigured wrapper) and backs the seat off as any failure does, so its
56
+ // events still release instead of waiting forever. A run with a gap of over
57
+ // two retry ceilings starts again (agent.js), so a released event that comes
58
+ // back later gets a new grace; the kernel's requeue attempts cap is the outer
59
+ // bound on that, and retires it after a few such rounds.
60
+ export const HOST_DEFERRAL_MAX_MS = 2 * 60 * 60 * 1000;
61
+
42
62
  // A stalled probe costs one first-output window, so the wait starts short and
43
63
  // doubles to the usual ceiling: 2, 4, 8, then 15 minutes.
44
64
  export const SPAWN_STALL_RETRY_BASE_MS = 2 * 60 * 1000;
@@ -243,8 +263,21 @@ export const spawnRetryPolicy = ({
243
263
  jitterRatio = 0,
244
264
  // The run loop's call: an outside signal still inside its grace (F293).
245
265
  externalSignal = false,
266
+ // The run loop's call: the nth host deferral in a row, still inside
267
+ // HOST_DEFERRAL_MAX_MS (F491). 0 when this failure isn't one.
268
+ hostDeferrals = 0,
246
269
  }) => {
247
270
  const safeIntervalMs = Number.isFinite(intervalMs) && intervalMs > 0 ? intervalMs : 5000;
271
+ if (Number.isInteger(hostDeferrals) && hostDeferrals > 0) {
272
+ return {
273
+ failureClass: SPAWN_FAILURE_CLASS.HOST_DEFERRED,
274
+ circuitOpen: false,
275
+ delayMs: applyJitter(
276
+ Math.min(SPAWN_RETRY_MAX_MS, HOST_DEFERRAL_RETRY_BASE_MS * (2 ** (hostDeferrals - 1))),
277
+ jitterRatio,
278
+ ),
279
+ };
280
+ }
248
281
  if (externalSignal) {
249
282
  return {
250
283
  failureClass: SPAWN_FAILURE_CLASS.SIGNALED,