@commonlyai/cli 0.1.319 → 0.1.320

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.319",
3
+ "version": "0.1.320",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -64,7 +64,9 @@ import {
64
64
  import { catchUpBeforeTurn } from '../lib/pod-catch-up.js';
65
65
  import { readLongTerm, syncBack } from '../lib/memory-bridge.js';
66
66
  import { pollRetryPolicy } from '../lib/poll-retry.js';
67
- import { createPollLiveness, formatStall, resolvePollLivenessMs } from '../lib/poll-liveness.js';
67
+ import {
68
+ createIdleHeartbeat, createPollLiveness, formatStall, resolveIdleLineMs, resolvePollLivenessMs,
69
+ } from '../lib/poll-liveness.js';
68
70
  import { detectMemorySources, composeImport, importMemory } from '../lib/memory-import.js';
69
71
  import { detectSkills, importSkills, parseSkillMeta } from '../lib/skills-import.js';
70
72
  import { compileServerSkills } from '../lib/server-skills.js';
@@ -2106,6 +2108,9 @@ export const performRun = ({
2106
2108
  pollLivenessMs,
2107
2109
  pollLivenessCheckMs,
2108
2110
  onPollStalled,
2111
+ // How often a seat that keeps polling and finds nothing says so. Undefined
2112
+ // reads COMMONLY_IDLE_LINE_MS, then ten minutes (lib/poll-liveness.js).
2113
+ idleLineMs,
2109
2114
  }) => {
2110
2115
  const stateKey = localKey || agentName;
2111
2116
  const supervising = superviseRuns ?? superviseRunsByDefault(adapter?.name);
@@ -2267,6 +2272,8 @@ export const performRun = ({
2267
2272
  onPollStalled?.({ stalledMs });
2268
2273
  },
2269
2274
  });
2275
+ // So an idle seat's log tells it apart from a wedged one (11-10).
2276
+ const idleHeartbeat = createIdleHeartbeat({ everyMs: resolveIdleLineMs(idleLineMs), log });
2270
2277
  const spawnJitterRatio = retryJitterRatio ?? spawnRetryJitter(agentName);
2271
2278
  // Per-seat cascade state — lives with the process, like the session store.
2272
2279
  // A wrapper restart forgets the streak; the decay window covers that gap.
@@ -4382,6 +4389,7 @@ export const performRun = ({
4382
4389
  const pageEvents = carriedFresh.length ? [...carriedFresh, ...events] : events;
4383
4390
  const pageInboxCount = (Number.isFinite(inboxCount) ? inboxCount : events.length)
4384
4391
  + carriedFresh.length;
4392
+ if (pageEvents.length) idleHeartbeat.busy(); else if (running) idleHeartbeat.empty();
4385
4393
 
4386
4394
  const eventGroups = new Map();
4387
4395
  for (const event of pageEvents) {
@@ -4744,6 +4752,7 @@ export const performRun = ({
4744
4752
  // token cannot heal itself; a network failure usually can, and a seat
4745
4753
  // that stops on one is dead until a human notices.
4746
4754
  consecutivePollFailures += 1;
4755
+ idleHeartbeat.busy();
4747
4756
  const retry = pollRetryPolicy({
4748
4757
  consecutiveFailures: consecutivePollFailures,
4749
4758
  intervalMs,
@@ -58,3 +58,46 @@ export const createPollLiveness = ({ limitMs, onStall, checkEveryMs }) => {
58
58
  stop: () => { clearInterval(timer); },
59
59
  };
60
60
  };
61
+
62
+ export const IDLE_LINE_DEFAULT_MS = 10 * 60 * 1000;
63
+
64
+ /**
65
+ * A healthy idle seat and a wedged one used to look the same in a log: both
66
+ * printed nothing. On 11-10 six seats sat silent for 4.6 hours after a
67
+ * `fetch failed` and were restarted as wedged, though nothing showed they had
68
+ * stopped polling. So a seat that keeps polling and finds nothing says so on a
69
+ * slow cadence, `polling ok (N empty polls since HH:MMZ)`. While a seat is idle
70
+ * (no turn running, no retry wait), no line for two cadences means the loop has
71
+ * stopped.
72
+ *
73
+ * `empty()` after each poll that settled with nothing to do; `busy()` after one
74
+ * that brought work or failed, which starts the next count, so a window never
75
+ * spans an outage. The first line comes one
76
+ * cadence after the seat goes quiet, never on start.
77
+ */
78
+ export const createIdleHeartbeat = ({ everyMs = IDLE_LINE_DEFAULT_MS, log, now = Date.now }) => {
79
+ let since = null;
80
+ let count = 0;
81
+ const hhmm = (ms) => `${new Date(ms).toISOString().slice(11, 16)}Z`;
82
+ return {
83
+ empty: () => {
84
+ const at = now();
85
+ if (since === null) since = at;
86
+ count += 1;
87
+ if (at - since < everyMs) return;
88
+ log(`polling ok (${count} empty poll${count === 1 ? '' : 's'} since ${hhmm(since)})`);
89
+ since = null;
90
+ count = 0;
91
+ },
92
+ busy: () => {
93
+ since = null;
94
+ count = 0;
95
+ },
96
+ };
97
+ };
98
+
99
+ export const resolveIdleLineMs = (value, env = process.env) => {
100
+ const candidate = [value, Number(env.COMMONLY_IDLE_LINE_MS)]
101
+ .find((ms) => Number.isFinite(ms) && ms > 0);
102
+ return candidate ?? IDLE_LINE_DEFAULT_MS;
103
+ };