neurastream 0.2.78 → 0.2.80

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.80",
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",
@@ -633,7 +633,9 @@ export function deliverOwnerInbox(pi: ExtensionHost, cfg: Config): void {
633
633
  let activeAdapterReset: (() => void) | null = null;
634
634
  /** This process's held Main session lock (plan 20261103_1146 P2): the first main session_start
635
635
  * locks `<queue_state>/mains/<id>/session.lock` for the process lifetime — the kernel frees it
636
- * when the process dies, so no release bookkeeping on any shutdown path. */
636
+ * when the process dies. A factory re-run must not release it (P4): dropping it lets another
637
+ * process take the id, and a new flock of the same file in this process is busy. reset() is the
638
+ * only release, so tests do not leak the flock into the next file. */
637
639
  let heldSessionLock: HeldLock | null = null;
638
640
  /** The limit tick: one check of the open episode every 30 s (plan 20261027_1500 P3). */
639
641
  const LIMIT_TICK_MS = 30_000;
@@ -1418,12 +1420,12 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
1418
1420
  flight = null;
1419
1421
  };
1420
1422
  // Clear the previous adapter's armed grace timer before this one overwrites the pointer (P3c).
1423
+ // Do not release heldSessionLock: this runs on every factory re-entry, and the lock is
1424
+ // process-lifetime (plan 20261103_1146 P4). reset() still releases it.
1421
1425
  activeAdapterReset?.();
1422
1426
  activeAdapterReset = (): void => {
1423
1427
  clearRolloverState();
1424
1428
  stopLimitTick();
1425
- heldSessionLock?.release();
1426
- heldSessionLock = null;
1427
1429
  };
1428
1430
  // The launcher restarts omp: the request file carries the note and the editor draft, and omp
1429
1431
  // shuts down only after the file is written. A failed write keeps the session running.
@@ -1810,13 +1812,16 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
1810
1812
  });
1811
1813
  }
1812
1814
 
1813
- /** Clear the active adapter's rollover state. Tests call this in afterAll so a stale
1814
- * grace-period timer does not fire into a later test file's sandbox paths (P3c). */
1815
+ /** Clear the active adapter's rollover state and release the session lock. Tests call this in
1816
+ * afterAll so a stale grace-period timer does not fire into a later test file's sandbox paths
1817
+ * (P3c), and so the process-lifetime flock does not leak into the next file (P4). */
1815
1818
  export function reset(): void {
1816
1819
  if (activeAdapterReset) {
1817
1820
  activeAdapterReset();
1818
1821
  activeAdapterReset = null;
1819
1822
  }
1823
+ heldSessionLock?.release();
1824
+ heldSessionLock = null;
1820
1825
  }
1821
1826
 
1822
1827
  /** package.json omp.extensions entry. */
@@ -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++;