@botbuddy/cli 1.73.6 → 1.73.7

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.73.7
4
+
5
+ - `bb stack run` says why a stack failed to provision and whose fault it was (BOT-3238). When the serving host rolls a provision back, the receipt now carries a typed `code` (`STACK_SCHEMA_FAILED` or `STACK_PROVISION_FAILED`, where before it was `null`), the lease's `reap_reason`, a `failure_kind` (`schema` or `platform`) and, when the host sent it, `provision_failure: { stage, sqlstate, migration }`. One stderr line names the cause. When Postgres rejects your own migrations or seed (a schema-stage failure with a SQLSTATE that is not a resource, connection or server condition), the run is recorded as a `script` failure and no platform feedback is offered, because retrying or moving host fails the same way. A lease that failed with no recorded reason says `reason_unavailable: true`. The exit code (6) is unchanged.
6
+
3
7
  ## 1.73.6
4
8
 
5
9
  - `bb stack run --callback-port` no longer refuses a callback tunnel just because the serving host is busy (BOT-2860). Before it opens the real `-R`, the GatewayPorts probe proves that the host keeps reverse forwards on loopback, using a spare host port. It gave up after 2 ports that already had a listener, and parallel sessions' tunnels crowd exactly the ranges it picks from. It now tries up to 20 ports (`PROBE_PORT_ATTEMPTS`), skipping busy ones, within a 60 s overall budget (`DEFAULT_PROBE_BUDGET_MS`) after which it refuses. Only a busy port moves it on: a wildcard bind, a missing `lsof`, an unconfirmed forward or a timeout still refuse at once.
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.73.6",
3
- "source_commit": "8723f67290b9eea90d6c618a2472431c302e45ce",
4
- "source_sha256": "62a99d9813094a12205e3e3384f21b71077069ebb039966614cc64ca7117576b",
2
+ "release_version": "1.73.7",
3
+ "source_commit": "d0189483f2caa6d81fad5f59be783bd1ec2d86d3",
4
+ "source_sha256": "c4773b3dbdf5faf65a3641dbcd676de8ee5962adaf2acac74c3146dc977fa686",
5
5
  "target": "darwin-arm64",
6
- "sha256": "4b3005f197c53290306a9671740784f6080fd4b999168cbf0004d445b69091a1"
6
+ "sha256": "247f88078a3a7f30617d2370b6a5ef751e4d1dac98a619936dc5923af8e0eb64"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.73.6",
3
- "source_commit": "8723f67290b9eea90d6c618a2472431c302e45ce",
4
- "source_sha256": "62a99d9813094a12205e3e3384f21b71077069ebb039966614cc64ca7117576b",
2
+ "release_version": "1.73.7",
3
+ "source_commit": "d0189483f2caa6d81fad5f59be783bd1ec2d86d3",
4
+ "source_sha256": "c4773b3dbdf5faf65a3641dbcd676de8ee5962adaf2acac74c3146dc977fa686",
5
5
  "target": "linux-x64",
6
- "sha256": "994535444d843cf29e359e447b376f14725714d46f214430bcddb05617711165"
6
+ "sha256": "dd5d13fefb7cb6e43b2d08a9d2a52e34b93f6a76744b052ccf21d3fc3d1ec7c4"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.73.6",
4
- "source_commit": "8723f67290b9eea90d6c618a2472431c302e45ce",
5
- "source_sha256": "62a99d9813094a12205e3e3384f21b71077069ebb039966614cc64ca7117576b",
3
+ "release_version": "1.73.7",
4
+ "source_commit": "d0189483f2caa6d81fad5f59be783bd1ec2d86d3",
5
+ "source_sha256": "c4773b3dbdf5faf65a3641dbcd676de8ee5962adaf2acac74c3146dc977fa686",
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": "4b3005f197c53290306a9671740784f6080fd4b999168cbf0004d445b69091a1",
11
+ "sha256": "247f88078a3a7f30617d2370b6a5ef751e4d1dac98a619936dc5923af8e0eb64",
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": "994535444d843cf29e359e447b376f14725714d46f214430bcddb05617711165",
18
+ "sha256": "dd5d13fefb7cb6e43b2d08a9d2a52e34b93f6a76744b052ccf21d3fc3d1ec7c4",
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.73.6",
3
+ "version": "1.73.7",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,81 @@
1
+ // BOT-3238 — name WHY a stack lease failed to provision, and whose fault it was.
2
+ //
3
+ // A provision the serving host rolled back ends `reaping / provision_failed`, and
4
+ // the host's bounded, redacted reason is persisted on the lease as `error`
5
+ // (BOT-2701 detail: `stage=<stage> outcome=<outcome> exit=<n> cleanup=<c>
6
+ // sqlstate=<SQLSTATE> migration=<version>`). Before this module the run receipt
7
+ // carried that text only inside its free-form `error`, with `code: null`, and the
8
+ // outcome record filed every such run as a `platform` failure. A migration in the
9
+ // caller's own repo that Postgres rejects is the caller's failure, not the host's:
10
+ // on ENT-7111 three runs blamed a healthy host for a `LOCK TABLE` outside a
11
+ // transaction (SQLSTATE 25P01).
12
+ //
13
+ // Pure: no I/O, so the classification is unit-tested on its own.
14
+
15
+ /** The caller's own schema (migrations + seed) was rejected by Postgres. Category `script`. */
16
+ export const STACK_SCHEMA_FAILED = "STACK_SCHEMA_FAILED";
17
+ /** Any other rolled-back provision: the host, its Docker engine or the stack start. Category `platform`. */
18
+ export const STACK_PROVISION_FAILED = "STACK_PROVISION_FAILED";
19
+
20
+ // SQLSTATE classes that describe the server, not the SQL it was given: connection
21
+ // (08), insufficient resources (53, e.g. 53200 max_locks_per_transaction), operator
22
+ // intervention (57, e.g. 57014 statement timeout), system error (58) and internal
23
+ // error (XX). A schema-stage failure in one of these stays a platform failure.
24
+ const PLATFORM_SQLSTATE_CLASSES = new Set(["08", "53", "57", "58", "XX"]);
25
+
26
+ const STAGE_RE = /(?:^|\s)stage=([a-z_]{1,32})(?=\s|$)/;
27
+ const SQLSTATE_RE = /(?:^|\s)sqlstate=([0-9A-Z]{5})(?=\s|$)/;
28
+ // A migration version, or `seed` when the host attributes the failure to the seed file
29
+ // (daemon/native_diagnostic.go; never guessed from the last migration).
30
+ const MIGRATION_RE = /(?:^|\s)migration=([0-9]{1,20}|seed)(?=\s|$)/;
31
+
32
+ /** The bounded detail fields of a host provision error, each null when absent. */
33
+ export function parseProvisionError(error) {
34
+ if (typeof error !== "string" || error.length === 0) return { stage: null, sqlstate: null, migration: null };
35
+ const text = error.slice(0, 2048);
36
+ return {
37
+ stage: STAGE_RE.exec(text)?.[1] ?? null,
38
+ sqlstate: SQLSTATE_RE.exec(text)?.[1] ?? null,
39
+ migration: MIGRATION_RE.exec(text)?.[1] ?? null,
40
+ };
41
+ }
42
+
43
+ /**
44
+ * The receipt fields for a lease that ended before reaching active, from one read of
45
+ * it (`get_stack_lease` data), or null when the read says nothing about a provision
46
+ * failure. `failure_kind` is `schema` (the caller's migrations or seed) or `platform`.
47
+ */
48
+ export function provisionFailureFields(lease) {
49
+ if (!lease || typeof lease !== "object") return null;
50
+ const reapReason = typeof lease.reap_reason === "string" && lease.reap_reason ? lease.reap_reason : null;
51
+ if (reapReason !== "provision_failed") return null;
52
+ const error = typeof lease.error === "string" && lease.error ? lease.error : null;
53
+ if (!error) {
54
+ return { code: STACK_PROVISION_FAILED, reapReason, failureKind: "platform", detail: null, reasonUnavailable: true };
55
+ }
56
+ const detail = parseProvisionError(error);
57
+ const schema = detail.stage === "schema" && detail.sqlstate != null && !PLATFORM_SQLSTATE_CLASSES.has(detail.sqlstate.slice(0, 2));
58
+ return {
59
+ code: schema ? STACK_SCHEMA_FAILED : STACK_PROVISION_FAILED,
60
+ reapReason,
61
+ failureKind: schema ? "schema" : "platform",
62
+ detail: detail.stage || detail.sqlstate || detail.migration ? detail : null,
63
+ reasonUnavailable: false,
64
+ };
65
+ }
66
+
67
+ /** One stderr line for a human reading the run, naming the cause and whose it is. */
68
+ export function provisionFailureLine(leaseId, failure, hostKey = null) {
69
+ if (!failure) return null;
70
+ const where = hostKey ? ` on ${hostKey}` : "";
71
+ if (failure.failureKind === "schema") {
72
+ const source = failure.detail?.migration;
73
+ const migration = source === "seed" ? "your seed" : source ? `migration ${source}` : "your schema";
74
+ return `stack: lease ${leaseId} failed to provision: ${migration} was rejected by Postgres (SQLSTATE ${failure.detail.sqlstate}). ` +
75
+ "This is your repo's migrations or seed, not the host — fix it and run again; retrying or moving host fails the same way.";
76
+ }
77
+ if (failure.reasonUnavailable) {
78
+ return `stack: lease ${leaseId} failed to provision${where}; the host recorded no reason — inspect \`bb stack status ${leaseId}\``;
79
+ }
80
+ return `stack: lease ${leaseId} failed to provision${where} (a platform failure, not your code) — see the receipt's \`error\``;
81
+ }
@@ -59,6 +59,8 @@ const EXIT_CLEANUP_FAILED = 8;
59
59
  const SIGNAL_EXITS = new Set([129, 130, 143]);
60
60
  // Typed codes that are the platform's fault whatever the exit code says.
61
61
  const PLATFORM_CODES = new Set(["TUNNEL_LOST", "LEASE_PREEMPTED", "HOST_CAPACITY_SOURCE_STALE"]);
62
+ // Mirrors stack-provision-failure.mjs STACK_SCHEMA_FAILED (kept local for the same reason as EXIT).
63
+ const STACK_SCHEMA_FAILED_CODE = "STACK_SCHEMA_FAILED";
62
64
 
63
65
  function boundedCode(value) {
64
66
  return typeof value === "string" && CODE_RE.test(value) ? value : null;
@@ -87,6 +89,14 @@ export function classifyStackRunOutcome(fields = {}, exitCode) {
87
89
  // BOT-3109: set only when the requester network probe proved a local change (never a guess).
88
90
  if (code === REQUESTER_CATEGORY_CODE) return { category: "requester", code };
89
91
  if (code && PLATFORM_CODES.has(code)) return { category: "platform", code };
92
+ // BOT-3238: Postgres rejected the caller's own migrations or seed while the stack
93
+ // provisioned. The host did its job; the repo's schema failed, so it is a script failure.
94
+ // Only when the run ended as that lease failure with its teardown proven: an unproven
95
+ // cleanup (exit 8, cleanup false) may still hold the host's containers, so it stays
96
+ // CLEANUP_FAILED / platform below.
97
+ if (code === STACK_SCHEMA_FAILED_CODE && fields.lease_fenced !== true && fields.cleanup !== false && exitCode === EXIT_LEASE_FAILED) {
98
+ return { category: "script", code };
99
+ }
90
100
  // The stdout fence also covers unresolved cleanup. The lifecycle supplies its
91
101
  // original lease-fence fact separately so coincident child exits cannot hide it.
92
102
  if ((fields.lease_fenced ?? fields.fenced) === true) return { category: "platform", code: code ?? "LEASE_LOST" };
package/src/stack.mjs CHANGED
@@ -61,6 +61,7 @@ import { ENGINE_PUBLISHES_BEYOND_LOOPBACK, engineSocketIsLocal, formatPublishIp,
61
61
  import { bold, dim, yellow } from "./utils.mjs";
62
62
  import { STACK_RELEASE_INTENT_ENV, classifyStackRunOutcome, observeStackRunSignal, ownerReleaseHeld, reportStackRunOutcome } from "./stack-run-outcome.mjs";
63
63
  import { REQUESTER_NETWORK_CANDIDATE_CODES, REQUESTER_NETWORK_LOST_CODE, createRequesterNetworkWatch, requesterNetworkLostMessage } from "./requester-network.mjs";
64
+ import { provisionFailureFields, provisionFailureLine } from "./stack-provision-failure.mjs";
64
65
 
65
66
  export const STACK_SCHEMA_VERSION = 1;
66
67
 
@@ -337,6 +338,10 @@ ${bold("EXIT CODES")}
337
338
  3 not authenticated
338
339
  4 invalid arguments 5 backend/coordination 6 lease failed/reaped
339
340
  7 internal error 8 cleanup/reap proof failed
341
+ A provision the host rolled back (exit 6) names its cause (BOT-3238): code STACK_SCHEMA_FAILED
342
+ (Postgres rejected your migrations/seed: failure_kind "schema", provision_failure {stage, sqlstate,
343
+ migration}; recorded as your script, not the platform) or STACK_PROVISION_FAILED (failure_kind
344
+ "platform"), plus reap_reason; reason_unavailable true when the host recorded none.
340
345
 
341
346
  ${bold("IDLE LEASES")} (BOT-1803)
342
347
  stack run sends stack_digest (the deterministic sha256 of the materialised stack bundle, also
@@ -5161,14 +5166,22 @@ async function runStackLifecycleOnce(opts, childArgv, adapters, incidentBox) {
5161
5166
  // BOT-2099 (hops 3–4): name the Helper's reason (e.g. `schema readiness rejected:
5162
5167
  // canonical_probe`) — it is persisted on the lease as `error` — instead of only the state.
5163
5168
  let why = "";
5169
+ // BOT-3238: a rolled-back provision also gets a typed code, its reap_reason and
5170
+ // whose failure it was (the caller's schema vs the platform) from the same read.
5171
+ let provisionFailure = null;
5164
5172
  if (active?.failed) {
5165
5173
  const read = await readLeaseQuietly(leaseId);
5166
5174
  if (read?.ok && read.data?.success && typeof read.data.error === "string" && read.data.error) why = ` — ${read.data.error}`;
5175
+ if (read?.ok && read.data?.success) provisionFailure = provisionFailureFields(read.data);
5176
+ }
5177
+ if (provisionFailure) {
5178
+ try { stderrLine(provisionFailureLine(leaseId, provisionFailure, placement?.hostKey ?? null)); } catch { /* the receipt still carries it */ }
5167
5179
  }
5168
5180
  const cleanup = await requestCleanup();
5169
5181
  return {
5170
5182
  exitCode: cleanup?.ok === false ? EXIT.CLEANUP_FAILED : (active?.auth ? EXIT.AUTH : EXIT.LEASE_FAILED),
5171
5183
  outcome: "error", leaseId, state: active?.state ?? null, error: active?.error || `lease ${active?.state ?? "failed"} before reaching active${why}`, cleanup,
5184
+ ...(provisionFailure ? { code: provisionFailure.code, reapReason: provisionFailure.reapReason, provisionFailure } : {}),
5172
5185
  ...(parkIncident ? { incident: parkIncident } : {}),
5173
5186
  };
5174
5187
  }
@@ -5551,6 +5564,12 @@ export function runReceiptFields(result) {
5551
5564
  ...(result.parkReason ? { park_reason: result.parkReason } : {}),
5552
5565
  // BOT-3094: why a queued lease was lost, and the lease a session re-request replaced.
5553
5566
  ...(result.reapReason ? { reap_reason: result.reapReason } : {}),
5567
+ // BOT-3238: whose fault a rolled-back provision was, and the host's bounded detail.
5568
+ ...(result.provisionFailure ? {
5569
+ failure_kind: result.provisionFailure.failureKind,
5570
+ ...(result.provisionFailure.detail ? { provision_failure: result.provisionFailure.detail } : {}),
5571
+ ...(result.provisionFailure.reasonUnavailable ? { reason_unavailable: true } : {}),
5572
+ } : {}),
5554
5573
  ...(result.requeuedFrom ? { requeued_from: result.requeuedFrom } : {}),
5555
5574
  // BOT-2142: where the lease ran and how the child reached it.
5556
5575
  execution_mode: result.execution?.mode ?? null,