benignswarm 0.12.107 → 0.12.109
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.
|
@@ -190,7 +190,10 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
190
190
|
}
|
|
191
191
|
catch { /* A machine without a live sample still uses its last stable report. */ }
|
|
192
192
|
const rep = liveReport ?? m.report ?? {};
|
|
193
|
+
const pressureText = (pressure) => `some ${pressure?.some_avg10 ?? "unknown"}% / full ${pressure?.full_avg10 ?? "unknown"}% (10s avg)`;
|
|
194
|
+
const agentPressure = rep.agent_cgroup_pressure;
|
|
193
195
|
const head = [
|
|
196
|
+
...[['I/O', 'io_pressure'], ['Memory', 'memory_pressure'], ['CPU', 'cpu_pressure']].map(([label, key]) => ` ${label} PSI host: ${pressureText(rep[key])}; agents: ${agentPressure?.status === "available" ? `${pressureText(agentPressure[key])} (${agentPressure.source})` : `${agentPressure?.status ?? "unknown"}; host PSI used when available`}${liveReport ? "" : "; live sample unavailable"}`),
|
|
194
197
|
`${m.name}: last report ${m.last_report_at ?? "never"}; labels ${(m.labels ?? []).join(", ") || "(none)"}; slots ${m.slots ?? "auto"}; writable ${(m.writable ?? []).join(", ") || "-"}; workdir ${rep.workdir ?? m.workdir ?? "~/bschat"}${rep.workdir_free_bytes ? ` (${Math.round(rep.workdir_free_bytes / 1e9)} GB free)` : ""}; cache budget ${m.cache_budget_gb ?? 40} GB (floor ${m.cache_floor_pct ?? 15}%)`,
|
|
195
198
|
rep.os ? ` ${rep.os}/${rep.arch} ${rep.hostname} as ${rep.user}; ${rep.cpus ?? "?"} CPUs, ${rep.mem_total_bytes ? `${Math.round(rep.mem_total_bytes / 1024 ** 3)} GB RAM` : "? RAM"}; b9s ${rep.bschat?.version}; codex ${rep.codex ? `${rep.codex.version}, ${rep.codex.logged_in ? "logged in" : "NOT logged in"}, sandbox ${rep.codex.sandbox ? (rep.codex.sandbox.ok ? "ok" : `FAILS (${rep.codex.sandbox.error})`) : "?"}` : "missing"}; hooks ${rep.managed_hooks ? "managed by policy" : "user-level"}; linger ${rep.linger ?? "n/a"}; disk free ${rep.disk_free_bytes ? `${Math.round(rep.disk_free_bytes / 1e9)} GB` : "?"}` : " (no report yet: is its daemon running?)",
|
|
196
199
|
rep.os ? ` Antigravity: ${rep.antigravity ? `${rep.antigravity.version ?? "agy"}, ${rep.antigravity.available ? "available" : "unavailable"}, ${rep.antigravity.logged_in ? "logged in" : "not logged in"}, sandbox ${rep.antigravity.sandbox ? (rep.antigravity.sandbox.ok ? "ok" : `FAILS (${rep.antigravity.sandbox.error})`) : "not checked"}` : "not installed"}` : null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, readlinkSync, realpathSync, readFileSync } from "node:fs";
|
|
1
|
+
import { readdirSync, readlinkSync, realpathSync, readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
3
|
import { isAbsolute, relative, sep } from "node:path";
|
|
4
4
|
const run = (command, args) => {
|
|
@@ -269,6 +269,57 @@ function linuxListenersForPid(pid) {
|
|
|
269
269
|
}
|
|
270
270
|
return [...new Set(out)];
|
|
271
271
|
}
|
|
272
|
+
function readLinuxProcessOrigin(pid, ppid) {
|
|
273
|
+
let parentUid = null;
|
|
274
|
+
let cgroup = null;
|
|
275
|
+
try {
|
|
276
|
+
parentUid = statSync(`/proc/${ppid}`).uid;
|
|
277
|
+
}
|
|
278
|
+
catch { /* unknown stays unknown */ }
|
|
279
|
+
try {
|
|
280
|
+
cgroup = readFileSync(`/proc/${pid}/cgroup`, "utf8").trim();
|
|
281
|
+
}
|
|
282
|
+
catch { /* unknown stays unknown */ }
|
|
283
|
+
return { parentPid: ppid, parentUid, cgroup };
|
|
284
|
+
}
|
|
285
|
+
/** True when the process no longer runs: /proc/<pid> is gone, or its state is Z (zombie) or X (dead). */
|
|
286
|
+
function linuxProcessEnded(pid) {
|
|
287
|
+
let stat;
|
|
288
|
+
try {
|
|
289
|
+
stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
return isDisappearedProcess(error);
|
|
293
|
+
}
|
|
294
|
+
const state = stat.slice(stat.lastIndexOf(")") + 2, stat.lastIndexOf(")") + 3);
|
|
295
|
+
return state === "Z" || state === "X";
|
|
296
|
+
}
|
|
297
|
+
/** User services a host runs for its user that are allowed to stay uninspected. Named, never by pattern. */
|
|
298
|
+
const UNINSPECTABLE_USER_SERVICES = new Set(["gpg-agent.service", "ssh-agent.service"]);
|
|
299
|
+
/**
|
|
300
|
+
* Why an uninspectable same-user process may be left out of a worktree scan, or null when it must fail
|
|
301
|
+
* the scan. The operator's rule (WU #472, 2026-11-17) allows exactly three exclusions:
|
|
302
|
+
* - a child of a root-owned process other than PID 1: login and session leaders (sshd-session).
|
|
303
|
+
* - a member of the user manager's init.scope: systemd --user and sd-pam.
|
|
304
|
+
* - a member of a named user service in UNINSPECTABLE_USER_SERVICES.
|
|
305
|
+
* Linux cannot prove where a non-dumpable process works, so these are a policy, not a proof. Accepted
|
|
306
|
+
* residual risk: a root-owned supervisor or subreaper that adopts or launches same-user work inside a
|
|
307
|
+
* checkout would pass the first rule; BenignSwarm hosts run no such supervisor for agent work.
|
|
308
|
+
* Unknown facts, PID 1 parents, transient run-* units and org.benignswarm.* units all return null.
|
|
309
|
+
*/
|
|
310
|
+
export function uninspectableExclusion(o) {
|
|
311
|
+
if (o.parentUid === 0 && o.parentPid > 1)
|
|
312
|
+
return "child of a root-owned daemon (login session leader)";
|
|
313
|
+
const unified = o.cgroup?.split("\n").find((l) => l.startsWith("0::"))?.slice(3) ?? null;
|
|
314
|
+
if (!unified)
|
|
315
|
+
return null;
|
|
316
|
+
if (/\/user@\d+\.service\/init\.scope$/.test(unified))
|
|
317
|
+
return "the user's systemd manager";
|
|
318
|
+
const unit = /\/user@\d+\.service\/app\.slice\/([^/]+\.service)$/.exec(unified)?.[1];
|
|
319
|
+
if (unit && UNINSPECTABLE_USER_SERVICES.has(unit))
|
|
320
|
+
return `user service ${unit}`;
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
272
323
|
function readLinuxProcessPaths(rows, worktree) {
|
|
273
324
|
const cwd = new Map();
|
|
274
325
|
const listeners = new Map();
|
|
@@ -278,8 +329,21 @@ function readLinuxProcessPaths(rows, worktree) {
|
|
|
278
329
|
cwd.set(row.pid, readlinkSync(`/proc/${row.pid}/cwd`));
|
|
279
330
|
}
|
|
280
331
|
catch (error) {
|
|
281
|
-
if (
|
|
282
|
-
|
|
332
|
+
if (isDisappearedProcess(error))
|
|
333
|
+
continue;
|
|
334
|
+
// The rows are this user's own processes (ps -u). The kernel denies /proc/<pid>/cwd (EACCES) for a
|
|
335
|
+
// non-dumpable process even to its own user. Non-dumpable is a setting any process may take, so it
|
|
336
|
+
// proves nothing about where the process works. Only the exclusions in uninspectableExclusion (the
|
|
337
|
+
// operator's rule) are left out; any other uninspectable process fails the scan (WU #472).
|
|
338
|
+
if (error.code === "EACCES") {
|
|
339
|
+
const excluded = uninspectableExclusion(readLinuxProcessOrigin(row.pid, row.parent_pid));
|
|
340
|
+
if (excluded)
|
|
341
|
+
continue;
|
|
342
|
+
// A process that exited while being scanned (gone, or a zombie awaiting its parent) is not working anywhere.
|
|
343
|
+
if (linuxProcessEnded(row.pid))
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
throw new Error(`cannot inspect working directory for process ${row.pid}: ${error.message}`);
|
|
283
347
|
}
|
|
284
348
|
}
|
|
285
349
|
for (const row of rows) {
|
|
@@ -298,7 +362,13 @@ export function scanWorktreeProcesses(worktree, scope, runner = run, sampledAt =
|
|
|
298
362
|
const uid = process.getuid?.();
|
|
299
363
|
if (uid === undefined)
|
|
300
364
|
throw new Error(`host process inspection is unsupported on ${process.platform}`);
|
|
301
|
-
|
|
365
|
+
// Only this user's processes. On Linux (procps) "-U uid -ax" is a union that lists every process on the
|
|
366
|
+
// host, and reading another user's /proc/<pid>/cwd fails with EACCES, which made every scan throw and
|
|
367
|
+
// every stopped session's turn "unknown" (WU #472); "-u uid" alone selects by effective user there.
|
|
368
|
+
// BSD ps on macOS needs -ax for processes without a terminal, and -U already restricts it to the user.
|
|
369
|
+
const ps = runner("ps", process.platform === "linux"
|
|
370
|
+
? ["-u", String(uid), "-ww", "-o", "pid=,ppid=,lstart=,command="]
|
|
371
|
+
: ["-U", String(uid), "-ww", "-axo", "pid=,ppid=,lstart=,command="]);
|
|
302
372
|
if (ps.status !== 0)
|
|
303
373
|
throw new Error(`could not inspect the host process table: ${ps.stderr.trim() || `ps exited ${ps.status}`}`);
|
|
304
374
|
const rows = parsePsProcessRows(ps.stdout);
|
|
@@ -115,6 +115,18 @@ export function machineResourceTelemetry(hostPlatform, readText, pageSizeBytes,
|
|
|
115
115
|
const memoryPressure = pressure("memory");
|
|
116
116
|
const cpuPressure = pressure("cpu");
|
|
117
117
|
const ioPressure = pressure("io");
|
|
118
|
+
const cgroupText = linux ? readText("/proc/self/cgroup") : null;
|
|
119
|
+
const unifiedPath = /^0::(\/[^\n\r]*)$/m.exec(cgroupText ?? "")?.[1];
|
|
120
|
+
const legacyCgroup = !!cgroupText && !unifiedPath && /^\d+:[^:\n]+:/m.test(cgroupText);
|
|
121
|
+
const components = unifiedPath?.split("/").filter(Boolean) ?? [];
|
|
122
|
+
const appSlice = components.indexOf("app.slice");
|
|
123
|
+
const userSlice = /^user-(\d+)\.slice$/.exec(components[1] ?? "");
|
|
124
|
+
const userService = /^user@(\d+)\.service$/.exec(components[2] ?? "");
|
|
125
|
+
const safePath = appSlice === 3 && components[0] === "user.slice" && !!userSlice && !!userService && userSlice[1] === userService[1]
|
|
126
|
+
? "/" + components.slice(0, appSlice + 1).join("/") : null;
|
|
127
|
+
const groupPressure = (kind) => safePath ? parsePressureStall(readText(`/sys/fs/cgroup${safePath}/${kind}.pressure`) ?? "") : null;
|
|
128
|
+
const groupMemory = groupPressure("memory"), groupCpu = groupPressure("cpu"), groupIo = groupPressure("io");
|
|
129
|
+
const groupAvailable = [groupMemory, groupCpu, groupIo].every((value) => value?.some?.avg10 != null) && groupIo?.full?.avg10 != null && groupMemory?.full?.avg10 != null;
|
|
118
130
|
const swapTotal = linuxMemory?.swap_total_bytes ?? macSwap?.total_bytes ?? null;
|
|
119
131
|
const swapUsed = linuxMemory?.swap_used_bytes ?? macSwap?.used_bytes ?? null;
|
|
120
132
|
const swapAvailable = swapTotal !== null && swapUsed !== null;
|
|
@@ -139,6 +151,13 @@ export function machineResourceTelemetry(hostPlatform, readText, pageSizeBytes,
|
|
|
139
151
|
memory_pressure: flattenPressure(memoryPressure),
|
|
140
152
|
cpu_pressure: flattenPressure(cpuPressure),
|
|
141
153
|
io_pressure: flattenPressure(ioPressure),
|
|
154
|
+
agent_cgroup_pressure: {
|
|
155
|
+
source: safePath,
|
|
156
|
+
status: !linux || legacyCgroup ? "unsupported" : groupAvailable ? "available" : "unavailable",
|
|
157
|
+
memory_pressure: flattenPressure(groupMemory),
|
|
158
|
+
cpu_pressure: flattenPressure(groupCpu),
|
|
159
|
+
io_pressure: flattenPressure(groupIo),
|
|
160
|
+
},
|
|
142
161
|
metric_availability: {
|
|
143
162
|
memory: linux ? (typeof linuxMemory?.total_bytes === "number" && typeof linuxMemory?.available_bytes === "number" ? "available" : "unavailable") : darwin ? (typeof macMemory?.available_bytes === "number" ? "available" : "unavailable") : "unsupported",
|
|
144
163
|
...(darwin ? { memory_source: "vm_stat_reclaimable_pages" } : {}),
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.109";
|