@feigi/fleet-ctl 3.158.39 → 3.160.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.
@@ -86,7 +86,16 @@
86
86
  // holds every dispatching row, ahead of the main-checkout reason;
87
87
  // it never refuses the tick. A step's `drift` or `unanswered` is
88
88
  // advice, named on the line and holding nothing. The receipt's
89
- // `session` fills the tier hold's step.
89
+ // `session` fills the tier hold's step. Its `merge` says whether
90
+ // the run's merge bot merges (true when it records none) and is
91
+ // read from the receipt alone, never from a flag: with it off the
92
+ // merge-bot row prints `IDLE (merging off)` whatever the queue
93
+ // holds, the in-flight hold reads `HOLD (in-flight n/B, awaiting
94
+ // human merge)`, a draining run is over with only
95
+ // `ready-to-merge` PRs open (one GitHub has not read MERGEABLE,
96
+ // one on a conflict hold, and one a member is still at work on
97
+ // each still hold it), and `--apply` reaps after each PR the
98
+ // ledger tracks that gh reads MERGED.
90
99
  // guard `.fleet/cost-guard.json` beside the shortlist, pr-cost.mjs
91
100
  // --guard's verdict on the implementer cells. Printed as the
92
101
  // `router` row and never acted on here: a missing or unreadable
@@ -384,7 +393,8 @@ function implementers(s) {
384
393
  // ready-to-merge queue adds no rebases per PR, and a review owed is the
385
394
  // reviewer row's DISPATCH on this same tick.
386
395
  if (s.inFlight >= s.bound) {
387
- const hold = `HOLD (in-flight ${s.inFlight}/${s.bound})`;
396
+ // With merging off the merge that brings n below B is the maintainer's.
397
+ const hold = `HOLD (in-flight ${s.inFlight}/${s.bound}${s.merging === true ? "" : ", awaiting human merge"})`;
388
398
  return s.owedCounted.length ? row(hold, { acts: true, extra: replaceStep(s.owedCounted, s.implNames) }) : row(hold);
389
399
  }
390
400
 
@@ -469,6 +479,10 @@ function mergeBot(s) {
469
479
  const parked = s.mergeParked;
470
480
  const row = mkRow("merge-bot", s.mergeBotLive, 1,
471
481
  `merge-queue=${s.mergeQueue} held=${s.mergeHeld}${parked.length > 0 ? ` parked=${parked.length}` : ""}`);
482
+ // A run whose merge bot is off dispatches none, whatever the queue holds:
483
+ // the maintainer merges what carries `ready-to-merge`. Only an explicit
484
+ // `true` turns the bot on, so a state that names no merging has none.
485
+ if (s.merging !== true) return row("IDLE (merging off)");
472
486
  if (s.mergeBotLive >= 1) return row("AT CAP");
473
487
  if (s.mergeQueue === 0) return row("IDLE OK");
474
488
  // `ready-to-merge` is the author's sign-off and nothing more. A bot
@@ -1083,6 +1097,9 @@ export const reviewOwed = (st, members, head) => st === undefined
1083
1097
  // The states a PR-state probe answers: anything else is no answer.
1084
1098
  const PR_STATES = ["OPEN", "MERGED", "CLOSED"];
1085
1099
 
1100
+ // Whether `pr` (an open PR as openPrs() reads it) carries the label `name`.
1101
+ const hasLabel = (pr, name) => pr.labels.some((l) => l && l.name === name);
1102
+
1086
1103
  export function deriveRun({ rows, dispatched, drain, retired = [] }, prs, queuedLabel, closed = new Set(), prStates = new Map()) {
1087
1104
  // `queuedLabel` is the tracker's string for the `ready-to-merge` role, from
1088
1105
  // the Label map the caller read (label-map.mjs) — this fold reads no cache.
@@ -1174,7 +1191,7 @@ export function deriveRun({ rows, dispatched, drain, retired = [] }, prs, queued
1174
1191
  const owedReplacement = newest.filter(owesReplacement).map((m) => m.name);
1175
1192
  const owedCounted = newest.filter((m) => owesReplacement(m) && !closed.has(m.number)).map((m) => m.name);
1176
1193
  const inFlightImpl = newest.filter((m) => m.outcome === null && !closing.has(m.number)).length + owedCounted.length;
1177
- const isQueued = (p) => p.labels.some((l) => l && l.name === queuedLabel);
1194
+ const isQueued = (p) => hasLabel(p, queuedLabel);
1178
1195
  const queued = prs.filter(isQueued);
1179
1196
  const asc = (a, b) => a - b;
1180
1197
  const state = (n) => byPr.get(n);
@@ -1264,6 +1281,7 @@ export function deriveRun({ rows, dispatched, drain, retired = [] }, prs, queued
1264
1281
  const finished = (n) => prStates.get(n) === "MERGED" || prStates.get(n) === "CLOSED";
1265
1282
  const liveReviews = reviewing.filter(([n]) => open.has(n) || !finished(n));
1266
1283
  const unsettled = all.filter((m) => m.outcome === null).map((m) => m.name);
1284
+ const prTracked = [...byPr.keys()].filter((n) => !open.has(n)).sort(asc);
1267
1285
  return {
1268
1286
  implLive: live("impl"),
1269
1287
  inFlight: inFlightImpl + prsIn.length,
@@ -1280,6 +1298,13 @@ export function deriveRun({ rows, dispatched, drain, retired = [] }, prs, queued
1280
1298
  // anything above.
1281
1299
  prClosed: prSurfaced.filter((k) => prStates.get(k.pr) === "CLOSED").map((k) => ({ ...k, live: liveOn(k.pr) })),
1282
1300
  prUnchecked: prSurfaced.filter((k) => !PR_STATES.includes(prStates.get(k.pr))),
1301
+ // Every PR the ledger tracks — a row resolves to it — that the open list
1302
+ // does not carry, ascending: with merging off, the PRs the caller probes
1303
+ // beside the keyed ones, since the maintainer merges them. `prMerged` is
1304
+ // those the probe read MERGED: each is a merge `--apply` reaps, reclaims
1305
+ // and evicts after, once (reapDuePrs).
1306
+ prTracked,
1307
+ prMerged: prTracked.filter((n) => prStates.get(n) === "MERGED"),
1283
1308
  fixLive: live("fix-pr"),
1284
1309
  mergeBotLive,
1285
1310
  // The number of every merge bot settled `done`: each is a merge pass
@@ -1293,6 +1318,12 @@ export function deriveRun({ rows, dispatched, drain, retired = [] }, prs, queued
1293
1318
  // The in-flight reviews of PRs the open list does not carry: the ones
1294
1319
  // the probe could retire, so the caller asks gh about these and no others.
1295
1320
  reviewsOffList: reviewing.filter(([n]) => !open.has(n)).map(([n]) => n).sort(asc),
1321
+ // Every PR a member is still at work on, ascending: an unsettled
1322
+ // fix-applier or finisher bound to it, or an in-flight review of it.
1323
+ prsWorked: [...new Set([
1324
+ ...all.filter((m) => m.outcome === null && (m.family === "fix-pr" || m.family === "finisher-pr")).map((m) => m.number),
1325
+ ...liveReviews.map(([n]) => n),
1326
+ ])].sort(asc),
1296
1327
  // Each PR a fix-applier is owed on (`fixOwed`), unless two fix-appliers
1297
1328
  // have settled `failed` on it since its latest review with none landed
1298
1329
  // after them — that PR is `fixEscalate`'s instead — or it is itself owed
@@ -1626,6 +1657,17 @@ export function reapDue(done, applied, controllerAt) {
1626
1657
  return notIn(done, reapedAfter(applied, controllerAt));
1627
1658
  }
1628
1659
 
1660
+ // The PR numbers `applied.reapAfterPrs` names for THIS run.
1661
+ export function reapedAfterPrs(applied, controllerAt) {
1662
+ return ofThisRun(applied, controllerAt)?.reapAfterPrs ?? [];
1663
+ }
1664
+
1665
+ // The merges owed their reap, reclaim and evict in a run whose merge bot is
1666
+ // off: every PR `merged` (run.prMerged) that reapedAfterPrs() does not name.
1667
+ export function reapDuePrs(merged, applied, controllerAt) {
1668
+ return notIn(merged, reapedAfterPrs(applied, controllerAt));
1669
+ }
1670
+
1629
1671
  // The members `applied.sweptAfter` names for THIS run.
1630
1672
  export function sweptAfter(applied, controllerAt) {
1631
1673
  return ofThisRun(applied, controllerAt)?.sweptAfter ?? [];
@@ -1704,7 +1746,7 @@ import { fleetFile, FleetDirUnresolvable, scratchRoot } from "./fleet-dir.mjs";
1704
1746
  import { LABEL_MAP_FILE, LabelMapUnreadable, readLabelMap } from "./label-map.mjs";
1705
1747
  import { statePath, readState, writeState, assessBeat, isStalled, isReported, stallReport, stallOwner } from "./fleet-state.mjs";
1706
1748
  import { checkMainCheckout, describe } from "./main-checkout.mjs";
1707
- import { readRunReceipt, phase0Gate, IN_FLIGHT_DEFAULT } from "./phase0-receipt.mjs";
1749
+ import { readRunReceipt, phase0Gate, mergingOf, IN_FLIGHT_DEFAULT } from "./phase0-receipt.mjs";
1708
1750
  import { judgeRecord, ProcUnreadable } from "./proc.mjs";
1709
1751
  import { reportFamily, readReport, reportPath, reportsDir } from "./report-files.mjs";
1710
1752
  import { ownClosingIssues } from "./closing-refs.mjs";
@@ -1724,8 +1766,9 @@ const MERGEABLE_STATES = ["MERGEABLE", "CONFLICTING", "UNKNOWN"];
1724
1766
  // cap, because refusing would suppress the one announcement a dead run leaves
1725
1767
  // behind. So it discloses instead — the line says the count is a floor.
1726
1768
  const CLAIMED_LIMIT = 200;
1727
- // The tick's last line once a draining run has nothing left in flight. The
1728
- // tick cannot write the stop — `beat` is fleet-heartbeat's — so it names it.
1769
+ // The tick's last line once a draining run has nothing left in flight (with
1770
+ // merging off, nothing but PRs the maintainer is to merge). The tick cannot
1771
+ // write the stop — `beat` is fleet-heartbeat's — so it names it.
1729
1772
  export const RUN_OVER = `ACTION: run over → fleet-heartbeat.mjs --stop "<reason>"`;
1730
1773
  const MAX_BUFFER = 64 * 1024 * 1024;
1731
1774
  // Every gh spawn below is killed at this bound, so a gh that never answers is
@@ -1764,12 +1807,13 @@ const OPTIONS = {
1764
1807
  "fold-unchanged": { type: "boolean", default: false },
1765
1808
  // `--apply` runs the idempotent follow-ups whose trigger the ledger and the
1766
1809
  // state file show, before the rows: reap.sh, reclaim-scratch.mjs and
1767
- // evict.mjs after every merge pass settled `done`, reclaim-scratch.mjs
1768
- // alone after every settle of a fix-applier, a finisher or a review launch
1769
- // `=failed`, and tier-check.mjs on every implementer
1770
- // the tick would hold as unchecked. It never dispatches, never settles a
1771
- // member and writes no ledger row but through those scripts. Without it the
1772
- // tick is read-only.
1810
+ // evict.mjs after every merge pass settled `done` — and, in a run whose
1811
+ // merge bot is off, after every PR its ledger tracks that gh reads MERGED
1812
+ // — reclaim-scratch.mjs alone after every settle of a fix-applier, a
1813
+ // finisher or a review launch `=failed`, and tier-check.mjs on every
1814
+ // implementer the tick would hold as unchecked. It never dispatches, never
1815
+ // settles a member and writes no ledger row but through those scripts.
1816
+ // Without it the tick is read-only.
1773
1817
  apply: { type: "boolean", default: false },
1774
1818
  // Path override, for tests. An empty value cannot be told from an absent one
1775
1819
  // under parseArgs, and no path is legitimately empty, so empty resolves to
@@ -2056,19 +2100,21 @@ function closedTickets(mismatched, owed, surfacing) {
2056
2100
  // The state of each PR the tick asks gh about, one aliased `gh api graphql`
2057
2101
  // read per hundred PRs however many readings need them: `reviews`, the PRs
2058
2102
  // whose review the ledger reads as in flight yet the open list does not carry,
2059
- // and `keyed`, each ticket's keyed PR the open list does not carry (deriveRun's
2060
- // `prKeyed`). The answer is OPEN, MERGED or CLOSED. A probe that could not
2103
+ // `keyed`, each ticket's keyed PR the open list does not carry (deriveRun's
2104
+ // `prKeyed`), and `tracked`, every PR the ledger tracks that the open list
2105
+ // does not carry (`prTracked`), asked only in a run whose merge bot is off.
2106
+ // The answer is OPEN, MERGED or CLOSED. A probe that could not
2061
2107
  // answer — a failed call, an alias GitHub errored on or answered with nothing,
2062
2108
  // a node carrying no state, a state that is none of the three — leaves its PR
2063
2109
  // out of the map and is disclosed, per PR, with what it leaves standing; a
2064
2110
  // call killed at GH_TIMEOUT_MS is disclosed with that bound.
2065
- function prStates(reviews, keyed) {
2111
+ function prStates(reviews, keyed, tracked = []) {
2066
2112
  const states = new Map();
2067
2113
  const reviewed = new Set(reviews);
2068
2114
  // Two tickets can be keyed on one PR: each is named, on its one probe.
2069
2115
  const ticketsOf = new Map();
2070
2116
  for (const k of keyed) ticketsOf.set(k.pr, [...(ticketsOf.get(k.pr) ?? []), k.n]);
2071
- const numbers = [...new Set([...reviews, ...ticketsOf.keys()])].sort((a, b) => a - b);
2117
+ const numbers = [...new Set([...reviews, ...ticketsOf.keys(), ...tracked])].sort((a, b) => a - b);
2072
2118
  const read = ghAliasedRead(numbers, { field: "pullRequest", selection: "{state}", timeoutMs: GH_TIMEOUT_MS });
2073
2119
  for (const number of numbers) {
2074
2120
  const r = read.get(number);
@@ -2080,9 +2126,10 @@ function prStates(reviews, keyed) {
2080
2126
  const unconfirmed = [
2081
2127
  ...(reviewed.has(number) ? [`review on PR#${number} unconfirmed finished, its unit stands`] : []),
2082
2128
  ...(ticketsOf.get(number) ?? []).map((n) => `#${n}'s PR#${number} unconfirmed closed, printed as pr-unchecked`),
2083
- ].join("; ");
2129
+ ...(tracked.includes(number) ? [`PR#${number} unconfirmed merged, its reap waits`] : []),
2130
+ ];
2084
2131
  const why = r.unreachable === "ETIMEDOUT" ? TIMED_OUT : r.unreachable ?? (r.notFound ? "no such pull request" : "no PR state");
2085
- console.error(`${NAME}: gh api graphql gave no answer for PR#${number} (${why}) — ${unconfirmed}`);
2132
+ console.error(`${NAME}: gh api graphql gave no answer for PR#${number} (${why}) — ${unconfirmed.join("; ")}`);
2086
2133
  }
2087
2134
  return states;
2088
2135
  }
@@ -2121,15 +2168,17 @@ function reportDuty(r, { label, duty, what, summarise }) {
2121
2168
  return summary !== null;
2122
2169
  }
2123
2170
 
2124
- // Reap, then reclaim, then evict, after the merge passes in `due` — once
2125
- // however many there are, since each sweeps the whole repository, scratch
2126
- // root or set of claim trees rather than one pass's share. Each runs whether
2127
- // or not the one before it did: none reads another's result. True only when
2128
- // all three applied, the one case `due` is recorded as reaped after; otherwise
2129
- // the next --apply tick runs them again. `{all, reclaimed}`: the second is true
2130
- // when the root sweep applied, which is also the sweep a settled member owes.
2131
- function applyReap(due) {
2132
- const label = `reap after ${due.map((n) => `merge-bot-${n}`).join(" ")}`;
2171
+ // Reap, then reclaim, then evict, after the merge passes and merges in `due` —
2172
+ // once however many there are, since each sweeps the whole repository, scratch
2173
+ // root or set of claim trees rather than one pass's or one merge's share. Each
2174
+ // runs whether or not the one before it did: none reads another's result. True
2175
+ // only when all three applied, the one case `due` is recorded as reaped after;
2176
+ // otherwise the next --apply tick runs them again. `{all, reclaimed}`: the
2177
+ // second is true when the root sweep applied, which is also the sweep a
2178
+ // settled member owes. `due` is merge-bot numbers, `duePrs` the PRs a
2179
+ // maintainer merged in a run whose merge bot is off.
2180
+ function applyReap(due, duePrs) {
2181
+ const label = `reap after ${[...due.map((n) => `merge-bot-${n}`), ...duePrs.map((n) => `PR#${n}`)].join(" ")}`;
2133
2182
  const reaped = reportDuty(runSibling("reap.sh", ["--apply"]), { label, duty: "reap", what: "reap.sh", summarise: reapSummary });
2134
2183
  const reclaimed = applySweep("reclaim");
2135
2184
  const evicted = reportDuty(runSibling("evict.mjs", ["--apply"]),
@@ -2261,12 +2310,15 @@ export function controllerState(controller, name = NAME) {
2261
2310
  // review unit; an unread state is never read as finished. The issue probe asks
2262
2311
  // only about the tickets whose keyed PR read CLOSED or could not be read: OPEN
2263
2312
  // and MERGED print nothing whatever the issue says. A ledger it cannot read
2264
- // refuses the tick.
2265
- function readRun(prs, queuedLabel) {
2313
+ // refuses the tick. `trackMerged` also asks the state of every other PR the
2314
+ // ledger tracks that the open list does not carry, which is how a PR the
2315
+ // maintainer merged is read MERGED (`prMerged`): a run whose merge bot is off
2316
+ // and that `--apply` reaps after hand merges.
2317
+ function readRun(prs, queuedLabel, { trackMerged = false } = {}) {
2266
2318
  try {
2267
2319
  const ledger = readLedger();
2268
2320
  const run = deriveRun(ledger, prs, queuedLabel);
2269
- const states = prStates(run.reviewsOffList, run.prKeyed);
2321
+ const states = prStates(run.reviewsOffList, run.prKeyed, trackMerged ? run.prTracked : []);
2270
2322
  const surfacing = run.prKeyed.filter((k) => states.get(k.pr) !== "OPEN" && states.get(k.pr) !== "MERGED").map((k) => k.n);
2271
2323
  const closed = closedTickets(run.tierMismatch, run.owedReplacement, surfacing);
2272
2324
  return deriveRun(ledger, prs, queuedLabel, closed, states);
@@ -2426,6 +2478,9 @@ function main() {
2426
2478
  const phase0 = phase0Gate(receipt.read, {
2427
2479
  path: receipt.path, controllerAt: controller?.at, controller: controllerState(controller),
2428
2480
  });
2481
+ // Whether the run's merge bot merges is the receipt's word and no flag's: a
2482
+ // tick that forgot an argument must never be the one that dispatches a bot.
2483
+ const merging = mergingOf(receipt.read);
2429
2484
  // The session directory's listing, ahead of every ledger read: a dispatch is
2430
2485
  // written to the ledger before its `task` call makes the transcript, so a
2431
2486
  // stem listed here is on whatever ledger is read after. Listed later, a
@@ -2440,7 +2495,10 @@ function main() {
2440
2495
  // lines are the exception, printed as each duty runs: they say what was
2441
2496
  // done, which is true whether or not the reconcile after them lands.
2442
2497
  const prs = openPrs();
2443
- let run = readRun(prs, labels["ready-to-merge"]);
2498
+ // A run whose merge bot is off learns of a hand merge through the state of
2499
+ // the PRs its ledger tracks, so `--apply` asks for them.
2500
+ const readOpts = { trackMerged: apply && !merging };
2501
+ let run = readRun(prs, labels["ready-to-merge"], readOpts);
2444
2502
 
2445
2503
  // The main checkout against the run's baseline, on every tick — the
2446
2504
  // backstop for what member-write-guard cannot see. Never a refusal of the tick:
@@ -2450,36 +2508,47 @@ function main() {
2450
2508
 
2451
2509
  if (apply) {
2452
2510
  // Reap, reclaim and evict after every merge pass settled `done` since the
2453
- // last time they ran, and the root sweep after every settle `sweepAfter`
2454
- // names that `sweptAfter` does not. A merge pass is recorded in `reapAfter`
2455
- // only once all three applied, and a settle in `sweptAfter` once a root
2456
- // sweep applied, the merge pass's own included; each on a fresh read of the
2457
- // state file so nothing the heartbeat wrote meanwhile is reverted, never
2458
- // onto a file that could not be read, and never with no controller
2459
- // record: nothing could tell a list recorded then from the next run's.
2511
+ // last time they ran — and, with merging off, after every PR the ledger
2512
+ // tracks that read MERGED since — and the root sweep after every settle
2513
+ // `sweepAfter` names that `sweptAfter` does not. A merge pass is recorded
2514
+ // in `reapAfter` and a merged PR in `reapAfterPrs` only once all three
2515
+ // applied, and a settle in `sweptAfter` once a root sweep applied, the
2516
+ // merge pass's own included; each on a fresh read of the state file so
2517
+ // nothing the heartbeat wrote meanwhile is reverted, never onto a file
2518
+ // that could not be read, and never with no controller record: nothing
2519
+ // could tell a list recorded then from the next run's.
2460
2520
  const run0 = controller?.at ?? null;
2461
2521
  const due = reapDue(run.mergeBotDone, priorState.applied, run0);
2522
+ const duePrs = merging ? [] : reapDuePrs(run.prMerged, priorState.applied, run0);
2462
2523
  const owed = sweepDue(run.sweepAfter, priorState.applied, run0);
2463
- const reap = due.length ? applyReap(due) : null;
2524
+ const reap = due.length || duePrs.length ? applyReap(due, duePrs) : null;
2464
2525
  // The root sweep a merge pass ran is the one a settled member owes too.
2465
2526
  const swept = owed.length > 0 && (reap?.reclaimed || applySweep(`reclaim after ${owed.join(" ")}`));
2466
2527
  const reaped = reap?.all ? due : [];
2467
- if (run0 !== null && (reaped.length > 0 || swept)) {
2528
+ const reapedPrs = reap?.all ? duePrs : [];
2529
+ if (run0 !== null && (reaped.length > 0 || reapedPrs.length > 0 || swept)) {
2468
2530
  const now = readState(path, NAME);
2469
2531
  if (!now.degraded) {
2470
2532
  const reapAfter = [...new Set([...reapedAfter(now.applied, run0), ...reaped])];
2533
+ const reapAfterPrs = [...new Set([...reapedAfterPrs(now.applied, run0), ...reapedPrs])];
2471
2534
  const sweptNames = [...new Set([...sweptAfter(now.applied, run0), ...(swept ? owed : [])])];
2472
- writeState(path, NAME, now, { applied: { run: run0, reapAfter, ...(sweptNames.length > 0 ? { sweptAfter: sweptNames } : {}) } });
2535
+ writeState(path, NAME, now, {
2536
+ applied: {
2537
+ run: run0, reapAfter,
2538
+ ...(reapAfterPrs.length > 0 ? { reapAfterPrs } : {}),
2539
+ ...(sweptNames.length > 0 ? { sweptAfter: sweptNames } : {}),
2540
+ },
2541
+ });
2473
2542
  }
2474
2543
  }
2475
2544
  // The tier check, on exactly the members the implementer row would hold
2476
2545
  // as unchecked — that row reads the same before the refresh as after it.
2477
2546
  // A verdict written changes the ledger, so the run is read again.
2478
2547
  const unchecked = tierCheckDue(reconcile({
2479
- ...caps, ...run, heads: unclaimed(current.entries, run), supply: current.scanned, dropped: current.dropped,
2548
+ ...caps, ...run, merging, heads: unclaimed(current.entries, run), supply: current.scanned, dropped: current.dropped,
2480
2549
  shortlistStatus: current.status, refresh: null, mainCheckout, phase0, router,
2481
2550
  }), run.tierUnchecked);
2482
- if (unchecked.length && applyTierChecks(unchecked, phase0.session)) run = readRun(prs, labels["ready-to-merge"]);
2551
+ if (unchecked.length && applyTierChecks(unchecked, phase0.session)) run = readRun(prs, labels["ready-to-merge"], readOpts);
2483
2552
  }
2484
2553
 
2485
2554
  // The scratch root of the report files and the Pull records alike.
@@ -2536,7 +2605,7 @@ function main() {
2536
2605
  }
2537
2606
 
2538
2607
  const rows = reconcile({
2539
- ...caps, ...run, heads, supply, dropped, shortlistStatus: current.status, refresh: fresh, mainCheckout, phase0, router, pulls,
2608
+ ...caps, ...run, merging, heads, supply, dropped, shortlistStatus: current.status, refresh: fresh, mainCheckout, phase0, router, pulls,
2540
2609
  });
2541
2610
  const said = describe(mainCheckout, run.live);
2542
2611
  // The report files of the live members, read before the state file for the
@@ -2570,10 +2639,20 @@ function main() {
2570
2639
  const above = [...(phase0.line === null ? [] : [phase0.line]), ...(said === null ? [] : [said]), ...stale.map((s) => s.line)];
2571
2640
  const rowLines = formatLines(rows);
2572
2641
  // The run is over once it is draining and nothing is left in flight: no
2573
- // open PR and no implementer still holding a claim. Printed last and read
2574
- // as actionable, so it never folds away: the stop it names is the run's
2575
- // last act, and only the controller can write it.
2576
- const over = run.draining !== null && prs.length === 0 && run.implLive === 0;
2642
+ // open PR and no implementer still holding a claim. With merging off a PR
2643
+ // carrying `ready-to-merge` is the maintainer's to merge and holds nothing
2644
+ // once GitHub reads it MERGEABLE, no conflict hold stands on it and no
2645
+ // member is at work on it. One GitHub reads CONFLICTING, or that a conflict
2646
+ // hold stands on, is owed a fix-applier first; one GitHub has not read yet
2647
+ // (UNKNOWN) is read again next tick; and a finisher, fix-applier or review
2648
+ // still live on one has not finished with it. Every other open PR,
2649
+ // unreviewed or unlabelled, still holds it. Printed last and read as
2650
+ // actionable, so it never folds away: the stop it names is the run's last
2651
+ // act, and only the controller can write it.
2652
+ const awaitsMaintainer = (p) => hasLabel(p, labels["ready-to-merge"]) && p.mergeable === "MERGEABLE"
2653
+ && !run.conflictHeld.includes(p.number) && !run.prsWorked.includes(p.number);
2654
+ const holding = merging ? prs : prs.filter((p) => !awaitsMaintainer(p));
2655
+ const over = run.draining !== null && holding.length === 0 && run.implLive === 0;
2577
2656
  if (over) rowLines.push(RUN_OVER);
2578
2657
  const advice = [...transcribed, ...reported];
2579
2658
  const lines = [...above, ...advice.map((a) => a.line), ...rowLines];
@@ -1036,10 +1036,16 @@ export function drawCell({ session, ticket, policyCell, cells }) {
1036
1036
  // STRATUM the group's rule path BRIEF the brief's chars
1037
1037
  // CRITERIA the criteria count PARENT a Slice's parent issue
1038
1038
  // SIZED arm B's sizing label OBJECTIVE cost | speed
1039
- // TRIPPED the guard's tripped Cells REASON the first thing that went wrong
1039
+ // TRIPPED the guard's tripped Cells UNRUNNABLE the Cells the install does not run
1040
+ // REASON the first thing that went wrong
1040
1041
  // DRAW and BY are `-` together (no draw); so are BRIEF and CRITERIA (no issue
1041
- // read), and PARENT is `-` with them. A line written before PARENT was a part
1042
- // carries none, and reads as `PARENT=-`.
1042
+ // read), and PARENT is `-` with them. UNRUNNABLE lists every Cell with an
1043
+ // implementer definition whose level its role's model does not run, sorted and
1044
+ // each once — a list out of that order is no Routing — `-` for none; it is
1045
+ // worked out when the Pull is routed and is no guard verdict. A
1046
+ // line written before PARENT was a part carries none, and reads as `PARENT=-`;
1047
+ // one written before UNRUNNABLE was a part carries none, and reads as
1048
+ // `UNRUNNABLE=-`.
1043
1049
  //
1044
1050
  // STRATUM names the group the Pull was routed to — the router table's node the
1045
1051
  // walk ended at — by its rule path. `*` is the root, the group of every ticket
@@ -1062,11 +1068,12 @@ export const isRulePath = (x) => typeof x === "string" && RULE_PATH.test(x);
1062
1068
  export const OBJECTIVES = Object.freeze(["cost", "speed"]);
1063
1069
  const DRAWN_BY = Object.freeze(["burn-in", "every-5th"]);
1064
1070
  export const ROUTING_REASONS = Object.freeze([
1065
- "ok", "no-issue-json", "no-sizing", "guard-missing", "guard-tripped", "table-cell-tripped", "fit-missing", "fit-unreadable", "fit-invalid",
1071
+ "ok", "no-issue-json", "no-sizing", "guard-missing", "guard-tripped", "table-cell-tripped", "table-cell-unrunnable", "fit-missing", "fit-unreadable", "fit-invalid",
1066
1072
  ]);
1067
1073
  const SIZINGS = Object.freeze(["light", "heavy"]);
1068
- const ROUTING_KEYS = Object.freeze(["POLICY", "CELL", "DRAW", "BY", "STRATUM", "BRIEF", "CRITERIA", "PARENT", "SIZED", "OBJECTIVE", "TRIPPED", "REASON"]);
1074
+ const ROUTING_KEYS = Object.freeze(["POLICY", "CELL", "DRAW", "BY", "STRATUM", "BRIEF", "CRITERIA", "PARENT", "SIZED", "OBJECTIVE", "TRIPPED", "UNRUNNABLE", "REASON"]);
1069
1075
  const PARENT_AT = ROUTING_KEYS.indexOf("PARENT");
1076
+ const UNRUNNABLE_AT = ROUTING_KEYS.indexOf("UNRUNNABLE");
1070
1077
  const ISSUE = /^[1-9][0-9]*$/;
1071
1078
  const COUNT = /^(?:0|[1-9][0-9]*)$/;
1072
1079
  const DRAW = /^([1-9][0-9]*)\/([1-9][0-9]*)$/;
@@ -1075,14 +1082,16 @@ const DRAW = /^([1-9][0-9]*)\/([1-9][0-9]*)$/;
1075
1082
  * A Routing line read into its parts, or null when it is not one.
1076
1083
  * @returns {null | { policy: string, cell: string, draw: null | { k: number, K: number }, by: null | string,
1077
1084
  * stratum: string, brief: null | number, criteria: null | number, parent: null | number, sized: null | string,
1078
- * objective: string, tripped: string[], reason: string }}
1085
+ * objective: string, tripped: string[], unrunnable: string[], reason: string }}
1079
1086
  */
1080
1087
  export function parseRouting(line) {
1081
1088
  if (typeof line !== "string") return null;
1082
1089
  const words = line.split(" ");
1083
- // A line written before PARENT was a part is one word short; one that holds
1084
- // PARENT= and lacks another key instead fails the per-key check.
1085
- if (words.length === ROUTING_KEYS.length - 1) words.splice(PARENT_AT, 0, "PARENT=-");
1090
+ // A line written before UNRUNNABLE was a part is one word short of the keys, and one written before PARENT
1091
+ // too is two short; each reads with the key it lacks as `-`. A line that holds PARENT= and lacks another
1092
+ // key instead fails the per-key check.
1093
+ if (words.length === ROUTING_KEYS.length - 2) words.splice(PARENT_AT, 0, "PARENT=-");
1094
+ if (words.length === ROUTING_KEYS.length - 1) words.splice(UNRUNNABLE_AT, 0, "UNRUNNABLE=-");
1086
1095
  if (words.length !== ROUTING_KEYS.length) return null;
1087
1096
  const v = {};
1088
1097
  for (const [i, key] of ROUTING_KEYS.entries()) {
@@ -1091,7 +1100,9 @@ export function parseRouting(line) {
1091
1100
  }
1092
1101
  const opt = (x, ok) => (x === "-" ? null : ok(x) ? x : undefined);
1093
1102
  const count = (x) => (x === "-" ? null : COUNT.test(x) ? Number(x) : undefined);
1094
- const tripped = v.TRIPPED === "-" ? [] : v.TRIPPED.split(",");
1103
+ const cellList = (x) => (x === "-" ? [] : x.split(","));
1104
+ const tripped = cellList(v.TRIPPED);
1105
+ const unrunnable = cellList(v.UNRUNNABLE);
1095
1106
  const d = DRAW.exec(v.DRAW);
1096
1107
  const r = {
1097
1108
  policy: CELL.test(v.POLICY) ? v.POLICY : undefined,
@@ -1105,6 +1116,7 @@ export function parseRouting(line) {
1105
1116
  sized: opt(v.SIZED, (x) => SIZINGS.includes(x)),
1106
1117
  objective: OBJECTIVES.includes(v.OBJECTIVE) ? v.OBJECTIVE : undefined,
1107
1118
  tripped: tripped.every((c) => CELL.test(c)) ? tripped : undefined,
1119
+ unrunnable: unrunnable.every((c, i) => CELL.test(c) && (i === 0 || unrunnable[i - 1] < c)) ? unrunnable : undefined,
1108
1120
  reason: ROUTING_REASONS.includes(v.REASON) ? v.REASON : undefined,
1109
1121
  };
1110
1122
  if (Object.values(r).includes(undefined)) return null;
@@ -1115,12 +1127,13 @@ export function parseRouting(line) {
1115
1127
  }
1116
1128
 
1117
1129
  /** The Routing line for parsed parts; throws on parts no Routing line can carry, so nothing writes one parseRouting refuses. */
1118
- export function formatRouting({ policy, cell, draw, by, stratum, brief, criteria, parent, sized, objective, tripped, reason }) {
1130
+ export function formatRouting({ policy, cell, draw, by, stratum, brief, criteria, parent, sized, objective, tripped, unrunnable, reason }) {
1119
1131
  const none = (x) => (x === null ? "-" : String(x));
1132
+ const cells = (xs) => (xs.length === 0 ? "-" : xs.join(","));
1120
1133
  const line = [
1121
1134
  `POLICY=${policy}`, `CELL=${cell}`, `DRAW=${draw === null ? "-" : `${draw.k}/${draw.K}`}`, `BY=${none(by)}`,
1122
1135
  `STRATUM=${stratum}`, `BRIEF=${none(brief)}`, `CRITERIA=${none(criteria)}`, `PARENT=${none(parent)}`, `SIZED=${none(sized)}`,
1123
- `OBJECTIVE=${objective}`, `TRIPPED=${tripped.length === 0 ? "-" : tripped.join(",")}`, `REASON=${reason}`,
1136
+ `OBJECTIVE=${objective}`, `TRIPPED=${cells(tripped)}`, `UNRUNNABLE=${cells(unrunnable)}`, `REASON=${reason}`,
1124
1137
  ].join(" ");
1125
1138
  if (parseRouting(line) === null) throw new Error(`not a Routing: ${line}`);
1126
1139
  return line;
@@ -4,13 +4,17 @@
4
4
  // corpus written before its latest columns, refresh the cost guard over it, then
5
5
  // write the Fit beside that guard.
6
6
  //
7
- // metrics-refresh.mjs [--repo <dir>] [--no-fit]
7
+ // metrics-refresh.mjs [--repo <dir>] [--no-fit] [--model-roles <path>] [--catalog <path>]
8
8
  //
9
9
  // --repo the workspace whose `.fleet/` and `docs/metrics/` the duties read
10
10
  // and write; default the main checkout of the repository the cwd is
11
11
  // in, where the router script appends its pending rows
12
12
  // --no-fit the duties only, no Fit: close-out passes it, so a run computes
13
13
  // one Fit, at its phase 0, and each close-out's rows route the next run
14
+ // --model-roles, --catalog
15
+ // the files holding `modelRoles` and omp's model catalog, read in
16
+ // place of omp's own, as for `ticket-router.mjs route`; the Fit
17
+ // reads them to count the starting Cells the install runs
14
18
  //
15
19
  // DRAIN. `ticket-router.mjs route` appends one row per Pull to
16
20
  // `.fleet/ticket-features.pending.tsv`; this moves them into
@@ -81,13 +85,18 @@
81
85
  // file. A split stands in the `table` once it has passed at two consecutive
82
86
  // Fits on the same input or inputs, and is gone at the first Fit it fails;
83
87
  // the next Fit reads the previous one's `gate` from the file this one
84
- // replaces, which is all it carries forward. The Fit is a pure function of
85
- // the records, the guard, the prior and that `gate`: the TSVs at the recorded
86
- // blob ids, the guard and the prior fit to the same table again. So a Fit
87
- // whose `records` are the previous one's is no look at the gate: it keeps
88
- // that one's `passed` and `stands`, and a phase 0 run again over records that
89
- // have not changed neither advances a split's count nor resets it. With no
90
- // records it is the starting table's fit, as any other. It is called
88
+ // replaces, which is all it carries forward. Burn-in holds until every
89
+ // starting Cell the install runs has its merged PRs, and the `table` records
90
+ // that set as `starting_cells`: the install is read as `ticket-router.mjs
91
+ // route` reads it — live, or from the files `--model-roles <path>` and
92
+ // `--catalog <path>` name — and a read that fails warns on stderr and counts
93
+ // all three starting Cells. The Fit is a pure function of the records, the
94
+ // guard, the prior, that set and that `gate`: the TSVs at the recorded blob
95
+ // ids, the guard, the prior and the recorded set fit to the same table again.
96
+ // So a Fit whose `records` are the previous one's is no look at the gate: it
97
+ // keeps that one's `passed` and `stands`, and a phase 0 run again over records
98
+ // that have not changed neither advances a split's count nor resets it. With
99
+ // no records it is the starting table's fit, as any other. It is called
91
100
  // in-process because a fit has no verdict for an exit status to carry. It
92
101
  // never fails the run: an error prints `metrics-refresh: fit: failed — <why>`,
93
102
  // leaves the old file in place, so the run routes by the last Fit that
@@ -114,7 +123,7 @@ import { COLUMNS as MEMBER_COLUMNS, ENDINGS, isImplementer, parseTsv as parseMem
114
123
  import { blobId } from "./pr-cost.mjs";
115
124
  import { FEATURE_COLUMNS, parseFeatures } from "./pull-attribution.mjs";
116
125
  import { REPORT_STATUSES } from "./report-files.mjs";
117
- import { DEFAULT_TABLE, FIT_FILE, INSTALL_PACKAGE, fitTree, installVersion, readGuard, validateTable } from "./ticket-router.mjs";
126
+ import { DEFAULT_TABLE, FIT_FILE, INSTALL_PACKAGE, fitTree, installVersion, readGuard, readInstall, startingCellsOf, validateTable } from "./ticket-router.mjs";
118
127
  import { parseTierOutcomes } from "./tier-outcomes.mjs";
119
128
 
120
129
  const NAME = "metrics-refresh";
@@ -317,10 +326,12 @@ function previousGate(repo) {
317
326
  // The Fit over `repo`'s working-tree TSVs and `written`, the guard file the
318
327
  // guard duty just wrote (parsed), with the router table at `tablePath` as its
319
328
  // prior, written to `.fleet/router-fit.json` through a temp file and a rename.
320
- // Throws on anything it cannot read, fit or write, before the rename, so the
329
+ // Burn-in counts `startingCells`, the starting Cells the install runs — all
330
+ // three when none is named — which the Fit's `table` records. Throws on anything
331
+ // it cannot read, fit or write, before the rename, so the
321
332
  // old file stays as it was: a Fit that throws is no look at the split gate,
322
333
  // and the next one reads the gate the old file holds.
323
- export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath = INSTALL_PACKAGE, now = new Date() } = {}) {
334
+ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath = INSTALL_PACKAGE, now = new Date(), startingCells } = {}) {
324
335
  const guard = readGuard(written);
325
336
  if (guard === null) throw new Error(`${GUARD} is not a guard the router reads`);
326
337
  let prior;
@@ -341,7 +352,7 @@ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath
341
352
  const members = read(MEMBERS, parseMemberTsv);
342
353
  const verdicts = read(TIERS, parseTierOutcomes);
343
354
  const features = read(FEATURES, parseFeatures);
344
- const { table, gate } = fitTree({ prior, features, members, verdicts, guard, previous });
355
+ const { table, gate } = fitTree({ prior, features, members, verdicts, guard, previous, startingCells });
345
356
  // The tree the gate grew is the one `route` will read it through.
346
357
  const valid = validateTable(table);
347
358
  if (valid instanceof Error) throw valid;
@@ -368,11 +379,17 @@ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath
368
379
 
369
380
  // The Fit as the run calls it: only beside a guard the guard duty wrote, and
370
381
  // never a failure of the run — its error is a line, and the exit stays as it was.
371
- function fit(repo, written) {
382
+ // `sources` name the files the install read takes in place of omp's own (ticket-router.mjs's
383
+ // readInstall): burn-in counts the starting Cells that install runs, all three when it cannot be read.
384
+ function fit(repo, written, sources) {
372
385
  if (written === null) return say(`fit: skipped, no guard written — ${FIT} left as it is`);
386
+ const { install, why } = readInstall(sources);
387
+ if (install === null) {
388
+ process.stderr.write(`${NAME}: WARNING cannot read what this install runs: ${why} — burn-in counts all three starting Cells\n`);
389
+ }
373
390
  let p;
374
391
  try {
375
- p = writeFit(repo, written);
392
+ p = writeFit(repo, written, { startingCells: startingCellsOf(install) });
376
393
  } catch (e) {
377
394
  return say(`fit: failed — ${e.message}`);
378
395
  }
@@ -381,7 +398,7 @@ function fit(repo, written) {
381
398
 
382
399
  function main() {
383
400
  const die = makeDie(NAME);
384
- const F = defineFlags(die, { flags: { repo: "value", "no-fit": "bool" } });
401
+ const F = defineFlags(die, { flags: { repo: "value", "no-fit": "bool", "model-roles": "value", catalog: "value" } });
385
402
  F.sweep();
386
403
  F.stray();
387
404
  let repo = F.arg("repo") === null ? null : resolve(F.arg("repo"));
@@ -404,7 +421,7 @@ function main() {
404
421
  return;
405
422
  }
406
423
  }
407
- if (!F.has("no-fit")) fit(repo, written);
424
+ if (!F.has("no-fit")) fit(repo, written, { modelRoles: F.arg("model-roles"), catalog: F.arg("catalog") });
408
425
  }
409
426
 
410
427
  if (isCLI(import.meta.url)) main();
@@ -2,9 +2,11 @@
2
2
  // after every step (its header gives the shape); this module is its readers'
3
3
  // half: the tick's dispatch gate, the session directory tier-check.mjs
4
4
  // and ticket-router.mjs take when their own flag is omitted, the Objective
5
- // ticket-router.mjs takes likewise, with its default, and the In-flight
6
- // bound the drivers hand the tick, with its default. One reading of the file,
7
- // so the gate and the session readers cannot disagree about what a receipt is.
5
+ // ticket-router.mjs takes likewise, with its default, the In-flight
6
+ // bound the drivers hand the tick, with its default, and whether the run's
7
+ // merge bot merges, which the tick reads from the receipt alone. One reading
8
+ // of the file, so the gate and the session readers cannot disagree about what
9
+ // a receipt is.
8
10
  //
9
11
  // Zero deps: node builtins and sibling modules only.
10
12
 
@@ -164,6 +166,26 @@ export function objectiveFromReceipt(opts) {
164
166
  throw new Error(`no objective given and none in the phase-0 receipt ${path} (${why}) — give one (${OBJECTIVES.join(" or ")}), or run ${phase0Command(null)} first`);
165
167
  }
166
168
 
169
+ // Whether a run's merge bot merges when nobody says: phase0.mjs records the
170
+ // run's choice in its receipt as `merge`, and a receipt written before it
171
+ // recorded one is read as the default when phase 0 resumes it.
172
+ export const MERGE_DEFAULT = true;
173
+
174
+ /**
175
+ * Whether the run's merge bot merges, read off `read` (readRunReceipt()'s
176
+ * `read`): the receipt's `merge`, and the default (on) when there is no
177
+ * receipt, it cannot be read, or it records none. With no usable receipt
178
+ * phase0Gate holds every dispatching row, so that default dispatches no bot.
179
+ * The tick reads this every pass, so it meets what a hand left in the file:
180
+ * a `merge` present but not a boolean reads as off, since a bot dispatched on
181
+ * a value nobody can read is the failure the switch exists to prevent, while
182
+ * a merge not made waits for the maintainer or a later run.
183
+ */
184
+ export function mergingOf(read) {
185
+ if (read.state !== "ok" || read.receipt.merge === undefined) return MERGE_DEFAULT;
186
+ return read.receipt.merge === true;
187
+ }
188
+
167
189
  // The In-flight bound a run takes when nobody gives one: the most tickets
168
190
  // between Claim and merge at once. Its one definition — phase0.mjs and the
169
191
  // tick's own flag default both read it from here.