@botbuddy/cli 1.73.6 → 1.74.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 +8 -0
- 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/commands.mjs +2 -0
- package/src/release-notes.mjs +106 -0
- package/src/stack-provision-failure.mjs +81 -0
- package/src/stack-run-outcome.mjs +10 -0
- package/src/stack.mjs +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.74.0
|
|
4
|
+
|
|
5
|
+
- `bb release-notes grants list|add|remove` (BOT-3160). A tenant owner names who may submit or manage release notes: `grants add <email> <submit|manage>` grants one scope to one member of the tenant, `grants remove` revokes it, and `grants list` prints the owners (who manage implicitly), the effective grants and the newest changes. The commands use your own sign-in (`bb login`), never the agent session, and take `--tenant <slug>` and `--json`. A refusal names its code (`scope_missing`, `member_not_in_tenant`, `owner_scope_is_implicit`, `scope_unknown`, `entitlement_missing`) and changes nothing; repeating a grant or a revoke changes nothing twice.
|
|
6
|
+
|
|
7
|
+
## 1.73.7
|
|
8
|
+
|
|
9
|
+
- `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.
|
|
10
|
+
|
|
3
11
|
## 1.73.6
|
|
4
12
|
|
|
5
13
|
- `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.
|
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.74.0",
|
|
3
|
+
"source_commit": "07346042a7617efbf032661a79bae0528e4ae2f4",
|
|
4
|
+
"source_sha256": "53d3c62c6e011b65b455d7d37dd2a10445e4555e1a48ea92faaa33f9db601440",
|
|
5
5
|
"target": "darwin-arm64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "bb0942d5d7a8a247dcbe9ab733bfe38fa40e6e72f5f2432038cb473d6c85338b"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.74.0",
|
|
3
|
+
"source_commit": "07346042a7617efbf032661a79bae0528e4ae2f4",
|
|
4
|
+
"source_sha256": "53d3c62c6e011b65b455d7d37dd2a10445e4555e1a48ea92faaa33f9db601440",
|
|
5
5
|
"target": "linux-x64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "bccb77188742510964be176335390f4c3da231aee6cfb52bcf1cb3dd190f7a11"
|
|
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.74.0",
|
|
4
|
+
"source_commit": "07346042a7617efbf032661a79bae0528e4ae2f4",
|
|
5
|
+
"source_sha256": "53d3c62c6e011b65b455d7d37dd2a10445e4555e1a48ea92faaa33f9db601440",
|
|
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": "bb0942d5d7a8a247dcbe9ab733bfe38fa40e6e72f5f2432038cb473d6c85338b",
|
|
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": "bccb77188742510964be176335390f4c3da231aee6cfb52bcf1cb3dd190f7a11",
|
|
19
19
|
"mode": "0755"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
|
@@ -348,6 +348,8 @@ ${bold("EVIDENCE")} (${cyan("bb help evidence")})
|
|
|
348
348
|
Prepare or send a BotBuddy issue report
|
|
349
349
|
release-notes submit <note.json>
|
|
350
350
|
Submit one release note for your tenant (stored as draft)
|
|
351
|
+
release-notes grants list|add|remove
|
|
352
|
+
Owners grant members the release-note submit or manage scope
|
|
351
353
|
status-band install Install the bb-status band into Claude Code (bb setup does it)
|
|
352
354
|
status-band read|relay The band's own reads and live wake (run by the mod)
|
|
353
355
|
evidence require <file> Record an exact-head evidence disposition → botbuddy/ready
|
package/src/release-notes.mjs
CHANGED
|
@@ -7,6 +7,9 @@ import { readFile } from "node:fs/promises";
|
|
|
7
7
|
import { CALL_EXIT, callToolJson, resolveCallAuth } from "./api.mjs";
|
|
8
8
|
|
|
9
9
|
export const RELEASE_NOTES_USAGE = `Usage: bb release-notes submit <note.json> [--json]
|
|
10
|
+
bb release-notes grants list [--tenant <slug>] [--json]
|
|
11
|
+
bb release-notes grants add <email> <submit|manage> [--tenant <slug>] [--json]
|
|
12
|
+
bb release-notes grants remove <email> <submit|manage> [--tenant <slug>] [--json]
|
|
10
13
|
|
|
11
14
|
Submits one release note for your tenant. The file is a schema-1 payload:
|
|
12
15
|
|
|
@@ -30,6 +33,16 @@ An unchanged resubmit (a retry) adds none. A refusal names its code
|
|
|
30
33
|
(schema_invalid, type_unknown, markup_refused, link_refused,
|
|
31
34
|
entitlement_missing) and stores nothing.
|
|
32
35
|
|
|
36
|
+
Scopes. Every member and agent key of the tenant reads. Agent keys submit
|
|
37
|
+
unless their scope list is read-only. Tenant owners manage (and submit)
|
|
38
|
+
implicitly; a member submits or manages only when an owner grants it:
|
|
39
|
+
grants add names one member of your tenant and one scope (submit, or manage,
|
|
40
|
+
which includes submit); grants remove revokes it; grants list shows owners,
|
|
41
|
+
the effective grants and the newest changes. Grants use your own sign-in
|
|
42
|
+
(bb login), never the agent session. Refusals: scope_missing (you are not an
|
|
43
|
+
owner), member_not_in_tenant, owner_scope_is_implicit, scope_unknown,
|
|
44
|
+
entitlement_missing.
|
|
45
|
+
|
|
33
46
|
Exit codes: 0 stored · 1 refused · 2 usage · 3 authentication · 5 BotBuddy unreachable.`;
|
|
34
47
|
|
|
35
48
|
const TOOL = "submit_release_note";
|
|
@@ -45,6 +58,7 @@ export async function cmdReleaseNotes(args, {
|
|
|
45
58
|
(args.length === 0 ? errorLog : log)(RELEASE_NOTES_USAGE);
|
|
46
59
|
return args.length === 0 ? 2 : CALL_EXIT.OK;
|
|
47
60
|
}
|
|
61
|
+
if (args[0] === "grants") return cmdGrants(args.slice(1), { resolveAuth, call, log, errorLog });
|
|
48
62
|
const json = args.includes("--json");
|
|
49
63
|
const rest = args.filter((a) => a !== "--json");
|
|
50
64
|
if (rest[0] !== "submit" || rest.length !== 2 || !rest[1] || rest[1].startsWith("-")) {
|
|
@@ -100,3 +114,95 @@ export async function cmdReleaseNotes(args, {
|
|
|
100
114
|
errorLog("✗ BotBuddy did not confirm the submit. Retry the same command; an unchanged resubmit adds no revision.");
|
|
101
115
|
return CALL_EXIT.ERROR;
|
|
102
116
|
}
|
|
117
|
+
|
|
118
|
+
// ── BOT-3160: bb release-notes grants list|add|remove ─────────────────
|
|
119
|
+
|
|
120
|
+
const GRANT_TOOLS = { add: "grant_release_note_scope", remove: "revoke_release_note_scope", list: "list_release_note_scope_grants" };
|
|
121
|
+
|
|
122
|
+
function printRefusalOrFailure(result, json, log, errorLog, nothing) {
|
|
123
|
+
const data = result?.data;
|
|
124
|
+
if (result?.ok && data?.ok === false && typeof data.error === "string") {
|
|
125
|
+
const refusal = { ok: false, error: data.error, ...(data.field ? { field: data.field } : {}), message: data.message ?? null };
|
|
126
|
+
if (json) log(JSON.stringify(refusal));
|
|
127
|
+
errorLog(`✗ ${refusal.error}${refusal.field ? ` (${refusal.field})` : ""}: ${refusal.message ?? nothing}`);
|
|
128
|
+
return CALL_EXIT.ERROR;
|
|
129
|
+
}
|
|
130
|
+
if (result?.auth) {
|
|
131
|
+
if (json) log(JSON.stringify({ ok: false, error: "authentication_failed" }));
|
|
132
|
+
errorLog(`✗ BotBuddy could not authenticate this command. Sign in with bb login, then retry. ${nothing}`);
|
|
133
|
+
return CALL_EXIT.AUTH;
|
|
134
|
+
}
|
|
135
|
+
if (!result?.ok && result?.status == null) {
|
|
136
|
+
if (json) log(JSON.stringify({ ok: false, error: "transport_unavailable" }));
|
|
137
|
+
errorLog(`✗ BotBuddy is unreachable. Retry the same command. ${nothing}`);
|
|
138
|
+
return CALL_EXIT.TRANSPORT;
|
|
139
|
+
}
|
|
140
|
+
if (json) log(JSON.stringify({ ok: false, error: "receipt_unavailable" }));
|
|
141
|
+
errorLog(`✗ BotBuddy did not confirm the command. Retry it; repeating a grant or revoke changes nothing twice.`);
|
|
142
|
+
return CALL_EXIT.ERROR;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function cmdGrants(argv, { resolveAuth, call, log, errorLog }) {
|
|
146
|
+
const json = argv.includes("--json");
|
|
147
|
+
let tenant = null;
|
|
148
|
+
const rest = [];
|
|
149
|
+
for (let i = 0; i < argv.length; i++) {
|
|
150
|
+
const a = argv[i];
|
|
151
|
+
if (a === "--json") continue;
|
|
152
|
+
if (a === "--tenant") {
|
|
153
|
+
const v = argv[i + 1];
|
|
154
|
+
if (!v || v.startsWith("-")) { errorLog(RELEASE_NOTES_USAGE); return 2; }
|
|
155
|
+
tenant = v;
|
|
156
|
+
i++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
rest.push(a);
|
|
160
|
+
}
|
|
161
|
+
const [sub, email, scope, ...extra] = rest;
|
|
162
|
+
const tool = GRANT_TOOLS[sub];
|
|
163
|
+
const isChange = sub === "add" || sub === "remove";
|
|
164
|
+
if (!tool || extra.length > 0 || (sub === "list" && email !== undefined) || (isChange && (!email || !scope || email.startsWith("-") || scope.startsWith("-")))) {
|
|
165
|
+
errorLog(RELEASE_NOTES_USAGE);
|
|
166
|
+
return 2;
|
|
167
|
+
}
|
|
168
|
+
const args = isChange ? { member_email: email, scope } : {};
|
|
169
|
+
|
|
170
|
+
let result;
|
|
171
|
+
try {
|
|
172
|
+
const resolved = await resolveAuth({ toolName: tool, preferSession: false });
|
|
173
|
+
result = resolved?.error || !resolved?.auth
|
|
174
|
+
? { ok: false, auth: true }
|
|
175
|
+
: await call(tool, args, { auth: resolved.auth, tenant, signal: AbortSignal.timeout(30_000) });
|
|
176
|
+
} catch {
|
|
177
|
+
result = { ok: false, status: null };
|
|
178
|
+
}
|
|
179
|
+
const data = result?.data;
|
|
180
|
+
if (!(result?.ok && data?.ok === true)) return printRefusalOrFailure(result, json, log, errorLog, isChange ? "Nothing was changed." : "");
|
|
181
|
+
|
|
182
|
+
if (json) {
|
|
183
|
+
log(JSON.stringify(data));
|
|
184
|
+
return CALL_EXIT.OK;
|
|
185
|
+
}
|
|
186
|
+
if (isChange) {
|
|
187
|
+
const where = `in tenant ${data.tenant}`;
|
|
188
|
+
if (sub === "add") log(data.changed ? `Granted ${data.scope} to ${data.member_email} ${where}.` : `${data.member_email} already holds ${data.scope} ${where}; nothing changed.`);
|
|
189
|
+
else log(data.changed ? `Revoked ${data.scope} from ${data.member_email} ${where}.` : `${data.member_email} does not hold ${data.scope} ${where}; nothing changed.`);
|
|
190
|
+
return CALL_EXIT.OK;
|
|
191
|
+
}
|
|
192
|
+
const owners = Array.isArray(data.owners) ? data.owners : [];
|
|
193
|
+
const effective = Array.isArray(data.effective) ? data.effective : [];
|
|
194
|
+
const rows = Array.isArray(data.rows) ? data.rows : [];
|
|
195
|
+
log(`Release-note scopes in tenant ${data.tenant}`);
|
|
196
|
+
log(`Owners (manage implicitly): ${owners.length ? owners.join(", ") : "none"}`);
|
|
197
|
+
if (effective.length === 0) log("Grants: none");
|
|
198
|
+
else {
|
|
199
|
+
log("Grants:");
|
|
200
|
+
for (const g of effective) log(` ${g.member_email} ${g.scope}`);
|
|
201
|
+
}
|
|
202
|
+
if (rows.length === 0) log("Recent changes: none");
|
|
203
|
+
else {
|
|
204
|
+
log("Recent changes:");
|
|
205
|
+
for (const r of rows) log(` ${r.created_at} ${r.action} ${r.scope} ${r.member_email ?? r.member_user_id} by ${r.granted_by_email ?? r.granted_by}`);
|
|
206
|
+
}
|
|
207
|
+
return CALL_EXIT.OK;
|
|
208
|
+
}
|
|
@@ -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,
|