@commonlyai/cli 0.1.350 → 0.1.351

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.350",
3
+ "version": "0.1.351",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -1014,6 +1014,12 @@ const HELD_RETRY_MAX_FAILURES = 3;
1014
1014
  // server redelivers it under its cap, and may retire it with the TASK-656 line,
1015
1015
  // which is skipped if the agent has posted in the pod since.
1016
1016
  const PAST_CAP_MAX_CARRIES = 5;
1017
+ // F236: how often a seat waiting out an open circuit checks its inbox, so a pod
1018
+ // that first asks during the wait is told why within about a minute instead of
1019
+ // at the probe (up to ~16 minutes). The check runs no turn: the circuit's delay
1020
+ // is unchanged, and the can't-answer limit (once per cause per pod per hour)
1021
+ // still decides who hears it.
1022
+ const CIRCUIT_NOTICE_CHECK_MS = 60 * 1000;
1017
1023
 
1018
1024
  // Who gets a slot when a batch is past the cap. 'unknown' counts as a person:
1019
1025
  // only a row the snapshot and the kernel's stamp both can't place reads so, and
@@ -4470,7 +4476,7 @@ export const performRun = ({
4470
4476
  tickTimer = null;
4471
4477
  if (!running) return;
4472
4478
  tickInFlight = true;
4473
- try { await runTick(); } finally {
4479
+ try { await (circuitNotice ? runCircuitNoticeCheck() : runTick()); } finally {
4474
4480
  tickInFlight = false;
4475
4481
  if (!running) {
4476
4482
  try { await handBackCarryOnStop(); } finally { resolveStopped(); }
@@ -4478,8 +4484,12 @@ export const performRun = ({
4478
4484
  }
4479
4485
  };
4480
4486
 
4487
+ // F236: set when a retry opens the circuit for a failure a person can be
4488
+ // told about; `remainingMs` is what is left of the wait after the next check.
4489
+ let circuitNotice = null;
4481
4490
  const runTick = async () => {
4482
4491
  tickUnsettled = [];
4492
+ circuitNotice = null;
4483
4493
  let nextPollDelayMs = intervalMs;
4484
4494
  let completedModelTurn = false;
4485
4495
  let retryScheduled = false;
@@ -4659,6 +4669,9 @@ export const performRun = ({
4659
4669
  });
4660
4670
  nextPollDelayMs = retry.delayMs;
4661
4671
  retryScheduled = true;
4672
+ circuitNotice = retry.circuitOpen && cantAnswerNotice(err) && !modelUnavailableFailure(err)
4673
+ ? { error: err, remainingMs: retry.delayMs }
4674
+ : null;
4662
4675
  tickUnsettled.push(...claimedAfter(groupIndex));
4663
4676
  const attempted = failedEvents.filter((event) => !pastCapEvents.includes(event));
4664
4677
  await noteFailedTurnPart(attempted);
@@ -4933,7 +4946,55 @@ export const performRun = ({
4933
4946
  // names it, and a sibling's completed turn must not shorten the backoff.
4934
4947
  // A wait the loop schedules itself always ends, so it is not a stall.
4935
4948
  pollLiveness.pause();
4936
- if (running) tickTimer = setTimeoutImpl(tick, completedModelTurn && !retryScheduled ? 3000 : nextPollDelayMs);
4949
+ const waitMs = completedModelTurn && !retryScheduled ? 3000 : nextPollDelayMs;
4950
+ const checkMs = Math.max(CIRCUIT_NOTICE_CHECK_MS, intervalMs);
4951
+ if (circuitNotice && waitMs > checkMs) circuitNotice.remainingMs = waitMs - checkMs;
4952
+ else circuitNotice = null;
4953
+ if (running) tickTimer = setTimeoutImpl(tick, circuitNotice ? checkMs : waitMs);
4954
+ };
4955
+
4956
+ // F236: one check during a circuit wait. What it claims joins the carry, so
4957
+ // the probe runs it, a stop hands it back, and its leases are renewed; each
4958
+ // newly waiting pod is told why. No turn runs here.
4959
+ const runCircuitNoticeCheck = async () => {
4960
+ const wait = circuitNotice;
4961
+ try {
4962
+ pollLiveness.arm();
4963
+ const carriedCount = [...heldRetry, ...heldGreeting]
4964
+ .filter((event) => event.deliveryMode !== 'digest').length;
4965
+ const page = await client.get('/api/agents/runtime/events', {
4966
+ agentName, instanceId, limit: Math.max(1, batchLimit - carriedCount),
4967
+ ...(adapter?.name ? { reportedCli: adapter.name } : {}),
4968
+ });
4969
+ pollLiveness.arm();
4970
+ if (pollStalled) return;
4971
+ const fetched = page?.events || [];
4972
+ // A carried id comes back only after the server requeued it, so the
4973
+ // fetched copy holds the live deliveryId and the carried one's is dead.
4974
+ // The fetched copy wins, as in runTick: otherwise the probe, which can no
4975
+ // longer fetch it, would ack a stale nonce and stop the run.
4976
+ const fetchedById = new Map(fetched.map((event) => [String(event._id), event]));
4977
+ // Reassigned only when a copy changes, so the renewal's `heldRetry !== carry`
4978
+ // guard skips its pruning only when there was something to replace.
4979
+ const refetched = (carry) => carry.some((event) => fetchedById.has(String(event._id)));
4980
+ const refreshCarry = (carry) => carry.map((event) => fetchedById.get(String(event._id)) || event);
4981
+ if (refetched(heldRetry)) heldRetry = refreshCarry(heldRetry);
4982
+ if (refetched(heldGreeting)) heldGreeting = refreshCarry(heldGreeting);
4983
+ const carriedIds = new Set([...heldRetry, ...heldGreeting].map((event) => String(event._id)));
4984
+ const fresh = fetched.filter((event) => !carriedIds.has(String(event._id)));
4985
+ if (fetched.length) idleHeartbeat.busy();
4986
+ if (fresh.length) await holdForRetry([], fresh);
4987
+ if (fetched.length) keepHeldLeases(wait.remainingMs);
4988
+ if (fresh.length) await noticeCantAnswer(wait.error, fresh);
4989
+ } catch (error) {
4990
+ log(`[inbox.batch] inbox check during the circuit wait failed: ${error.message}`);
4991
+ }
4992
+ pollLiveness.pause();
4993
+ const checkMs = Math.max(CIRCUIT_NOTICE_CHECK_MS, intervalMs);
4994
+ const stepMs = Math.min(checkMs, wait.remainingMs);
4995
+ wait.remainingMs -= stepMs;
4996
+ if (wait.remainingMs <= 0) circuitNotice = null;
4997
+ if (running) tickTimer = setTimeoutImpl(tick, stepMs);
4937
4998
  };
4938
4999
 
4939
5000
  tick();