@commonlyai/cli 0.1.287 → 0.1.289

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.287",
3
+ "version": "0.1.289",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -2532,6 +2532,7 @@ export const performRun = ({
2532
2532
  // settled; anything thrown after a spawn that resolved means the reply never
2533
2533
  // reached the pod. Off, `turn` writes nothing.
2534
2534
  const runTurn = async (args) => {
2535
+ wrapperSpokeInTurn = false;
2535
2536
  const turn = turnRunner.begin({ eventType: args.event.type });
2536
2537
  try {
2537
2538
  return await runTurnBody({ ...args, turn });
@@ -2559,7 +2560,7 @@ export const performRun = ({
2559
2560
  const key = `model-unavailable:${failure.model || 'unknown'}`;
2560
2561
  try {
2561
2562
  if (!noticeDue(agentName, key, MODEL_UNAVAILABLE_HINT_WINDOW_MS)) return;
2562
- const delivery = await deliverChatReply({
2563
+ const delivery = await deliverTurnNotice({
2563
2564
  client,
2564
2565
  podId: hintPodId,
2565
2566
  text: modelUnavailableHint(failure.model),
@@ -2627,10 +2628,22 @@ export const performRun = ({
2627
2628
  // past its duplicate guard, since a second cut-off has no open ask to carry it.
2628
2629
  // A turn only agents woke gets no line: "ask me again" isn't for them, and in
2629
2630
  // an agent-dm the line would wake the peer into a paid turn.
2630
- const noticeCutOff = async (lostEvents) => {
2631
+ // F279: an event let go after three failures counts too, because the server's
2632
+ // retry is 10 to 20 minutes off and the kernel skips its own line once the
2633
+ // agent has posted. `part` is what one of its attempts posted. It may come back
2634
+ // and fail again, so it hears this once.
2635
+ const noteFailedTurnPart = async (failedEvents) => {
2636
+ if (!failedTurn?.preSpawnIds || wrapperSpokeInTurn) return;
2637
+ const tail = await failedTurn.snapshotMessages(50);
2638
+ const ownPost = tail && newestOwnPostSince(tail, failedTurn.preSpawnIds);
2639
+ if (ownPost) failedEvents.forEach((event) => heldRetryParts.set(String(event._id), ownPost));
2640
+ };
2641
+
2642
+ const noticeCutOff = async (lostEvents, { released = [], part = null } = {}) => {
2631
2643
  const turnArgs = failedTurn;
2632
2644
  failedTurn = null;
2633
- const waiting = lostEvents.filter((event) => event.deliveryMode !== 'digest'
2645
+ const waiting = [...lostEvents, ...released].filter((event) => event.deliveryMode !== 'digest'
2646
+ && !cutOffTold.has(String(event._id))
2634
2647
  && (someoneIsWaiting(event) || PERSON_WAITING_EVENT_TYPES.has(event.type)));
2635
2648
  if (!turnArgs || turnArgs.trigger === 'agent' || waiting.length === 0) return;
2636
2649
  const { eventPodId } = turnArgs;
@@ -2642,8 +2655,9 @@ export const performRun = ({
2642
2655
  // prove this seat replied, and this has no own-post check.
2643
2656
  // It stands on the prompt instead: a person's direct @ isn't offered
2644
2657
  // silence, so their item checkpoints only after a reply. That holds only
2645
- // for a known person, which an 'unknown' comment isn't.
2646
- if (turnArgs.trigger !== 'human') return;
2658
+ // for a known person, which an 'unknown' comment isn't, and for an item
2659
+ // that checkpointed, which a released one didn't.
2660
+ if (turnArgs.trigger !== 'human' || !lostEvents.includes(waiting[0])) return;
2647
2661
  delivery = await deliverCommentReply({
2648
2662
  client, ...target, text: CUT_OFF_NOTICE, onlyIfUnanswered: false,
2649
2663
  });
@@ -2651,7 +2665,8 @@ export const performRun = ({
2651
2665
  const tail = turnArgs.preSpawnIds ? await turnArgs.snapshotMessages(50) : null;
2652
2666
  // Nothing of this seat's in the pod means no half answer to explain: a
2653
2667
  // deliberate silence checkpoints too, and a requeue takes a row as well.
2654
- const ownPost = tail && newestOwnPostSince(tail, turnArgs.preSpawnIds);
2668
+ const ownPost = (lostEvents.some((event) => waiting.includes(event))
2669
+ && tail && newestOwnPostSince(tail, turnArgs.preSpawnIds)) || part;
2655
2670
  if (!ownPost) return;
2656
2671
  delivery = await deliverChatReply({
2657
2672
  client,
@@ -2666,7 +2681,12 @@ export const performRun = ({
2666
2681
  if (delivery.skipped || delivery.refused) {
2667
2682
  log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: `
2668
2683
  + `${delivery.reason || 'the notice was not posted'}`);
2669
- } else log(`[inbox.batch] told pod ${eventPodId} this agent was cut off before it finished`);
2684
+ } else {
2685
+ waiting.forEach((event) => cutOffTold.add(String(event._id)));
2686
+ // The line covers every part so far, so a sibling let go later has none.
2687
+ heldRetryParts.clear();
2688
+ log(`[inbox.batch] told pod ${eventPodId} this agent was cut off before it finished`);
2689
+ }
2670
2690
  } catch (noticeError) {
2671
2691
  log(`[inbox.batch] pod ${eventPodId} was not told this agent was cut off: ${noticeError.message}`);
2672
2692
  }
@@ -2807,7 +2827,7 @@ export const performRun = ({
2807
2827
  } catch (error) {
2808
2828
  if (error.code === 'seat_model_missing' && eventPodId && !missingModelNotices.has(eventPodId)) {
2809
2829
  try {
2810
- const delivery = await deliverChatReply({
2830
+ const delivery = await deliverTurnNotice({
2811
2831
  client,
2812
2832
  podId: eventPodId,
2813
2833
  text: "This agent has no model set; add environment.model to its configuration.",
@@ -3412,7 +3432,7 @@ export const performRun = ({
3412
3432
  });
3413
3433
  let posted = false;
3414
3434
  try {
3415
- const delivery = await deliverChatReply({
3435
+ const delivery = await deliverTurnNotice({
3416
3436
  client,
3417
3437
  podId: eventPodId,
3418
3438
  text,
@@ -3471,6 +3491,18 @@ export const performRun = ({
3471
3491
  let tickUnsettled = [];
3472
3492
  // eventId → consecutive local failures, for HELD_RETRY_MAX_FAILURES.
3473
3493
  const heldRetryFailures = new Map();
3494
+ // Event id to what a failed attempt on it posted, for noticeCutOff. Read as each
3495
+ // attempt fails, because the attempt's own snapshot then leaves out the notices
3496
+ // the wrapper posted after earlier ones: those aren't part of an answer. A notice
3497
+ // inside the attempt can't be told from a post that way, so that attempt isn't
3498
+ // read, which can only cost the line.
3499
+ const heldRetryParts = new Map();
3500
+ let wrapperSpokeInTurn = false;
3501
+ const deliverTurnNotice = (notice) => {
3502
+ wrapperSpokeInTurn = true;
3503
+ return deliverChatReply(notice);
3504
+ };
3505
+ const cutOffTold = new Set();
3474
3506
  // eventId → turns passed over, for PAST_CAP_MAX_CARRIES.
3475
3507
  const pastCapCarries = new Map();
3476
3508
  // The current batch's items past the cap. Kept out here because the tick needs
@@ -3525,6 +3557,7 @@ export const performRun = ({
3525
3557
  // tick adds to the carry, never replaces it.
3526
3558
  const holdForRetry = async (failedEvents, untriedEvents = [], pastCap = []) => {
3527
3559
  const released = [];
3560
+ let part = null;
3528
3561
  const carry = [];
3529
3562
  const seen = new Set();
3530
3563
  for (const event of failedEvents) {
@@ -3534,8 +3567,10 @@ export const performRun = ({
3534
3567
  const failures = (heldRetryFailures.get(id) || 0) + 1;
3535
3568
  // A stop wins over the local limit: the sweep would make this event
3536
3569
  // wait 10–20 minutes, and the server's ceiling bounds a hand-back.
3537
- if (running && failures >= HELD_RETRY_MAX_FAILURES) released.push(event);
3538
- else {
3570
+ if (running && failures >= HELD_RETRY_MAX_FAILURES) {
3571
+ released.push(event);
3572
+ part = part || heldRetryParts.get(id) || null;
3573
+ } else {
3539
3574
  heldRetryFailures.set(id, failures);
3540
3575
  carry.push(event);
3541
3576
  }
@@ -3576,6 +3611,7 @@ export const performRun = ({
3576
3611
  if (!running) {
3577
3612
  heldRetry = [...heldRetry, ...carry];
3578
3613
  heldRetryFailures.clear();
3614
+ heldRetryParts.clear();
3579
3615
  pastCapCarries.clear();
3580
3616
  const confirmed = await renewHeldDeliveries(failedEvents);
3581
3617
  return {
@@ -3589,7 +3625,7 @@ export const performRun = ({
3589
3625
  const dropped = carry.filter((event) => !stillHeld(event, confirmed));
3590
3626
  heldRetry = [...heldRetry, ...held];
3591
3627
  const heldIds = new Set(heldRetry.map((event) => String(event._id)));
3592
- for (const counts of [heldRetryFailures, pastCapCarries]) {
3628
+ for (const counts of [heldRetryFailures, heldRetryParts, pastCapCarries]) {
3593
3629
  for (const id of [...counts.keys()]) {
3594
3630
  if (!heldIds.has(id)) counts.delete(id);
3595
3631
  }
@@ -3601,7 +3637,7 @@ export const performRun = ({
3601
3637
  );
3602
3638
  }
3603
3639
  return {
3604
- held, released, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
3640
+ held, released, part, handedBack: [], lost: dropped.filter((event) => failedEvents.includes(event)),
3605
3641
  };
3606
3642
  };
3607
3643
 
@@ -3659,6 +3695,7 @@ export const performRun = ({
3659
3695
  heldGreeting = [];
3660
3696
  tickUnsettled = [];
3661
3697
  heldRetryFailures.clear();
3698
+ heldRetryParts.clear();
3662
3699
  clearHeldRenewal();
3663
3700
  return carry.length ? handBackDeliveries(carry, 'stop') : Promise.resolve([]);
3664
3701
  };
@@ -4314,8 +4351,10 @@ export const performRun = ({
4314
4351
  nextPollDelayMs = retry.delayMs;
4315
4352
  retryScheduled = true;
4316
4353
  tickUnsettled.push(...claimedAfter(groupIndex));
4354
+ const attempted = failedEvents.filter((event) => !pastCapEvents.includes(event));
4355
+ await noteFailedTurnPart(attempted);
4317
4356
  const hold = await holdForRetry(
4318
- failedEvents.filter((event) => !pastCapEvents.includes(event)),
4357
+ attempted,
4319
4358
  untriedAfter(groupIndex),
4320
4359
  pastCapEvents,
4321
4360
  );
@@ -4348,7 +4387,7 @@ export const performRun = ({
4348
4387
  });
4349
4388
  if (onError) onError(wrapped);
4350
4389
  else log(`[inbox.batch] ${wrapped.message}`);
4351
- await noticeCutOff(hold.lost);
4390
+ await noticeCutOff(hold.lost, { released: hold.released, part: hold.part });
4352
4391
  await noticeCantAnswer(err, [...failedEvents, ...untriedAfter(groupIndex)]);
4353
4392
  };
4354
4393
  let batch;
@@ -65,8 +65,9 @@ const jsonBody404 = (text) => {
65
65
  }
66
66
  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return false;
67
67
  const error = parsed.error && typeof parsed.error === 'object' ? parsed.error : parsed;
68
- const is404 = [parsed.status, parsed.code, error.status, error.code]
69
- .some((value) => String(value) === '404') || error.type === 'not_found_error';
68
+ const statuses = [parsed.status, parsed.code, error.status, error.code];
69
+ if (statuses.some((value) => Number(value) >= 500)) return false;
70
+ const is404 = statuses.some((value) => String(value) === '404') || error.type === 'not_found_error';
70
71
  const message = error.message ?? parsed.message;
71
72
  return is404 && typeof message === 'string' && modelShaped(message);
72
73
  };
@@ -114,11 +115,13 @@ export const modelUnavailableFailure = (error, { fallbackModel = null } = {}) =>
114
115
  const lines = text.split('\n');
115
116
  const keyScope = NOT_AVAILABLE_FOR_KEY_RE.test(text) && (attached !== null ? attached === 403
116
117
  : lines.some((line) => STATUS_403_RE.test(line) && NOT_AVAILABLE_FOR_KEY_RE.test(line)));
118
+ // The attached status reads the message, so its model shape must be on the
119
+ // message's own first line, not in what later stderr happens to mention.
117
120
  const notFound = attached !== null
118
- ? attached === 404 && (lines.some(modelShaped) || jsonBody404(text))
121
+ ? attached === 404 && (modelShaped(String(error.message).split('\n')[0]) || jsonBody404(text))
119
122
  : sameLine404(text) || jsonBody404(text);
120
123
  const matched = keyScope
121
- || error.providerCode === 'model_not_found'
124
+ || (error.providerCode === 'model_not_found' && !(attached >= 500))
122
125
  || notFound;
123
126
  if (!matched) return null;
124
127
  for (const pattern of MODEL_NAME_RES) {
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { PUBLIC_MCP_NOT_READY_CODE, PUBLIC_TOOL_FAILED_CODE } from './public-tool-error.js';
11
11
  import { PUBLIC_CODEX_VERSION_CODE } from './adapters/tested-version.js';
12
+ import { modelUnavailableFailure } from './model-unavailable.js';
12
13
 
13
14
  export const SPAWN_FAILURE_CLASS = Object.freeze({
14
15
  // The provider refused the request's CONTENT. Re-sending the same content
@@ -125,6 +126,8 @@ const THROTTLE_WORDING_RE = /(?:rate[ -]?limit|too many requests|overloaded|capa
125
126
  const RATE_LIMIT_RE = /(?:rate[ -]?limit|too many requests|\b429\b|overloaded|capacity)/i;
126
127
  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;
127
128
 
129
+ const CONNECTION_FAULT_RE = /(?:ECONNRESET|ECONNREFUSED|ETIMEDOUT|EPIPE|socket hang up|fetch failed)/;
130
+
128
131
  const errorText = (error) => [
129
132
  error?.message,
130
133
  error?.stderr,
@@ -170,11 +173,17 @@ export const classifySpawnFailure = (error) => {
170
173
  if (error?.status === 429 || RATE_LIMIT_RE.test(text)) {
171
174
  return SPAWN_FAILURE_CLASS.RATE_LIMIT;
172
175
  }
176
+ // A model the provider won't run fails the same way until someone changes it.
177
+ // A 403 for that reads as configuration below; a 404 has no status of its own
178
+ // there, so without this it retried in seconds against the same answer. A
179
+ // turn's text can hold a tool's 404 from before a dropped connection killed
180
+ // the turn, so a connection fault keeps the quick retry.
173
181
  if (
174
182
  error?.code === 'ENOENT'
175
183
  || error?.status === 401
176
184
  || error?.status === 403
177
185
  || CONFIGURATION_RE.test(text)
186
+ || (modelUnavailableFailure(error) && !CONNECTION_FAULT_RE.test(text))
178
187
  ) {
179
188
  return SPAWN_FAILURE_CLASS.CONFIGURATION;
180
189
  }