@botbuddy/cli 1.106.1 → 1.107.0

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.106.2
4
+
5
+ - BOT-3025: `bb stack run --host <host> --callback-port N` now goes through the identified admission like an unpinned run: it asks for `callback_policy auto` (the pin is sent as `host_key`) and reserves a requester origin. On a Linux Go host (protocol 5) the lease answers `native_origin_v1` and the callback takes the native route, instead of the loopback `-R` that a Linux container cannot reach through `host.docker.internal`; generated GoTrue links name the requester origin, never the unforwarded remote API port. A pin to a host that cannot serve the native route is refused `HOST_CALLBACK_TRANSPORT_UNSUPPORTED` before the child starts (never a fallback to `-R`). A pin that names this machine stays co-located and unchanged. `--stack-path` and fixed-nonce runs keep the legacy path, and a beta-ring `--host` pin is still refused a requester origin.
6
+
3
7
  ## 1.106.1
4
8
 
5
9
  - `bb run status --help` shows the status, inspection and log commands without reporting an invalid run or contacting BotBuddy.
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.106.1",
3
- "source_commit": "a42995651757e19e32e9b95da4fbdb804613f469",
4
- "source_sha256": "187860770903800533170769d60ef4079bd936b19a675854228f891011b6647f",
2
+ "release_version": "1.107.0",
3
+ "source_commit": "bbda34bfadab78ec0bf056e15ec9669dda75954e",
4
+ "source_sha256": "10eac18b5425447d79b3fa4decc8f8e5fabd3ddadf21f06612abced020c68b55",
5
5
  "target": "darwin-arm64",
6
- "sha256": "d7f4b731ffb2e93cab1111085ea653eee141726f2517fdc896cd6a417001a0b3"
6
+ "sha256": "14ed211a70632afd58cc9c24f494cedc0e8f4c5a0359500f0870bf5195b9d452"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.106.1",
3
- "source_commit": "a42995651757e19e32e9b95da4fbdb804613f469",
4
- "source_sha256": "187860770903800533170769d60ef4079bd936b19a675854228f891011b6647f",
2
+ "release_version": "1.107.0",
3
+ "source_commit": "bbda34bfadab78ec0bf056e15ec9669dda75954e",
4
+ "source_sha256": "10eac18b5425447d79b3fa4decc8f8e5fabd3ddadf21f06612abced020c68b55",
5
5
  "target": "linux-x64",
6
- "sha256": "4e67cd6cfec582e7eef01faa6d27697b860ba14edc25821bcb3fb9b140ff763d"
6
+ "sha256": "805d0cbf0b949a3c908a9117eabfbc227d0db1e92484bb4e473dae3be6c43251"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.106.1",
4
- "source_commit": "a42995651757e19e32e9b95da4fbdb804613f469",
5
- "source_sha256": "187860770903800533170769d60ef4079bd936b19a675854228f891011b6647f",
3
+ "release_version": "1.107.0",
4
+ "source_commit": "bbda34bfadab78ec0bf056e15ec9669dda75954e",
5
+ "source_sha256": "10eac18b5425447d79b3fa4decc8f8e5fabd3ddadf21f06612abced020c68b55",
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": "d7f4b731ffb2e93cab1111085ea653eee141726f2517fdc896cd6a417001a0b3",
11
+ "sha256": "14ed211a70632afd58cc9c24f494cedc0e8f4c5a0359500f0870bf5195b9d452",
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": "4e67cd6cfec582e7eef01faa6d27697b860ba14edc25821bcb3fb9b140ff763d",
18
+ "sha256": "805d0cbf0b949a3c908a9117eabfbc227d0db1e92484bb4e473dae3be6c43251",
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.106.1",
3
+ "version": "1.107.0",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
package/src/stack.mjs CHANGED
@@ -73,9 +73,10 @@ export const STACK_SCHEMA_VERSION = 1;
73
73
  * BOT-2780 / BOT-2788: a `stack run` that may be served by another host reserves a requester
74
74
  * origin and allocates through BOT-2499's identified admission. Stable (the default ring):
75
75
  * auto or remote placement, with or without `--reap` (an idle stack is continued on the same
76
- * logical origin by a later run), callback runs included (BOT-2775 stable activation: they ask
77
- * for callback_policy auto, see runStackLifecycle); runs that pin a host, a prepared stack
78
- * path, a fixed nonce or a co-located placement keep the legacy path unchanged. Beta:
76
+ * logical origin by a later run), callback runs and `--host` pins included (BOT-2775 stable
77
+ * activation: they ask for callback_policy auto, see runStackLifecycle; BOT-3025: the pin is
78
+ * placement only); runs with a prepared stack path, a fixed nonce or a co-located placement
79
+ * keep the legacy path unchanged. Beta:
79
80
  * BOT-2780's `--remote --reap` gate, which refuses those contexts instead.
80
81
  */
81
82
  export const requesterOriginEnabled = (opts) => {
@@ -83,7 +84,11 @@ export const requesterOriginEnabled = (opts) => {
83
84
  // Beta keeps BOT-2780's gate (remote + --reap); its idle/callback runs stay on BOT-2775's path.
84
85
  if (opts.executionRing === "beta") return opts.execution === "remote" && opts.reap === true;
85
86
  if (opts.execution != null && opts.execution !== "auto" && opts.execution !== "remote") return false;
86
- return opts.host == null && opts.stackNonce == null && (opts.stackPath == null || opts.stackPath === "" || opts.stackPath === ".");
87
+ // BOT-3025: a --host pin only constrains placement (the identified admission carries it as
88
+ // host_key), so a pinned run gets the same origin and callback_policy auto as an unpinned one.
89
+ // Without them a pinned callback took the loopback -R, which a Linux container cannot reach, and
90
+ // GoTrue links named the unforwarded remote API port.
91
+ return opts.stackNonce == null && (opts.stackPath == null || opts.stackPath === "" || opts.stackPath === ".");
87
92
  };
88
93
  // Exact replays of one identified request after an uncertain answer (lost response, 5xx,
89
94
  // ADMISSION_UNCERTAIN, pending delivery). The same request_id can never create a second lease.
@@ -199,6 +204,15 @@ ${bold("up OPTIONS")}
199
204
  supabase/config.toml declares a DISTINCT project_id + remapped ports,
200
205
  or use 'stack run', which materializes one for you.
201
206
  --purpose <text> Free-text purpose recorded on the lease.
207
+ --admission-class <label>
208
+ BOT-3363 (up and run): the workload class this request declares (a-z, 0-9, . _ : -).
209
+ A host with admission settings reserves memory per class = tenant + label; a host
210
+ whose settings name gated labels gates only requests declaring one of them.
211
+ --admission-cost <size> BOT-3363 (up and run): the declared default memory cost (3GiB, 512MiB or bytes). The
212
+ host admission ledger admits the lease only when baseline + reserved + this cost fits
213
+ the host's memory ceiling and observed free memory; otherwise it waits and prints
214
+ bb wait 'admit:id=<lease_id>'. A cost above the ceiling is refused at once
215
+ (ADMISSION_COST_EXCEEDS_CEILING). Omitted = the host's default cost.
202
216
  --idle-ttl <seconds> Idle seconds before the reaper STOPS an unused stack (default 1800).
203
217
  --timeout <seconds> Seconds to park for capacity (default ${DEFAULT_TIMEOUT_SEC} = 72 h, BOT-2400). At the
204
218
  deadline the lease is NOT released: it keeps its queue place (owner hold) and the
@@ -345,7 +359,8 @@ ${bold("run OPTIONS")}
345
359
  --execution-ring R Capacity rollout ring: stable (default) excludes beta daemon hosts.
346
360
  beta is explicit opt-in and requires \`stack run --remote\`.
347
361
  Requester origin (BOT-2780/BOT-2788): a stable \`stack run\` that may be
348
- served remotely (auto or --remote; no --host/--stack-path/--callback-port)
362
+ served remotely (auto or --remote, --host and --callback-port included;
363
+ no --stack-path or fixed nonce)
349
364
  and --remote --execution-ring beta --reap reserve a loopback origin first;
350
365
  only the remote bundle's config names it as [auth] external_url, so
351
366
  generated auth links (/auth/v1/verify…) reach the stack unchanged even when
@@ -359,14 +374,16 @@ ${bold("run OPTIONS")}
359
374
  host.docker.internal:N (e.g. 4600): sent as callback_port. A remote
360
375
  callback is served by a Linux Go runtime with native callbacks (protocol
361
376
  5): a private SSH Unix-socket route to a fixed requester gateway, renewed
362
- against current owned authorization (BOT-2775). An unpinned stable/auto run
363
- asks for callback_policy auto: it runs co-located or on a host with native
364
- callbacks, and Swift Helper hosts no longer take it remotely. With --remote
377
+ against current owned authorization (BOT-2775). A stable/auto run, pinned
378
+ with --host or not (BOT-3025), asks for callback_policy auto: it runs
379
+ co-located or on a host with native callbacks, and Swift Helper hosts no
380
+ longer take it remotely (a pin to one is refused
381
+ HOST_CALLBACK_TRANSPORT_UNSUPPORTED before the child starts). With --remote
365
382
  --execution-ring beta the native transport is required explicitly. A remote
366
383
  lease the backend does not acknowledge with it fails
367
384
  HOST_CALLBACK_TRANSPORT_UNSUPPORTED (never a legacy -R); the child never
368
- receives the route capability. A run pinned with --host, --stack-path or a
369
- fixed nonce keeps the legacy -R forward: it first probes the host with a
385
+ receives the route capability. A run with --stack-path or a fixed nonce
386
+ keeps the legacy -R forward: it first probes the host with a
370
387
  throwaway reverse forward and opens -R 127.0.0.1:N:127.0.0.1:N only when
371
388
  the host keeps it on loopback (sshd GatewayPorts no/clientspecified);
372
389
  otherwise exit 5 CALLBACK_NOT_LOOPBACK (BOT-2184).
@@ -603,6 +620,8 @@ export function parseStackArgs(argv) {
603
620
  const opts = {
604
621
  slot: null, host: null, repo: null, ticket: null, ticketUrl: null,
605
622
  prId: null, prUrl: null, purpose: null, runId: null, idleTtl: null, stackPath: ".", stackPathExplicit: false,
623
+ // BOT-3363: the admission class label and declared default memory cost (bytes) of this request.
624
+ admissionClass: null, admissionCostBytes: null,
606
625
  timeout: DEFAULT_TIMEOUT_SEC, provisionTimeout: null, reapTimeout: 300, hardTtl: null,
607
626
  connectionFile: null, noWait: false, claimOnly: false, localExec: false, keepVolumes: false, waitCapacity: null, holdOnTimeout: null,
608
627
  dockerContext: null, dockerEndpoint: null,
@@ -639,6 +658,22 @@ export function parseStackArgs(argv) {
639
658
  case "--pr": if (need(a, rest[i + 1])) opts.prId = rest[++i]; break;
640
659
  case "--pr-url": if (need(a, rest[i + 1])) opts.prUrl = rest[++i]; break;
641
660
  case "--purpose": if (need(a, rest[i + 1])) opts.purpose = rest[++i]; break;
661
+ case "--admission-class": {
662
+ if (need(a, rest[i + 1])) {
663
+ const label = String(rest[++i]).trim().toLowerCase();
664
+ if (!ADMISSION_CLASS_PATTERN.test(label)) errors.push("--admission-class must be 1-64 characters of a-z, 0-9, \".\", \"_\", \":\" or \"-\", starting with a letter or digit");
665
+ else opts.admissionClass = label;
666
+ }
667
+ break;
668
+ }
669
+ case "--admission-cost": {
670
+ if (need(a, rest[i + 1])) {
671
+ const bytes = parseAdmissionCost(rest[++i]);
672
+ if (bytes == null) errors.push("--admission-cost must be a memory size from 1MiB to 1TiB: bytes, or a number with MiB or GiB (e.g. 3GiB)");
673
+ else opts.admissionCostBytes = bytes;
674
+ }
675
+ break;
676
+ }
642
677
  case "--run-id": if (need(a, rest[i + 1])) opts.runId = rest[++i]; break;
643
678
  case "--stack-path": if (need(a, rest[i + 1])) { opts.stackPath = rest[++i]; opts.stackPathExplicit = true; } break;
644
679
  case "--local-max-locks": {
@@ -943,6 +978,47 @@ export function parseStackArgs(argv) {
943
978
  return { command, leaseId, opts, errors, errorCodes, childArgv };
944
979
  }
945
980
 
981
+ // BOT-3363: the admission class label grammar the control plane accepts.
982
+ export const ADMISSION_CLASS_PATTERN = /^[a-z0-9][a-z0-9._:-]{0,63}$/;
983
+ const ADMISSION_COST_MIN = 1024 * 1024;
984
+ const ADMISSION_COST_MAX = 1024 ** 4;
985
+
986
+ /** BOT-3363: `3GiB`, `512MiB` or plain bytes → bytes, or null when malformed / out of range. */
987
+ export function parseAdmissionCost(raw) {
988
+ const m = /^\s*(\d+(?:\.\d+)?)\s*(gib|mib|b)?\s*$/i.exec(String(raw ?? ""));
989
+ if (!m) return null;
990
+ const unit = (m[2] ?? "b").toLowerCase();
991
+ if (unit === "b" && m[1].includes(".")) return null;
992
+ const bytes = Math.round(Number(m[1]) * (unit === "gib" ? 1024 ** 3 : unit === "mib" ? 1024 ** 2 : 1));
993
+ return Number.isSafeInteger(bytes) && bytes >= ADMISSION_COST_MIN && bytes <= ADMISSION_COST_MAX ? bytes : null;
994
+ }
995
+
996
+ /** BOT-3363: the request fields for a declared admission class / cost (none when undeclared). */
997
+ export function admissionLeaseArgs(opts) {
998
+ return {
999
+ ...(opts?.admissionClass ? { admission_class: opts.admissionClass } : {}),
1000
+ ...(opts?.admissionCostBytes ? { admission_cost_bytes: opts.admissionCostBytes } : {}),
1001
+ };
1002
+ }
1003
+
1004
+ const gib = (b) => (Number.isFinite(Number(b)) ? `${(Number(b) / 1024 ** 3).toFixed(2)} GiB` : "?");
1005
+
1006
+ /**
1007
+ * BOT-3363: the human lines for a host admission ledger receipt (host_admission_receipt.v1) on
1008
+ * a queued or refused lease: what it waits on, its cost against the ceiling, and the exact
1009
+ * `bb wait 'admit:id=…'` that wakes when it is admitted. Nothing for an ungated host.
1010
+ */
1011
+ export function describeAdmission(admission) {
1012
+ if (!admission || typeof admission !== "object" || admission.gated !== true) return [];
1013
+ const cls = admission.class?.key ?? "?";
1014
+ const line = `admission: ${admission.mode ?? "?"} ${admission.verdict ?? "?"} — ${admission.code ?? "?"} (class ${cls}, cost ${gib(admission.cost_bytes)} ${admission.cost_source ?? "?"}`
1015
+ + `, free ${gib(admission.free_before_bytes)} of ceiling ${gib(admission.ceiling_bytes)}, baseline ${gib(admission.baseline_bytes)}, reserved ${gib(admission.reserved_bytes)}`
1016
+ + `, observed available ${gib(admission.observed_available_bytes)})`;
1017
+ const lines = [line];
1018
+ if (typeof admission.wait === "string" && admission.wait) lines.push(`admission: wait with ${admission.wait} — it wakes when this lease is admitted, or ends admission_refused`);
1019
+ return lines;
1020
+ }
1021
+
946
1022
  /**
947
1023
  * BOT-2019: the human line for a queued lease's server position. `queue_position` is the
948
1024
  * server's dispatch rank (stack_lease_dispatch_queue — the order leases are considered in,
@@ -1166,13 +1242,15 @@ export async function resolveRunExecution(cwd, opts, { materialize = materialize
1166
1242
  }
1167
1243
  return execution;
1168
1244
  };
1169
- // BOT-2780: the requester origin is only for a CLI-managed stack context. A prepared path,
1170
- // pinned host or fixed nonce could resume a stack whose generated links name another
1171
- // invocation's listener (a stable run with one of them is simply not an origin run).
1245
+ // BOT-2780: the requester origin is only for a CLI-managed stack context. A prepared path or
1246
+ // fixed nonce could resume a stack whose generated links name another invocation's listener
1247
+ // (a stable run with one of them is simply not an origin run). BOT-3025: a stable --host pin
1248
+ // is placement only and is an origin run; beta still refuses it.
1172
1249
  // A stable origin run is the caller's choice to supply its admission identity (runStack
1173
1250
  // always does); a beta run without one is refused below.
1174
1251
  const originRun = requesterOriginEnabled(opts) && (opts.executionRing === "beta" || (UUID_RE.test(opts.admissionRequestId ?? "") && Boolean(opts.requesterMachineId)));
1175
- if (originRun && (opts.host != null || opts.stackNonce != null || (opts.stackPath && opts.stackPath !== ".") ||
1252
+ // BOT-3025: a --host pin is refused only on the beta ring; a stable pinned run is an origin run.
1253
+ if (originRun && ((opts.host != null && opts.executionRing === "beta") || opts.stackNonce != null || (opts.stackPath && opts.stackPath !== ".") ||
1176
1254
  !UUID_RE.test(opts.admissionRequestId ?? "") || !opts.requesterMachineId)) {
1177
1255
  const error = new Error("beta requester origins require a fresh CLI-managed stack context (no --host, --stack-path or fixed nonce)");
1178
1256
  error.code = "REQUESTER_ORIGIN_CONTEXT_REFUSED";
@@ -2933,6 +3011,7 @@ async function cmdUpOnce(opts, {
2933
3011
  ticket_id: opts.ticket || undefined, ticket_url: opts.ticketUrl || undefined,
2934
3012
  pr_id: opts.prId || undefined, pr_url: opts.prUrl || undefined,
2935
3013
  purpose: opts.purpose || undefined, idle_ttl_secs: opts.idleTtl ?? undefined,
3014
+ ...admissionLeaseArgs(opts),
2936
3015
  stack_path: execution.stackPath,
2937
3016
  worktree_root: execution.worktreeRoot,
2938
3017
  machine_uuid: hardwareUuid,
@@ -3072,9 +3151,10 @@ async function cmdUpOnce(opts, {
3072
3151
  const where = describeQueuePosition(d);
3073
3152
  reportLaneStatus({ phase: "waiting", reason: "queued_for_capacity", detail: where || "host at capacity" });
3074
3153
  process.stderr.write(`stack: lease ${leaseId} queued — ${where}\n`);
3154
+ for (const line of describeAdmission(d.admission)) process.stderr.write(`stack: ${line}\n`);
3075
3155
  for (const line of describeUnitLedger(d.ledger)) process.stderr.write(`stack: ${line}\n`);
3076
3156
  if (opts.noWait) {
3077
- return emitResult(buildReceipt({ command: "up", outcome: "queued", lease_id: leaseId, state, host_key: d.host_key, slot, queued: true, ...queueReceiptFields(d), holders: d.holders, ...(d.ledger ? { unit_ledger: d.ledger } : {}) }), opts, EXIT.QUEUED);
3157
+ return emitResult(buildReceipt({ command: "up", outcome: "queued", lease_id: leaseId, state, host_key: d.host_key, slot, queued: true, ...queueReceiptFields(d), holders: d.holders, ...(d.ledger ? { unit_ledger: d.ledger } : {}), ...(d.admission ? { admission: d.admission } : {}) }), opts, EXIT.QUEUED);
3078
3158
  }
3079
3159
  // Park zero-poll until the lease leaves the queue (granted in BOT-1187 order).
3080
3160
  // BOT-2013: a lease reaped while queued (orphaned_agent, …) is lost, not "left the queue".
@@ -4425,7 +4505,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
4425
4505
  let tunnelLost = null;
4426
4506
  // BOT-2780: the requester origin closed under a live run (SSH loss or forward failure).
4427
4507
  let originLost = null;
4428
- const placement = { mode: null, hostKey: null, requesterHost: null, transport: "none", forwards: null, bundle: null, placementReason: null, considered: null,
4508
+ const placement = { mode: null, hostKey: null, requesterHost: null, transport: "none", forwards: null, bundle: null, placementReason: null, considered: null, admission: null,
4429
4509
  // BOT-3371: the optional services this run asked for, and what the stack reports it runs.
4430
4510
  supabaseServicesRequested: opts.supabaseServices ?? [], supabaseServices: null };
4431
4511
  incidentBox.execution = placement;
@@ -4798,6 +4878,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
4798
4878
  slot, host_key: opts.host || undefined, repo: opts.repo, ticket_id: opts.ticket,
4799
4879
  ticket_url: opts.ticketUrl || undefined, pr_id: opts.prId || undefined, pr_url: opts.prUrl || undefined,
4800
4880
  purpose: opts.purpose || "stack run", idle_ttl_secs: opts.idleTtl ?? undefined,
4881
+ ...admissionLeaseArgs(opts),
4801
4882
  stack_path: execution.stackPath, worktree_root: execution.worktreeRoot,
4802
4883
  machine_uuid: hardwareUuid,
4803
4884
  execution: executionRequest,
@@ -5187,6 +5268,8 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
5187
5268
  // BOT-2207: why the server placed (or queued) it there, and every host it weighed.
5188
5269
  placement.placementReason = request.data.placement_reason ?? null;
5189
5270
  placement.considered = Array.isArray(request.data.considered) ? request.data.considered : null;
5271
+ // BOT-3363: the host admission ledger receipt (queued or admitted), when the host is gated.
5272
+ placement.admission = request.data.admission ?? null;
5190
5273
  if (executionRequest === "remote" && !remoteLease) {
5191
5274
  const cleanup = await requestCleanup();
5192
5275
  return {
@@ -5282,6 +5365,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
5282
5365
  if (state === "queued") {
5283
5366
  // BOT-2019: say where the lease sits (server dispatch rank, or why it has none) before parking.
5284
5367
  stderrLine(`stack: lease ${leaseId} queued — ${describeQueuePosition(parkView)}`);
5368
+ for (const line of describeAdmission(parkView.admission)) stderrLine(`stack: ${line}`);
5285
5369
  for (const line of describeUnitLedger(parkView.ledger)) stderrLine(`stack: ${line}`);
5286
5370
  for (const line of describeConsidered(parkView.considered)) stderrLine(`stack: ${line}`);
5287
5371
  parkReason = queuedParkReason(parkView) ?? parkReason;
@@ -5460,6 +5544,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
5460
5544
  placement.mode = current.data.execution_mode ?? placement.mode ?? (remoteLease ? "remote" : null);
5461
5545
  placement.placementReason = current.data.placement_reason ?? placement.placementReason;
5462
5546
  if (Array.isArray(current.data.considered)) placement.considered = current.data.considered;
5547
+ if (current.data.admission) placement.admission = current.data.admission;
5463
5548
  // BOT-2207: a queued auto lease may have been MOVED to another owned host while it waited.
5464
5549
  // Follow it exactly like a first-time remote placement: forward to the NEW host's ssh_target.
5465
5550
  const servedRemote = remoteLease || current.data.execution_mode === "remote";
@@ -6060,6 +6145,8 @@ export function runReceiptFields(result) {
6060
6145
  // BOT-2207: why it ran where it did (e.g. moved_remote_on_requeue) and every host weighed.
6061
6146
  ...(result.execution?.placementReason ? { placement_reason: result.execution.placementReason } : {}),
6062
6147
  ...(result.execution?.considered ? { considered: result.execution.considered } : {}),
6148
+ // BOT-3363: the host admission ledger receipt this lease started with (gated hosts only).
6149
+ ...(result.execution?.admission ? { admission: result.execution.admission } : {}),
6063
6150
  fenced: result.fenced === true || result.cleanup?.ok === false, error: result.error ?? result.cleanup?.error ?? null,
6064
6151
  // BOT-2099: a platform auth/availability blip during the park is reported as an
6065
6152
  // incident (reason, window, attempts, recovered) — never as the lease's outcome.
package/src/wait-core.mjs CHANGED
@@ -44,6 +44,9 @@ export const EXIT = Object.freeze({
44
44
  // fire: the receipt carries the incident and the caller's role; re-arm from
45
45
  // next_cursor (the wait's cursor_start) after acting on the incident.
46
46
  PREEMPTED: 14,
47
+ // BOT-3363: an `admit:id=` wait whose lease the host admission ledger refused for good (its
48
+ // memory cost is above the host's admission ceiling). The receipt names the typed reason.
49
+ ADMISSION_REFUSED: 15,
47
50
  });
48
51
 
49
52
  // BOT-2013: the uuid spellings Postgres accepts for a lease id (uuid_in), mirrored by the SQL
@@ -323,6 +326,17 @@ const VALIDATORS = {
323
326
  if (!p.request) throw new Error("guidance needs request=<request_id>");
324
327
  return { request: String(p.request) };
325
328
  },
329
+ // BOT-3363 — admit: one stack lease admitted by its host's memory admission ledger. The
330
+ // relay sees the lease's own stack_lease frames (serverConditions); it wakes on the start
331
+ // (provisioning/active), or ends admission_refused / lease_lost when the lease ends unadmitted.
332
+ admit: (p) => {
333
+ const unexpected = Object.keys(p).filter((key) => key !== "id");
334
+ if (unexpected.length) throw new Error(`admit does not accept ${unexpected.join(", ")}`);
335
+ const m = LEASE_UUID_SPELLING.exec(String(p.id ?? "").trim().toLowerCase());
336
+ if (!m) throw new Error("admit needs id=<the lease id bb stack printed>");
337
+ const hex = m[1].replace(/-/g, "");
338
+ return { id: `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}` };
339
+ },
326
340
  // BOT-1220 — lease: park on a batch stack lease (BOT-1218) leaving the queue /
327
341
  // becoming active, so `botbuddy stack up` on a saturated host wakes zero-poll the
328
342
  // instant it's granted in BOT-1187 order. The signal is recipient-scoped to the
@@ -806,7 +820,30 @@ function prReviewFiltersMatch(signal, params, guard) {
806
820
  * server's command-run terminal condition for its run; its `waiting_over` stays local.
807
821
  */
808
822
  export function serverConditions(conditions) {
809
- return conditions.map((c) => (c.type === "push" ? { id: c.id, type: "command-run", params: { runId: c.params.runId } } : c));
823
+ return conditions.map((c) => {
824
+ if (c.type === "push") return { id: c.id, type: "command-run", params: { runId: c.params.runId } };
825
+ // BOT-3363: an admit wait is the relay's recipient-scoped lease wait for that lease.
826
+ if (c.type === "admit") return { id: c.id, type: "lease", params: { id: c.params.id } };
827
+ return c;
828
+ });
829
+ }
830
+
831
+ // BOT-3363: the lease states that mean an admit: wait's lease was admitted (it started).
832
+ const ADMITTED_LEASE_STATES = Object.freeze(new Set(["provisioning", "active"]));
833
+
834
+ /** BOT-3363: the terminal detail of an admit: frame — admitted, refused (typed) or lost. */
835
+ export function admitDetail(signal, condition) {
836
+ if (condition?.type !== "admit" || signal?.signal_type !== "stack_lease") return null;
837
+ const p = signal.payload ?? {};
838
+ const leaseState = p.state ?? null;
839
+ const reapReason = typeof p.reap_reason === "string" ? p.reap_reason : null;
840
+ const base = { lease_id: p.lease_id ?? condition.params?.id ?? null, lease_state: leaseState };
841
+ if (ADMITTED_LEASE_STATES.has(leaseState)) return { kind: "admitted", state: { ...base, admitted: true } };
842
+ if (LEASE_LOST_STATES.has(leaseState)) {
843
+ if (reapReason && reapReason.startsWith("admission_")) return { kind: "refused", state: { ...base, admitted: false, reap_reason: reapReason } };
844
+ return { kind: "lost", state: { ...base, admitted: false, reap_reason: reapReason } };
845
+ }
846
+ return null;
810
847
  }
811
848
 
812
849
  export function parseConditions(specs) {
@@ -1506,6 +1543,10 @@ function conditionMatchesSignal(condition, signal, waitSessionId) {
1506
1543
  signal.payload?.run_id === params.id && Number.isInteger(signal.payload?.exit_code);
1507
1544
  case "guidance":
1508
1545
  return signal.signal_type === "guidance_response" && signal.subject_key === params.request;
1546
+ case "admit":
1547
+ // BOT-3363: only a start or an end decides an admit wait; a queued frame keeps waiting.
1548
+ return signal.signal_type === "stack_lease" && signal.subject_key === `lease:${params.id}` &&
1549
+ (ADMITTED_LEASE_STATES.has(signal.payload?.state) || LEASE_LOST_STATES.has(signal.payload?.state));
1509
1550
  case "lease":
1510
1551
  // BOT-1220: recipient-scoped stack-lease transition (queued→provisioning, or
1511
1552
  // →active). The relay only delivers it to the lease's owning agent, so any
@@ -2025,6 +2066,16 @@ export async function runWaitLoop({
2025
2066
  reap_reason: typeof p.reap_reason === "string" ? p.reap_reason : null, cleanup_unverified: true },
2026
2067
  });
2027
2068
  }
2069
+ const admit = admitDetail(signal, condition);
2070
+ if (admit?.kind === "refused") {
2071
+ return finalize("admission_refused", { exitCode: EXIT.ADMISSION_REFUSED, matched: [entry], state: admit.state, error: admit.state.reap_reason });
2072
+ }
2073
+ if (admit?.kind === "lost") {
2074
+ return finalize("lease_lost", { exitCode: EXIT.LEASE_LOST, matched: [entry], state: admit.state, error: "lease_lost" });
2075
+ }
2076
+ if (admit?.kind === "admitted") {
2077
+ return finalize("matched", { exitCode: EXIT.MATCHED, matched: [entry], state: admit.state });
2078
+ }
2028
2079
  const lost = leaseLostDetail(signal, condition);
2029
2080
  if (lost) {
2030
2081
  return finalize("lease_lost", { exitCode: EXIT.LEASE_LOST, matched: [entry], state: lost, error: "lease_lost" });
@@ -12,7 +12,7 @@ const MAX_RECEIPT_BYTES = 64 * 1024;
12
12
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
13
13
  const COMMAND_STATUSES = new Set(["success", "failure", "cancelled", "timed_out", "owner_lost"]);
14
14
  // BOT-2783: review_timeout is terminal (exit 13, typed REVIEW_TIMEOUT provenance).
15
- const TERMINAL_OUTCOMES = new Set(["matched", "timeout", "error", "superseded", "lease_lost", "abandoned", "cancelled", "review_timeout", "preempted"]);
15
+ const TERMINAL_OUTCOMES = new Set(["matched", "timeout", "error", "superseded", "lease_lost", "abandoned", "cancelled", "review_timeout", "preempted", "admission_refused"]);
16
16
 
17
17
  // Persisted != delivered. Await the stream callback before exiting, including
18
18
  // when a bounded receipt is larger than the pipe's immediately writable space.
package/src/wait.mjs CHANGED
@@ -194,6 +194,12 @@ CONDITIONS (TYPE:key=val,key=val — repeat for several; --any wakes on the fir
194
194
  child_exit_code, category, outcome and code. Live-only and
195
195
  recipient-scoped to the run's agent. Never substitute a
196
196
  lease: transition, a log tail or a polling loop.
197
+ admit:id=<lease_id> BOT-3363: that stack lease admitted by its host's memory
198
+ admission ledger (bb stack prints this wait when the ledger
199
+ holds a lease). Matches when the lease starts
200
+ (state.admitted true); a lease the ledger can never admit
201
+ ends admission_refused (exit 15, state.reap_reason); any
202
+ other loss ends lease_lost (exit 9). Level-triggered.
197
203
  lease:id=<lease_id>[,state=<s>] a batch stack lease (BOT-1218). Without state=: the lease
198
204
  leaving the queue / becoming active — the zero-poll wake
199
205
  for a parked bb stack up (recipient-scoped to the owner).
@@ -336,7 +342,10 @@ OUTPUT
336
342
  command) · 13 review timeout
337
343
  (REVIEW_TIMEOUT: a Codex review still incomplete at its
338
344
  deadline; receipt error carries minutes/source/reason —
339
- use the fallback reviewer, never infer approval).
345
+ use the fallback reviewer, never infer approval)
346
+ · 15 admission refused (an admit:id= lease the host's
347
+ admission ledger can never admit; receipt state.reap_reason
348
+ names why — lower the declared cost or use another host).
340
349
  If the receipt has
341
350
  reacquire_lock (claim=true), acquire_lock again FIRST and re-run
342
351
  only on a queued/busy result (granted = you hold it — just resume);
@@ -871,6 +880,8 @@ async function registerWait(opts, conditions, deadlineIso) {
871
880
  // `error` and its stored receipt carries the precise outcome.
872
881
  export function cloudStatusForOutcome(outcome) {
873
882
  if (outcome === "lease_lost") return "error";
883
+ // BOT-3363: nor admission_refused — the stored receipt carries the typed reason.
884
+ if (outcome === "admission_refused") return "error";
874
885
  // BOT-2783: no review_timeout status either — the session ends `timeout` and the
875
886
  // stored receipt (and the guard) carry the typed REVIEW_TIMEOUT provenance.
876
887
  if (outcome === "review_timeout") return "timeout";
@@ -885,6 +896,14 @@ export function leaseLostNotice(receipt) {
885
896
  `(reap_reason=${st.reap_reason ?? "unknown"}) — request a new lease (exit ${EXIT.LEASE_LOST})`;
886
897
  }
887
898
 
899
+ /** BOT-3363: the one stderr line for an admission_refused receipt (null for any other outcome). */
900
+ export function admissionRefusedNotice(receipt) {
901
+ if (receipt?.outcome !== "admission_refused") return null;
902
+ const st = receipt.state ?? {};
903
+ return `bb-wait: lease ${st.lease_id ?? "?"} can never be admitted on its host ` +
904
+ `(reap_reason=${st.reap_reason ?? "unknown"}) — lower its declared cost or request another host (exit ${EXIT.ADMISSION_REFUSED})`;
905
+ }
906
+
888
907
  /**
889
908
  * BOT-2360: the one stderr line for an `abandoned` receipt (null for any other outcome). The
890
909
  * server ended this wait (its liveness reaper or a cancel) while the client was
@@ -993,7 +1012,7 @@ export function stagingSuspectNotice(receipt) {
993
1012
  }
994
1013
 
995
1014
  function writeLeaseLostNotice(receipt, conditionArgs = [], options = {}) {
996
- const notice = leaseLostNotice(receipt) ?? waitAbandonedNotice(receipt) ?? reviewTimeoutNotice(receipt) ??
1015
+ const notice = leaseLostNotice(receipt) ?? admissionRefusedNotice(receipt) ?? waitAbandonedNotice(receipt) ?? reviewTimeoutNotice(receipt) ??
997
1016
  waitPreemptedNotice(receipt, conditionArgs, options) ?? stagingSuspectNotice(receipt);
998
1017
  if (notice) process.stderr.write(`${notice}\n`);
999
1018
  }
@@ -1797,6 +1816,7 @@ export function recoveredExitCode(receipt) {
1797
1816
  if (receipt?.outcome === "matched") return EXIT.MATCHED;
1798
1817
  if (receipt?.outcome === "review_timeout") return EXIT.REVIEW_TIMEOUT;
1799
1818
  if (receipt?.outcome === "lease_lost") return EXIT.LEASE_LOST;
1819
+ if (receipt?.outcome === "admission_refused") return EXIT.ADMISSION_REFUSED;
1800
1820
  if (receipt?.outcome === "cancelled") return EXIT.MATCHED;
1801
1821
  if (receipt?.outcome === "timeout") return EXIT.TIMEOUT;
1802
1822
  if (receipt?.outcome === "superseded") return EXIT.SUPERSEDED;