@feigi/fleet-ctl 3.71.0 → 3.71.2

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.
@@ -376,7 +376,7 @@ Arm with `persistent: true`, description `ready-to-merge label on this repo's PR
376
376
  - Seed `seen` **before** the loop so PRs already handled — including ones skipped for `CHANGES_REQUESTED` or left on red CI — do not re-fire every minute. Only a label appearing after arming is an event. The seed poll is guarded the same way as every tick: a `gh` call failing on the very first poll must not arm on an empty `seen`, which would replay the whole labeled set as spurious events on tick one.
377
377
  - The `if cur=$(poll)` guard — seed and every tick alike — keeps `seen` intact when a `gh` call fails transiently; without it a failed poll reads as an empty labeled set and either arms on nothing (the seed) or wipes `seen` (a tick), both replaying the full labeled set as events on the next successful poll. The guard depends on `poll` ending in the bare `gh` call, not in a pipe: `tr` sits at the call sites (not inside `poll`) precisely so a failing `gh` call's exit status reaches `cur=$(poll)` / `seed=$(poll)` instead of being swallowed by `tr`, which exits 0 regardless of what it reads.
378
378
  - **A full page is not a whole reading either.** `gh pr list` stops at its `--limit` — 30 when the flag is absent — with exit 0 and no warning, so `poll` passes an explicit one (`cap`, one variable for the flag and the check), and `capcheck` says once when a poll fills it and once when one comes back under it: the DEGRADED/RECOVERED latch `run-team/SKILL.md`'s CI Monitor uses for the same cause, and never a line per tick. The numbers a capped poll did return are still real events; the line is for the labels past them, which fire nothing while it holds.
379
- - **The per-PR loop is heredoc-fed on purpose — `for n in $cur` is the one form that cannot work here.** This runs under zsh, which word-splits an unquoted command substitution's result but *not* an unquoted parameter expansion, and `cur` is a parameter. Measured on zsh 5.9 with `seen` holding two PR numbers and `cur` those two plus a third: the bare form runs **one** iteration with the whole list glued into a single value and emits one `ready-to-merge label added:` event with all three numbers glued into it, one nonsense event naming no PR, while the real new PR is never reported; the heredoc form emits the third alone. `run-team/SKILL.md`'s **Shell traps** carries the mechanism and the `</dev/null` trap that bites the next command added inside this loop, and `run-team/references/shell-traps.md` carries the remedy table. Note the contrast with step 1's `for _ in $(seq 1 60)`: that is a command substitution, it splits, and it is correct as written.
379
+ - **The per-PR loop is heredoc-fed on purpose — `for n in $cur` is the one form that cannot work here.** This runs under zsh, which word-splits an unquoted command substitution's result but *not* an unquoted parameter expansion, and `cur` is a parameter. Measured on zsh 5.9 with `seen` holding two PR numbers and `cur` those two plus a third: the bare form runs **one** iteration with the whole list glued into a single value and emits one `ready-to-merge label added:` event with all three numbers glued into it, one nonsense event naming no PR, while the real new PR is never reported; the heredoc form emits the third alone. `run-team/references/shell-traps.md`'s **Shell traps** carries the mechanism and the `</dev/null` trap that bites the next command added inside this loop, and that file carries the remedy table. Note the contrast with step 1's `for _ in $(seq 1 60)`: that is a command substitution, it splits, and it is correct as written.
380
380
  - 60s poll — remote API, stay off rate limits.
381
381
  - A held PR stays in `seen`, so its own label will not re-fire. Fine: what unblocks it is the **lower** PR getting labeled, which does fire, and step 4's re-evaluation picks up both in numeric order.
382
382
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.71.0",
3
+ "version": "3.71.2",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/scripts/proc.mjs CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  import { readFileSync } from "node:fs";
6
6
  import { spawnSync } from "node:child_process";
7
- import { basename } from "node:path";
7
+ import { basename, join } from "node:path";
8
+ import { isDigits } from "./arg.mjs";
8
9
 
9
10
  // ESRCH alone is dead. EPERM is a live process we may not signal, and any
10
11
  // other error is not evidence of death either.
@@ -17,23 +18,29 @@ export function isDead(pid) {
17
18
  }
18
19
  }
19
20
 
20
- // Thrown when the process tree or a start time cannot be read. A caller that
21
- // would act on a verdict refuses instead: a controller nobody could judge is
22
- // never judged dead.
21
+ // Thrown when the process tree or a start identity cannot be read. A caller
22
+ // that would act on a verdict refuses instead: a controller nobody could judge
23
+ // is never judged dead.
23
24
  export class ProcUnreadable extends Error {}
24
25
 
25
26
  // The two reads the controller record needs — a process's parent and argv,
26
- // and its start time — behind one source. The real one is `ps`. A
27
- // FLEET_PROC_TABLE file replaces it whole: a test suite run from inside a live
28
- // omp session would otherwise find that session's omp as its ancestor. The
29
- // file is a JSON object keyed by pid:
27
+ // and its start identity — behind one source. The parent comes from `ps` on
28
+ // every platform. The start identity comes from procfs on Linux and from `ps`
29
+ // everywhere else, chosen by platform rather than by whether /proc can be
30
+ // read: the run that writes a record and the run that judges it must read it
31
+ // the same way, and a key read one way never equals one read the other way.
32
+ // A FLEET_PROC_TABLE file replaces both whole: a test suite run from inside a
33
+ // live omp session would otherwise find that session's omp as its ancestor.
34
+ // The file is a JSON object keyed by pid:
30
35
  //
31
36
  // { "<pid>": { "ppid": <pid>, "argv": ["bun", "/…/omp"], "lstart": "<start>" } }
32
37
  //
33
- // A pid the table does not name has no parent and no start time, as a pid
34
- // `ps` does not list.
38
+ // A pid the table does not name has no parent and no start identity, as a
39
+ // pid that is gone.
35
40
  export function processSource(env = process.env) {
36
- return env.FLEET_PROC_TABLE ? tableSource(env.FLEET_PROC_TABLE) : psSource(env);
41
+ if (env.FLEET_PROC_TABLE) return tableSource(env.FLEET_PROC_TABLE);
42
+ const ps = psSource(env);
43
+ return process.platform === "linux" ? { ...ps, startTime: (pid) => procfsStartTime(pid) } : ps;
37
44
  }
38
45
 
39
46
  function tableSource(path) {
@@ -69,10 +76,13 @@ function tableProblem(table) {
69
76
  return null;
70
77
  }
71
78
 
72
- function psSource(env) {
73
- // `lstart` is printed in the caller's zone and locale, and a later run —
74
- // with its own TZ — compares it as an opaque string. Pinning both makes the
75
- // string a property of the process, not of whoever asked.
79
+ // The `ps` source: the process tree, and a start identity that is the
80
+ // process's start time as `ps -o lstart=` prints it. On macOS that time is
81
+ // written once, when the process forks, so it never changes for a live
82
+ // process. It is printed in the caller's zone and locale, and a later run —
83
+ // with its own TZ — compares it as an opaque string. Pinning both makes the
84
+ // string a property of the process, not of whoever asked.
85
+ export function psSource(env) {
76
86
  const psEnv = { ...env, TZ: "UTC", LC_ALL: "C" };
77
87
  const ps = (args) => {
78
88
  const r = spawnSync("ps", args, { encoding: "utf8", env: psEnv });
@@ -103,6 +113,40 @@ function psSource(env) {
103
113
  };
104
114
  }
105
115
 
116
+ // The Linux start identity, `<boot id> <start ticks>`, read from the procfs
117
+ // mounted at `root`. The ticks are field 22 of `<pid>/stat`, the process's
118
+ // start time in clock ticks since boot, which never changes for a live
119
+ // process; `ps -o lstart=` adds them to a boot time that moves with every
120
+ // step of the wall clock. Within a boot a reused pid starts later, and the
121
+ // boot id tells two boots' processes apart. Only a missing stat file is a gone
122
+ // process; any other failure, and any failure to read the boot id, is
123
+ // unreadable — never a reason to ask `ps` instead.
124
+ export function procfsStartTime(pid, root = "/proc") {
125
+ const unreadable = (why) => new ProcUnreadable(`cannot read the start identity of pid ${pid}: ${why}`);
126
+ const bootIdPath = join(root, "sys", "kernel", "random", "boot_id");
127
+ let bootId;
128
+ try {
129
+ bootId = readFileSync(bootIdPath, "utf8").trim();
130
+ } catch (e) {
131
+ throw unreadable(e.message);
132
+ }
133
+ if (bootId === "") throw unreadable(`${bootIdPath} is empty`);
134
+ const statPath = join(root, String(pid), "stat");
135
+ let stat;
136
+ try {
137
+ stat = readFileSync(statPath, "utf8");
138
+ } catch (e) {
139
+ if (e.code === "ENOENT") return null;
140
+ throw unreadable(e.message);
141
+ }
142
+ // Field 2, comm, is wrapped in parentheses and may itself hold spaces and
143
+ // `)`, so the fields are counted from the last `)`: field 3 comes first.
144
+ const close = stat.lastIndexOf(")");
145
+ const ticks = close === -1 ? undefined : stat.slice(close + 1).trim().split(/\s+/)[22 - 3];
146
+ if (!isDigits(ticks)) throw unreadable(`${statPath} has no start time in field 22`);
147
+ return `${bootId} ${ticks}`;
148
+ }
149
+
106
150
  // `args` is argv joined by single spaces, so an argument that itself holds a
107
151
  // space splits here; the omp match only reads argv[0] and argv[1], and a path
108
152
  // with a space in it misses the match rather than mismatching.
@@ -147,11 +191,14 @@ export function controllerOf(source, chain) {
147
191
 
148
192
  // What a recorded controller is now, judged against the caller's chain:
149
193
  // none no record
150
- // dead isDead() says so, or the pid's start time is not the recorded
151
- // one — a reused pid, which the record must outlast for days
152
- // where the ledger lock tolerates it for seconds
194
+ // dead isDead() says so, or the pid's start identity is not the
195
+ // recorded one — a reused pid, which the record must outlast for
196
+ // days where the ledger lock tolerates it for seconds
153
197
  // ancestor the record names one of the caller's own ancestors
154
198
  // alive any other live controller
199
+ // `lstart` is a start identity, not a printed time: it never changes for a
200
+ // live process and differs for a reused pid — on Linux both within a boot and
201
+ // across boots — so an exact comparison is the whole test.
155
202
  export function judgeController(record, source, chain) {
156
203
  if (!record) return "none";
157
204
  if (isDead(record.pid)) return "dead";