neurastream 0.2.78 → 0.2.79

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": "neurastream",
3
- "version": "0.2.78",
3
+ "version": "0.2.79",
4
4
  "description": "Guardrails for running many AI coding agents at once: plan queue, blockers, call budgets, provider caps, scoring, merge-verified close.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -2,7 +2,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import { basename, dirname, join } from "node:path";
3
3
  import type { Config } from "../../core/config.ts";
4
4
  import type { MainSession, Run, RunMessage, RunSource, RunStatus, TaskResult } from "../../core/adapter.ts";
5
- import { nowSec } from "../../core/clock.ts";
5
+ import { bootSec, nowSec } from "../../core/clock.ts";
6
6
  import { readBudgets } from "../../core/guards.ts";
7
7
  import { pyDumps } from "../../core/pyjson.ts";
8
8
 
@@ -249,6 +249,15 @@ function build(file: string, cfg: Config, mtime: number, agentsDir: string): Run
249
249
  state = "DIED: never replied";
250
250
  neverReplied = true;
251
251
  }
252
+ // A session last written before the machine's boot time cannot be alive: the reboot killed it
253
+ // (INCIDENT I-20261103-81). Main's own rows keep the idle bound; a crash without a reboot
254
+ // (no boot-time evidence) is out of scope.
255
+ let bootDead = false;
256
+ const boot = bootSec();
257
+ if (!id.startsWith("MAIN") && !exited && !err && !done && boot !== null && mtime < boot) {
258
+ state = "DIED: killed before the last boot";
259
+ bootDead = true;
260
+ }
252
261
  if ((state.startsWith("RUNNING") || state.startsWith("WAITING")) && !id.startsWith("MAIN")) {
253
262
  const cap = readBudgets(cfg.paths.queue_state)[id] ?? cfg.guards.sub_max_calls;
254
263
  if (calls > cap) state += ` OVER-BUDGET(${calls}>${cap} calls)`;
@@ -278,7 +287,7 @@ function build(file: string, cfg: Config, mtime: number, agentsDir: string): Run
278
287
  scoreModel,
279
288
  scoreCost,
280
289
  scoreHours: ((last ?? 0) - (first ?? 0)) / 3600,
281
- scoreRunning: neverReplied ? false : !exited && !scoreErr && !done,
290
+ scoreRunning: neverReplied || bootDead ? false : !exited && !scoreErr && !done,
282
291
  scoreSurvived: neverReplied ? false : done && !scoreErr,
283
292
  scoreEnd: scoreErr || (done ? "done" : "no final message"),
284
293
  };
package/src/core/clock.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Wall clock. Tests pin NEURASTREAM_NOW (unix seconds) so output matches a frozen original.
2
2
 
3
+ import { readFileSync } from "node:fs";
4
+
3
5
  export function nowSec(): number {
4
6
  const raw = process.env.NEURASTREAM_NOW;
5
7
  if (raw !== undefined && raw !== "") {
@@ -9,6 +11,23 @@ export function nowSec(): number {
9
11
  return Date.now() / 1000;
10
12
  }
11
13
 
14
+ // Boot time of the machine (unix seconds): NEURASTREAM_BOOT pins it for tests, as NEURASTREAM_NOW
15
+ // pins nowSec; else the kernel's btime line. null when neither is readable (non-Linux): no boot
16
+ // rule then.
17
+ export function bootSec(): number | null {
18
+ const raw = process.env.NEURASTREAM_BOOT;
19
+ if (raw !== undefined && raw !== "") {
20
+ const n = Number(raw);
21
+ if (Number.isFinite(n)) return n;
22
+ }
23
+ try {
24
+ const m = /^btime (\d+)$/m.exec(readFileSync("/proc/stat", "utf8"));
25
+ return m ? Number(m[1]) : null;
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
12
31
  export function strftime(epoch: number, fmt: string): string {
13
32
  const d = new Date(epoch * 1000);
14
33
  const p = (n: number) => String(n).padStart(2, "0");
@@ -2425,8 +2425,9 @@ export function checkStop(e: StopEvent, cfg: Config): Decision {
2425
2425
  }
2426
2426
  }
2427
2427
  if (open.length === 0) return { ...ALLOW, state };
2428
- if (liveSubagents(e.ledgerText).length > 0) {
2429
- log(cfg.paths.guard_log, "ALLOW stop: live subagents");
2428
+ const live = liveSubagents(e.ledgerText);
2429
+ if (live.length > 0) {
2430
+ log(cfg.paths.guard_log, `ALLOW stop: live subagents: ${live.join(", ")}`);
2430
2431
  return { ...ALLOW, state };
2431
2432
  }
2432
2433
  if (state.callsSinceStop === 0) state.idleStops++;