@botbuddy/cli 1.85.3 → 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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## 1.85.3
4
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
+
5
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.
6
8
 
7
9
  ## 1.85.2
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.85.3",
3
- "source_commit": "f50cff97138fdb3acd0b3f65cacdd5fed4fd3281",
4
- "source_sha256": "ea892b69f5b20bb442632b518c1b29c3df3509296847cef4da168f52aec01be4",
2
+ "release_version": "1.85.4",
3
+ "source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
4
+ "source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
5
5
  "target": "darwin-arm64",
6
- "sha256": "34b0c7bf77043626f94db8162888a65ecff5e964b24fcb57131076ae8d9775eb"
6
+ "sha256": "787782e24b89959b3a4135d19307e599f3fcbdaa292b916cf9475e298ce3da54"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.85.3",
3
- "source_commit": "f50cff97138fdb3acd0b3f65cacdd5fed4fd3281",
4
- "source_sha256": "ea892b69f5b20bb442632b518c1b29c3df3509296847cef4da168f52aec01be4",
2
+ "release_version": "1.85.4",
3
+ "source_commit": "0503fade8adc0492e474586d62f8449c412efe4e",
4
+ "source_sha256": "c62e2e674b3631d269878779754d19cb8fe9117ca9be82a6ff92218396ef6e91",
5
5
  "target": "linux-x64",
6
- "sha256": "8cdad6a23bbf3fecb3a140a7e5f8834ddd29cbca93af3733abe2e67130b10efe"
6
+ "sha256": "d0989aef2450836d8ae26c58ef6227da015ccfc63204c3f2fcbbe77e632c1e39"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.85.3",
4
- "source_commit": "f50cff97138fdb3acd0b3f65cacdd5fed4fd3281",
5
- "source_sha256": "ea892b69f5b20bb442632b518c1b29c3df3509296847cef4da168f52aec01be4",
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": "34b0c7bf77043626f94db8162888a65ecff5e964b24fcb57131076ae8d9775eb",
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": "8cdad6a23bbf3fecb3a140a7e5f8834ddd29cbca93af3733abe2e67130b10efe",
18
+ "sha256": "d0989aef2450836d8ae26c58ef6227da015ccfc63204c3f2fcbbe77e632c1e39",
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.85.3",
3
+ "version": "1.85.4",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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 group is sampled for peak
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 = "ps_pgid_sample";
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({ pid: Number(m[1]), pgid: Number(m[2]), rssBytes: Number(m[3]) * 1024, cpuSeconds: parseCpuTime(m[4]), comm: m[5] });
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 group (it is spawned detached, so its pid is the group id).
146
- * Peak memory is the largest summed RSS seen; CPU-seconds sums each process's last seen
147
- * CPU time. Processes that live less than one interval are missed: `method` says so.
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(pgid, { ps = readPs, intervalMs = SAMPLE_INTERVAL_MS, setInterval: si = setInterval, clearInterval: ci = clearInterval, now = Date.now } = {}) {
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 cpuByPid = new Map();
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 group = rows.filter((r) => r.pgid === pgid);
158
- if (!group.length) return;
203
+ const tree = treeOf(rows);
204
+ if (!tree.size) return;
159
205
  samples++;
160
- peakRss = Math.max(peakRss, group.reduce((n, r) => n + r.rssBytes, 0));
161
- for (const r of group) if (r.cpuSeconds != null) cpuByPid.set(r.pid, Math.max(cpuByPid.get(r.pid) ?? 0, r.cpuSeconds));
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 = [...cpuByPid.values()].reduce((a, b) => a + b, 0);
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,