@botbuddy/cli 1.106.2 → 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/daemon/bin/darwin-arm64/botbuddy-daemon +0 -0
- package/daemon/bin/linux-x64/botbuddy-daemon +0 -0
- package/daemon-release/darwin-arm64.json +4 -4
- package/daemon-release/linux-x64.json +4 -4
- package/daemon-release/manifest.json +5 -5
- package/package.json +1 -1
- package/src/stack.mjs +79 -2
- package/src/wait-core.mjs +52 -1
- package/src/wait-result.mjs +1 -1
- package/src/wait.mjs +22 -2
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.107.0",
|
|
3
|
+
"source_commit": "bbda34bfadab78ec0bf056e15ec9669dda75954e",
|
|
4
|
+
"source_sha256": "10eac18b5425447d79b3fa4decc8f8e5fabd3ddadf21f06612abced020c68b55",
|
|
5
5
|
"target": "darwin-arm64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "14ed211a70632afd58cc9c24f494cedc0e8f4c5a0359500f0870bf5195b9d452"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.107.0",
|
|
3
|
+
"source_commit": "bbda34bfadab78ec0bf056e15ec9669dda75954e",
|
|
4
|
+
"source_sha256": "10eac18b5425447d79b3fa4decc8f8e5fabd3ddadf21f06612abced020c68b55",
|
|
5
5
|
"target": "linux-x64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "805d0cbf0b949a3c908a9117eabfbc227d0db1e92484bb4e473dae3be6c43251"
|
|
7
7
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema_version": 1,
|
|
3
|
-
"release_version": "1.
|
|
4
|
-
"source_commit": "
|
|
5
|
-
"source_sha256": "
|
|
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": "
|
|
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": "
|
|
18
|
+
"sha256": "805d0cbf0b949a3c908a9117eabfbc227d0db1e92484bb4e473dae3be6c43251",
|
|
19
19
|
"mode": "0755"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
package/src/stack.mjs
CHANGED
|
@@ -204,6 +204,15 @@ ${bold("up OPTIONS")}
|
|
|
204
204
|
supabase/config.toml declares a DISTINCT project_id + remapped ports,
|
|
205
205
|
or use 'stack run', which materializes one for you.
|
|
206
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.
|
|
207
216
|
--idle-ttl <seconds> Idle seconds before the reaper STOPS an unused stack (default 1800).
|
|
208
217
|
--timeout <seconds> Seconds to park for capacity (default ${DEFAULT_TIMEOUT_SEC} = 72 h, BOT-2400). At the
|
|
209
218
|
deadline the lease is NOT released: it keeps its queue place (owner hold) and the
|
|
@@ -611,6 +620,8 @@ export function parseStackArgs(argv) {
|
|
|
611
620
|
const opts = {
|
|
612
621
|
slot: null, host: null, repo: null, ticket: null, ticketUrl: null,
|
|
613
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,
|
|
614
625
|
timeout: DEFAULT_TIMEOUT_SEC, provisionTimeout: null, reapTimeout: 300, hardTtl: null,
|
|
615
626
|
connectionFile: null, noWait: false, claimOnly: false, localExec: false, keepVolumes: false, waitCapacity: null, holdOnTimeout: null,
|
|
616
627
|
dockerContext: null, dockerEndpoint: null,
|
|
@@ -647,6 +658,22 @@ export function parseStackArgs(argv) {
|
|
|
647
658
|
case "--pr": if (need(a, rest[i + 1])) opts.prId = rest[++i]; break;
|
|
648
659
|
case "--pr-url": if (need(a, rest[i + 1])) opts.prUrl = rest[++i]; break;
|
|
649
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
|
+
}
|
|
650
677
|
case "--run-id": if (need(a, rest[i + 1])) opts.runId = rest[++i]; break;
|
|
651
678
|
case "--stack-path": if (need(a, rest[i + 1])) { opts.stackPath = rest[++i]; opts.stackPathExplicit = true; } break;
|
|
652
679
|
case "--local-max-locks": {
|
|
@@ -951,6 +978,47 @@ export function parseStackArgs(argv) {
|
|
|
951
978
|
return { command, leaseId, opts, errors, errorCodes, childArgv };
|
|
952
979
|
}
|
|
953
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
|
+
|
|
954
1022
|
/**
|
|
955
1023
|
* BOT-2019: the human line for a queued lease's server position. `queue_position` is the
|
|
956
1024
|
* server's dispatch rank (stack_lease_dispatch_queue — the order leases are considered in,
|
|
@@ -2943,6 +3011,7 @@ async function cmdUpOnce(opts, {
|
|
|
2943
3011
|
ticket_id: opts.ticket || undefined, ticket_url: opts.ticketUrl || undefined,
|
|
2944
3012
|
pr_id: opts.prId || undefined, pr_url: opts.prUrl || undefined,
|
|
2945
3013
|
purpose: opts.purpose || undefined, idle_ttl_secs: opts.idleTtl ?? undefined,
|
|
3014
|
+
...admissionLeaseArgs(opts),
|
|
2946
3015
|
stack_path: execution.stackPath,
|
|
2947
3016
|
worktree_root: execution.worktreeRoot,
|
|
2948
3017
|
machine_uuid: hardwareUuid,
|
|
@@ -3082,9 +3151,10 @@ async function cmdUpOnce(opts, {
|
|
|
3082
3151
|
const where = describeQueuePosition(d);
|
|
3083
3152
|
reportLaneStatus({ phase: "waiting", reason: "queued_for_capacity", detail: where || "host at capacity" });
|
|
3084
3153
|
process.stderr.write(`stack: lease ${leaseId} queued — ${where}\n`);
|
|
3154
|
+
for (const line of describeAdmission(d.admission)) process.stderr.write(`stack: ${line}\n`);
|
|
3085
3155
|
for (const line of describeUnitLedger(d.ledger)) process.stderr.write(`stack: ${line}\n`);
|
|
3086
3156
|
if (opts.noWait) {
|
|
3087
|
-
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);
|
|
3088
3158
|
}
|
|
3089
3159
|
// Park zero-poll until the lease leaves the queue (granted in BOT-1187 order).
|
|
3090
3160
|
// BOT-2013: a lease reaped while queued (orphaned_agent, …) is lost, not "left the queue".
|
|
@@ -4435,7 +4505,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
|
|
|
4435
4505
|
let tunnelLost = null;
|
|
4436
4506
|
// BOT-2780: the requester origin closed under a live run (SSH loss or forward failure).
|
|
4437
4507
|
let originLost = null;
|
|
4438
|
-
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,
|
|
4439
4509
|
// BOT-3371: the optional services this run asked for, and what the stack reports it runs.
|
|
4440
4510
|
supabaseServicesRequested: opts.supabaseServices ?? [], supabaseServices: null };
|
|
4441
4511
|
incidentBox.execution = placement;
|
|
@@ -4808,6 +4878,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
|
|
|
4808
4878
|
slot, host_key: opts.host || undefined, repo: opts.repo, ticket_id: opts.ticket,
|
|
4809
4879
|
ticket_url: opts.ticketUrl || undefined, pr_id: opts.prId || undefined, pr_url: opts.prUrl || undefined,
|
|
4810
4880
|
purpose: opts.purpose || "stack run", idle_ttl_secs: opts.idleTtl ?? undefined,
|
|
4881
|
+
...admissionLeaseArgs(opts),
|
|
4811
4882
|
stack_path: execution.stackPath, worktree_root: execution.worktreeRoot,
|
|
4812
4883
|
machine_uuid: hardwareUuid,
|
|
4813
4884
|
execution: executionRequest,
|
|
@@ -5197,6 +5268,8 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
|
|
|
5197
5268
|
// BOT-2207: why the server placed (or queued) it there, and every host it weighed.
|
|
5198
5269
|
placement.placementReason = request.data.placement_reason ?? null;
|
|
5199
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;
|
|
5200
5273
|
if (executionRequest === "remote" && !remoteLease) {
|
|
5201
5274
|
const cleanup = await requestCleanup();
|
|
5202
5275
|
return {
|
|
@@ -5292,6 +5365,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
|
|
|
5292
5365
|
if (state === "queued") {
|
|
5293
5366
|
// BOT-2019: say where the lease sits (server dispatch rank, or why it has none) before parking.
|
|
5294
5367
|
stderrLine(`stack: lease ${leaseId} queued — ${describeQueuePosition(parkView)}`);
|
|
5368
|
+
for (const line of describeAdmission(parkView.admission)) stderrLine(`stack: ${line}`);
|
|
5295
5369
|
for (const line of describeUnitLedger(parkView.ledger)) stderrLine(`stack: ${line}`);
|
|
5296
5370
|
for (const line of describeConsidered(parkView.considered)) stderrLine(`stack: ${line}`);
|
|
5297
5371
|
parkReason = queuedParkReason(parkView) ?? parkReason;
|
|
@@ -5470,6 +5544,7 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
|
|
|
5470
5544
|
placement.mode = current.data.execution_mode ?? placement.mode ?? (remoteLease ? "remote" : null);
|
|
5471
5545
|
placement.placementReason = current.data.placement_reason ?? placement.placementReason;
|
|
5472
5546
|
if (Array.isArray(current.data.considered)) placement.considered = current.data.considered;
|
|
5547
|
+
if (current.data.admission) placement.admission = current.data.admission;
|
|
5473
5548
|
// BOT-2207: a queued auto lease may have been MOVED to another owned host while it waited.
|
|
5474
5549
|
// Follow it exactly like a first-time remote placement: forward to the NEW host's ssh_target.
|
|
5475
5550
|
const servedRemote = remoteLease || current.data.execution_mode === "remote";
|
|
@@ -6070,6 +6145,8 @@ export function runReceiptFields(result) {
|
|
|
6070
6145
|
// BOT-2207: why it ran where it did (e.g. moved_remote_on_requeue) and every host weighed.
|
|
6071
6146
|
...(result.execution?.placementReason ? { placement_reason: result.execution.placementReason } : {}),
|
|
6072
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 } : {}),
|
|
6073
6150
|
fenced: result.fenced === true || result.cleanup?.ok === false, error: result.error ?? result.cleanup?.error ?? null,
|
|
6074
6151
|
// BOT-2099: a platform auth/availability blip during the park is reported as an
|
|
6075
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) =>
|
|
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" });
|
package/src/wait-result.mjs
CHANGED
|
@@ -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;
|