@feigi/fleet-ctl 3.158.25 → 3.158.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.158.25",
3
+ "version": "3.158.26",
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/arg.mjs CHANGED
@@ -316,6 +316,18 @@ export function isDigits(value) {
316
316
  return /^[0-9]+$/.test(value);
317
317
  }
318
318
 
319
+ // The bound, in ms, a script kills each of its `gh` spawns at:
320
+ // `defaultSeconds`, unless `override` — the script's own environment variable,
321
+ // in seconds — is a positive whole number below it. It can only ever SHORTEN
322
+ // the bound (ledger.mjs's LEDGER_GIT_TIMEOUT rule), so no environment can
323
+ // stretch a stalled `gh` past the default; anything else leaves the default
324
+ // standing, in silence. The override is for a test that has to see the
325
+ // timeout fire without waiting the default out.
326
+ export function ghBudget(defaultSeconds, override) {
327
+ const seconds = isDigits(String(override)) ? Number(override) : 0;
328
+ return (seconds > 0 && seconds < defaultSeconds ? seconds : defaultSeconds) * 1000;
329
+ }
330
+
319
331
  // numArg() is built ON arg(), not beside it, so the digits test runs AFTER arg()'s own
320
332
  // value guards: `--pr` given trailing still reports "--pr needs a value" and
321
333
  // `--pr=5` still reports the `=` form. Where both would refuse, the more
@@ -35,6 +35,7 @@ import { readReceipt } from "./phase0-receipt.mjs";
35
35
  import { RECEIPT, RECEIPT_HELD, CLOSEOUT_RECEIPT, OBJECTIVES, isOmpSessionDirName } from "./ledger-grammar.mjs";
36
36
  import { lastSegment } from "./pull-attribution.mjs";
37
37
  import { NAME, warnOnce, execRead } from "./board-common.mjs";
38
+ import { ghBudget } from "./arg.mjs";
38
39
  import { mergedReadPrs, issuesOfPrs } from "./compute-board.mjs";
39
40
  import { readCostGuard } from "./fleet-tick.mjs";
40
41
  import { parseFrontmatter } from "./tier-roles.mjs";
@@ -77,11 +78,24 @@ function jsonKind(v) {
77
78
  return v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
78
79
  }
79
80
 
81
+ // The `gh` reads below pass this bound (readMainMetrics keeps its own), so a
82
+ // `gh` that never answers is a failed read on that read's own path — tryRun's
83
+ // null, readStates' `none` — never a gather that does not return. 30 s: the
84
+ // lists are capped at a hundred rows (OPEN_PR_LIMIT, POOL_LIMIT).
85
+ // BOARD_GH_TIMEOUT can only shorten it (arg.mjs's ghBudget()).
86
+ const GH_TIMEOUT_MS = ghBudget(30, process.env.BOARD_GH_TIMEOUT);
87
+
80
88
  // Every external read is wrapped: a failure returns null and the caller keeps a
81
89
  // last-known value. Partial board beats a crashed loop or a false alarm.
82
- async function tryRun(cmd, args) {
83
- const r = await execRead(cmd, args);
84
- if (r.error) { console.error(`${NAME}: ${cmd} ${args.join(" ")} failed: ${r.error.message}`); return null; }
90
+ // `opts` joins execRead's for this read; a read its `timeout` killed is named
91
+ // as timed out, since the error's own message names only the command.
92
+ async function tryRun(cmd, args, opts = {}) {
93
+ const r = await execRead(cmd, args, opts);
94
+ if (r.error) {
95
+ const why = opts.timeout !== undefined && r.error.killed && r.code === null ? `timed out after ${opts.timeout / 1000}s` : r.error.message;
96
+ console.error(`${NAME}: ${cmd} ${args.join(" ")} failed: ${why}`);
97
+ return null;
98
+ }
85
99
  return r.stdout;
86
100
  }
87
101
 
@@ -200,13 +214,14 @@ async function readStates(prNums, issueNums) {
200
214
  ...issueNums.map((n) => `i${n}:issue(number:${n}){state}`),
201
215
  ].join(" ");
202
216
  const r = await execRead("gh", ["api", "graphql", "-F", "owner={owner}", "-F", "name={repo}",
203
- "-f", `query=query($owner:String!,$name:String!){repository(owner:$owner,name:$name){${fields}}}`]);
217
+ "-f", `query=query($owner:String!,$name:String!){repository(owner:$owner,name:$name){${fields}}}`], { timeout: GH_TIMEOUT_MS });
204
218
  let repo;
205
219
  try { repo = JSON.parse(r.stdout)?.data?.repository; } catch {}
206
220
  if (!isJsonObject(repo) || !prNums.some((n) => Object.prototype.hasOwnProperty.call(repo, `p${n}`))) {
207
- // `how` as runCiState() spells it; never r.error.message, which repeats
221
+ // `how` as runCiState() spells it, but a read this bound killed is named
222
+ // as timed out, as tryRun() names one; never r.error.message, which repeats
208
223
  // the whole query — one field per number — into every failed tick's line.
209
- const how = r.code ?? (r.signal ? `killed by ${r.signal}` : `exit ${r.status}`);
224
+ const how = r.error?.killed && r.code === null ? `timed out after ${GH_TIMEOUT_MS / 1000}s` : (r.code ?? (r.signal ? `killed by ${r.signal}` : `exit ${r.status}`));
210
225
  const n = prNums.length;
211
226
  console.error(`${NAME}: gh api graphql merged read (${n} PR${n === 1 ? "" : "s"}) failed (${how}) with no usable answer`);
212
227
  return none;
@@ -1213,7 +1228,7 @@ export async function gather({ ledgerFile, prevFile, stateFile = null, stateDir
1213
1228
  }
1214
1229
 
1215
1230
  const issuesJson = roles === null ? null : await tryRun("gh", ["issue", "list", "--label", roles["ready-for-agent"],
1216
- "--state", "open", "--limit", String(POOL_LIMIT), "--json", "number,title,labels"]);
1231
+ "--state", "open", "--limit", String(POOL_LIMIT), "--json", "number,title,labels"], { timeout: GH_TIMEOUT_MS });
1217
1232
  // title: falls back to the same `#<number>` placeholder titleFor() already
1218
1233
  // uses for an issue it cannot find at all (compute-board.mjs). An unrowed
1219
1234
  // issue becomes a POOL card straight from this array — compute-board.mjs's
@@ -1237,7 +1252,7 @@ export async function gather({ ledgerFile, prevFile, stateFile = null, stateDir
1237
1252
  }));
1238
1253
 
1239
1254
  const prsJson = await tryRun("gh", ["pr", "list", "--state", "open", "--limit", String(OPEN_PR_LIMIT),
1240
- "--json", "number,state,labels,title,headRefOid"]);
1255
+ "--json", "number,state,labels,title,headRefOid"], { timeout: GH_TIMEOUT_MS });
1241
1256
  // No default for `title` or `state` here, unlike the issue row above — raw
1242
1257
  // passthrough, deliberately. `title`: compute-board.mjs's titleFor() already
1243
1258
  // falls through a falsy `pr.title` to the real issue title (`if (pr &&
@@ -1299,7 +1314,7 @@ export async function gather({ ledgerFile, prevFile, stateFile = null, stateDir
1299
1314
  // Repo identity + web URL for PR links — the url carries the host, so links
1300
1315
  // resolve on GitHub Enterprise, not just github.com. From the fleet's cwd, so
1301
1316
  // the board stays repo-agnostic. On failure, carry the previous board's values.
1302
- const repoJson = await tryRun("gh", ["repo", "view", "--json", "nameWithOwner,url"]);
1317
+ const repoJson = await tryRun("gh", ["repo", "view", "--json", "nameWithOwner,url"], { timeout: GH_TIMEOUT_MS });
1303
1318
  let repo = prev?.repo ?? null;
1304
1319
  let repoUrl = prev?.repoUrl ?? null;
1305
1320
  if (repoJson) {
@@ -43,7 +43,7 @@
43
43
 
44
44
  import { execFileSync } from "node:child_process";
45
45
  import { parseArgs } from "node:util";
46
- import { makeDie, makeArg, makeHas } from "./arg.mjs";
46
+ import { makeDie, makeArg, makeHas, ghBudget } from "./arg.mjs";
47
47
  import { LABEL_ROLES, readLabelMap } from "./label-map.mjs";
48
48
 
49
49
  const NAME = "candidates";
@@ -71,6 +71,12 @@ const withDropped = has("with-dropped");
71
71
  const limit = Number(arg("limit") ?? 500);
72
72
  if (!Number.isInteger(limit) || limit < 1) die(`--limit must be a positive integer, got '${arg("limit")}'`);
73
73
 
74
+ // The issue read below is killed after this long, so a `gh` that never answers
75
+ // is a failed query — the die() below, naming ETIMEDOUT — never a caller left
76
+ // waiting. 60 s: it is one read, but of up to `limit` issues with their whole
77
+ // bodies. CANDIDATES_GH_TIMEOUT can only shorten it (arg.mjs's ghBudget()).
78
+ const GH_TIMEOUT_MS = ghBudget(60, process.env.CANDIDATES_GH_TIMEOUT);
79
+
74
80
  // The accepted flag set, declared once, and the only check on flag NAMES.
75
81
  // Before this check, an unrecognised flag was ignored, so
76
82
  // `--label ready-for-agent` — the spelling run-team's own phase 0 rule carried
@@ -460,7 +466,7 @@ function query(label) {
460
466
  console.error(`$ gh ${args.join(" ")}`);
461
467
  let out;
462
468
  try {
463
- out = execFileSync("gh", args, { encoding: "utf8" });
469
+ out = execFileSync("gh", args, { encoding: "utf8", timeout: GH_TIMEOUT_MS });
464
470
  } catch (e) {
465
471
  // Fail closed. A failed query and an empty queue are different facts, and
466
472
  // only one of them means "there is no work".
@@ -13,7 +13,7 @@
13
13
 
14
14
  import { execFileSync } from "node:child_process";
15
15
  import { gitEnv } from "./git-env.mjs";
16
- import { makeDie, defineFlags, writeAll } from "./arg.mjs";
16
+ import { makeDie, defineFlags, writeAll, ghBudget } from "./arg.mjs";
17
17
 
18
18
  const NAME = "ci-state";
19
19
 
@@ -134,9 +134,17 @@ function emitRateLimited(query) {
134
134
  // reads pass a larger one (see graphql() below). `capture` keeps the child's
135
135
  // stderr instead of forwarding it, for the one read whose failure can still
136
136
  // turn out to be an answer (see graphql()).
137
+ //
138
+ // Every read is killed at GH_TIMEOUT_MS, so a `gh` that never answers fails
139
+ // on its caller's own path — run() dies ETIMEDOUT at exit 2, tryRun()'s
140
+ // behind-count stays unknown — never a call that does not return. 120 s: the
141
+ // longest reads here walk pages, the rulesets read's `--paginate` and the
142
+ // workflow-tree graphql reply that carries every workflow file at two
143
+ // commits. CI_STATE_GH_TIMEOUT can only shorten it (arg.mjs's ghBudget()).
144
+ const GH_TIMEOUT_MS = ghBudget(120, process.env.CI_STATE_GH_TIMEOUT);
137
145
  function spawn(cmd, args, { maxBuffer, capture = false } = {}) {
138
146
  vlog(`$ ${cmd} ${args.join(" ")}`);
139
- return execFileSync(cmd, args, { encoding: "utf8", env: gitEnv(), ...(maxBuffer ? { maxBuffer } : {}), ...(capture ? { stdio: "pipe" } : {}) });
147
+ return execFileSync(cmd, args, { encoding: "utf8", env: gitEnv(), timeout: GH_TIMEOUT_MS, ...(maxBuffer ? { maxBuffer } : {}), ...(capture ? { stdio: "pipe" } : {}) });
140
148
  }
141
149
 
142
150
  // Three disjoint shapes — Node-aborted (ENOENT/ENOBUFS), signal, exit.
@@ -18,7 +18,7 @@
18
18
 
19
19
  import { execFileSync } from "node:child_process";
20
20
  import { isCLI } from "./is-cli.mjs";
21
- import { makeDie, defineFlags } from "./arg.mjs";
21
+ import { makeDie, defineFlags, ghBudget } from "./arg.mjs";
22
22
 
23
23
  const NAME = "diff-stats";
24
24
 
@@ -171,10 +171,15 @@ const { arg, numArg, sweep, stray } = defineFlags(die, { flags: { pr: "value", r
171
171
  const MARKER = "… (truncated)";
172
172
  const cut = (s, n = 120) => (s.length > n ? `${s.slice(0, Math.max(0, n - MARKER.length))}${MARKER}` : s);
173
173
 
174
+ // run()'s one child is `gh pr view`, killed at GH_TIMEOUT_MS so a `gh` that
175
+ // never answers is a failed query — the die() below, naming ETIMEDOUT — never a
176
+ // review left waiting. 30 s: one PR view. DIFF_STATS_GH_TIMEOUT can only
177
+ // shorten it (arg.mjs's ghBudget()).
178
+ const GH_TIMEOUT_MS = ghBudget(30, process.env.DIFF_STATS_GH_TIMEOUT);
174
179
  function run(cmd, args) {
175
180
  console.error(`$ ${cmd} ${args.join(" ")}`);
176
181
  try {
177
- return execFileSync(cmd, args, { encoding: "utf8" });
182
+ return execFileSync(cmd, args, { encoding: "utf8", timeout: GH_TIMEOUT_MS });
178
183
  } catch (e) {
179
184
  // Fail closed. A broken query must not read as "empty diff". The harm is not
180
185
  // a trim — computeStats([]) yields profile "empty", which review-core.mjs
@@ -94,7 +94,7 @@
94
94
  import { spawnSync } from "node:child_process";
95
95
  import { statSync } from "node:fs";
96
96
  import { resolve } from "node:path";
97
- import { makeDie, defineFlags, writeAll } from "./arg.mjs";
97
+ import { makeDie, defineFlags, writeAll, ghBudget } from "./arg.mjs";
98
98
  import { inertVerdict } from "./finisher-scope.mjs";
99
99
  import { gitEnv } from "./git-env.mjs";
100
100
  import { LABEL_LIST_ARGS, LABEL_LIST_LIMIT, releaseLabelsDefined, releaseLabelsIn } from "./release-labels.mjs";
@@ -180,9 +180,16 @@ try {
180
180
  // GIT_DIR would retarget every call at another repository.
181
181
  const GH_ENV = gitEnv();
182
182
 
183
+ // Each call is killed at GH_TIMEOUT_MS, so a `gh` that never answers fails its
184
+ // step at exit 2, its `error` naming ETIMEDOUT, never a finisher that does not
185
+ // return. 60 s: the longest read is `read-labels`, a PR view carrying every
186
+ // comment on the PR. FINISHER_LABEL_GH_TIMEOUT can only shorten it (arg.mjs's
187
+ // ghBudget()).
188
+ const GH_TIMEOUT_MS = ghBudget(60, process.env.FINISHER_LABEL_GH_TIMEOUT);
189
+
183
190
  // stdout parsed, stderr captured: what `gh` said is the receipt's `error`.
184
191
  function gh(step, args) {
185
- const r = spawnSync("gh", args, { encoding: "utf8", env: GH_ENV, stdio: ["ignore", "pipe", "pipe"], ...(repo === null ? {} : { cwd: repo }) });
192
+ const r = spawnSync("gh", args, { encoding: "utf8", env: GH_ENV, stdio: ["ignore", "pipe", "pipe"], timeout: GH_TIMEOUT_MS, ...(repo === null ? {} : { cwd: repo }) });
186
193
  if (r.error) fail(step, `could not run gh: ${r.error.message}`);
187
194
  if (r.signal) fail(step, `gh was killed by ${r.signal}`);
188
195
  if (r.status !== 0) fail(step, (r.stderr ?? "").trim() || `gh exited ${r.status}`);
@@ -1697,7 +1697,7 @@ import { dirname, join } from "node:path";
1697
1697
  import { fileURLToPath } from "node:url";
1698
1698
  import { isCLI } from "./is-cli.mjs";
1699
1699
  import { parseArgs } from "node:util";
1700
- import { makeDie, isDigits } from "./arg.mjs";
1700
+ import { makeDie, isDigits, ghBudget } from "./arg.mjs";
1701
1701
  import { gitEnv } from "./git-env.mjs";
1702
1702
  import { ghAliasedRead } from "./gh-aliased-read.mjs";
1703
1703
  import { fleetFile, FleetDirUnresolvable, scratchRoot } from "./fleet-dir.mjs";
@@ -1735,13 +1735,7 @@ const MAX_BUFFER = 64 * 1024 * 1024;
1735
1735
  // not per tick: the probes run one after another, so a tick whose probes all
1736
1736
  // hang waits one bound for each of them. 20 s, shortlist.mjs's own gh bound.
1737
1737
  // FLEET_TICK_GH_TIMEOUT overrides it, in seconds, and can only ever
1738
- // SHORTEN it — ledger.mjs's LEDGER_GIT_TIMEOUT rule: a value that is not a
1739
- // positive whole number below the default leaves the default standing, in
1740
- // silence. Exported for its own test; it touches nothing.
1741
- export function ghBudget(defaultSeconds, override) {
1742
- const seconds = isDigits(String(override)) ? Number(override) : 0;
1743
- return (seconds > 0 && seconds < defaultSeconds ? seconds : defaultSeconds) * 1000;
1744
- }
1738
+ // SHORTEN it — arg.mjs's ghBudget().
1745
1739
  const GH_TIMEOUT_MS = ghBudget(20, process.env.FLEET_TICK_GH_TIMEOUT);
1746
1740
  const TIMED_OUT = `timed out after ${GH_TIMEOUT_MS / 1000}s`;
1747
1741
  // Why a `gh` execFileSync threw. Never interpolates e.stderr or e.message:
@@ -55,7 +55,7 @@
55
55
  import { spawnSync } from "node:child_process";
56
56
  import { statSync } from "node:fs";
57
57
  import { resolve } from "node:path";
58
- import { makeDie, defineFlags, writeAll } from "./arg.mjs";
58
+ import { makeDie, defineFlags, writeAll, ghBudget } from "./arg.mjs";
59
59
  import { gitEnv } from "./git-env.mjs";
60
60
  import { readLabelMap } from "./label-map.mjs";
61
61
  import { newestHeadRecord } from "./ready-to-merge-head.mjs";
@@ -110,8 +110,14 @@ if (repo !== null) {
110
110
  // GIT_DIR would retarget every call at another repository.
111
111
  const GH_ENV = gitEnv();
112
112
 
113
+ // Each read is killed at GH_TIMEOUT_MS, so a `gh` that never answers fails its
114
+ // step at exit 2, its `error` naming ETIMEDOUT, never a route decided late or
115
+ // not at all. 60 s: `read-timeline` walks every page of the PR's timeline.
116
+ // LABELLED_HEAD_GH_TIMEOUT can only shorten it (arg.mjs's ghBudget()).
117
+ const GH_TIMEOUT_MS = ghBudget(60, process.env.LABELLED_HEAD_GH_TIMEOUT);
118
+
113
119
  function gh(step, args) {
114
- const r = spawnSync("gh", args, { encoding: "utf8", env: GH_ENV, stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024, ...(repo === null ? {} : { cwd: repo }) });
120
+ const r = spawnSync("gh", args, { encoding: "utf8", env: GH_ENV, stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024, timeout: GH_TIMEOUT_MS, ...(repo === null ? {} : { cwd: repo }) });
115
121
  if (r.error) fail(step, `could not run gh: ${r.error.message}`);
116
122
  if (r.signal) fail(step, `gh was killed by ${r.signal}`);
117
123
  if (r.status !== 0) fail(step, (r.stderr ?? "").trim() || `gh exited ${r.status}`);
@@ -98,7 +98,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
98
98
  import { tmpdir } from "node:os";
99
99
  import { dirname, join } from "node:path";
100
100
  import { fileURLToPath } from "node:url";
101
- import { makeDie, defineFlags, writeAll } from "./arg.mjs";
101
+ import { makeDie, defineFlags, writeAll, ghBudget } from "./arg.mjs";
102
102
  import { gitEnv, mainCheckoutDirFromGitCommonDir } from "./git-env.mjs";
103
103
  import { readLabelMap } from "./label-map.mjs";
104
104
 
@@ -271,8 +271,15 @@ function readInstruments() {
271
271
  // --- gh pr view -----------------------------------------------------------
272
272
  // null for anything that is not the four fields in their gh shapes: a parse
273
273
  // that succeeds on the wrong shape must not reach a check that reads it.
274
+ //
275
+ // Killed at GH_TIMEOUT_MS, so a `gh` that never answers is a failed read like
276
+ // any other — null, the gate's `pr-unreadable` — never a gate that does not
277
+ // return. Joined to CHILD here rather than in it: the other children CHILD
278
+ // serves are not `gh`. 30 s: one PR view. MERGE_GATE_GH_TIMEOUT can only
279
+ // shorten it (arg.mjs's ghBudget()).
280
+ const GH_TIMEOUT_MS = ghBudget(30, process.env.MERGE_GATE_GH_TIMEOUT);
274
281
  function readPr() {
275
- const r = spawnSync("gh", ["pr", "view", String(pr), "--json", "labels,reviewDecision,headRefOid,body,url,closingIssuesReferences"], CHILD);
282
+ const r = spawnSync("gh", ["pr", "view", String(pr), "--json", "labels,reviewDecision,headRefOid,body,url,closingIssuesReferences"], { ...CHILD, timeout: GH_TIMEOUT_MS });
276
283
  if (r.error || r.status !== 0) return null;
277
284
  let v;
278
285
  try {
@@ -97,7 +97,7 @@ import { execFileSync } from "node:child_process";
97
97
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
98
98
  import { dirname, join } from "node:path";
99
99
  import { fileURLToPath } from "node:url";
100
- import { makeDie, defineFlags } from "./arg.mjs";
100
+ import { makeDie, defineFlags, ghBudget } from "./arg.mjs";
101
101
  import { gitEnv } from "./git-env.mjs";
102
102
  import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
103
103
  import { isCLI } from "./is-cli.mjs";
@@ -118,6 +118,11 @@ export const BASELINE_CELL = "slow-high";
118
118
  export const MIN_N = 20;
119
119
  export const EXIT = { ok: 0, tripped: 3, none: 4 };
120
120
  export const GH_PR_LIMIT = 1000;
121
+ // Each slice's `gh pr list` is killed after this long, so a `gh` that never
122
+ // answers is a failed read — the die() in main(), naming ETIMEDOUT — never a
123
+ // report that does not return. 120 s: one slice is up to GH_PR_LIMIT PRs.
124
+ // PR_COST_GH_TIMEOUT can only shorten it (arg.mjs's ghBudget()).
125
+ const GH_TIMEOUT_MS = ghBudget(120, process.env.PR_COST_GH_TIMEOUT);
121
126
 
122
127
  // A slice of the window that cannot be proven fully read.
123
128
  export class PrListIncomplete extends Error {}
@@ -441,7 +446,7 @@ function main() {
441
446
  try {
442
447
  out = execFileSync("gh", ["pr", "list", "--state", "all", "--search", `created:${created}`,
443
448
  "--limit", String(GH_PR_LIMIT), "--json", "number,state,mergedAt"], {
444
- encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024, env: gitEnv(),
449
+ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024, env: gitEnv(), timeout: GH_TIMEOUT_MS,
445
450
  });
446
451
  } catch (e) {
447
452
  die(`gh pr list failed: ${e.code ?? (e.signal ? `killed by ${e.signal}` : `exit ${e.status}`)}`);