@botbuddy/cli 1.115.2 → 1.117.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/bin/botbuddy.mjs +10 -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/run-delivery.mjs +5 -3
- package/src/run-markers.mjs +27 -0
- package/src/run-ownership.mjs +738 -0
- package/src/run.mjs +66 -5
- package/src/stack-run-outcome.mjs +31 -12
- package/src/stack.mjs +100 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.117.0
|
|
4
|
+
|
|
5
|
+
- BOT-3463: a run started by `bb stack run`, `bb run` (foreground and detached, so `bb test` and `bb push` too) owns every process its command launches. The child's environment carries a run-scoped marker (`BOTBUDDY_RUN_ID`, `BOTBUDDY_RUN_REGISTRY`) that every descendant inherits, `setsid` daemons included, and the run writes an owner record under `~/.botbuddy/owned-runs/` (0600). When the run ends (exit, signal, timeout, lease loss) its owner stops what is still marked, plus the child's process group and its descendants: SIGTERM, then SIGKILL after 5 s. A detached worker whose command exited lets its output drain for 2 s, then stops what kept the pipes open. When the owner itself dies (SIGKILL), the per-machine reaper (`bb __reap-orphans`, started by bb, one lock per machine) stops that run's tree within one 10 s interval. A `bb` invocation also starts a sweep when none ran for 10 minutes; it stops leftovers of earlier releases by their run-scoped `BOTBUDDY_STACK_LEASE_ID` / `BOTBUDDY_TEST_RUN_ID` marker once the run's top process has only init above it. Processes are never matched by name: one without a marker, such as a dev server started by hand, is never touched. Each stopped process group is one `sensor_events` row (`bb-cli` / `run_process_reaped`: run id, PID, PGID, age), kept in a local outbox until `sensor-ingest` takes it. `BOTBUDDY_RUN_REAPER=off` disables the reaper. Host test children are unchanged: their systemd unit (`KillMode=control-group`) already ends with the run.
|
|
6
|
+
|
|
7
|
+
## 1.116.0
|
|
8
|
+
|
|
9
|
+
- BOT-3536: `bb stack run --ticket <Y>` follows an agent to its next ticket. When the server refuses the run with a session-scope `STALE_AGENT_CONTEXT` (the session is still registered for X), and this checkout's branch names Y, the run sends one ticket-moving `heartbeat` on the worktree's own cached session and one fresh admission, which the unchanged fence judges again. A run for a ticket the branch does not name, an agent-scope refusal, and an env- or flag-supplied token are never rebound, and a run rebinds at most once. The refusal hint no longer offers `bb doctor --fix` (it renews the session in place and keeps its ticket); it names `bb call heartbeat --json '{"ticket_id":"Y"}'`. The receipt carries `context_rebound: {from, to}` and `registered_ticket_id`; the `stack_run_outcome` row carries `registered_ticket_id` (stale-context rows only) and `context_rebound: true`, and an older server's unknown-key refusal drops each newer key in turn. Needs MCP 2.157.2 for the two outcome keys.
|
|
10
|
+
|
|
3
11
|
## 1.115.2
|
|
4
12
|
|
|
5
13
|
- BOT-3532: the host daemon declares the status-v1 refusal contract when it submits a no-execution recovery proof (`X-BotBuddy-Recovery-Refusal: status-v1`). The server then answers a refused settlement as HTTP 409 with its fixed reason code, and the daemon reads that code exactly as it read the legacy HTTP 200 refusal: an expiry refusal re-signs a fresh proof, any other refusal keeps the proof and the fence. An unknown 409 code stays an opaque error. Needs MCP 2.157.1; older daemons keep the legacy 200 shape.
|
package/bin/botbuddy.mjs
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
import { run } from "../src/commands.mjs";
|
|
3
3
|
import { ensureRunDelivery } from "../src/run-delivery.mjs";
|
|
4
4
|
import { feedbackReminder } from "../src/feedback-reminder.mjs";
|
|
5
|
+
import { ensureOrphanReaper, runOrphanReaper } from "../src/run-ownership.mjs";
|
|
5
6
|
import { writeSync } from "node:fs";
|
|
6
7
|
|
|
7
8
|
const argv = process.argv.slice(2);
|
|
9
|
+
|
|
10
|
+
// BOT-3463: the per-machine orphan reaper (started detached by bb, never typed by hand).
|
|
11
|
+
if (argv[0] === "__reap-orphans") {
|
|
12
|
+
runOrphanReaper().then(() => process.exit(0), () => process.exit(1));
|
|
13
|
+
} else {
|
|
8
14
|
// Some commands exit directly; observe the final exit once so those paths
|
|
9
15
|
// receive the same stderr-only guidance without changing their exit status.
|
|
10
16
|
process.once("exit", (code) => {
|
|
@@ -29,6 +35,9 @@ const readOnly = flags.some((flag) => flag === "--help" || flag === "-h")
|
|
|
29
35
|
// Feedback must not start unrelated delivery while an agent reports a blocker.
|
|
30
36
|
const feedbackCommand = argv[0] === "feedback";
|
|
31
37
|
const delivery = deliveryProcessArgs || readOnly || feedbackCommand ? Promise.resolve() : ensureRunDelivery().catch(() => {});
|
|
38
|
+
// BOT-3463 (AC-2): a `bb` invocation sweeps the processes dead runs left behind when no sweep ran
|
|
39
|
+
// for ten minutes. A stat and a small read when nothing is due; it never fails the command.
|
|
40
|
+
if (!deliveryProcessArgs && !readOnly && !feedbackCommand) void ensureOrphanReaper().catch(() => {});
|
|
32
41
|
|
|
33
42
|
delivery.then(() => run(argv)).then((code) => {
|
|
34
43
|
if (typeof code === "number") process.exitCode = code;
|
|
@@ -36,3 +45,4 @@ delivery.then(() => run(argv)).then((code) => {
|
|
|
36
45
|
console.error(`\x1b[31m✗\x1b[0m ${err?.message || err}`);
|
|
37
46
|
process.exit(1);
|
|
38
47
|
});
|
|
48
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.117.0",
|
|
3
|
+
"source_commit": "733fb1c67fcc343490a74b98677ead3158aa70c5",
|
|
4
|
+
"source_sha256": "2276e0c95a7db937521fc6e035b3c3fef8c6210766589264210f0748a05139f0",
|
|
5
5
|
"target": "darwin-arm64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "00c84c074ec601776773a6a69b6b7e3a64b6d46ca2b43ff40cad9864f9c85e63"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.117.0",
|
|
3
|
+
"source_commit": "733fb1c67fcc343490a74b98677ead3158aa70c5",
|
|
4
|
+
"source_sha256": "2276e0c95a7db937521fc6e035b3c3fef8c6210766589264210f0748a05139f0",
|
|
5
5
|
"target": "linux-x64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "7e3673b294a9d0133cf15436130238201f319d4e49f6acf2288b74f5628e8f69"
|
|
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.117.0",
|
|
4
|
+
"source_commit": "733fb1c67fcc343490a74b98677ead3158aa70c5",
|
|
5
|
+
"source_sha256": "2276e0c95a7db937521fc6e035b3c3fef8c6210766589264210f0748a05139f0",
|
|
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": "00c84c074ec601776773a6a69b6b7e3a64b6d46ca2b43ff40cad9864f9c85e63",
|
|
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": "7e3673b294a9d0133cf15436130238201f319d4e49f6acf2288b74f5628e8f69",
|
|
19
19
|
"mode": "0755"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
package/src/run-delivery.mjs
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import { createHash, randomUUID } from "node:crypto";
|
|
26
26
|
import { chmod, link, mkdir, readdir, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
27
27
|
import { execFile, spawn } from "node:child_process";
|
|
28
|
+
import { withoutRunMarkers } from "./run-markers.mjs";
|
|
28
29
|
import { dirname, join } from "node:path";
|
|
29
30
|
import { homedir } from "node:os";
|
|
30
31
|
import { fileURLToPath } from "node:url";
|
|
@@ -337,8 +338,8 @@ export async function drainOnce({
|
|
|
337
338
|
* Take the per-machine delivery lock. A lock whose holder PID is gone is stale
|
|
338
339
|
* and is taken over.
|
|
339
340
|
*/
|
|
340
|
-
export async function acquireDeliveryLock({ home = homedir(), pid = process.pid, isAlive = pidAlive } = {}) {
|
|
341
|
-
|
|
341
|
+
export async function acquireDeliveryLock({ home = homedir(), pid = process.pid, isAlive = pidAlive, lockFile = deliveryLockPath(home) } = {}) {
|
|
342
|
+
// BOT-3463: the orphan reaper takes its own per-machine lock through the same mechanism.
|
|
342
343
|
await mkdir(dirname(lockFile), { recursive: true });
|
|
343
344
|
const candidate = `${lockFile}.${pid}.${randomUUID()}.tmp`;
|
|
344
345
|
await writeFile(candidate, JSON.stringify({ pid, started_at: new Date().toISOString() }), { mode: 0o600 });
|
|
@@ -487,7 +488,8 @@ export async function ensureRunDelivery({
|
|
|
487
488
|
const holder = await readJson(deliveryLockPath(home));
|
|
488
489
|
if (Number.isInteger(holder?.pid) && isAlive(holder.pid)) return { started: false, reason: "held" };
|
|
489
490
|
const bin = join(dirname(fileURLToPath(import.meta.url)), "..", "bin", "botbuddy.mjs");
|
|
490
|
-
|
|
491
|
+
// BOT-3463: the delivery process outlives the run that started it, so it carries no run marker.
|
|
492
|
+
const child = spawnImpl(process.execPath, [bin, "run", "--deliver"], { detached: true, stdio: "ignore", cwd: home, env: withoutRunMarkers(env), windowsHide: true });
|
|
491
493
|
child.on?.("error", () => { /* best effort: the next invocation retries */ });
|
|
492
494
|
child.unref?.();
|
|
493
495
|
return { started: true, reason: "pending" };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// BOT-3463 — the run-scoped environment marker every bb run puts on the processes it launches.
|
|
2
|
+
//
|
|
3
|
+
// The marker is what identifies a run's processes later, never a process name: a dev
|
|
4
|
+
// server a user started by hand carries no marker and is never touched.
|
|
5
|
+
|
|
6
|
+
/** The run that launched this process (inherited by every descendant, setsid or not). */
|
|
7
|
+
export const RUN_ID_ENV = "BOTBUDDY_RUN_ID";
|
|
8
|
+
/** Which ownership record directory (a hash of it) judges that run, so another HOME never does. */
|
|
9
|
+
export const RUN_REGISTRY_ENV = "BOTBUDDY_RUN_REGISTRY";
|
|
10
|
+
/**
|
|
11
|
+
* Run-scoped markers that bb releases before BOT-3463 already set on a run's child:
|
|
12
|
+
* `bb stack run` exports the lease, `bb test` the test run. Orphans left by those
|
|
13
|
+
* releases are found by them (AC-2). Order is precedence when a process has both.
|
|
14
|
+
*/
|
|
15
|
+
export const LEGACY_RUN_MARKERS = Object.freeze(["BOTBUDDY_STACK_LEASE_ID", "BOTBUDDY_TEST_RUN_ID"]);
|
|
16
|
+
export const ALL_RUN_MARKERS = Object.freeze([RUN_ID_ENV, RUN_REGISTRY_ENV, ...LEGACY_RUN_MARKERS]);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The environment for a long-lived bb helper (the run delivery process, the orphan
|
|
20
|
+
* reaper) that must outlive the run whose process started it: no run marker, so it is
|
|
21
|
+
* never taken for part of that run's tree.
|
|
22
|
+
*/
|
|
23
|
+
export function withoutRunMarkers(env = process.env) {
|
|
24
|
+
const clean = { ...env };
|
|
25
|
+
for (const name of ALL_RUN_MARKERS) delete clean[name];
|
|
26
|
+
return clean;
|
|
27
|
+
}
|