@botbuddy/cli 1.117.0 → 1.118.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.118.0
4
+
5
+ - BOT-3519: `bb stack run --test-child --child-placement require-host` places the stack lease only on a host that can run the child. The CLI derives the child's whole prerequisite set before the lease (toolchain or the declared tools, `child-layer`, `system-packages-<distro>` for the head's declared system packages, `host-local-callback` for a `--callback-port` run, and `--child-requires`) and sends it as `child_host_prerequisites`. The control plane then weighs only owned hosts in `child_exec_hosts` whose capabilities, reported in the last 15 minutes, provide all of it; a busy one queues the lease as usual. When none qualifies the run ends before any lease or bundle upload with exit 5 and `CHILD_HOST_PREREQUISITES_MISSING` (also for a `--host` pin that lacks one): the receipt's `child_placement.considered[]` names each host with `child_reason` and `missing_prerequisites`, and the run prints one line per host. When the only host that could run it is draining or in maintenance, the code is `CHILD_HOST_UNAVAILABLE` and `child_placement.child_host` names it. `prefer-host` is unchanged. Needs MCP 2.158.0.
6
+
3
7
  ## 1.117.0
4
8
 
5
9
  - BOT-3463: a run started by `bb stack run`, `bb run` (foreground and detached, so `bb test` and `bb push` too) owns every process its command launches. The child's environment carries a run-scoped marker (`BOTBUDDY_RUN_ID`, `BOTBUDDY_RUN_REGISTRY`) that every descendant inherits, `setsid` daemons included, and the run writes an owner record under `~/.botbuddy/owned-runs/` (0600). When the run ends (exit, signal, timeout, lease loss) its owner stops what is still marked, plus the child's process group and its descendants: SIGTERM, then SIGKILL after 5 s. A detached worker whose command exited lets its output drain for 2 s, then stops what kept the pipes open. When the owner itself dies (SIGKILL), the per-machine reaper (`bb __reap-orphans`, started by bb, one lock per machine) stops that run's tree within one 10 s interval. A `bb` invocation also starts a sweep when none ran for 10 minutes; it stops leftovers of earlier releases by their run-scoped `BOTBUDDY_STACK_LEASE_ID` / `BOTBUDDY_TEST_RUN_ID` marker once the run's top process has only init above it. Processes are never matched by name: one without a marker, such as a dev server started by hand, is never touched. Each stopped process group is one `sensor_events` row (`bb-cli` / `run_process_reaped`: run id, PID, PGID, age), kept in a local outbox until `sensor-ingest` takes it. `BOTBUDDY_RUN_REAPER=off` disables the reaper. Host test children are unchanged: their systemd unit (`KillMode=control-group`) already ends with the run.
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.117.0",
3
- "source_commit": "733fb1c67fcc343490a74b98677ead3158aa70c5",
4
- "source_sha256": "2276e0c95a7db937521fc6e035b3c3fef8c6210766589264210f0748a05139f0",
2
+ "release_version": "1.118.1",
3
+ "source_commit": "223984d2978836d0c0b6a0189e564e98660dcf84",
4
+ "source_sha256": "8918a3015bdde8b9939f222acf8e15847a4830986a01351eec49bee1e24a0403",
5
5
  "target": "darwin-arm64",
6
- "sha256": "00c84c074ec601776773a6a69b6b7e3a64b6d46ca2b43ff40cad9864f9c85e63"
6
+ "sha256": "b8a204cfcfae4486b13d8240d5928864a0df4f053fcc0038f90d5377c74b6c88"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.117.0",
3
- "source_commit": "733fb1c67fcc343490a74b98677ead3158aa70c5",
4
- "source_sha256": "2276e0c95a7db937521fc6e035b3c3fef8c6210766589264210f0748a05139f0",
2
+ "release_version": "1.118.1",
3
+ "source_commit": "223984d2978836d0c0b6a0189e564e98660dcf84",
4
+ "source_sha256": "8918a3015bdde8b9939f222acf8e15847a4830986a01351eec49bee1e24a0403",
5
5
  "target": "linux-x64",
6
- "sha256": "7e3673b294a9d0133cf15436130238201f319d4e49f6acf2288b74f5628e8f69"
6
+ "sha256": "42b817ee885c407c0bcf99c678a0dbb5e89b464a83e3dca93579246e93590958"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.117.0",
4
- "source_commit": "733fb1c67fcc343490a74b98677ead3158aa70c5",
5
- "source_sha256": "2276e0c95a7db937521fc6e035b3c3fef8c6210766589264210f0748a05139f0",
3
+ "release_version": "1.118.1",
4
+ "source_commit": "223984d2978836d0c0b6a0189e564e98660dcf84",
5
+ "source_sha256": "8918a3015bdde8b9939f222acf8e15847a4830986a01351eec49bee1e24a0403",
6
6
  "targets": {
7
7
  "darwin-arm64": {
8
8
  "goos": "darwin",
9
9
  "goarch": "arm64",
10
10
  "binary": "daemon/bin/darwin-arm64/botbuddy-daemon",
11
- "sha256": "00c84c074ec601776773a6a69b6b7e3a64b6d46ca2b43ff40cad9864f9c85e63",
11
+ "sha256": "b8a204cfcfae4486b13d8240d5928864a0df4f053fcc0038f90d5377c74b6c88",
12
12
  "mode": "0755"
13
13
  },
14
14
  "linux-x64": {
15
15
  "goos": "linux",
16
16
  "goarch": "amd64",
17
17
  "binary": "daemon/bin/linux-x64/botbuddy-daemon",
18
- "sha256": "7e3673b294a9d0133cf15436130238201f319d4e49f6acf2288b74f5628e8f69",
18
+ "sha256": "42b817ee885c407c0bcf99c678a0dbb5e89b464a83e3dca93579246e93590958",
19
19
  "mode": "0755"
20
20
  }
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/cli",
3
- "version": "1.117.0",
3
+ "version": "1.118.1",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,6 +17,7 @@ import { spawnSync } from "node:child_process";
17
17
  import { readFileSync } from "node:fs";
18
18
  import { homedir, platform } from "node:os";
19
19
  import { basename, join } from "node:path";
20
+ import { cmdHostUpgrade, HOST_UPGRADE_USAGE } from "./host-upgrade.mjs";
20
21
 
21
22
  export const HELPER_WORKER_LABEL = "com.botbuddy.helper.worker";
22
23
  export const HELPER_WORKER_BINARY = "botbuddyhelper-worker";
@@ -74,7 +75,7 @@ export function readHelperHostKey({ home = homedir(), nowMs = Date.now(), readFi
74
75
  };
75
76
  }
76
77
 
77
- const HOST_USAGE = "Usage: bb host key [--json]";
78
+ const HOST_USAGE = "Usage: bb host key [--json] | bb host upgrade request|status|start …";
78
79
 
79
80
  export function hostHelp() {
80
81
  return `${HOST_USAGE}
@@ -83,16 +84,21 @@ Prints this Mac's managed-container host key from the BotBuddy Helper's status
83
84
  file, whatever the file's age: the key is this machine's static identity. A file
84
85
  older than ${HELPER_STATUS_FRESH_SECONDS} s still prints the key (exit 0) with a freshness warning on
85
86
  stderr. Exit 4 when the file is missing or names no host key.
86
- --json prints {host_key, checked_at, age_seconds, fresh, path}.`;
87
+ --json prints {host_key, checked_at, age_seconds, fresh, path}.
88
+
89
+ ${HOST_UPGRADE_USAGE}
90
+ Pre-approved drain → daemon upgrade → undrain cycle (BOT-3551); see \`bb host upgrade --help\`.`;
87
91
  }
88
92
 
89
93
  /** `bb host key [--json]` → exit code. */
90
94
  export async function cmdHost(args, {
91
95
  log = (line) => console.log(line), errorLog = (line) => console.error(line),
92
96
  read = () => readHelperHostKey(),
97
+ upgrade = (upgradeArgs) => cmdHostUpgrade(upgradeArgs, { log, errorLog }),
93
98
  } = {}) {
94
99
  const [sub, ...rest] = args;
95
100
  if (sub === "help" || sub === "--help" || sub === "-h") { log(hostHelp()); return 0; }
101
+ if (sub === "upgrade") return upgrade(rest);
96
102
  const json = rest.includes("--json");
97
103
  const unknown = rest.filter((a) => a !== "--json");
98
104
  if (sub !== "key" || unknown.length) { errorLog(HOST_USAGE); return 4; }
@@ -0,0 +1,101 @@
1
+ // BOT-3551 — `bb host upgrade request|status|start`: pre-approved host upgrade
2
+ // cycles. A thin client of the MCP tools request_host_upgrade_grant,
3
+ // get_host_upgrade_grant and start_host_upgrade_cycle (ADR 2026-11-20): every
4
+ // permission, expiry and single-use rule is the server's. The agent session
5
+ // token is required so the grant binds to this session's agent.
6
+ //
7
+ // bb host upgrade request <bbh-…> [--reason <text>] [--json]
8
+ // → prints the code and link for the host owner, and the exact bb wait.
9
+ // bb host upgrade status <grant_id> [--json]
10
+ // bb host upgrade start <grant_id> [--json]
11
+ // → starts the one drain → daemon upgrade → undrain cycle.
12
+ import { callToolJson } from "./api.mjs";
13
+
14
+ export const HOST_UPGRADE_USAGE =
15
+ "Usage: bb host upgrade request <host_key> [--reason <text>] [--json] | status <grant_id> [--json] | start <grant_id> [--json]";
16
+
17
+ export function hostUpgradeHelp() {
18
+ return `${HOST_UPGRADE_USAGE}
19
+
20
+ Pre-approve one drain → daemon upgrade → undrain cycle on a host, the way a
21
+ remote \`bb login\` is approved: \`request\` prints a short code and a link on
22
+ app.bot-buddy.ai for the host's owner. After the owner approves, \`start\` runs
23
+ the cycle once (within 24 h). The host drains, takes the stable daemon release
24
+ when idle, and returns to active. The grant is bound to this agent session and
25
+ this host, single use, and revocable by the owner from the same page.
26
+
27
+ Exit codes: 0 ok · 3 refused by the server (code on stderr) · 4 usage ·
28
+ 5 not signed in to an agent session (run \`bb doctor --fix\`) · 6 transport.`;
29
+ }
30
+
31
+ const TOOLS = { request: "request_host_upgrade_grant", status: "get_host_upgrade_grant", start: "start_host_upgrade_cycle" };
32
+
33
+ function parse(args) {
34
+ const [sub, ...rest] = args;
35
+ if (!TOOLS[sub]) return null;
36
+ let json = false; let reason = null; const positional = [];
37
+ for (let i = 0; i < rest.length; i++) {
38
+ const a = rest[i];
39
+ if (a === "--json") json = true;
40
+ else if (a === "--reason" && sub === "request" && i + 1 < rest.length) reason = rest[++i];
41
+ else if (a.startsWith("--reason=") && sub === "request") reason = a.slice("--reason=".length);
42
+ else if (a.startsWith("-")) return null;
43
+ else positional.push(a);
44
+ }
45
+ if (positional.length !== 1) return null;
46
+ const toolArgs = sub === "request"
47
+ ? { host_key: positional[0], ...(reason ? { reason } : {}) }
48
+ : { grant_id: positional[0] };
49
+ return { sub, json, toolArgs };
50
+ }
51
+
52
+ function describeGrant(g) {
53
+ if (!g) return [];
54
+ const lines = [`grant ${g.grant_id} · host ${g.host_key} · ${g.status}`];
55
+ if (g.approver_email) lines.push(`approved by ${g.approver_email}`);
56
+ if (g.start_by && g.status === "approved") lines.push(`start before ${g.start_by}`);
57
+ return lines;
58
+ }
59
+
60
+ /** `bb host upgrade …` → exit code. */
61
+ export async function cmdHostUpgrade(args, {
62
+ log = (line) => console.log(line), errorLog = (line) => console.error(line),
63
+ call = (tool, toolArgs) => callToolJson(tool, toolArgs, { requireSessionToken: true }),
64
+ } = {}) {
65
+ if (args[0] === "help" || args[0] === "--help" || args[0] === "-h" || args.length === 0) {
66
+ (args.length === 0 ? errorLog : log)(args.length === 0 ? HOST_UPGRADE_USAGE : hostUpgradeHelp());
67
+ return args.length === 0 ? 4 : 0;
68
+ }
69
+ const parsed = parse(args);
70
+ if (!parsed) { errorLog(HOST_UPGRADE_USAGE); return 4; }
71
+ const res = await call(TOOLS[parsed.sub], parsed.toolArgs);
72
+ if (!res?.ok) {
73
+ if (res?.auth || res?.error === "session_token_required") {
74
+ errorLog("bb host upgrade: an agent session is required so the grant binds to your agent; run `bb doctor --fix` (or `bb setup`) and retry.");
75
+ return 5;
76
+ }
77
+ errorLog(`bb host upgrade: ${res?.code ?? res?.error ?? "request failed"}`);
78
+ return 6;
79
+ }
80
+ const data = res.data ?? {};
81
+ if (parsed.json) log(JSON.stringify(data));
82
+ if (data.success !== true) {
83
+ errorLog(`bb host upgrade ${parsed.sub}: ${data.code ?? "REFUSED"}: ${data.message ?? "refused"}`);
84
+ return 3;
85
+ }
86
+ if (parsed.json) return 0;
87
+ if (parsed.sub === "request") {
88
+ log(`Ask the owner of ${data.host_key} to approve this upgrade cycle:`);
89
+ log(` code: ${data.user_code}`);
90
+ log(` open: ${data.verification_uri_complete}`);
91
+ log(`(expires in ${data.expires_in} s; grant ${data.grant_id})`);
92
+ log(`Wait for the decision: ${data.wait}`);
93
+ log(`Then start it: bb host upgrade start ${data.grant_id}`);
94
+ return 0;
95
+ }
96
+ for (const line of describeGrant(data.grant)) log(line);
97
+ const op = data.operation;
98
+ if (op) log(`operation ${op.id} · ${op.status}${op.requested_version ? ` · ${op.from_version ?? "?"} → ${op.requested_version}` : ""}${op.failure_code ? ` · ${op.failure_code}` : ""}`);
99
+ if (data.next) log(data.next);
100
+ return 0;
101
+ }
package/src/stack.mjs CHANGED
@@ -339,7 +339,14 @@ ${bold("run OPTIONS")}
339
339
  requester pool) is refused before the child starts with CHILD_PLACEMENT_REQUIRED
340
340
  (exit 5); the receipt adds child_placement_reason, missing_prerequisites and
341
341
  serving_host, and the slot and the lease are released. A full serving-host
342
- pool still waits for a slot.
342
+ pool still waits for a slot. BOT-3519: require-host also places the LEASE
343
+ only on an owned host whose child capabilities meet the whole prerequisite
344
+ set (toolchain, child-layer, system-packages-<distro>, host-local-callback
345
+ and --child-requires); a busy one is waited for. Refused before any lease
346
+ or upload (exit 5): CHILD_HOST_PREREQUISITES_MISSING (child_placement.
347
+ considered[] names each host and what it lacks; also a --host pin that
348
+ lacks one) or CHILD_HOST_UNAVAILABLE (the only host that could is
349
+ draining or in maintenance; child_placement.child_host names it).
343
350
  --child-requires LIST BOT-3030: what the child needs on a host (comma list: node>=24,pnpm,deno,
344
351
  curl,git,jq,psql,tar,tar-extract,playwright-chromium-libs, or a name the
345
352
  head's system_packages provide, e.g. playwright-webkit-libs). node, pnpm
@@ -1717,6 +1724,39 @@ export function stackPathRootRefusalNotice(code, message) {
1717
1724
  return `${yellow("⚠")} stack: ${message || STACK_PATH_ROOT_REFUSED_FALLBACK}`;
1718
1725
  }
1719
1726
 
1727
+ /**
1728
+ * BOT-3240/3407/3396/3470/3399: a --test-child run's whole host prerequisite set — the head's
1729
+ * toolchain (or its declared tools), its dependency layer, its declared system packages and a
1730
+ * host-local callback — plus --child-requires. BOT-3519: computed once before the lease, so a
1731
+ * require-host run's lease is placed only on a host that provides all of it.
1732
+ */
1733
+ export function childPrerequisiteSet(opts, worktreeRoot, adapters = {}, log = () => {}) {
1734
+ const head = (adapters.headToolchain ?? headToolchain)(worktreeRoot);
1735
+ const toolchain = toolchainPrerequisites(opts.childRequires ?? [], head);
1736
+ if (head.manifest) log(`stack: this head declares its toolchain (mise.toml, mise.lock): placement requires a host with \`toolchain\`${toolchain.provided.length ? `; ${toolchain.provided.join(", ")} come from the manifest` : ""}`);
1737
+ else if (head.lockMissing) log("stack: this head commits mise.toml without mise.lock, so a host builds no toolchain for it; run `mise lock` and commit mise.lock to give host children the repo's own tools");
1738
+ const declaresLayer = (adapters.headDeclaresChildLayer ?? headDeclaresChildLayer)(worktreeRoot);
1739
+ if (declaresLayer) log("stack: this head declares a dependency layer (.botbuddy/child-layer.json): placement requires a host with `child-layer`");
1740
+ const systemPackages = declaresLayer ? (adapters.headSystemPackages ?? headSystemPackages)(worktreeRoot) : null;
1741
+ const system = systemPackagesPrerequisites(childLayerPrerequisites(toolchain.prerequisites, declaresLayer), systemPackages);
1742
+ if (systemPackages) log(`stack: this head declares ${systemPackages.distribution} system packages: placement requires a host with \`${system.prerequisites.at(-1)}\`${system.provided.length ? `; ${system.provided.join(", ")} come from them, proven by the declared probe` : ""}`);
1743
+ const prerequisites = [...system.prerequisites];
1744
+ if (hostLocalCallbackRun(opts) && !prerequisites.includes(HOST_LOCAL_CALLBACK_CAPABILITY)) prerequisites.push(HOST_LOCAL_CALLBACK_CAPABILITY);
1745
+ return prerequisites;
1746
+ }
1747
+
1748
+ /** BOT-3519: the lease refusals that mean no owned host can run this require-host test child. */
1749
+ export const CHILD_HOST_REFUSAL_CODES = Object.freeze(["CHILD_HOST_PREREQUISITES_MISSING", "CHILD_HOST_UNAVAILABLE", CHILD_PLACEMENT_REQUIRED]);
1750
+
1751
+ /** BOT-3519: one line per considered host — what it lacks, or why it cannot take the child. */
1752
+ export function childHostRefusalLines(data) {
1753
+ const name = (c) => (typeof c.display_name === "string" && c.display_name && c.display_name !== c.host_key ? `${c.display_name} (${c.host_key})` : c.host_key);
1754
+ return (Array.isArray(data?.considered) ? data.considered : [])
1755
+ .filter((c) => c && typeof c.host_key === "string" && c.verdict_code === "HOST_CHILD_UNQUALIFIED")
1756
+ .map((c) => ` ${name(c)}: ${c.child_reason === "stack_colocated" ? "this machine's own host (a co-located stack never serves a host child)"
1757
+ : Array.isArray(c.missing_prerequisites) && c.missing_prerequisites.length ? `lacks ${c.missing_prerequisites.join(", ")} (${c.child_reason ?? "unknown"})` : c.child_reason ?? "cannot run the child"}`);
1758
+ }
1759
+
1720
1760
  /**
1721
1761
  * Exit code for a lease the server REFUSED (`success: false`). A refused root path is a
1722
1762
  * bad argument the caller must fix — INVALID (4) — not a backend fault, which automation
@@ -4568,6 +4608,8 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
4568
4608
  let testChild = null;
4569
4609
  let testChildRenew = null;
4570
4610
  let testChildWaitAbort = null;
4611
+ // BOT-3519: the test child's whole prerequisite set, derived before the lease is requested.
4612
+ let childPrerequisites = null;
4571
4613
  const releaseTestChild = async (resources) => {
4572
4614
  if (!testChild?.slotId) return null;
4573
4615
  const slotId = testChild.slotId;
@@ -4976,6 +5018,10 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
4976
5018
  // BOT-3399: a host-local callback is declared on the host run, never on the lease.
4977
5019
  const hostLocalCallback = hostLocalCallbackRun(opts);
4978
5020
  const requesterCallbackPort = hostLocalCallback ? null : opts.callbackPort;
5021
+ // BOT-3519: a require-host child's lease goes only to a host that can run it, so the whole
5022
+ // prerequisite set is known (and sent) before the lease exists.
5023
+ const requireHostChild = Boolean(opts.testChild) && opts.childPlacement === "require-host";
5024
+ childPrerequisites = opts.testChild ? childPrerequisiteSet(opts, execution.worktreeRoot, adapters, stderrLine) : null;
4979
5025
  const requireNativeCallback = requesterCallbackPort != null && opts.executionRing === "beta" && executionRequest !== "local";
4980
5026
  const autoCallbackPolicy = requesterCallbackPort != null && opts.executionRing !== "beta" && executionRequest !== "local" && Boolean(execution.admissionRequestId);
4981
5027
  let useNativeCallback = requireNativeCallback;
@@ -4994,6 +5040,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
4994
5040
  require_stack_digest: true,
4995
5041
  // BOT-2269: what the bundle carries beyond the defaults (paths, sha256, key NAMES).
4996
5042
  ...(bundle?.included?.length ? { bundle_included: bundle.included } : {}),
5043
+ ...(requireHostChild ? { child_host_prerequisites: childPrerequisites } : {}),
4997
5044
  ...(requesterCallbackPort != null ? { callback_port: requesterCallbackPort,
4998
5045
  ...(requireNativeCallback ? { callback_transport: NATIVE_CALLBACK_TRANSPORT } : autoCallbackPolicy ? { callback_policy: "auto" } : {}) } : {}),
4999
5046
  };
@@ -5327,6 +5374,28 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
5327
5374
  // an idle mode mismatch) is not proof that its ports are free. Keep the
5328
5375
  // claim until owner-safe cleanup is verified; never reap a possibly live batch.
5329
5376
  if (request.data?.lease_id) retainBlock = true;
5377
+ // BOT-3519: no owned host can run this require-host child: refused before any lease or upload.
5378
+ // A held lease on a host that cannot run the child is named too (held_lease); its id is kept so
5379
+ // the operator can release it, and its port block stays retained.
5380
+ if (requireHostChild && CHILD_HOST_REFUSAL_CODES.includes(request.data?.code) && (!request.data?.lease_id || request.data.held_lease === true)) {
5381
+ const d = request.data;
5382
+ if (d.lease_id) retainBlock = true;
5383
+ for (const line of childHostRefusalLines(d)) stderrLine(line);
5384
+ return {
5385
+ exitCode: EXIT.BACKEND, outcome: "refused", code: d.code,
5386
+ error: `--child-placement require-host: ${d.message ?? d.code}`,
5387
+ ...(d.lease_id ? { leaseId: d.lease_id, state: d.state ?? null } : {}),
5388
+ childHostRefusal: {
5389
+ prerequisites: Array.isArray(d.prerequisites) ? d.prerequisites : childPrerequisites,
5390
+ considered: Array.isArray(d.considered) ? d.considered : [],
5391
+ ...(d.child_host ? { child_host: d.child_host } : {}),
5392
+ ...(d.host_key ? { host_key: d.host_key } : {}),
5393
+ ...(d.child_reason ? { child_reason: d.child_reason } : {}),
5394
+ ...(d.child_placement_reason ? { child_placement_reason: d.child_placement_reason } : {}),
5395
+ ...(Array.isArray(d.missing_prerequisites) ? { missing_prerequisites: d.missing_prerequisites } : {}),
5396
+ },
5397
+ };
5398
+ }
5330
5399
  // BOT-2977: name the re-registration command; the refusal itself is never retried here.
5331
5400
  const fenceScope = staleContextFenceScope(request.data);
5332
5401
  const branchTicket = request.data?.code === "STALE_AGENT_CONTEXT" ? await (adapters.branchTicket ?? currentBranchTicket)() : undefined;
@@ -5825,22 +5894,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
5825
5894
  const waitTouch = clock.setInterval(() => { void touchWhileWaiting(); }, waitCadenceMs);
5826
5895
  waitTouch?.unref?.();
5827
5896
  let placed;
5828
- // BOT-3407: a head that commits mise.toml and mise.lock brings its own tools, so
5829
- // placement asks the host for `toolchain` instead of for those tools.
5830
- const head = (adapters.headToolchain ?? headToolchain)(execution.worktreeRoot);
5831
- const toolchain = toolchainPrerequisites(opts.childRequires, head);
5832
- if (head.manifest) stderrLine(`stack: this head declares its toolchain (mise.toml, mise.lock): placement requires a host with \`toolchain\`${toolchain.provided.length ? `; ${toolchain.provided.join(", ")} come from the manifest` : ""}`);
5833
- else if (head.lockMissing) stderrLine("stack: this head commits mise.toml without mise.lock, so a host builds no toolchain for it; run `mise lock` and commit mise.lock to give host children the repo's own tools");
5834
- // BOT-3396: a head that commits .botbuddy/child-layer.json needs a host that builds it.
5835
- const declaresLayer = (adapters.headDeclaresChildLayer ?? headDeclaresChildLayer)(execution.worktreeRoot);
5836
- if (declaresLayer) stderrLine("stack: this head declares a dependency layer (.botbuddy/child-layer.json): placement requires a host with `child-layer`");
5837
- // BOT-3470: its declared system packages bring the capabilities they provide with them.
5838
- const systemPackages = declaresLayer ? (adapters.headSystemPackages ?? headSystemPackages)(execution.worktreeRoot) : null;
5839
- const system = systemPackagesPrerequisites(childLayerPrerequisites(toolchain.prerequisites, declaresLayer), systemPackages);
5840
- if (systemPackages) stderrLine(`stack: this head declares ${systemPackages.distribution} system packages: placement requires a host with \`${system.prerequisites.at(-1)}\`${system.provided.length ? `; ${system.provided.join(", ")} come from them, proven by the declared probe` : ""}`);
5841
- const prerequisites = system.prerequisites;
5842
- // BOT-3399: a host-local callback child goes only to a host whose daemon serves the route.
5843
- if (hostLocalCallbackRun(opts) && !prerequisites.includes(HOST_LOCAL_CALLBACK_CAPABILITY)) prerequisites.push(HOST_LOCAL_CALLBACK_CAPABILITY);
5897
+ const prerequisites = childPrerequisites ?? childPrerequisiteSet(opts, execution.worktreeRoot, adapters, stderrLine);
5844
5898
  testChildWaitAbort = new AbortController();
5845
5899
  try {
5846
5900
  placed = await acquireTestChildSlot({
@@ -6254,6 +6308,15 @@ export function runReceiptFields(result) {
6254
6308
  ...(result.requiredPlacement.missing_prerequisites?.length ? { missing_prerequisites: result.requiredPlacement.missing_prerequisites } : {}),
6255
6309
  ...(result.requiredPlacement.serving_host ? { serving_host: result.requiredPlacement.serving_host } : {}),
6256
6310
  } : {}),
6311
+ // BOT-3519: a require-host lease refused before it existed: the child's prerequisite set and
6312
+ // every considered host with what it lacks (or the one host it would wait for).
6313
+ ...(result.childHostRefusal ? {
6314
+ child_placement: { prerequisites: result.childHostRefusal.prerequisites, considered: result.childHostRefusal.considered,
6315
+ ...(result.childHostRefusal.child_host ? { child_host: result.childHostRefusal.child_host } : {}) },
6316
+ ...(result.childHostRefusal.child_placement_reason ? { child_placement_reason: result.childHostRefusal.child_placement_reason } : {}),
6317
+ ...(result.childHostRefusal.host_key ? { serving_host: result.childHostRefusal.host_key } : {}),
6318
+ ...(result.childHostRefusal.missing_prerequisites?.length ? { missing_prerequisites: result.childHostRefusal.missing_prerequisites } : {}),
6319
+ } : {}),
6257
6320
  // BOT-1803: an idle release is `cleanup: { idle: true, idle_since }` (nothing was reaped).
6258
6321
  cleanup: result.cleanup?.idle ? { idle: true, idle_since: result.cleanup.idle_since ?? null } : result.cleanup?.ok ?? null,
6259
6322
  cleanup_code: result.cleanup?.code ?? null,
package/src/wait-core.mjs CHANGED
@@ -145,6 +145,10 @@ export const SIGNAL_TYPES = Object.freeze([
145
145
  // BOT-3030: a host-placed test child started or ended (subject = the run's UUID).
146
146
  // `bb stack run --test-child` waits on it while its child runs on the serving host.
147
147
  "test_child_run",
148
+ // BOT-3551: the host owner decided (approved, denied or revoked) a pre-approved
149
+ // upgrade cycle (subject = the grant's lower-case UUID), recipient-scoped to
150
+ // the requesting agent. `bb host upgrade request` prints this exact wait.
151
+ "host_upgrade_grant",
148
152
  ]);
149
153
 
150
154
  const LOCK_SUBTYPES = Object.freeze(["playwright_lane", "vite_port", "backend_port", "supabase_local"]);
@@ -604,6 +608,12 @@ const VALIDATORS = {
604
608
  if (p.type === "test_child_slot" && !subject) {
605
609
  throw new Error("event:type=test_child_slot needs subject=<run host>");
606
610
  }
611
+ // BOT-3551: a host upgrade grant wait names its grant, as the emitter writes it.
612
+ if (p.type === "host_upgrade_grant") {
613
+ const id = subject ? subject.toLowerCase() : "";
614
+ if (!CANONICAL_UUID_RE.test(id)) throw new Error("event:type=host_upgrade_grant needs subject=<grant UUID>");
615
+ return { type: p.type, subject: id };
616
+ }
607
617
  // BOT-3030: a test_child_run wait names its run, as the emitter writes it.
608
618
  if (p.type === "test_child_run") {
609
619
  const id = subject ? subject.toLowerCase() : "";