benignswarm 0.12.113 → 0.12.114
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/dist/commands/machine.js +3 -2
- package/dist/commands/watch.js +38 -62
- package/dist/help.js +5 -4
- package/dist/image-caches.js +37 -0
- package/dist/output.js +3 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/machine.js
CHANGED
|
@@ -24,6 +24,7 @@ import { defaultWorkspaceWritableRoots } from "../start-options.js";
|
|
|
24
24
|
import { antigravityPath, antigravitySandboxPermissions, antigravityTurnArgs, antigravityTurnEnv, parseAntigravityJson } from "../antigravity.js";
|
|
25
25
|
import { bootTimeMs } from "../boot-time.js";
|
|
26
26
|
import { DEFAULT_CACHE_FLOOR_PCT, manageBuildCaches } from "../build-caches.js";
|
|
27
|
+
import { imageCacheBaseDir, imageCacheProjectRoot, projectsWithImageCaches } from "../image-caches.js";
|
|
27
28
|
import { agentContainerName, agentContainerRunArgs, detectEc2Host, ensurePinnedImagePulled, isolatedBuildCommand, isolatedDevcontainerBuildCommand, isolatedImagePullCommands, isolatedSubprocessEnv, probeContainerImdsIsolation, networklessRuntimeWrapper, parseContainerRuntimeVersion, probeImdsIsolation, probeNestedSandbox, readGitIdentity, resolveSessionSecretDelivery, resolveWritableMounts, validateDevcontainerSpec, BUILD_SECRET_KEY_NAME_RE, BUILD_SECRET_CONTENT_RE, containsBuildSecretMaterial, sanitizeBuildDiagnosticText, } from "../container.js";
|
|
28
29
|
import { machineEnvironmentChecks } from "../environment-checks.js";
|
|
29
30
|
import { machineResourceTelemetry, parsePageSize } from "../machine-telemetry.js";
|
|
@@ -804,7 +805,7 @@ export async function launchDesiredSession(opts) {
|
|
|
804
805
|
writableFolders: rawWritable,
|
|
805
806
|
platform: opts.project?.image?.target_arch,
|
|
806
807
|
allowedCaches: opts.project?.image?.allowed_caches ?? [],
|
|
807
|
-
cacheRootDir:
|
|
808
|
+
cacheRootDir: imageCacheProjectRoot(opts.accountId, opts.project?.id ?? opts.s.project ?? "account"),
|
|
808
809
|
detach: true,
|
|
809
810
|
extraEnv: {
|
|
810
811
|
...opts.secretEnv,
|
|
@@ -1227,7 +1228,7 @@ export async function reconcile(m, log, reportIntervalSeconds = 30, deps) {
|
|
|
1227
1228
|
budgetGb: me.machine?.cache_budget_gb ?? null,
|
|
1228
1229
|
floorPct: me.machine?.cache_floor_pct ?? null,
|
|
1229
1230
|
machineCaches: me.machine?.build_caches ?? [],
|
|
1230
|
-
projects,
|
|
1231
|
+
projects: projectsWithImageCaches(accountId, projects, imageCacheBaseDir()),
|
|
1231
1232
|
workdir,
|
|
1232
1233
|
protectedWorktrees,
|
|
1233
1234
|
});
|
package/dist/commands/watch.js
CHANGED
|
@@ -5,7 +5,7 @@ import { drainingUntil } from "../maintenance.js";
|
|
|
5
5
|
import { probeFor, turnHarness } from "../harnesses.js";
|
|
6
6
|
import { applyAck } from "./wake.js";
|
|
7
7
|
import { launchdSessionTypeXml, lingerEnabled, plistLaunchdDomain, loadSystemdUnit, reloadLaunchAgent, removeService, requireInstall, systemdUnit, systemdUserDir, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
|
|
8
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statfsSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import { homedir, userInfo } from "node:os";
|
|
11
11
|
import { basename, dirname, join } from "node:path";
|
|
@@ -725,66 +725,42 @@ export function estimatedTurnCostMicros(reservation, tokens) {
|
|
|
725
725
|
const TURN_RETRY_MS = 5 * 60_000;
|
|
726
726
|
const KEY_CHECK_MS = 5 * 60_000;
|
|
727
727
|
const MACHINE_PRESSURE_NOTICE_INTERVAL_MS = 30 * 60_000;
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
let hash = 0;
|
|
755
|
-
for (const char of `${name}:${pressure.sample_at ?? ""}`)
|
|
756
|
-
hash = (hash * 31 + char.charCodeAt(0)) >>> 0;
|
|
757
|
-
resumeAfter = Date.now() + (hash % 60_000);
|
|
758
|
-
}
|
|
759
|
-
const observedChanged = prior?.state !== state;
|
|
760
|
-
let pendingNotice = prior?.pending_notice;
|
|
761
|
-
if (observedChanged && (state !== "normal" || (prior && prior.state !== "normal"))) {
|
|
762
|
-
pendingNotice = { state, ...(pressure.machine ? { machine: pressure.machine } : {}), ...(pressure.reasons?.length ? { reasons: pressure.reasons.slice(0, 3) } : {}), age_seconds: pressure.age_seconds, ...(prior?.state ? { from_state: prior.state } : {}) };
|
|
728
|
+
const GiB = 1024 ** 3;
|
|
729
|
+
let lastDiskRefusal = null;
|
|
730
|
+
/**
|
|
731
|
+
* The one machine check before a turn starts (WU #517): the checkout's volume and b9s's own state volume
|
|
732
|
+
* must keep at least 1 GiB and 2% free. Stateless: it reads the volumes each time, holds nothing between
|
|
733
|
+
* polls, and logs only when its answer changes. A full disk truncated three agents' state files on ronald
|
|
734
|
+
* (2026-11-11), which is why this guard stays when machine pressure became advisory.
|
|
735
|
+
*/
|
|
736
|
+
export function diskFloorRefusal(paths, statfs = (p) => statfsSync(p)) {
|
|
737
|
+
for (const path of [...new Set(paths)]) {
|
|
738
|
+
let st;
|
|
739
|
+
try {
|
|
740
|
+
st = statfs(path);
|
|
741
|
+
}
|
|
742
|
+
catch (e) {
|
|
743
|
+
// Only a path that no longer exists has no volume to protect; any other failure (EACCES, EIO) means
|
|
744
|
+
// the floor can't be read, which refuses the turn rather than assuming the disk is fine.
|
|
745
|
+
if (e.code === "ENOENT")
|
|
746
|
+
continue;
|
|
747
|
+
return `cannot read free space for ${path}: ${e.code ?? e.message}`;
|
|
748
|
+
}
|
|
749
|
+
const free = Number(st.bavail) * Number(st.bsize);
|
|
750
|
+
const total = Number(st.blocks) * Number(st.bsize);
|
|
751
|
+
const floor = Math.max(GiB, total * 0.02);
|
|
752
|
+
if (free < floor)
|
|
753
|
+
return `the volume holding ${path} has ${(free / GiB).toFixed(1)} GiB free, below its floor of ${(floor / GiB).toFixed(1)} GiB (1 GiB or 2%)`;
|
|
763
754
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
else if (pendingNotice.state === "pressured" || pendingNotice.state === "unknown")
|
|
772
|
-
log(`machine pressure ${pendingNotice.state} on ${machine}${reasons}; light turns may continue, heavy permits remain paused; last sample ${age}; reevaluating on the next machine sample`);
|
|
773
|
-
else if (pendingNotice.from_state && pendingNotice.from_state !== "normal")
|
|
774
|
-
log(`machine pressure cleared on ${machine}; staggered turn recovery begins${resumeAfter && resumeAfter > Date.now() ? ` after ${new Date(resumeAfter).toISOString()}` : " now"}`);
|
|
775
|
-
lastNoticeAt = Date.now();
|
|
776
|
-
pendingNotice = undefined;
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
function diskFloorAllowsTurn(log, env) {
|
|
758
|
+
const refusal = diskFloorRefusal([process.cwd(), configRoot(env)]);
|
|
759
|
+
if (refusal !== lastDiskRefusal) {
|
|
760
|
+
log(refusal ? `no new turn starts: ${refusal}; free space there to continue` : "disk space is back above its floor; turns may start");
|
|
761
|
+
lastDiskRefusal = refusal;
|
|
777
762
|
}
|
|
778
|
-
|
|
779
|
-
state, ...(pressure.machine ? { machine: pressure.machine } : {}), ...(resumeAfter ? { resume_after: resumeAfter } : {}),
|
|
780
|
-
...(criticalHold ? { critical_hold: true } : {}), ...(recoveryPending && !freshNormal ? { recovery_hold: true } : {}),
|
|
781
|
-
...(lastNoticeAt ? { last_notice_at: lastNoticeAt } : {}), ...(pendingNotice ? { pending_notice: pendingNotice } : {}),
|
|
782
|
-
} }, env);
|
|
783
|
-
if (criticalHold)
|
|
784
|
-
return false;
|
|
785
|
-
if (state === "normal" && resumeAfter && Date.now() < resumeAfter)
|
|
786
|
-
return false;
|
|
787
|
-
return true;
|
|
763
|
+
return refusal === null;
|
|
788
764
|
}
|
|
789
765
|
/**
|
|
790
766
|
* One poll in turn mode. While a turn runs nothing else starts: the turn's own hooks (Stop with new
|
|
@@ -970,8 +946,8 @@ export async function turnStep(ctl, probe, timeoutMin, log, wake, name, turnsPer
|
|
|
970
946
|
debug(`no inbox poll: machine maintenance runs until ${maint.end}`);
|
|
971
947
|
return;
|
|
972
948
|
}
|
|
973
|
-
if (!(
|
|
974
|
-
debug("no inbox poll:
|
|
949
|
+
if (!diskFloorAllowsTurn(log, env)) {
|
|
950
|
+
debug("no inbox poll: a volume is below its disk floor; session and pending wake are preserved");
|
|
975
951
|
return;
|
|
976
952
|
}
|
|
977
953
|
const st = readState(name, env);
|
|
@@ -1034,7 +1010,7 @@ export async function beginTurnGuardAttempt(name, turnsPerHour, log, env = proce
|
|
|
1034
1010
|
return false;
|
|
1035
1011
|
}
|
|
1036
1012
|
}
|
|
1037
|
-
if (!(
|
|
1013
|
+
if (!diskFloorAllowsTurn(log, env))
|
|
1038
1014
|
return false;
|
|
1039
1015
|
const before = await turnActivity(name, env);
|
|
1040
1016
|
current = readState(name, env);
|
package/dist/help.js
CHANGED
|
@@ -224,8 +224,9 @@ Machine placement shares capacity across the account's projects: session seats a
|
|
|
224
224
|
run an agent headless: enroll, start or adopt its session, turn-mode watcher
|
|
225
225
|
--machine-session-id is normally supplied by b9s-admin for a managed machine session
|
|
226
226
|
Persistent watcher startup waits a random logged 0..60 s by default; set --startup-jitter-seconds 0 to disable it for a deterministic start.
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
Machine pressure is advisory: it is reported, never a reason to hold a turn. A turn is refused only while
|
|
228
|
+
the checkout's or state volume has under 1 GiB or 2% free (checked fresh each time, nothing latched).
|
|
229
|
+
Heavy machine-job permits still wait for normal, fresh telemetry.
|
|
229
230
|
Claude Code workspace-write defaults to a $1 per-turn cap; configure it with --max-budget-usd
|
|
230
231
|
Account turn-spend caps are set by the account operator separately; token caps support subscriptions,
|
|
231
232
|
missing usage remains reserved. Hard caps alone do not enable judgment capture; the account owner explicitly
|
|
@@ -401,7 +402,7 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
401
402
|
b9s-admin machine list | show <name> | remove <name> [--preview] [--confirm <name> --impact-revision <revision>]
|
|
402
403
|
show includes host readiness, configured disk floors and named readiness refusals; removal previews sessions, work, keys, recovery blockers and replanned slots
|
|
403
404
|
the API requires a fresh revision for removal
|
|
404
|
-
b9s-admin machine companion run <handoff-code> [--confirm <name>] accept a 15-minute, single-use
|
|
405
|
+
b9s-admin machine companion run <handoff-code> [--confirm <name>] accept a 15-minute, single-use handoff from Account > Machines; confirms locally and reports progress
|
|
405
406
|
b9s-admin machine maintenance <name> --at <ISO | HH:MM> --for <30m | 2h> | --cancel a window: no new turns from
|
|
406
407
|
15 min before, its agents away until the machine reports back after booting
|
|
407
408
|
b9s-admin machine resize <name> --type <t> [--instance-id <id>] [--drain-timeout 5m] [--yes] [--on-running-turn wait|proceed|abort] [--extend 5m] [--ssh <host>]
|
|
@@ -444,7 +445,7 @@ BYO AWS cloud machines (the connection is account-scoped; AWS bills the account
|
|
|
444
445
|
|
|
445
446
|
Project devcontainer images & immutable registry builds (console controls in WU #377)
|
|
446
447
|
b9s-admin project image validate --file <.devcontainer/devcontainer.json> [--dockerfile Dockerfile] [--arch linux/amd64|linux/arm64] validate @sha256 pins and reject secrets/host mounts/--privileged
|
|
447
|
-
b9s-admin project image config <project> [--path <path>] [--arch linux/amd64|linux/arm64] [--cache name,...] [--pool-sessions on|off] [--registry <ns>] configure immutable per-account image registry,
|
|
448
|
+
b9s-admin project image config <project> [--path <path>] [--arch linux/amd64|linux/arm64] [--cache name,...] [--pool-sessions on|off] [--registry <ns>] configure immutable per-account image registry, project-scoped writable cache mounts, and SSH-machine container pool opt-in
|
|
448
449
|
b9s-admin project image show <project> active digest, rollback target, latest build, and image capability probes
|
|
449
450
|
b9s-admin project image build <project> --commit <sha> --file <.devcontainer/devcontainer.json> [--dockerfile Dockerfile] [--arch <arch>] build only the reviewed declaration commit; machine validation runs its image probes and project test before ready
|
|
450
451
|
b9s-admin project image activate <project> <sha256:...> explicitly select a ready candidate for future or restarted sessions
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
const CACHE_NAME_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
5
|
+
export function imageCacheBaseDir() {
|
|
6
|
+
return join(homedir(), ".cache", "bschat", "project-image-caches");
|
|
7
|
+
}
|
|
8
|
+
function scopedSegment(kind, id) {
|
|
9
|
+
if (!id.trim())
|
|
10
|
+
throw new Error(`refusing image cache without a ${kind} id`);
|
|
11
|
+
return createHash("sha256").update(`${kind}\0${id}`).digest("hex");
|
|
12
|
+
}
|
|
13
|
+
/** A stable host directory shared only by sessions in the same account and project. */
|
|
14
|
+
export function imageCacheProjectRoot(accountId, projectId, baseDir = imageCacheBaseDir()) {
|
|
15
|
+
return join(baseDir, scopedSegment("account", accountId), scopedSegment("project", projectId));
|
|
16
|
+
}
|
|
17
|
+
export function imageCacheBuildSpecs(accountId, projectId, names, baseDir = imageCacheBaseDir()) {
|
|
18
|
+
return [...new Set(names)].sort().map((name) => {
|
|
19
|
+
if (!CACHE_NAME_RE.test(name))
|
|
20
|
+
throw new Error(`invalid allowed cache name ${JSON.stringify(name)}`);
|
|
21
|
+
return {
|
|
22
|
+
path: join(imageCacheProjectRoot(accountId, projectId, baseDir), name),
|
|
23
|
+
tool: "generic",
|
|
24
|
+
processes: [],
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Adds writable image caches to the same declared-cache budget/cleanup path as build caches. */
|
|
29
|
+
export function projectsWithImageCaches(accountId, projects, baseDir = imageCacheBaseDir()) {
|
|
30
|
+
return projects.map((project) => ({
|
|
31
|
+
name: project.name,
|
|
32
|
+
build_caches: [
|
|
33
|
+
...(project.build_caches ?? []),
|
|
34
|
+
...imageCacheBuildSpecs(accountId, project.id, project.image?.allowed_caches ?? [], baseDir),
|
|
35
|
+
],
|
|
36
|
+
}));
|
|
37
|
+
}
|
package/dist/output.js
CHANGED
|
@@ -53,7 +53,7 @@ export function fmtMessage(m) {
|
|
|
53
53
|
export function fmtStatus(s) {
|
|
54
54
|
const machineWaiting = s.machine_pressure?.waiting === true;
|
|
55
55
|
const parts = [
|
|
56
|
-
`${s.state === "benched" ? "BENCHED " : ""}${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.away ? ` (away until ${s.away.until}: ${s.away.reason})` : s.usage_limit_until ? ` (usage limit until ${s.usage_limit_until})` : machineWaiting
|
|
56
|
+
`${s.state === "benched" ? "BENCHED " : ""}${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.away ? ` (away until ${s.away.until}: ${s.away.reason})` : s.usage_limit_until ? ` (usage limit until ${s.usage_limit_until})` : machineWaiting && !s.machine_pressure.blocks_turns ? " (waiting: heavy machine permit)" : s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : s.liveness === "scheduled" ? ` (checks every ${s.checks_every} min, next ${(s.next_check_at ?? "").slice(11, 16)} UTC)` : s.liveness === "missed" ? ` (missed its ${s.checks_every}-min check)` : ""}`,
|
|
57
57
|
`state=${s.state ?? "-"}`,
|
|
58
58
|
s.goal ? `goal="${s.goal}"` : null,
|
|
59
59
|
s.task ? `task="${s.task}"` : null,
|
|
@@ -61,7 +61,8 @@ export function fmtStatus(s) {
|
|
|
61
61
|
`model=${s.model ?? "-"}`,
|
|
62
62
|
s.machine ? `machine=${s.machine}` : null,
|
|
63
63
|
s.machine_pressure ? `machine_health=${s.machine_pressure.state ?? "unknown"} (sample_age=${typeof s.machine_pressure.age_seconds === "number" ? `${Math.floor(s.machine_pressure.age_seconds)}s` : "unknown"}${s.machine_pressure.reasons?.length ? `; reasons=${s.machine_pressure.reasons.join(",")}` : ""})` : null,
|
|
64
|
-
|
|
64
|
+
// WU #517: pressure is advisory, so an older API's blocks_turns is not rendered as a held turn.
|
|
65
|
+
machineWaiting && !s.machine_pressure.blocks_turns ? "machine_wait=heavy_permit" : null,
|
|
65
66
|
s.capabilities?.length ? `capabilities=${s.capabilities.map((c) => `${c.name}:${c.ready ? c.version ?? "ok" : c.error ?? "stale/unknown"}`).join(",")}` : null,
|
|
66
67
|
s.branch ? `branch=${s.branch}${s.dirty ? "*" : ""}@${s.head ?? "?"}` : null,
|
|
67
68
|
s.worktree ? `worktree=${s.worktree}` : null,
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.114";
|