pi-straw-boss 0.109.0 → 0.109.1

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.
@@ -22180,6 +22180,7 @@ Session: ${session} \xB7 resume: call_tower worker {device: <this box>, resume:
22180
22180
 
22181
22181
  // src/server/workerrelay.ts
22182
22182
  var WORKER_STOP_MS = 60 * 6e4;
22183
+ var SWEEP_SLEPT_MS = 5 * 6e4;
22183
22184
  var REPORT_MAX = 48e3;
22184
22185
  var failed = (a) => a?.ok === false;
22185
22186
  function workerReport(d, route, text14, fallback) {
@@ -22200,6 +22201,7 @@ ${body2.length > REPORT_MAX ? `${body2.slice(0, REPORT_MAX)}\u2026` : body2}${se
22200
22201
  }
22201
22202
  function createWorkerEnds(d) {
22202
22203
  const idleFrom = /* @__PURE__ */ new Map(), goneSeen = /* @__PURE__ */ new Map();
22204
+ let lastSweep;
22203
22205
  const tidy3 = async (row2) => {
22204
22206
  const w = row2.route.worker;
22205
22207
  const end = await closeWorktree({ dir: w.path, branch: w.branch, baseSha: w.baseSha, ...d.git ? { git: d.git } : {} }).catch((e) => ({ removed: false, reason: e.message, head: void 0 }));
@@ -22255,10 +22257,12 @@ function createWorkerEnds(d) {
22255
22257
  };
22256
22258
  return {
22257
22259
  async sweep() {
22258
- const rows = d.rows(), live = new Set(rows.map((r) => r.route.to));
22260
+ const at = d.now(), rows = d.rows(), live = new Set(rows.map((r) => r.route.to));
22261
+ if (lastSweep !== void 0 && at - lastSweep > SWEEP_SLEPT_MS) for (const [k, v] of idleFrom) idleFrom.set(k, v + at - lastSweep);
22259
22262
  for (const k of [...idleFrom.keys()]) if (!live.has(k)) idleFrom.delete(k);
22260
22263
  tidied = new Map([...tidied].filter(([k]) => live.has(k)));
22261
22264
  for (const row2 of rows) await one4(row2).catch((e) => d.log("worker-sweep-failed", { main: row2.route.to, error: e.message.slice(0, 160) }));
22265
+ lastSweep = d.now();
22262
22266
  }
22263
22267
  };
22264
22268
  }
@@ -27495,6 +27499,10 @@ function createRuns2(o) {
27495
27499
  watcher = setInterval(() => void tick().catch((cause) => error("run-watch", cause.message)), t.watch);
27496
27500
  watcher.unref();
27497
27501
  };
27502
+ const giveBack = (a, ms3) => {
27503
+ a.slept = (a.slept ?? 0) + ms3;
27504
+ for (const k of ["idleSince", "closing", "terminating", "escalated", "recovering", "boss", "bossSince", "graceUntil"]) if (a[k] !== void 0) a[k] = a[k] + ms3;
27505
+ };
27498
27506
  let ticking = false, lastTick;
27499
27507
  const tick = async () => {
27500
27508
  if (ticking) return;
@@ -27502,11 +27510,17 @@ function createRuns2(o) {
27502
27510
  try {
27503
27511
  const at = now();
27504
27512
  if (lastTick !== void 0 && at - lastTick > Math.max(t.lost, 10 * t.watch)) {
27505
- for (const a of byRun.values()) if (!a.ended && a.lastPoll < at) a.lastPoll = at;
27513
+ for (const a of byRun.values()) {
27514
+ if (a.ended) continue;
27515
+ if (a.lastPoll < at) a.lastPoll = at;
27516
+ const ms3 = at - Math.max(lastTick, a.started) - t.watch;
27517
+ if (ms3 > 0) giveBack(a, ms3);
27518
+ }
27519
+ log.line("run-slept", { ms: at - lastTick, runs: byRun.size });
27506
27520
  }
27507
27521
  for (const a of [...byRun.values()]) {
27508
27522
  if (a.ended) continue;
27509
- const age2 = now() - a.started;
27523
+ const age2 = now() - a.started - (a.slept ?? 0);
27510
27524
  const exited = gone(a) || a.rec.pid === void 0 && a.token !== void 0 && (await panes(o.run, a.rec.workspace).catch(() => void 0))?.every((p) => p.pane_id !== a.rec.pane) === true;
27511
27525
  if (!exited) a.goneSeen = false;
27512
27526
  if (exited) {
@@ -27596,7 +27610,7 @@ function createRuns2(o) {
27596
27610
  }
27597
27611
  if (!byRun.size) clearInterval(watcher), watcher = void 0;
27598
27612
  } finally {
27599
- lastTick = now();
27613
+ lastTick = watcher ? now() : void 0;
27600
27614
  ticking = false;
27601
27615
  }
27602
27616
  };
@@ -27950,7 +27964,7 @@ Its .pi settings, extensions, skills, and prompts load only if you trust it. Yes
27950
27964
  idle,
27951
27965
  ...idle && a.boss !== void 0 ? { idleAt: Math.max(a.boss, a.idleSince) + t.bossAway } : {},
27952
27966
  idleMs: t.bossAway,
27953
- capAt: (a.bossSince ?? a.started) + t.bossMax,
27967
+ capAt: (a.bossSince ?? a.started + (a.slept ?? 0)) + t.bossMax,
27954
27968
  ...a.closing !== void 0 || a.terminating !== void 0 ? { closing: true } : {}
27955
27969
  };
27956
27970
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.109.0",
3
+ "version": "0.109.1",
4
4
  "description": "Straw Boss coordination for pi in Herdr: sessions join a tab's net by choice, the first joiner is its main agent, a workspace tower opens on demand with a live monitoring dashboard, and boss_broadcast reaches the rest",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -237,6 +237,8 @@ interface Active {
237
237
  unbound?: true;
238
238
  idleSince?: number;
239
239
  started: number;
240
+ /** Time the computer slept (or the server stood still) while this run was live: no part of its age (`giveBack`). */
241
+ slept?: number;
240
242
  closing?: number;
241
243
  steeredLong?: boolean;
242
244
  steeredIdle?: boolean;
@@ -1136,6 +1138,15 @@ export function createRuns(o: RunsOptions) {
1136
1138
  watcher = setInterval(() => void tick().catch((cause: Error) => error("run-watch", cause.message)), t.watch);
1137
1139
  watcher.unref();
1138
1140
  };
1141
+ /**
1142
+ * The computer slept, or the server stood still as long, for `ms` of the run's life: the time goes back to the run. Its age (the cap), its idle and the boss's silence, its wrap-up grace, and the waits after a quit all count
1143
+ * awake time only, so a lid closed over a live run neither times it out nor charges its events a crash (a wakeAfter timer that fired in a dark wake was parked after two such runs). No Node clock does this: on macOS
1144
+ * `process.hrtime` and `performance.now` run on through a sleep (measured 2026-11-27: both equal the wall time since boot), so the gap between ticks is the measure.
1145
+ */
1146
+ const giveBack = (a: Active, ms: number) => {
1147
+ a.slept = (a.slept ?? 0) + ms;
1148
+ for (const k of ["idleSince", "closing", "terminating", "escalated", "recovering", "boss", "bossSince", "graceUntil"] as const) if (a[k] !== undefined) a[k] = a[k]! + ms;
1149
+ };
1139
1150
  let ticking = false, lastTick: number | undefined;
1140
1151
  const tick = async () => {
1141
1152
  if (ticking) return;
@@ -1145,10 +1156,19 @@ export function createRuns(o: RunsOptions) {
1145
1156
  // silence counted from now, and the poll that follows is what shows it alive; a run that is really gone is still found, one `lost` later. The gap is measured from the end of the last tick: a tick that was slow
1146
1157
  // (Herdr hanging, calls of 5 s one after another) is no sleep, and slow ticks in a row must not keep a hung pi from ever being lost (RV8-F002).
1147
1158
  const at = now();
1148
- if (lastTick !== undefined && at - lastTick > Math.max(t.lost, 10 * t.watch)) for (const a of byRun.values()) if (!a.ended && a.lastPoll < at) a.lastPoll = at;
1159
+ if (lastTick !== undefined && at - lastTick > Math.max(t.lost, 10 * t.watch)) {
1160
+ for (const a of byRun.values()) {
1161
+ if (a.ended) continue;
1162
+ if (a.lastPoll < at) a.lastPoll = at;
1163
+ // Of the gap, a run begun in it lived only its own part; one watch interval of it was awake.
1164
+ const ms = at - Math.max(lastTick, a.started) - t.watch;
1165
+ if (ms > 0) giveBack(a, ms);
1166
+ }
1167
+ log.line("run-slept", { ms: at - lastTick, runs: byRun.size });
1168
+ }
1149
1169
  for (const a of [...byRun.values()]) {
1150
1170
  if (a.ended) continue;
1151
- const age = now() - a.started;
1171
+ const age = now() - a.started - (a.slept ?? 0);
1152
1172
  const exited = gone(a) || (a.rec.pid === undefined && a.token !== undefined && (await panes(o.run, a.rec.workspace).catch(() => undefined))?.every((p) => p.pane_id !== a.rec.pane) === true);
1153
1173
  if (!exited) a.goneSeen = false; // a sighting counts only with the next tick's (RVAE-F002)
1154
1174
  if (exited) {
@@ -1239,7 +1259,8 @@ export function createRuns(o: RunsOptions) {
1239
1259
  }
1240
1260
  if (!byRun.size) (clearInterval(watcher), (watcher = undefined));
1241
1261
  } finally {
1242
- lastTick = now();
1262
+ // A watcher that stops forgets its last tick: the next one starts with a run that was not live in the time between.
1263
+ lastTick = watcher ? now() : undefined;
1243
1264
  ticking = false;
1244
1265
  }
1245
1266
  };
@@ -1626,7 +1647,7 @@ export function createRuns(o: RunsOptions) {
1626
1647
  return {
1627
1648
  since: a.rec.startedAt, resumed: c.resumed, ...(c.why ? { why: c.why } : {}), turns: a.turns ?? c.turns, idle,
1628
1649
  ...(idle && a.boss !== undefined ? { idleAt: Math.max(a.boss, a.idleSince!) + t.bossAway } : {}),
1629
- idleMs: t.bossAway, capAt: (a.bossSince ?? a.started) + t.bossMax,
1650
+ idleMs: t.bossAway, capAt: (a.bossSince ?? a.started + (a.slept ?? 0)) + t.bossMax,
1630
1651
  ...(a.closing !== undefined || a.terminating !== undefined ? { closing: true as const } : {}),
1631
1652
  };
1632
1653
  };
@@ -8,6 +8,8 @@ import { type BookEntry, markBook, sessionLine } from "./workerbook.ts";
8
8
  // handles it; the sweep then closes its tab and removes its worktree when nothing would be lost. A worker gone without a report, or idle 60 minutes without one, gets a code receipt instead.
9
9
 
10
10
  export const WORKER_STOP_MS = 60 * 60_000;
11
+ /** A sweep this long after the last (they come every 15 s) means the computer slept or the server stood still: the gap is no worker's idle time (runs.ts `giveBack`). */
12
+ export const SWEEP_SLEPT_MS = 5 * 60_000;
11
13
  const REPORT_MAX = 48_000;
12
14
 
13
15
  export interface RelayDeps {
@@ -64,6 +66,7 @@ export interface EndDeps {
64
66
 
65
67
  export function createWorkerEnds(d: EndDeps) {
66
68
  const idleFrom = new Map<string, number>(), goneSeen = new Map<string, number>();
69
+ let lastSweep: number | undefined;
67
70
  /** The worktree at the end: removed when clean and pushed or untouched, else kept and the tower told. The line says which, for a receipt. */
68
71
  const tidy = async (row: WorkerRow): Promise<string> => {
69
72
  const w = row.route.worker!; // git finds the repository from the worktree itself
@@ -117,10 +120,13 @@ export function createWorkerEnds(d: EndDeps) {
117
120
  };
118
121
  return {
119
122
  async sweep(): Promise<void> {
120
- const rows = d.rows(), live = new Set(rows.map((r) => r.route.to));
123
+ const at = d.now(), rows = d.rows(), live = new Set(rows.map((r) => r.route.to));
124
+ // A worker idle when the lid closed is not stopped at the wake: the time asleep moves its idle clock on (measured from the end of the last sweep, so a slow sweep is no sleep).
125
+ if (lastSweep !== undefined && at - lastSweep > SWEEP_SLEPT_MS) for (const [k, v] of idleFrom) idleFrom.set(k, v + at - lastSweep);
121
126
  for (const k of [...idleFrom.keys()]) if (!live.has(k)) idleFrom.delete(k);
122
127
  tidied = new Map([...tidied].filter(([k]) => live.has(k)));
123
128
  for (const row of rows) await one(row).catch((e: Error) => d.log("worker-sweep-failed", { main: row.route.to, error: e.message.slice(0, 160) }));
129
+ lastSweep = d.now();
124
130
  },
125
131
  };
126
132
  }