@botbuddy/cli 1.85.1 → 1.85.4
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 +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/agent-doctor.mjs +4 -0
- package/src/agent-session.mjs +12 -1
- package/src/harness-holder.mjs +25 -4
- package/src/test-child.mjs +62 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.85.3
|
|
4
|
+
|
|
5
|
+
- BOT-3276: `bb stack run --test-child` measures the child's whole process tree, including browsers and servers that move to their own process group or session. `child_resources.method` is now `ps_tree_sample`; the receipt's fields are unchanged.
|
|
6
|
+
|
|
7
|
+
- Ships the `bb doctor --fix` reused-worktree repair to npm (BOT-3307). A sub-agent working in another worktree keeps that worktree's own identity.
|
|
8
|
+
|
|
9
|
+
## 1.85.2
|
|
10
|
+
|
|
11
|
+
- `bb doctor --fix` repairs the current session's identity in a reused worktree (BOT-3307): a Claude Desktop session whose transcript is in the worktree replaces a previous session's cache once that session has gone, instead of renewing it and leaving the bb-status band refusing with "BB identity belongs to another session". A session still active in the worktree keeps its cache, and doctor says so with `session_still_active`.
|
|
12
|
+
|
|
3
13
|
## 1.85.1
|
|
4
14
|
|
|
5
15
|
- `bb bootstrap` connects in a reused worktree when you are signed in as the owner (BOT-3253): another session's stale cached session is retired with its own credential instead of failing with `agent_identity_required`, and a cached credential the server no longer accepts is left to expire. A session that is still live keeps its cache and waits, and the command names it and says what to do next.
|
|
Binary file
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.85.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.85.4",
|
|
3
|
+
"source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
|
|
4
|
+
"source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
|
|
5
5
|
"target": "darwin-arm64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "787782e24b89959b3a4135d19307e599f3fcbdaa292b916cf9475e298ce3da54"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"release_version": "1.85.
|
|
3
|
-
"source_commit": "
|
|
4
|
-
"source_sha256": "
|
|
2
|
+
"release_version": "1.85.4",
|
|
3
|
+
"source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
|
|
4
|
+
"source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
|
|
5
5
|
"target": "linux-x64",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "d0989aef2450836d8ae26c58ef6227da015ccfc63204c3f2fcbbe77e632c1e39"
|
|
7
7
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema_version": 1,
|
|
3
|
-
"release_version": "1.85.
|
|
4
|
-
"source_commit": "
|
|
5
|
-
"source_sha256": "
|
|
3
|
+
"release_version": "1.85.4",
|
|
4
|
+
"source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
|
|
5
|
+
"source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
|
|
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": "787782e24b89959b3a4135d19307e599f3fcbdaa292b916cf9475e298ce3da54",
|
|
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": "d0989aef2450836d8ae26c58ef6227da015ccfc63204c3f2fcbbe77e632c1e39",
|
|
19
19
|
"mode": "0755"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
package/src/agent-doctor.mjs
CHANGED
|
@@ -96,6 +96,10 @@ export function repairFailureRecovery(code, error = null) {
|
|
|
96
96
|
if (code === "client_key_unavailable") {
|
|
97
97
|
return "the client key could not be read (locked or failing credential store); unlock it, then run `bb doctor --fix`";
|
|
98
98
|
}
|
|
99
|
+
// BOT-3307: another session is still working in this worktree; its cache is kept.
|
|
100
|
+
if (code === "session_still_active") {
|
|
101
|
+
return "another session is still active in this worktree and keeps its identity; use another worktree, or run `bb doctor --fix` once that session has ended";
|
|
102
|
+
}
|
|
99
103
|
// BOT-1787: this is a server-side identity conflict, not an authentication
|
|
100
104
|
// failure. Preserve the real remedy so a healthy credential is never needlessly
|
|
101
105
|
// rotated; `bb setup` clears this worktree's cache and re-registers it.
|
package/src/agent-session.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import { getConfig } from "./config.mjs";
|
|
|
16
16
|
import { acquireStackLock } from "./stack-file-lock.mjs";
|
|
17
17
|
import { AGENT_KEY_RE, readAgentSessionTokenEnv, legacyAgentAliasHint } from "./agent-key.mjs";
|
|
18
18
|
import { agentStatePath, cacheBelongsToHarness, clearAgentState, harnessSessionIdFromEnv, isAgentStateFresh, readAgentState, resolveMachineId, worktreeRoot, writeAgentState } from "./agent-state.mjs";
|
|
19
|
+
import { claudeHolderActive, worktreeHarnessSessionId } from "./harness-holder.mjs";
|
|
19
20
|
import { machineUuid } from "./machine-id.mjs";
|
|
20
21
|
import { machineHost } from "./machine-host.mjs";
|
|
21
22
|
|
|
@@ -265,12 +266,22 @@ export async function selfHealAgentSession({
|
|
|
265
266
|
const renewal = rejectedCredential !== null;
|
|
266
267
|
// BOT-2425: the harness session this process runs in (exported by the
|
|
267
268
|
// SessionStart hook). A cache belongs to it only when it recorded the same id.
|
|
268
|
-
|
|
269
|
+
// BOT-3307: a Claude Desktop shell is recognised by its transcript in this
|
|
270
|
+
// worktree. A rejected-token renewal keeps the cached identity either way.
|
|
271
|
+
const envHarness = renewal ? harnessSessionIdFromEnv(env) : await worktreeHarnessSessionId(cwd, env);
|
|
269
272
|
// BOT-3257 (Codex P1): a cache minted by another server origin is never
|
|
270
273
|
// reused, renewed or compared here — its token must not reach this server.
|
|
271
274
|
// It is treated as absent: a mint for this origin replaces it.
|
|
272
275
|
const sameServer = !current || cacheBelongsToServer(current, env);
|
|
273
276
|
const ownCache = !!current && sameServer && cacheBelongsToHarness(current, envHarness);
|
|
277
|
+
// BOT-3307: the same holder rule as the band and `bb bootstrap` (BOT-3281): a
|
|
278
|
+
// session still working here keeps its cache, and one that has gone is replaced.
|
|
279
|
+
if (!renewal && env?.CLAUDE_CODE_CHILD_SESSION === "1" && envHarness && current && sameServer && !ownCache && current.harness_session_id) {
|
|
280
|
+
const active = await claudeHolderActive(current.harness_session_id, await worktreeRoot(cwd), { env, now: () => now().getTime() }).catch(() => null);
|
|
281
|
+
if (active === true || (active === null && isFresh(current, now()))) {
|
|
282
|
+
throw missing("session_still_active", `BB session ${current.session_id} is still live and holds this worktree's session cache, so it was left running. Use another worktree, or retry once that session has ended.`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
274
285
|
let bound;
|
|
275
286
|
let registrationWorktree = cwd;
|
|
276
287
|
if (renewal) {
|
package/src/harness-holder.mjs
CHANGED
|
@@ -13,15 +13,38 @@
|
|
|
13
13
|
import { readFile, readdir, realpath, rename, stat } from "node:fs/promises";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { homedir } from "node:os";
|
|
16
|
+
import { harnessSessionIdFromEnv, worktreeRoot } from "./agent-state.mjs";
|
|
16
17
|
|
|
17
18
|
export const HOLDER_IDLE_MS = 30 * 60 * 1000;
|
|
18
19
|
const UUID_ONLY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
20
|
+
const claudeProjects = (env) => join(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "projects");
|
|
21
|
+
// Claude Code names a project's directory after its path, every
|
|
22
|
+
// non-alphanumeric character replaced by "-".
|
|
23
|
+
const claudeProjectDir = (worktree) => String(worktree).replace(/[^a-zA-Z0-9]/g, "-");
|
|
24
|
+
|
|
25
|
+
// BOT-3307: the harness session running in this worktree. Claude Desktop sets
|
|
26
|
+
// CLAUDE_CODE_CHILD_SESSION=1 in main-thread and sub-agent shells alike, with
|
|
27
|
+
// identical environments, so the flag alone cannot name the session. The
|
|
28
|
+
// session's transcript can: it lives under the directory the session runs in,
|
|
29
|
+
// so a sub-agent in another worktree still never claims its parent's id.
|
|
30
|
+
export async function worktreeHarnessSessionId(cwd, env = process.env) {
|
|
31
|
+
if (env?.CLAUDE_CODE_CHILD_SESSION !== "1") return harnessSessionIdFromEnv(env);
|
|
32
|
+
const claimed = harnessSessionIdFromEnv({ ...env, CLAUDE_CODE_CHILD_SESSION: undefined });
|
|
33
|
+
if (!claimed) return null;
|
|
34
|
+
try {
|
|
35
|
+
await stat(join(claudeProjects(env), claudeProjectDir(await worktreeRoot(cwd)), `${claimed}.jsonl`));
|
|
36
|
+
return claimed;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
19
42
|
// true: the holder's transcript was written within HOLDER_IDLE_MS; false: it
|
|
20
43
|
// exists and has been silent longer; null: no transcript found (unknown).
|
|
21
44
|
export async function claudeHolderActive(holder, worktree, { env = process.env, now = () => Date.now() } = {}) {
|
|
22
45
|
const id = String(holder || "").toLowerCase();
|
|
23
46
|
if (!UUID_ONLY.test(id)) return null;
|
|
24
|
-
const projects =
|
|
47
|
+
const projects = claudeProjects(env);
|
|
25
48
|
const mtime = async (dir) => {
|
|
26
49
|
try {
|
|
27
50
|
return (await stat(join(projects, dir, `${id}.jsonl`))).mtimeMs;
|
|
@@ -29,9 +52,7 @@ export async function claudeHolderActive(holder, worktree, { env = process.env,
|
|
|
29
52
|
return null;
|
|
30
53
|
}
|
|
31
54
|
};
|
|
32
|
-
|
|
33
|
-
// non-alphanumeric character replaced by "-".
|
|
34
|
-
let at = await mtime(String(worktree).replace(/[^a-zA-Z0-9]/g, "-"));
|
|
55
|
+
let at = await mtime(claudeProjectDir(worktree));
|
|
35
56
|
if (at == null) {
|
|
36
57
|
let dirs = [];
|
|
37
58
|
try {
|
package/src/test-child.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Before the child starts, the run asks the control plane where it runs and takes exactly
|
|
4
4
|
// ONE `test_child` slot on that run host (BOT-3239 R-e: place first, then one slot; a run
|
|
5
5
|
// that is waiting holds nothing). The slot's TTL is renewed by the run itself, so a killed
|
|
6
|
-
// run frees it within one TTL. While the child runs, its process
|
|
6
|
+
// run frees it within one TTL. While the child runs, its process tree is sampled for peak
|
|
7
7
|
// memory and CPU-seconds; at exit the slot is released and the cost recorded on the lease.
|
|
8
8
|
//
|
|
9
9
|
// The kill switch and the default-off flag are read by the server on every decision.
|
|
@@ -19,7 +19,7 @@ export const TEST_CHILD_UNAVAILABLE = "TEST_CHILD_UNAVAILABLE";
|
|
|
19
19
|
/** A full pool with no reported expiry parks at most one default slot TTL. */
|
|
20
20
|
export const FALLBACK_PARK_MS = 180_000;
|
|
21
21
|
export const SAMPLE_INTERVAL_MS = 5_000;
|
|
22
|
-
export const SAMPLE_METHOD = "
|
|
22
|
+
export const SAMPLE_METHOD = "ps_tree_sample";
|
|
23
23
|
|
|
24
24
|
/** The three tool calls, over the run's retrying caller. */
|
|
25
25
|
export function testChildApi(rpc) {
|
|
@@ -123,42 +123,88 @@ export function parseCpuTime(raw) {
|
|
|
123
123
|
return days * 86_400 + secs;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
/** Rows of `ps -A -o pid=,pgid=,rss=,time=,comm=` (rss in KiB). */
|
|
126
|
+
/** Rows of `ps -A -o pid=,ppid=,pgid=,rss=,time=,lstart=,comm=` (rss in KiB, lstart in the C locale). */
|
|
127
127
|
export function parsePsRows(text) {
|
|
128
128
|
const rows = [];
|
|
129
129
|
for (const line of String(text ?? "").split("\n")) {
|
|
130
|
-
const m = line.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/);
|
|
130
|
+
const m = line.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S+\s+\S+\s+\d+\s+\S+\s+\d+)\s+(.*)$/);
|
|
131
131
|
if (!m) continue;
|
|
132
|
-
rows.push({
|
|
132
|
+
rows.push({
|
|
133
|
+
pid: Number(m[1]), ppid: Number(m[2]), pgid: Number(m[3]), rssBytes: Number(m[4]) * 1024,
|
|
134
|
+
cpuSeconds: parseCpuTime(m[5]), startedAt: m[6].replace(/\s+/g, " "), comm: m[7],
|
|
135
|
+
});
|
|
133
136
|
}
|
|
134
137
|
return rows;
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
export function readPs({ run = spawnSync } = {}) {
|
|
138
141
|
// nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- fixed argv, no shell.
|
|
139
|
-
const r = run("ps", ["-A", "-o", "pid=,pgid=,rss=,time=,comm="], { encoding: "utf8", timeout: 5_000 });
|
|
142
|
+
const r = run("ps", ["-A", "-o", "pid=,ppid=,pgid=,rss=,time=,lstart=,comm="], { encoding: "utf8", timeout: 5_000, env: { ...process.env, LC_ALL: "C" } });
|
|
140
143
|
if (r.status !== 0 || typeof r.stdout !== "string") return null;
|
|
141
144
|
return parsePsRows(r.stdout);
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
/** A pid is reused over a long run; the pid with its start time names one process. */
|
|
148
|
+
const processKey = (row) => `${row.pid}@${row.startedAt}`;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Follows one child's process tree across `ps` frames. A process belongs to the tree when it
|
|
152
|
+
* is the child, a child of a member, or in a process group a member leads, so a descendant
|
|
153
|
+
* that calls setsid or setpgid stays in it. A member stays one after its parent dies.
|
|
154
|
+
*/
|
|
155
|
+
function childTreeTracker(rootPid) {
|
|
156
|
+
const members = new Set();
|
|
157
|
+
const groups = new Map([[rootPid, null]]); // group id → the identity of its leader
|
|
158
|
+
let rootSeen = false;
|
|
159
|
+
return (rows) => {
|
|
160
|
+
const childrenOf = new Map(); const inGroup = new Map();
|
|
161
|
+
for (const row of rows) {
|
|
162
|
+
childrenOf.set(row.ppid, [...(childrenOf.get(row.ppid) ?? []), row]);
|
|
163
|
+
inGroup.set(row.pgid, [...(inGroup.get(row.pgid) ?? []), row]);
|
|
164
|
+
if (row.pid !== row.pgid || !groups.has(row.pid)) continue;
|
|
165
|
+
const leader = groups.get(row.pid);
|
|
166
|
+
if (leader === null) groups.set(row.pid, processKey(row));
|
|
167
|
+
else if (leader !== processKey(row)) groups.delete(row.pid); // the group id was reused
|
|
168
|
+
}
|
|
169
|
+
if (!rootSeen) {
|
|
170
|
+
const root = rows.find((row) => row.pid === rootPid);
|
|
171
|
+
if (root) { rootSeen = true; members.add(processKey(root)); }
|
|
172
|
+
}
|
|
173
|
+
const tree = new Map();
|
|
174
|
+
const pending = rows.filter((row) => members.has(processKey(row)) || groups.has(row.pgid));
|
|
175
|
+
while (pending.length) {
|
|
176
|
+
const row = pending.pop();
|
|
177
|
+
const key = processKey(row);
|
|
178
|
+
if (tree.has(key)) continue;
|
|
179
|
+
tree.set(key, row);
|
|
180
|
+
members.add(key);
|
|
181
|
+
if (row.pid === row.pgid) { groups.set(row.pid, key); pending.push(...(inGroup.get(row.pid) ?? [])); }
|
|
182
|
+
pending.push(...(childrenOf.get(row.pid) ?? []));
|
|
183
|
+
}
|
|
184
|
+
return tree;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
144
188
|
/**
|
|
145
|
-
* Samples the child's process
|
|
146
|
-
*
|
|
147
|
-
* CPU time.
|
|
189
|
+
* Samples the child's process tree. Peak memory is the largest summed RSS seen, so memory
|
|
190
|
+
* shared between processes counts once per process; CPU-seconds sums each process's last seen
|
|
191
|
+
* CPU time. Sampling stops when the child exits. A process that lives less than one interval
|
|
192
|
+
* is missed, as is one that leaves the tree (a double fork) before a sample sees it.
|
|
148
193
|
*/
|
|
149
|
-
export function startChildSampler(
|
|
194
|
+
export function startChildSampler(rootPid, { ps = readPs, intervalMs = SAMPLE_INTERVAL_MS, setInterval: si = setInterval, clearInterval: ci = clearInterval, now = Date.now } = {}) {
|
|
150
195
|
const startedAt = now();
|
|
151
196
|
let peakRss = 0; let samples = 0; let failed = 0;
|
|
152
|
-
const
|
|
197
|
+
const cpuByProcess = new Map();
|
|
198
|
+
const treeOf = childTreeTracker(rootPid);
|
|
153
199
|
const sample = () => {
|
|
154
200
|
let rows;
|
|
155
201
|
try { rows = ps(); } catch { rows = null; }
|
|
156
202
|
if (!rows) { failed++; return; }
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
203
|
+
const tree = treeOf(rows);
|
|
204
|
+
if (!tree.size) return;
|
|
159
205
|
samples++;
|
|
160
|
-
peakRss = Math.max(peakRss,
|
|
161
|
-
for (const r of
|
|
206
|
+
peakRss = Math.max(peakRss, [...tree.values()].reduce((n, r) => n + r.rssBytes, 0));
|
|
207
|
+
for (const [key, r] of tree) if (r.cpuSeconds != null) cpuByProcess.set(key, Math.max(cpuByProcess.get(key) ?? 0, r.cpuSeconds));
|
|
162
208
|
};
|
|
163
209
|
sample();
|
|
164
210
|
const timer = si(sample, intervalMs);
|
|
@@ -166,7 +212,7 @@ export function startChildSampler(pgid, { ps = readPs, intervalMs = SAMPLE_INTER
|
|
|
166
212
|
return {
|
|
167
213
|
stop() {
|
|
168
214
|
ci(timer);
|
|
169
|
-
const cpu = [...
|
|
215
|
+
const cpu = [...cpuByProcess.values()].reduce((a, b) => a + b, 0);
|
|
170
216
|
return {
|
|
171
217
|
peak_rss_bytes: peakRss, cpu_seconds: Math.round(cpu * 100) / 100,
|
|
172
218
|
samples, failed_samples: failed, interval_ms: intervalMs,
|