Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

review: read telemetry once per worker per beat; re-home decide()'s docblock; doc wording

Gastón Péchieu21c9a5eaddf9
diff --git a/src/main/index.ts b/src/main/index.ts
index 2035035c..f8e3ffff 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -5155,6 +5155,9 @@ function runWorkerWakeBeat(): void {
const t = Date.parse(m.created_at ?? '');
if (Number.isFinite(t) && (oldestMailAt === 0 || t < oldestMailAt)) oldestMailAt = t;
}
+ // One telemetry read per worker per beat: with no live OTel the collector
+ // falls back to the transcript (registry + transcript directory reads).
+ const usage = telemetry.getAgentUsage(agentId);
facts.push({
agentId,
isGod: agentId === reg.godId,
@@ -5169,8 +5172,8 @@ function runWorkerWakeBeat(): void {
// but it does prove the CLI exports telemetry (Claude Code only), which
// is what lets the stall rule read "no turn" as evidence. Other engines
// show their turns through hook events, which the watchdog hears itself.
- lastActivityAt: activityEvidenceAt({ usage: telemetry.getAgentUsage(agentId), spans: telemetry.getSpans(agentId) }),
- hasTelemetry: telemetry.getAgentUsage(agentId) !== null,
+ lastActivityAt: activityEvidenceAt({ usage, spans: telemetry.getSpans(agentId) }),
+ hasTelemetry: usage !== null,
oldestMailAt
});
}
diff --git a/src/main/workerWake.ts b/src/main/workerWake.ts
index 7faae481..b505b020 100644
--- a/src/main/workerWake.ts
+++ b/src/main/workerWake.ts
@@ -127,8 +127,8 @@ export interface WorkerWakeFacts {
autoDeliveryPaused: boolean;
paused: boolean;
halted: boolean;
- /** Timestamp of the agent's last telemetry usage sample — the CLI's own
- * evidence of a turn — or 0/undefined when it has never reported one. */
+ /** When telemetry last showed the CLI doing a turn — a tool span, or a usage
+ * sample WITH tokens (activityEvidenceAt) — or 0/undefined when it never has. */
lastActivityAt?: number;
/** True when the telemetry collector holds ANY usage sample for the agent
* (even the zero-token one stamped at session start): its CLI exports
@@ -200,6 +200,9 @@ export class WorkerWakeWatchdog {
private hookSeenAt = new Map<string, number>();
/** agentId → timestamp of its last hook event that proves a turn. */
private lastTurnHookAt = new Map<string, number>();
+ /** agentId → when its hold was last reported, so the beat logs a held worker
+ * once per cooldown instead of every 15 s. */
+ private lastHoldReportAt = new Map<string, number>();
/** Record a PTY spawn so its boot sequence is left alone. */
noteSpawn(ptyId: string, at = Date.now()): void {
@@ -243,8 +246,6 @@ export class WorkerWakeWatchdog {
if (ptyId) this.spawnedAt.delete(ptyId);
}
- /** The worker ids that should be nudged right now, in stable registry order.
- * Pure decision — the caller types the nudge. */
/** Why this worker is held right now, or null when it should be nudged.
* The same checks decide() applies, in the same order, exposed so the beat
* can LOG why a worker with old pending mail is not being woken — the
@@ -274,6 +275,10 @@ export class WorkerWakeWatchdog {
return null;
}
+ /** The worker ids that should be nudged right now, in stable registry order.
+ * Pure decision — the caller types the nudge. Remembers what it announced
+ * (the edge trigger) and when (the cooldown); a drained inbox forgets the
+ * announcement, so the remembered set is bounded by live mail. */
decide(facts: readonly WorkerWakeFacts[], now = Date.now()): string[] {
const out: string[] = [];
for (const f of facts) {
@@ -290,10 +295,6 @@ export class WorkerWakeWatchdog {
return out;
}
- /** agentId → when its hold was last reported, so the beat logs a held worker
- * once per cooldown instead of every 15 s. */
- private lastHoldReportAt = new Map<string, number>();
-
/** True once per WORKER_WAKE_COOLDOWN_MS per worker — the beat's log gate. */
shouldReportHold(agentId: string, now = Date.now()): boolean {
const last = this.lastHoldReportAt.get(agentId) ?? 0;
diff --git a/test/worker-wake-stall.test.cjs b/test/worker-wake-stall.test.cjs
index ef27b270..a1c2a4f8 100644
--- a/test/worker-wake-stall.test.cjs
+++ b/test/worker-wake-stall.test.cjs
@@ -5,9 +5,12 @@
// order — 0 tokens, no transcript, mail unread — and the watchdog never fired.
// Its rules infer "busy" from PTY output and "booting" from no output, but a
// TUI redraws its chrome without doing any work and the boot sequence itself is
-// output. Telemetry is the CLI's own evidence of a turn: mail older than
-// WORKER_WAKE_STALL_MS with no usage sample since it landed is a stalled
-// worker, and the nudge goes in whatever the terminal is printing — and again
+// output. Session activity is the CLI's own evidence of a turn — telemetry (a
+// tool span or a usage sample with tokens; Claude Code only) or a turn-proving
+// hook event (every shimmed engine): mail older than WORKER_WAKE_STALL_MS with
+// no such evidence since it landed is a stalled worker (as long as the agent
+// has a channel that could show one at all), and the nudge goes in whatever
+// the terminal is printing — and again
// after each cooldown, even though its ids were already announced (#358's
// edge trigger is for a worker that heard the announcement; a stalled one did
// not).