@feigi/fleet-ctl 3.151.2 → 3.153.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.151.2",
3
+ "version": "3.153.0",
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": {
@@ -190,14 +190,19 @@ const FIELD_WORDS = [
190
190
 
191
191
  // Merged PRs against `min_n`. A Cell is judged only while the baseline has
192
192
  // `min_n` merged PRs itself: below that the guard holds nothing back, whatever a
193
- // Cell's own n.
193
+ // Cell's own n. A Cell the guard lists `unmatched` has `min_n` of its own but is
194
+ // short of them, on its side or the baseline's, in the stretches both were drawn
195
+ // in, so it was not judged either.
194
196
  function mergedFigure(e, g, isBase) {
195
197
  const n = e.n;
196
198
  const min = g.min_n;
197
199
  const base = g.baseline.cell;
198
- const judged = isBase || g.verdict !== "none";
200
+ const unmatched = !isBase && Array.isArray(g.unmatched) && g.unmatched.includes(e.cell);
201
+ const judged = isBase || (g.verdict !== "none" && !unmatched);
199
202
  const text = n >= min
200
- ? judged ? `${n} ≥ ${min} ✓` : `${n} ≥ ${min}: not judged until ${base} has ${min}`
203
+ ? judged ? `${n} ≥ ${min} ✓`
204
+ : unmatched ? `${n} ≥ ${min}: not judged, under ${min} on a side in the stretches shared with ${base}`
205
+ : `${n} ≥ ${min}: not judged until ${base} has ${min}`
201
206
  : `${n} of ${min}: not judged`;
202
207
  const beside = [];
203
208
  const unchecked = [];
@@ -210,9 +215,11 @@ function mergedFigure(e, g, isBase) {
210
215
  }
211
216
 
212
217
  // The fail rate with its gap to the baseline's and to the floor, worked from the
213
- // claim and failure counts. Whole counts and the integer cross-product are what
214
- // the guard itself judges by (`underFloor`), so a gap near the floor reads the
215
- // way the guard rules; a rounded rate never enters it.
218
+ // claim and failure counts of the Cell's whole generation. Whole counts and the
219
+ // integer cross-product are what the guard itself judges by, so a rounded rate
220
+ // never enters it. The guard holds a Cell to the baseline only over the stretches
221
+ // both were drawn in, so a gap read from the whole generations can differ from
222
+ // the one the guard ruled on, and `tripped` is what it ruled.
216
223
  function failFigure(e, g, baseEntry, isBase) {
217
224
  const claims = count(e.n_claims);
218
225
  const failed = count(e.n_failed);
@@ -0,0 +1,154 @@
1
+ // What an Evict removes from a git tree, and the one removal sequence every
2
+ // removal here and in Reclaim goes through. evict.mjs (a claim tree),
3
+ // reclaim-scratch.mjs (a review run's snapshot and copies, in its `--pr` pass)
4
+ // and review-core.mjs (the same trees, when a review ends) all import it; a
5
+ // module of its own so none of the three loads another's CLI, and so the
6
+ // enumeration of "every path git ignores" is written once.
7
+ //
8
+ // IGNORED PATHS. `ignoredPaths(tree)` is every path `git ls-files --others
9
+ // --ignored --exclude-standard --directory` lists in the tree, but the
10
+ // `agent-test` runner: a directory is listed whole, once, and nothing inside
11
+ // one already listed. Tracked files, the tree's .git and untracked files git
12
+ // does not ignore are not in it.
13
+ //
14
+ // A TREE, for `evictTrees(root)`, is a directory that holds `.git` at its own
15
+ // top level and whose `git rev-parse --show-toplevel` resolves, by realpath,
16
+ // to that same directory. A directory that resolves to an enclosing repository
17
+ // — one with no `.git` of its own, or with one git cannot read — is never
18
+ // stripped, and git is never asked about a directory with no `.git`. The walk
19
+ // goes down from `root` at any depth and never follows a symlink, never enters
20
+ // a `.git`, and never enters a path it removes (or, in a dry run, would
21
+ // remove) as ignored, so a repository inside `node_modules` goes with that
22
+ // directory and is not a tree of its own.
23
+ //
24
+ // No status check, no mark, no restore: a tree is evicted whatever `git status`
25
+ // says. A claim tree's status check and its mark are evict.mjs's own.
26
+
27
+ import { spawnSync } from "node:child_process";
28
+ import { lstatSync, readdirSync, realpathSync } from "node:fs";
29
+ import { join } from "node:path";
30
+ import { how } from "./evict-mark.mjs";
31
+ import { gitEnv } from "./git-env.mjs";
32
+
33
+ export const RUNNER = "agent-test";
34
+ const GIT_TIMEOUT_MS = 30_000;
35
+ const MAX_BUFFER = 64 * 1024 * 1024;
36
+
37
+ // The one removal sequence. `$1` is the entry. A symlink entry is unlinked
38
+ // before anything else runs, so no chmod or chflags ever sees it: whether a
39
+ // recursive chmod dereferences a link given as its operand differs between
40
+ // BSD and GNU, and either would change the mode or flags of a target outside
41
+ // the entry being removed. Links met inside a directory are left to `rm`,
42
+ // which unlinks them without following. `chmod -R` fails
43
+ // on a flagged directory, and `chflags -R` cannot read a mode-000 directory it
44
+ // has just unflagged, so when the first pass fails each directory's flag and
45
+ // mode come off together, top-down, before anything inside it is read.
46
+ const REMOVE = [
47
+ 'd=$1',
48
+ 'if [ -L "$d" ]; then rm -f "$d"; exit $?; fi',
49
+ 'chmod -R u+rwx "$d" 2>/dev/null; m=$?',
50
+ 'if command -v chflags >/dev/null 2>&1; then',
51
+ ' [ $m -eq 0 ] || { chflags nouchg,nouappnd "$d"; chmod u+rwx "$d"; find "$d" -type d -exec chflags nouchg,nouappnd {} ";" -exec chmod u+rwx {} ";"; } 2>/dev/null',
52
+ ' chflags -R nouchg,nouappnd "$d" 2>/dev/null',
53
+ 'fi',
54
+ 'rm -rf "$d"',
55
+ ].join("\n");
56
+
57
+ /** Remove `path` through REMOVE; null on success, else the reason. */
58
+ export function removeEntry(path) {
59
+ const r = spawnSync("sh", ["-c", REMOVE, "sh", path], { encoding: "utf8" });
60
+ return r.error || r.status !== 0 ? how(r) : null;
61
+ }
62
+
63
+ const git = (tree, args) =>
64
+ spawnSync("git", ["-C", tree, ...args], { encoding: "utf8", maxBuffer: MAX_BUFFER, env: gitEnv(), timeout: GIT_TIMEOUT_MS });
65
+
66
+ /** Every path the tree ignores, relative to it, but the runner; throws what git cannot answer. */
67
+ export function ignoredPaths(tree) {
68
+ const r = git(tree, ["ls-files", "-z", "--others", "--ignored", "--exclude-standard", "--directory"]);
69
+ if (r.error || r.status !== 0) throw new Error(`git ls-files --ignored failed (${how(r)})`);
70
+ const out = [];
71
+ for (const p of r.stdout.split("\0").filter(Boolean).sort()) {
72
+ const bare = p.replace(/\/$/, "");
73
+ if (bare === RUNNER) continue;
74
+ if (out.some((q) => q.endsWith("/") && p.startsWith(q))) continue;
75
+ out.push(p);
76
+ }
77
+ return out;
78
+ }
79
+
80
+ /** Remove each of `ignored` (relative to `tree`); null, or every error in one string. */
81
+ export function removeIgnored(tree, ignored) {
82
+ const errors = [];
83
+ for (const p of ignored) {
84
+ const error = removeEntry(join(tree, p.replace(/\/$/, "")));
85
+ if (error !== null) errors.push(`${p}: ${error}`);
86
+ }
87
+ return errors.length ? `could not remove ${errors.join("; ")}` : null;
88
+ }
89
+
90
+ // Whether `dir` is a tree: a `.git` of its own, and git answering for this
91
+ // directory rather than for an enclosing repository.
92
+ function isTree(dir) {
93
+ try {
94
+ lstatSync(join(dir, ".git"));
95
+ } catch {
96
+ return false;
97
+ }
98
+ const r = git(dir, ["rev-parse", "--show-toplevel"]);
99
+ if (r.error || r.status !== 0) return false;
100
+ try {
101
+ return realpathSync(r.stdout.replace(/\n$/, "")) === realpathSync(dir);
102
+ } catch {
103
+ return false;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Evict every tree under `root`, `root` itself included: `{evicted, failed}`.
109
+ * `evicted` is `[{path, ignored}]` for each tree that held ignored paths — in a
110
+ * dry run, what `apply` would remove — and a tree holding none is in neither.
111
+ * `failed` is `[{path, error}]`: a tree whose ignored paths cannot be listed or
112
+ * all removed, or a directory whose listing fails for any reason but its being
113
+ * gone, not a directory, or unreadable. Best-effort: the walk goes on.
114
+ */
115
+ export function evictTrees(root, { apply }) {
116
+ const evicted = [];
117
+ const failed = [];
118
+ const skip = new Set();
119
+ const stack = [root];
120
+ while (stack.length) {
121
+ const dir = stack.pop();
122
+ if (isTree(dir)) {
123
+ let ignored;
124
+ try {
125
+ ignored = ignoredPaths(dir);
126
+ } catch (e) {
127
+ failed.push({ path: dir, error: e.message });
128
+ continue;
129
+ }
130
+ for (const p of ignored) skip.add(join(dir, p.replace(/\/$/, "")));
131
+ if (ignored.length > 0) {
132
+ const error = apply ? removeIgnored(dir, ignored) : null;
133
+ if (error === null) evicted.push({ path: dir, ignored });
134
+ else failed.push({ path: dir, error });
135
+ }
136
+ }
137
+ let entries;
138
+ try {
139
+ entries = readdirSync(dir, { withFileTypes: true });
140
+ } catch (e) {
141
+ // A directory the walk cannot list or search holds no tree it can reach:
142
+ // skipped, as freshUnder() skips one it cannot read, and never a failure.
143
+ if (!["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(e.code)) failed.push({ path: dir, error: `cannot list it (${e.code ?? e.message})` });
144
+ continue;
145
+ }
146
+ for (const e of entries) {
147
+ if (e.name === ".git" || !e.isDirectory()) continue;
148
+ const path = join(dir, e.name);
149
+ if (!skip.has(path)) stack.push(path);
150
+ }
151
+ }
152
+ const byPath = (a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
153
+ return { evicted: evicted.sort(byPath), failed: failed.sort(byPath) };
154
+ }
package/scripts/evict.mjs CHANGED
@@ -54,7 +54,7 @@
54
54
  //
55
55
  // `--apply` judges each tree to evict again, writes the mark (EVICTED, a file
56
56
  // in the tree's git admin dir) unless the tree carries it already, then removes
57
- // every ignored path but the runner through reclaim-scratch.mjs's one removal
57
+ // every ignored path but the runner through evict-tree.mjs's one removal
58
58
  // sequence. Tracked files, HEAD, the branch and the registration are not
59
59
  // touched. Best-effort per tree: a tree whose mark cannot be written, or a path
60
60
  // in it that cannot be removed, lands in `failed`; the sweep goes on. A mark
@@ -99,10 +99,11 @@ import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
99
99
  import { fileURLToPath } from "node:url";
100
100
  import { defineFlags, isDigits, makeDie, writeAll } from "./arg.mjs";
101
101
  import { adminDir, EVICTED, evictionMark, how, RESTORED } from "./evict-mark.mjs";
102
+ import { RUNNER, ignoredPaths, removeIgnored } from "./evict-tree.mjs";
102
103
  import { gitEnv } from "./git-env.mjs";
103
104
  import { isCLI } from "./is-cli.mjs";
104
105
  import { liveOnLedger, parseMember, REVIEWER } from "./ledger-grammar.mjs";
105
- import { ledgerFile, readLedger, removeEntry } from "./reclaim-scratch.mjs";
106
+ import { ledgerFile, readLedger } from "./reclaim-scratch.mjs";
106
107
  import { CLAIM_BRANCH, CLAIM_WORKTREE } from "./stranded.mjs";
107
108
 
108
109
  const NAME = "evict";
@@ -114,7 +115,6 @@ const DAY_MS = 24 * 60 * 60 * 1000;
114
115
  export const IDLE_MS = 7 * DAY_MS;
115
116
  /** Whether a tree whose HEAD last moved, or which was last restored, at `last` is idle at `now`. */
116
117
  export const isIdle = (now, last) => now - last >= IDLE_MS;
117
- const RUNNER = "agent-test";
118
118
  const GIT_TIMEOUT_MS = 30_000;
119
119
  const MAX_BUFFER = 64 * 1024 * 1024;
120
120
  // claim-ticket.sh's `rederive`, word for word. The refusals that send their
@@ -277,21 +277,6 @@ function restoredAt(dir) {
277
277
  return at;
278
278
  }
279
279
 
280
- // Every path the tree ignores, relative to it, but the runner — a directory
281
- // git lists whole once, and nothing listed inside one already listed.
282
- function ignoredPaths(tree) {
283
- const r = git(tree, ["ls-files", "-z", "--others", "--ignored", "--exclude-standard", "--directory"]);
284
- if (r.error || r.status !== 0) throw new Error(`git ls-files --ignored failed (${how(r)})`);
285
- const out = [];
286
- for (const p of r.stdout.split("\0").filter(Boolean).sort()) {
287
- const bare = p.replace(/\/$/, "");
288
- if (bare === RUNNER) continue;
289
- if (out.some((q) => q.endsWith("/") && p.startsWith(q))) continue;
290
- out.push(p);
291
- }
292
- return out;
293
- }
294
-
295
280
  const within = (path, root) => path === root || path.startsWith(root.endsWith(sep) ? root : root + sep);
296
281
 
297
282
  /**
@@ -370,12 +355,7 @@ function evictTree(path, verdict, now) {
370
355
  return `could not write ${join(verdict.dir, EVICTED)} (${e.code ?? e.message}), so nothing was removed`;
371
356
  }
372
357
  }
373
- const errors = [];
374
- for (const p of verdict.ignored) {
375
- const error = removeEntry(join(path, p.replace(/\/$/, "")));
376
- if (error !== null) errors.push(`${p}: ${error}`);
377
- }
378
- return errors.length ? `could not remove ${errors.join("; ")}` : null;
358
+ return removeIgnored(path, verdict.ignored);
379
359
  }
380
360
 
381
361
  function sweep({ afterRotate, apply }) {
@@ -55,13 +55,27 @@
55
55
  // so a cell that abandons work carries that spend; `median_usd` over the
56
56
  // merged Pulls alone, descriptive; `router_usd`, the Pulls' own routing cost,
57
57
  // summed and never in their spend. `usd_diff_ci95` is a bootstrap 95% interval
58
- // on `mean_usd` minus the baseline's — printed to be read, never judged on.
59
- // Then the `left_out`, `unpriced` and `untimed` Pull counts, and the cell's
60
- // `excluded` count, which no generation owns. The baseline, the guard file's
61
- // cells and every trip are each cell's newest generation alone, so a cell
62
- // whose model changed is judged afresh once its new generation reaches MIN_N
63
- // merged PRs. Each older generation prints on its own line beside the newest,
64
- // with no verdict and no interval.
58
+ // on the $ per merged PR difference from the baseline, over the stretches in
59
+ // which both were drawn (TIME-MATCHED, below) — printed to be read, never
60
+ // judged on. Then the `left_out`, `unpriced` and `untimed` Pull counts, and the
61
+ // cell's `excluded` count, which no generation owns. The baseline, the guard
62
+ // file's cells and every trip are each cell's newest generation alone, so a
63
+ // cell whose model changed is judged afresh once its new generation reaches
64
+ // MIN_N merged PRs. Each older generation prints on its own line beside the
65
+ // newest, with no verdict and no interval.
66
+ //
67
+ // TIME-MATCHED. The figures above are each cell's own, over every Pull of its
68
+ // generation in the window. A trip is not read off them: a cell is compared
69
+ // with the baseline only over the stretches (pull-attribution.mjs's
70
+ // STRETCHES) in which both were drawn, each stretch compared on its own and
71
+ // the stretches pooled, so a shift that hits every cell at once cancels, and
72
+ // the baseline's other weeks, in which the cell never ran, move no verdict.
73
+ // The matched $ per merged PR counts a stretch's spend even where a side
74
+ // merged nothing in it, so a cell that abandons work carries that spend there
75
+ // too. MIN_N counts each side's merged PRs in those stretches. A cell with
76
+ // MIN_N merged PRs of its own that is short of them there, or shares no
77
+ // stretch with the baseline, is not judged and never trips: its line says
78
+ // `unmatched`, and the report's `unmatched` lists it.
65
79
  //
66
80
  // THE GUARD FILE keeps each cell's whole entry as the report computed it —
67
81
  // `n` (its `n_merged`, which readers key on) beside every figure above and its
@@ -74,8 +88,9 @@
74
88
  // list. `no_ruling_prs` and `pending_prs` name the PRs behind the last two,
75
89
  // ascending, as the report's top-level `pending` list does: a `no_ruling`
76
90
  // Pull contributes the implementer PRs that make it one. Beside `min_n` it
77
- // records `trip_points`, the floor's margin, and
78
- // `tsv_blobs`: the git blob id of each TSV it read, by the path it read it at.
91
+ // records `trip_points`, the floor's margin, `unmatched`, the report's list of
92
+ // the cells not judged, and `tsv_blobs`: the git blob id of each TSV it read,
93
+ // by the path it read it at.
79
94
 
80
95
  import { createHash } from "node:crypto";
81
96
  import { execFileSync } from "node:child_process";
@@ -87,7 +102,7 @@ import { gitEnv } from "./git-env.mjs";
87
102
  import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
88
103
  import { isCLI } from "./is-cli.mjs";
89
104
  import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
90
- import { AttributionError, TRIP_POINTS, attribute, bootUnit, bootstrapDiffCI, parseFeatures, tally, underFloor } from "./pull-attribution.mjs";
105
+ import { AttributionError, TRIP_POINTS, attribute, compareCells, parseFeatures, tally } from "./pull-attribution.mjs";
91
106
  import { STARTING_CELLS } from "./ledger-grammar.mjs";
92
107
  import { RulingError, parseTierOutcomes } from "./tier-outcomes.mjs";
93
108
 
@@ -95,7 +110,9 @@ const NAME = "pr-cost";
95
110
  const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
96
111
 
97
112
  // The guard's window opens here and never rolls: it is reset only by editing
98
- // this constant in a reviewed change.
113
+ // this constant in a reviewed change. It is the lower bound of the Pulls the
114
+ // guard reads; the baseline is not cumulative over it, for a cell is compared
115
+ // with the baseline only over the stretches in which both were drawn.
99
116
  export const WINDOW_START = "2026-10-03";
100
117
  export const BASELINE_CELL = "slow-high";
101
118
  export const MIN_N = 20;
@@ -150,17 +167,26 @@ function median(xs) {
150
167
  return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
151
168
  }
152
169
 
153
- // The trip rule: the quality floor (pull-attribution.mjs's `underFloor`, in
154
- // integer counts), or a mean $ at least the baseline's. Each side is
155
- // `{ claims, failed, mean_usd }`.
170
+ // Whether `m`, `compareCells`' comparison of a cell with the baseline, has MIN_N merged PRs on each side. They are
171
+ // counted over the stretches both were drawn in, so a cell is never judged on a handful of matched Pulls because
172
+ // it has many unmatched ones.
173
+ const judged = (m) => m.cell.merged >= MIN_N && m.base.merged >= MIN_N;
174
+
175
+ // The trip rule, over the stretches in which both cells were drawn (`cell` and `base` are the two cells' newest
176
+ // generations' counted Pulls, as `compareCells` reads them): the cell's fail rate TRIP_POINTS or more points above
177
+ // the baseline's, in integer counts, or its $ per merged PR at least the baseline's. The $ leg takes the unrounded
178
+ // figures: the cent-rounded ones are for display, and a trip is sticky, so a cell cheaper by under half a cent
179
+ // must not trip on rounding alone. A cell that shares no stretch with the baseline, or has under MIN_N merged PRs
180
+ // on either side in those it shares, is not judged and does not trip. `tripsOn` holds the rule on a comparison,
181
+ // `trips` on two cells' Pulls.
182
+ const tripsOn = (m) => judged(m) && (m.underFloor || (m.cell.usd_per_merged !== null && m.cell.usd_per_merged >= m.base.usd_per_merged));
156
183
  export function trips(cell, base) {
157
- return underFloor(cell, base) || cell.mean_usd >= base.mean_usd;
184
+ return tripsOn(compareCells(cell, base));
158
185
  }
159
186
 
160
187
  export function computeReport({ members, tiers, features, prs, routerTable = null, pricing = null, windowStart = WINDOW_START }) {
161
188
  const units = attribute({ features, members, tiers, prs, windowStart });
162
189
  const tallies = new Map(tally(units).map((t) => [t.cell, t]));
163
- const bootUnits = (g) => g.pulls.map((u) => bootUnit(u));
164
190
  const meanUsd = (t) => (t.merged ? t.spend / t.merged : null);
165
191
  const base = tallies.get(BASELINE_CELL) ?? null;
166
192
  // The PRs behind each generation's `no_ruling` and `pending` counts, as the
@@ -194,7 +220,7 @@ export function computeReport({ members, tiers, features, prs, routerTable = nul
194
220
  pending: g.pending,
195
221
  pending_prs: prList(held?.pending_prs),
196
222
  router_usd: round(g.pulls.reduce((s, u) => s + routerUsd(u.pull), 0), 4),
197
- usd_diff_ci95: !newest || cell === BASELINE_CELL || !base ? null : bootstrapDiffCI(bootUnits(g), bootUnits(base)),
223
+ usd_diff_ci95: !newest || cell === BASELINE_CELL || !base ? null : compareCells(g.pulls, base.pulls).range("usd"),
198
224
  left_out: g.left_out,
199
225
  unpriced: g.unpriced,
200
226
  untimed: g.untimed,
@@ -209,14 +235,17 @@ export function computeReport({ members, tiers, features, prs, routerTable = nul
209
235
  // The guard, over each cell's newest generation alone.
210
236
  const b = figures.find((f) => f.cell === BASELINE_CELL) ?? { generation: null, n_merged: 0, mean_usd: null, fail_rate: null };
211
237
  const baseline = { cell: BASELINE_CELL, generation: b.generation, n: b.n_merged, mean_usd: b.mean_usd, fail_rate: b.fail_rate };
212
- // The $ leg takes the unrounded means: the cent-rounded figures are for
213
- // display, and a trip is sticky, so a cell cheaper by under half a cent
214
- // must not trip on rounding alone. The fail leg reads the claims.
215
- const quality = (t) => ({ claims: t.claims, failed: t.failed, mean_usd: meanUsd(t) });
238
+ // Each cell is held to the baseline over the stretches in which both were drawn (`compareCells`): `judged` is
239
+ // whether MIN_N merged PRs a side there let the trip rule apply, and `tripsOn` the rule. A cell short of them is
240
+ // `unmatched`.
216
241
  const tripped = [];
242
+ const unmatched = [];
217
243
  if (baseline.n >= MIN_N) {
218
244
  for (const t of tallies.values()) {
219
- if (t.cell !== BASELINE_CELL && t.merged >= MIN_N && trips(quality(t), quality(base))) tripped.push(t.cell);
245
+ if (t.cell === BASELINE_CELL || t.merged < MIN_N) continue;
246
+ const m = compareCells(t.pulls, base.pulls);
247
+ if (!judged(m)) unmatched.push(t.cell);
248
+ else if (tripsOn(m)) tripped.push(t.cell);
220
249
  }
221
250
  }
222
251
  const verdict = baseline.n < MIN_N ? "none" : tripped.length ? "tripped" : "ok";
@@ -230,6 +259,7 @@ export function computeReport({ members, tiers, features, prs, routerTable = nul
230
259
  baseline,
231
260
  cells: figures,
232
261
  tripped,
262
+ unmatched,
233
263
  verdict,
234
264
  retire,
235
265
  pending: [...new Set(units.filter((u) => u.status === "pending").map((u) => u.pendingPr))].sort((x, y) => Number(x) - Number(y)),
@@ -295,12 +325,15 @@ const TSV_COLUMNS = [
295
325
  "excluded", "left_out", "unpriced", "untimed", "guard",
296
326
  ];
297
327
 
298
- // One line per cell's newest generation, carrying the guard's verdict on it,
299
- // then one per older generation of that cell, which carries none.
328
+ // One line per cell's newest generation, carrying the guard's verdict on it:
329
+ // `tripped`, `ok`, `unmatched` (merged PRs enough of its own, too few in the
330
+ // stretches it shares with the baseline to be judged) or `n<MIN_N`; then one
331
+ // per older generation of that cell, which carries none.
300
332
  export function formatReport(report) {
301
333
  const guardOf = (f) => {
302
334
  if (f.cell === BASELINE_CELL) return "baseline";
303
335
  if (report.tripped.includes(f.cell)) return "tripped";
336
+ if (report.unmatched.includes(f.cell)) return "unmatched";
304
337
  return f.n_merged >= MIN_N && report.verdict !== "none" ? "ok" : `n<${MIN_N}`;
305
338
  };
306
339
  const cell = (v) => (v === null || v === undefined ? "" : Array.isArray(v) ? `[${v.join(", ")}]` : String(v));
@@ -336,6 +369,7 @@ export function guardFile(report, computedAt, tsvBlobs = {}) {
336
369
  return { cell, generation, n: f.n_merged, ...rest };
337
370
  }),
338
371
  tripped: report.tripped,
372
+ unmatched: report.unmatched,
339
373
  verdict: report.verdict,
340
374
  retire: report.retire,
341
375
  // The n the baseline and every judged cell need, and the margin the fail
@@ -1,8 +1,9 @@
1
1
  // The one booking of member rows, merges and claims to Pulls, read by both the
2
2
  // cost guard (pr-cost.mjs) and the router's fit (ticket-router.mjs), so the two
3
3
  // print the same figures for a cell. Neither CLI imports the other; both import
4
- // this, and with it the two judgements they share: the quality floor (the
5
- // guard's fail leg) and the bootstrap range of a $ per merged PR difference.
4
+ // this, and with it the comparison of two cells they share: the quality floor
5
+ // (the guard's fail leg), the figures a row is judged by and the bootstrap range
6
+ // of a $ per merged PR difference.
6
7
  //
7
8
  // THE UNIT is the Pull, a ticket-features.tsv row, booked AS ROUTED to its
8
9
  // `chosen_cell`: its merge, its Ruling and all its spend. A ticket Pulled twice
@@ -79,9 +80,38 @@
79
80
  // earlier model rejoins that generation's Pulls. Only the newest generation's
80
81
  // figures are judged; older ones are reported beside them, never pooled.
81
82
  //
83
+ // STRETCHES. Two cells are compared only over the stretches in which both were
84
+ // drawn. A stretch is one UTC calendar week of `run_date`, Monday first, cut
85
+ // again wherever the recorded `plugin_version` changes. The cut is global: it
86
+ // is read off the sequence of every windowed Pull, by session id then file
87
+ // order, so every cell shares the same boundaries. A blank version is unknown
88
+ // and never itself a cut; only a change between two recorded, different
89
+ // versions cuts, before the Pull that records the newer one. `attribute` gives
90
+ // every unit its stretch.
91
+ //
92
+ // THE COMPARISON. `compareCells` holds two cells' newest-generation counted
93
+ // Pulls against each other over their shared stretches: each stretch on its
94
+ // own, then the stretches pooled with Mantel-Haenszel weights. A stretch
95
+ // weighs w_cell·w_base/(w_cell + w_base) over the counts w the figure is
96
+ // weighed by — Pulls for $ and minutes per merged PR, claims for the fail
97
+ // rate. A side's $ (or minutes) per merged PR is its spend per Pull over its
98
+ // merged PRs per Pull, each averaged over the stretches with those weights, so
99
+ // the spend of a stretch in which it merged nothing still counts; its fail
100
+ // rate is its stretches' fail rates averaged, a stretch in which either side
101
+ // has no claim weighing nothing. Every Pull of a shared stretch is kept, none
102
+ // filtered or decayed, and one in a stretch the other has none in takes no
103
+ // part. A shift that hits both cells in a stretch cancels, since the gap is
104
+ // read inside it, and a cell that ran in one stretch is held to the other's
105
+ // Pulls of that stretch alone. With one shared stretch the comparison is the
106
+ // cells' own figures. The bootstrap resamples within each stretch.
107
+ //
82
108
  // THE FLOOR. A cell is under the floor against a baseline when its fail rate
83
- // is TRIP_POINTS or more points above the baseline's, compared in integer
84
- // counts. The guard holds it pooled; the fit holds it per row.
109
+ // is TRIP_POINTS or more points above the baseline's over the stretches they
110
+ // share, compared in integers so a gap of exactly the margin reads as one:
111
+ // each stretch's cross-product of the counts, weighted as above, summed as
112
+ // exact fractions, which with one stretch is the cross-product of the counts.
113
+ // The guard holds it over every group's Pulls together; the fit holds it per
114
+ // row.
85
115
 
86
116
  import { CELL } from "./ledger-grammar.mjs";
87
117
  import { parseMemberName } from "./member-record.mjs";
@@ -113,12 +143,6 @@ export const OPTIONAL_COLUMNS = new Set(FEATURE_COLUMNS.slice(FEATURE_COLUMNS.in
113
143
  // The quality floor's margin, in points of fail rate.
114
144
  export const TRIP_POINTS = 15;
115
145
 
116
- // The floor, in integer counts so a 3-of-20 difference is exactly 15 points
117
- // rather than 14.999… in floating point. Each side is `{ claims, failed }`.
118
- export function underFloor(cell, base) {
119
- return (cell.failed * base.claims - base.failed * cell.claims) * 100 >= TRIP_POINTS * cell.claims * base.claims;
120
- }
121
-
122
146
  const round2 = (x) => (Number.isFinite(x) ? Number(x.toFixed(2)) : null);
123
147
 
124
148
  // Deterministic, so a re-run reads the same range.
@@ -133,38 +157,148 @@ function mulberry32(seed) {
133
157
  };
134
158
  }
135
159
 
136
- // The bootstrap 95% range of (cell − base) per merged PR, its ends rounded to
137
- // two places. Each unit is one counted Pull, `bootUnit`'s shape:
138
- // `{ value, merged }`, `value` the measure `bootUnit` was asked for and
139
- // merged 0 or 1. The figure per merged PR is Σvalue / Σmerged. null when
140
- // either side has no unit, or when under half the resamples have a merged PR
141
- // on both sides.
160
+ // What a unit measures: its `value` over its `per` is the figure, $ or minutes of work time per merged PR, or the
161
+ // fail rate in points per claim; `weigh` is what it adds to the count its stretch is weighed by, one Pull or its
162
+ // claims.
163
+ const MEASURES = Object.freeze({
164
+ usd: { value: (u) => u.spend, per: (u) => (u.merged ? 1 : 0), weigh: () => 1 },
165
+ minutes: { value: (u) => u.workS / 60, per: (u) => (u.merged ? 1 : 0), weigh: () => 1 },
166
+ fail: { value: (u) => 100 * u.falseClaims, per: (u) => u.claims, weigh: (u) => u.claims },
167
+ });
168
+
169
+ // A counted Pull as a unit of `measure`, one of MEASURES: `{ value, per, weigh, stretch }`.
170
+ export const bootUnit = (u, measure = "usd") => {
171
+ const m = MEASURES[measure];
172
+ return { value: m.value(u), per: m.per(u), weigh: m.weigh(u), stretch: u.stretch };
173
+ };
174
+
175
+ // The stretches in which both sides have a unit, as `{ cell, base }` lists of those units, in the order the cell first meets them.
176
+ function sharedStretches(cellUnits, baseUnits) {
177
+ const byStretch = new Map();
178
+ for (const [side, units] of [["cell", cellUnits], ["base", baseUnits]]) {
179
+ for (const u of units) {
180
+ const held = byStretch.get(u.stretch) ?? byStretch.set(u.stretch, { cell: [], base: [] }).get(u.stretch);
181
+ held[side].push(u);
182
+ }
183
+ }
184
+ return [...byStretch.values()].filter((s) => s.cell.length > 0 && s.base.length > 0);
185
+ }
186
+
187
+ // One side's units in a stretch as `{ v, d, w }`: their values, their `per`s and their `weigh`s summed.
188
+ const sumOf = (units) => units.reduce((s, u) => ({ v: s.v + u.value, d: s.d + u.per, w: s.w + u.weigh }), { v: 0, d: 0, w: 0 });
189
+
190
+ // The two sides' figures pooled over the stretches: `sums` holds one `{ cell, base }` of `{ v, d, w }` per stretch.
191
+ // A stretch is weighted by w_cell·w_base/(w_cell + w_base), what the thinner side lets it weigh, one in which
192
+ // either side has no w taking no part, and a side's figure is its v per w over its d per w, each averaged with
193
+ // those weights: with w the d, the average of the stretches' v/d. A side's v and d of a stretch are scaled by
194
+ // its weight over its w, taken relative to the first stretch's, so that with one stretch the figure is v/d
195
+ // exactly. null when no stretch takes part, or when a side has no d in those that do.
196
+ function pool(sums) {
197
+ const weights = sums.map(({ cell, base }) => (cell.w > 0 && base.w > 0 ? (cell.w * base.w) / (cell.w + base.w) : 0));
198
+ const figure = (side) => {
199
+ let v = 0, d = 0, first = null;
200
+ sums.forEach((s, k) => {
201
+ if (weights[k] === 0) return;
202
+ const scale = weights[k] / s[side].w;
203
+ first ??= scale;
204
+ v += (scale / first) * s[side].v;
205
+ d += (scale / first) * s[side].d;
206
+ });
207
+ return d > 0 ? v / d : null;
208
+ };
209
+ const [cell, base] = [figure("cell"), figure("base")];
210
+ return cell === null || base === null ? null : { cell, base };
211
+ }
212
+
213
+ // The bootstrap 95% range of (cell − base), its ends rounded to two places, over the stretches in which both
214
+ // sides have units. Each stretch's units are resampled among themselves and the stretches pooled as `pool` pools
215
+ // them, so a shift in a stretch that hits both sides cancels in every resample. A unit is one counted Pull,
216
+ // `bootUnit`'s shape `{ value, per, weigh, stretch }`; units with no stretch are in one together. null when no
217
+ // stretch is shared, or when under half the resamples have a figure on both sides.
142
218
  export function bootstrapDiffCI(cellUnits, baseUnits, { iterations = 2000, seed = 1 } = {}) {
143
- if (!cellUnits.length || !baseUnits.length) return null;
219
+ const shared = sharedStretches(cellUnits, baseUnits);
220
+ if (shared.length === 0) return null;
144
221
  const rand = mulberry32(seed);
145
222
  const resample = (units) => {
146
- let u = 0, m = 0;
223
+ let v = 0, d = 0, w = 0;
147
224
  for (let i = 0; i < units.length; i++) {
148
225
  const x = units[Math.floor(rand() * units.length)];
149
- u += x.value; m += x.merged;
226
+ v += x.value; d += x.per; w += x.weigh;
150
227
  }
151
- return m ? u / m : null;
228
+ return { v, d, w };
152
229
  };
153
230
  const diffs = [];
154
231
  for (let i = 0; i < iterations; i++) {
155
- const a = resample(cellUnits), b = resample(baseUnits);
156
- if (a !== null && b !== null) diffs.push(a - b);
232
+ const cell = shared.map((s) => resample(s.cell));
233
+ const base = shared.map((s) => resample(s.base));
234
+ const pooled = pool(shared.map((_, k) => ({ cell: cell[k], base: base[k] })));
235
+ if (pooled !== null) diffs.push(pooled.cell - pooled.base);
157
236
  }
158
237
  if (diffs.length < iterations / 2) return null;
159
238
  diffs.sort((x, y) => x - y);
160
239
  return [round2(diffs[Math.floor(0.025 * (diffs.length - 1))]), round2(diffs[Math.ceil(0.975 * (diffs.length - 1))])];
161
240
  }
162
241
 
163
- // What a bootstrap unit measures: `usd`, its spend, or `minutes`, its work time.
164
- const METRIC = Object.freeze({ usd: (u) => u.spend, minutes: (u) => u.workS / 60 });
242
+ const countsOf = (units) => ({
243
+ n: units.length,
244
+ merged: units.filter((u) => u.merged).length,
245
+ claims: units.reduce((n, u) => n + u.claims, 0),
246
+ failed: units.reduce((n, u) => n + u.falseClaims, 0),
247
+ });
165
248
 
166
- // A counted Pull as a bootstrap unit, its `value` the Pull's `metric`.
167
- export const bootUnit = (u, metric = "usd") => ({ value: METRIC[metric](u), merged: u.merged ? 1 : 0 });
249
+ // Whether the pooled fail-rate gap reaches TRIP_POINTS, in integers so a gap of exactly the margin reads as one. A
250
+ // stretch adds (failed_cell·claims_base − failed_base·claims_cell)/(claims_cell + claims_base) to the gap and
251
+ // claims_cell·claims_base/(claims_cell + claims_base) to the weight `pool` gives it, a stretch in which either side
252
+ // has no claim adding nothing: with one stretch, the cross-product test of the counts. false when no stretch has a
253
+ // claim on both sides.
254
+ function reachesMargin(shared) {
255
+ let gap = [0n, 1n];
256
+ let weight = [0n, 1n];
257
+ for (const s of shared) {
258
+ const [c, b] = [countsOf(s.cell), countsOf(s.base)];
259
+ if (c.claims === 0 || b.claims === 0) continue;
260
+ const n = BigInt(c.claims + b.claims);
261
+ gap = [gap[0] * n + BigInt(c.failed * b.claims - b.failed * c.claims) * gap[1], gap[1] * n];
262
+ weight = [weight[0] * n + BigInt(c.claims * b.claims) * weight[1], weight[1] * n];
263
+ }
264
+ return weight[0] > 0n && 100n * gap[0] * weight[1] >= BigInt(TRIP_POINTS) * weight[0] * gap[1];
265
+ }
266
+
267
+ /**
268
+ * Two cells' newest-generation counted Pulls compared over the stretches in which both were drawn, the one
269
+ * comparison the fit's rows, its floor and the cost guard make. Within each shared stretch the two cells are
270
+ * compared, and the stretches are pooled by `pool`, so a shift that hits both cells in a stretch cancels and
271
+ * every Pull of a shared stretch is kept, its spend and work time in the $ and minutes per merged PR even where
272
+ * its side merged nothing in that stretch. A cell's Pulls in a stretch the other has none in take no part.
273
+ * Returns `{ stretches, cell, base, underFloor, range }`: `stretches`, how many were shared; `cell` and `base`,
274
+ * each side's counts over the shared stretches (`n`, `merged`, `claims`, `failed`) beside its figures pooled
275
+ * over them (`usd_per_merged`, `minutes_per_merged`, `fail_rate`, null where a side has no merged PR or no
276
+ * claim to carry one);
277
+ * `underFloor`, whether the cell's fail rate is TRIP_POINTS or more points above the base's, pooled; and
278
+ * `range(measure)`, the bootstrap range of (cell − base) for `measure`, one of `usd`, `minutes` (per merged
279
+ * PR) and `fail` (points), null where there is none. With one shared stretch these are the Pulls' own figures,
280
+ * the integer cross-product of their counts and the bootstrap of their units.
281
+ */
282
+ export function compareCells(cellPulls, basePulls) {
283
+ const shared = sharedStretches(cellPulls, basePulls);
284
+ const pooled = Object.fromEntries(Object.keys(MEASURES).map((measure) => [measure, pool(shared.map((s) => ({
285
+ cell: sumOf(s.cell.map((u) => bootUnit(u, measure))),
286
+ base: sumOf(s.base.map((u) => bootUnit(u, measure))),
287
+ })))]));
288
+ const side = (which) => ({
289
+ ...countsOf(shared.flatMap((s) => s[which])),
290
+ usd_per_merged: pooled.usd?.[which] ?? null,
291
+ minutes_per_merged: pooled.minutes?.[which] ?? null,
292
+ fail_rate: pooled.fail === null ? null : pooled.fail[which] / 100,
293
+ });
294
+ return {
295
+ stretches: shared.length,
296
+ cell: side("cell"),
297
+ base: side("base"),
298
+ underFloor: reachesMargin(shared),
299
+ range: (measure) => bootstrapDiffCI(cellPulls.map((u) => bootUnit(u, measure)), basePulls.map((u) => bootUnit(u, measure))),
300
+ };
301
+ }
168
302
 
169
303
  const ISSUE_NUMBER = /^[1-9][0-9]*$/;
170
304
 
@@ -283,9 +417,41 @@ function numberOf(row, field, column = field) {
283
417
  return n;
284
418
  }
285
419
 
420
+ const DAY_MS = 86_400_000;
421
+
422
+ // The Monday opening the UTC calendar week that `date` (YYYY-MM-DD) falls in, in the same form.
423
+ function weekOf(date) {
424
+ const [y, m, d] = date.split("-").map(Number);
425
+ const t = Date.UTC(y, m - 1, d);
426
+ return new Date(t - ((new Date(t).getUTCDay() + 6) % 7) * DAY_MS).toISOString().slice(0, 10);
427
+ }
428
+
429
+ /**
430
+ * Each of `pulls` to its stretch, a name: `<the Monday opening its run_date's UTC week>/<k>`, `k` the number of
431
+ * version changes before it. The changes are read off the sequence of every one of `pulls` — by session id, then
432
+ * in the order given, as `generations` orders them — so every cell is cut at the same places. Only a change
433
+ * between two recorded, different `plugin_version`s cuts, before the Pull that records the newer one: a blank
434
+ * version is unknown, leaves the stretch in force, and the first version recorded cuts nothing.
435
+ */
436
+ function stretchesOf(pulls) {
437
+ const sequence = pulls.map((pull, at) => ({ pull, at })).sort((a, b) => cmp(a.pull.session, b.pull.session) || a.at - b.at);
438
+ const stretch = new Map();
439
+ let changes = 0;
440
+ let version = "";
441
+ for (const { pull } of sequence) {
442
+ const recorded = pull.plugin_version ?? "";
443
+ if (recorded !== "") {
444
+ if (version !== "" && recorded !== version) changes++;
445
+ version = recorded;
446
+ }
447
+ stretch.set(pull, `${weekOf(pull.run_date)}/${changes}`);
448
+ }
449
+ return stretch;
450
+ }
451
+
286
452
  /**
287
453
  * One unit per ticket-features row dated on or after `windowStart` (every dated
288
- * row when null), in file order: `{ pull, cell, stratum, generation, status,
454
+ * row when null), in file order: `{ pull, cell, stratum, stretch, generation, status,
289
455
  * merged, pr, ruling, pendingPr, noRuling, noRulingPrs, claims, falseClaims, rows, spend, workS }`,
290
456
  * `generation` null exactly when the Pull is excluded. `noRulingPrs` are the
291
457
  * Pull's own implementer PRs that are merged and that no Pull holds a Ruling
@@ -294,7 +460,8 @@ function numberOf(row, field, column = field) {
294
460
  * booked `cost` is blank, and `workS`, its work time in seconds, when a booked
295
461
  * `work_s` of a row naming no parent is. `prs` is `gh pr list`'s
296
462
  * `{ number, state }` rows, or null when PR state is unknown (the fit). `stratum`
297
- * maps a features row to its stratum. Throws `AttributionError` on a features
463
+ * maps a features row to its stratum. `stretch` names the Pull's stretch among
464
+ * the windowed Pulls (`stretchesOf`), excluded Pulls included. Throws `AttributionError` on a features
298
465
  * row it cannot date or a booked `cost` or `work_s` it cannot read, and
299
466
  * `RulingError` as `rulingFor` does.
300
467
  */
@@ -327,6 +494,7 @@ export function attribute({ features, members, tiers, prs = null, windowStart =
327
494
 
328
495
  // Rulings: each PR's merge to one Pull, carriers first, then the date floor.
329
496
  const inWindow = pulls.filter((p) => windowStart === null || p.run_date >= windowStart);
497
+ const stretch = stretchesOf(inWindow);
330
498
  const rulings = rulingsByTicket(tiers);
331
499
  const fileOrder = new Map(tiers.map((t, i) => [t, i]));
332
500
  // Each PR to its latest ruling row in file order, whatever its ticket or date.
@@ -402,7 +570,7 @@ export function attribute({ features, members, tiers, prs = null, windowStart =
402
570
  else if (blank || (r && !r.carried)) status = "unpriced";
403
571
  else if (untimed) status = "untimed";
404
572
  return {
405
- pull, cell: pull.chosen_cell, stratum: stratum(pull), generation, status, merged, pr: r?.pr ?? null, ruling: r?.ruling ?? null,
573
+ pull, cell: pull.chosen_cell, stratum: stratum(pull), stretch: stretch.get(pull), generation, status, merged, pr: r?.pr ?? null, ruling: r?.ruling ?? null,
406
574
  noRuling: noRulingPrs.length > 0, noRulingPrs, pendingPr, claims, falseClaims, rows: booked, spend: blank ? null : spend, workS: untimed ? null : workS,
407
575
  };
408
576
  });
@@ -101,12 +101,16 @@
101
101
  // alone in GitHub's place.
102
102
  //
103
103
  // `--pr <N>` MODE is the review snapshot's prune: every directory
104
- // `<root>/pr<N>/run-*` idle past the retention is removed, and nothing else
105
- // is looked at — no ledger, no gh (a live review's own run root is seconds
106
- // old), no sibling under pr<N>/.
104
+ // `<root>/pr<N>/run-*` idle past the retention is removed whole, and every
105
+ // other one has the trees in it evicted — each directory that holds a .git of
106
+ // its own, at any depth, loses every path git ignores in it, which is
107
+ // evict-tree.mjs's rule: tracked files, each .git, untracked files git does not
108
+ // ignore and everything in the run root outside a tree stay. Nothing else is
109
+ // looked at — no ledger, no gh (a live review's own run root is seconds old
110
+ // and holds no tree yet), no sibling under pr<N>/.
107
111
  //
108
- // EVERY REMOVAL, in either mode, goes through REMOVE below: owner rwx
109
- // restored, darwin's user-immutable and append-only flags cleared where
112
+ // EVERY REMOVAL, in either mode, goes through evict-tree.mjs's REMOVE: owner
113
+ // rwx restored, darwin's user-immutable and append-only flags cleared where
110
114
  // `chflags` exists, then `rm -rf` — so a fixture that dropped its own read bit
111
115
  // or flagged a file cannot wedge it. Removal is best-effort per entry: a
112
116
  // failure lands in `failed[]` and the sweep continues.
@@ -116,10 +120,12 @@
116
120
  // "kept":[{"path","reason"}],"failed":[{"path","error"}]}
117
121
  // The sibling pass's kept entries also carry "idle": true when nothing under
118
122
  // the key was found modified within the retention, false otherwise.
123
+ // `--pr` mode adds `"evicted":[{"path","reason","ignored"}]` after `removed`:
124
+ // each tree that held ignored paths, `ignored` naming them.
119
125
  // `ledger` is the file read, or null when none was (`--pr` mode, or
120
126
  // `--after-rotate` with no file) — so "never read" stays distinct from "read
121
127
  // and found empty". A dry run prints the same receipt with "applied":false,
122
- // `removed` naming what --apply would remove.
128
+ // `removed` and `evicted` naming what --apply would remove.
123
129
  // Exit 0 whenever the receipt is printed, failures included; 2 for a refused
124
130
  // invocation — bad arguments, no --root, a root that is not a directory, a
125
131
  // root sweep or sibling pass whose --root is not this workspace's own scratch
@@ -133,6 +139,7 @@ import { lstatSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync,
133
139
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
134
140
  import { fileURLToPath } from "node:url";
135
141
  import { defineFlags, isDigits, makeDie, writeAll } from "./arg.mjs";
142
+ import { evictTrees, removeEntry } from "./evict-tree.mjs";
136
143
  import { fleetFile, FleetDirUnresolvable, SCRATCH_KEY_SHAPE, scratchRoot } from "./fleet-dir.mjs";
137
144
  import { gitEnv } from "./git-env.mjs";
138
145
  import { ghAliasedRead, how } from "./gh-aliased-read.mjs";
@@ -150,26 +157,6 @@ export const RETENTION_MS = 7 * DAY_MS;
150
157
  const GH_TIMEOUT_MS = 30_000;
151
158
  const MAX_BUFFER = 64 * 1024 * 1024;
152
159
 
153
- // The one removal sequence. `$1` is the entry. A symlink entry is unlinked
154
- // before anything else runs, so no chmod or chflags ever sees it: whether a
155
- // recursive chmod dereferences a link given as its operand differs between
156
- // BSD and GNU, and either would change the mode or flags of a target outside
157
- // the entry being removed. Links met inside a directory are left to `rm`,
158
- // which unlinks them without following. `chmod -R` fails
159
- // on a flagged directory, and `chflags -R` cannot read a mode-000 directory it
160
- // has just unflagged, so when the first pass fails each directory's flag and
161
- // mode come off together, top-down, before anything inside it is read.
162
- const REMOVE = [
163
- 'd=$1',
164
- 'if [ -L "$d" ]; then rm -f "$d"; exit $?; fi',
165
- 'chmod -R u+rwx "$d" 2>/dev/null; m=$?',
166
- 'if command -v chflags >/dev/null 2>&1; then',
167
- ' [ $m -eq 0 ] || { chflags nouchg,nouappnd "$d"; chmod u+rwx "$d"; find "$d" -type d -exec chflags nouchg,nouappnd {} ";" -exec chmod u+rwx {} ";"; } 2>/dev/null',
168
- ' chflags -R nouchg,nouappnd "$d" 2>/dev/null',
169
- 'fi',
170
- 'rm -rf "$d"',
171
- ].join("\n");
172
-
173
160
  const PR_ENTRY = /^pr([1-9][0-9]*)$/;
174
161
  const IMPL_ENTRY = /^impl-([1-9][0-9]*)$/;
175
162
  const DISPOSITIONS_ENTRY = /^dispositions-fix-pr-([1-9][0-9]*)(?:-[a-z])?\.json$/;
@@ -215,12 +202,6 @@ export function freshUnder(path, cutoff, unreadable = null) {
215
202
  return null;
216
203
  }
217
204
 
218
- /** Remove `path` through REMOVE; null on success, else the reason. */
219
- export function removeEntry(path) {
220
- const r = spawnSync("sh", ["-c", REMOVE, "sh", path], { encoding: "utf8" });
221
- return r.error || r.status !== 0 ? how(r) : null;
222
- }
223
-
224
205
  // The ledger's rows and `## Dispatched` entries, read through `ledger.mjs
225
206
  // read` so the ledger keeps one parser. `--file` names it outright, so the read
226
207
  // resolves no workspace and runs no git. `die` is the caller's, and `undone`
@@ -705,6 +686,8 @@ function main() {
705
686
 
706
687
  const now = Date.now();
707
688
  let ledger = null;
689
+ // `--pr` mode's evictions; null in every other mode.
690
+ let evicted = null;
708
691
  let remove;
709
692
  let kept = [];
710
693
  const failed = [];
@@ -716,6 +699,13 @@ function main() {
716
699
  remove = [];
717
700
  failed.push({ path: parent, error: e.message });
718
701
  }
702
+ // `--pr` mode also evicts the trees in every run root it keeps.
703
+ evicted = [];
704
+ for (const run of kept) {
705
+ const done = evictTrees(run.path, { apply });
706
+ for (const t of done.evicted) evicted.push({ path: t.path, reason: "a tree in a kept review run root", ignored: t.ignored });
707
+ failed.push(...done.failed);
708
+ }
719
709
  } else if (siblings) {
720
710
  if (apply) {
721
711
  const wrote = writeCheckout(root);
@@ -769,7 +759,8 @@ function main() {
769
759
  if (error === null) removed.push(entry);
770
760
  else failed.push({ path: entry.path, error });
771
761
  }
772
- writeAll(1, `${JSON.stringify({ applied: apply, ledger, removed, kept, failed })}\n`);
762
+ const receipt = { applied: apply, ledger, removed, ...(evicted === null ? {} : { evicted }), kept, failed };
763
+ writeAll(1, `${JSON.stringify(receipt)}\n`);
773
764
  }
774
765
 
775
766
  if (isCLI(import.meta.url)) main();
@@ -23,12 +23,14 @@
23
23
  // `null`, which every guard here — `if (snap) {...}`, `unrunCrashed`,
24
24
  // `verdictFor` — is written against).
25
25
  //
26
- // Three imports. arg.mjs's isDigits(): this file is an ordinary
26
+ // The imports. arg.mjs's isDigits(): this file is an ordinary
27
27
  // module, so it consumes the repo's digits rule directly rather than
28
28
  // declaring its own copy. node:path's `posix`, to normalise a
29
29
  // scratch path before `runnerScratchRefusal` reads its last component, and
30
- // its `isAbsolute`, to refuse a scratch that is not an absolute path.
31
- // fleet-dir.mjs's scratchRoot(), scratchRootRefusal() and FleetDirUnresolvable.
30
+ // its `isAbsolute`, to refuse a scratch that is not an absolute path; node:fs's
31
+ // `lstatSync`, to tell a real run-root directory from a symlink before the
32
+ // review's end evicts the trees in it. evict-tree.mjs's evictTrees(), which does
33
+ // that eviction. fleet-dir.mjs's scratchRoot(), scratchRootRefusal() and FleetDirUnresolvable.
32
34
  // scratchRoot() and FleetDirUnresolvable serve the one caller that passes no
33
35
  // `scratch` at all — a standalone review with no dispatcher — which takes the
34
36
  // fleet's own scratch root for this repository; scratchRootRefusal() vets every
@@ -41,8 +43,10 @@
41
43
  // review-eval.mjs's import of it failed. A suite sweep keeps a
42
44
  // shipped `.mjs` from importing a relative module under any other extension.
43
45
 
46
+ import { lstatSync } from "node:fs";
44
47
  import { isAbsolute, posix } from "node:path";
45
48
  import { isDigits } from "./arg.mjs";
49
+ import { evictTrees } from "./evict-tree.mjs";
46
50
  import { FleetDirUnresolvable, scratchRoot, scratchRootRefusal } from "./fleet-dir.mjs";
47
51
 
48
52
  // --- Schemas ----------------------------------------------------------
@@ -1003,7 +1007,65 @@ function standaloneScratchRoot() {
1003
1007
  return root;
1004
1008
  }
1005
1009
 
1010
+ /**
1011
+ * The review. When it returns or throws after its snapshot step has reported a
1012
+ * run root of this PR, it evicts every tree in that run root: the snapshot and
1013
+ * each specialist's and refuter's copy lose every path git ignores in them,
1014
+ * and nothing restores them. The run root's other files stay, review.json
1015
+ * among them. A failed eviction, and a reported run root it refuses to touch,
1016
+ * are logged; neither, nor a log that throws, changes what the review returns
1017
+ * or throws. A snapshot step that reported no run root evicts nothing and
1018
+ * logs nothing.
1019
+ */
1006
1020
  export async function runReview(host, args) {
1021
+ const run = { partition: null, runRoot: null };
1022
+ try {
1023
+ return await reviewRun(host, args, run);
1024
+ } finally {
1025
+ evictRunRoot(host.log, run);
1026
+ }
1027
+ }
1028
+
1029
+ // A reported run root eviction may touch: this PR's partition of the scratch
1030
+ // root — the very string the snapshot step's `mktemp` template starts with, so
1031
+ // a scratch spelled with a trailing slash or a `./` segment still matches — a
1032
+ // slash, `run-` and the eight `mktemp` characters, and nothing after — so no
1033
+ // `..` segment, no trailing slash, no other directory. It must also be a real
1034
+ // directory, not a symlink.
1035
+ function evictableRunRoot(runRoot, partition) {
1036
+ if (!runRoot.startsWith(`${partition}/`)) return false;
1037
+ if (!/^run-[A-Za-z0-9]{8}$/.test(runRoot.slice(partition.length + 1))) return false;
1038
+ try {
1039
+ return lstatSync(partition).isDirectory() && lstatSync(runRoot).isDirectory();
1040
+ } catch {
1041
+ return false;
1042
+ }
1043
+ }
1044
+
1045
+ // `run.runRoot` is set only once `run.partition` is, so a run root implies a
1046
+ // partition.
1047
+ function evictRunRoot(log, { partition, runRoot }) {
1048
+ const say = (m) => {
1049
+ try {
1050
+ log(m);
1051
+ } catch {
1052
+ // The review's own outcome stands whatever the log sink does.
1053
+ }
1054
+ };
1055
+ if (runRoot === null) return;
1056
+ try {
1057
+ if (!evictableRunRoot(runRoot, partition)) {
1058
+ say(`no eviction at the end of the review: the reported run root ${runRoot} is not a real directory named run- and eight characters directly in ${partition}`);
1059
+ return;
1060
+ }
1061
+ const done = evictTrees(runRoot, { apply: true });
1062
+ for (const f of done.failed) say(`eviction at the end of the review failed in ${f.path}: ${f.error}`);
1063
+ } catch (e) {
1064
+ say(`eviction at the end of the review failed in ${runRoot}: ${e?.message ?? e}`);
1065
+ }
1066
+ }
1067
+
1068
+ async function reviewRun(host, args, run) {
1007
1069
  const { agent, phase, log } = host;
1008
1070
  const pipeline = host.pipeline ?? defaultPipeline;
1009
1071
  const parallel = host.parallel ?? defaultParallel;
@@ -1069,6 +1131,7 @@ export async function runReview(host, args) {
1069
1131
  const rootRefusal = scratchRootRefusal(scratch);
1070
1132
  if (rootRefusal !== null) throw new Error(`review-pr: args.scratch: ${rootRefusal}`);
1071
1133
  }
1134
+ run.partition = runRootParent;
1072
1135
 
1073
1136
  const explicitDimensions = resolveDimensions(A.dimensions, DEFAULT_DIMENSIONS);
1074
1137
 
@@ -1255,6 +1318,9 @@ installError only replaces installCmd and installExit, and uncoveredError only
1255
1318
  replaces uncovered.`,
1256
1319
  { label: `snapshot${forPr}`, phase: "Snapshot", agentType: SNAPSHOT_AGENT_TYPE, schema: SNAPSHOT_SCHEMA },
1257
1320
  );
1321
+ // From here the run root the snapshot step made is known, whatever the
1322
+ // report says next: runReview's end evicts the trees in it.
1323
+ if (snap && typeof snap.runRoot === "string") run.runRoot = snap.runRoot;
1258
1324
 
1259
1325
  if (snap) {
1260
1326
  if (typeof snap.head === "string") snap.head = snap.head.trim().toLowerCase();
@@ -63,7 +63,7 @@ import { CELL, OBJECTIVES, POLICY_CELL, STARTING_CELLS, drawCell, formatRouting,
63
63
  import { objectiveFromReceipt, sessionFromReceipt } from "./phase0-receipt.mjs";
64
64
  import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
65
65
  import {
66
- AttributionError, FEATURE_COLUMNS, OPTIONAL_COLUMNS, TRIP_POINTS, attribute, bootUnit, bootstrapDiffCI, generations, parseFeatures, tally, underFloor,
66
+ AttributionError, FEATURE_COLUMNS, OPTIONAL_COLUMNS, TRIP_POINTS, attribute, compareCells, generations, parseFeatures, tally,
67
67
  } from "./pull-attribution.mjs";
68
68
  import { RulingError, parseTierOutcomes } from "./tier-outcomes.mjs";
69
69
  import { LINE_REF, briefPaths, briefText } from "./ticket-text.mjs";
@@ -734,10 +734,11 @@ function estimate(units, order, nodes) {
734
734
  }
735
735
 
736
736
  // What each objective's judge reads and says: the figure per merged PR it
737
- // minimises (`estimate()`'s name and its bootstrap metric), its verdict for a
738
- // candidate past the margin and for one with no reliable difference, the key
739
- // a pair names its better side by, and its reasons for a winner every other
740
- // qualifier was reliably worse than and for one ahead on the figure.
737
+ // minimises (a `compareCells` side's name for it) and the measure its range is
738
+ // read in (`range()`'s), its verdict for a candidate past the margin and for
739
+ // one with no reliable difference, the key a pair names its better side by,
740
+ // and its reasons for a winner every other qualifier was reliably worse than
741
+ // and for one ahead on the figure.
741
742
  const JUDGE = Object.freeze({
742
743
  cost: {
743
744
  figure: "usd_per_merged", metric: "usd", over: "too-dear", unreliable: "not-reliably-cheaper",
@@ -754,35 +755,45 @@ const JUDGE = Object.freeze({
754
755
  const unjudged = () => ({ cell: null, reason: "unjudged", cells: {}, pairs: [] });
755
756
 
756
757
  /**
757
- * One row's cell under one objective — a node's of the tree — and
758
- * why. The quality floor is held twice: pooled by the guard, whose trip takes
759
- * a cell out of every row and out of the exploration draw, and per row by the
760
- * fit, which refuses a cell under the floor that row alone. The floor is
761
- * measured against the default cell under both objectives. Every figure read
762
- * is the cell's newest generation's, the default cell's included. `est` and
763
- * `pulls` are the row's `estimate()` figures and counted Pulls; `baseCell` is
764
- * the cell the row holds unless a candidate qualifies: the default cell under
765
- * `cost`, the `cost` row's cell under `speed`. The figure is $ per merged PR
766
- * under `cost` and minutes of work time per merged PR under `speed`.
758
+ * One row's cell under one objective — a node's of the tree — and why. The
759
+ * quality floor is held twice: by the guard over every group's Pulls together,
760
+ * whose trip takes a cell out of every row and out of the exploration draw,
761
+ * and per row by the fit, which refuses a cell under the floor that row alone.
762
+ * The floor is measured against the default cell under both objectives. Every
763
+ * figure read is the cell's newest generation's, the default cell's included,
764
+ * and every comparison is `compareCells`': two cells over the stretches in
765
+ * which both were drawn, the stretches pooled, so a base's other weeks move
766
+ * no verdict and a shift that hits every cell at once cancels in every gap.
767
+ * The one test it does not cancel in is ADOPT_RATIO's, a ratio of the two
768
+ * figures: a shift that raises both by the same amount brings the ratio nearer
769
+ * 1, so it can move a candidate from qualifying to `too-dear` or `too-slow`.
770
+ * `pulls` holds the row's counted Pulls per cell (`estimate()`'s); `baseCell`
771
+ * is the cell the row holds unless a candidate qualifies: the default cell
772
+ * under `cost`, the `cost` row's cell under `speed`. The figure is $ per
773
+ * merged PR under `cost` and minutes of work time per merged PR under `speed`.
767
774
  *
768
775
  * A candidate is a cell of `cells` other than the base. Its `verdict`, the
769
776
  * first that applies: `tripped` by the guard; `too-few`, under MIN_N merged
770
- * PRs in the row; `under-floor` against the default cell there; `too-dear`
771
- * (`cost`) or `too-slow` (`speed`), above ADOPT_RATIO of the base's figure;
772
- * `not-reliably-cheaper` or `not-reliably-faster`, its `range` does not lie
773
- * wholly below zero (its upper end, as `bootstrapDiffCI` returns it, is not
774
- * below zero) or there is none; else it `qualifies`. A candidate past
775
- * `too-few` records whether it is `under_floor`, the floor's `bar` (the
776
- * default cell's fail rate plus TRIP_POINTS, rounded as a fail rate is, for
777
- * reading only: the floor compares counts) and its `range`, the bootstrap 95%
778
- * range of (candidate − base) figure over those Pulls; the others record null
779
- * for each.
777
+ * PRs in the row, on either side, in the stretches it shares with the base or
778
+ * with the default cell (none shared, none counted); `under-floor` against the
779
+ * default cell there; `too-dear` (`cost`) or `too-slow` (`speed`), above
780
+ * ADOPT_RATIO of the base's figure, both figures over the stretches it shares
781
+ * with the base; `not-reliably-cheaper` or `not-reliably-faster`, its `range`
782
+ * does not lie wholly below zero (its upper end, as `bootstrapDiffCI` returns
783
+ * it, is not below zero) or there is none; else it `qualifies`. A candidate
784
+ * past `too-few` records whether it is `under_floor`, the floor's `bar` (the
785
+ * default cell's fail rate over the stretches it shares with the candidate,
786
+ * plus TRIP_POINTS, rounded as a fail rate is, for reading only: the floor
787
+ * compares counts) and its `range`, the bootstrap 95% range of (candidate −
788
+ * base) figure over the Pulls of those stretches; the others record null for
789
+ * each.
780
790
  *
781
791
  * Several qualifiers: each pair records the range of (the better by the
782
- * figure, else by name − the other) in `pairs`, naming the better side
783
- * `cheaper` or `faster`, and a qualifier another is reliably better than is
784
- * dropped. Among the rest the lower fail rate, compared in counts, wins, then
785
- * the lower figure, then the name.
792
+ * figure, else by name − the other) in `pairs`, the pair compared over the
793
+ * stretches it shares, naming the better side `cheaper` or `faster`, and a
794
+ * qualifier another is reliably better than is dropped. Among the rest the
795
+ * lower fail rate wins, then the lower figure, then the name; each is the
796
+ * qualifier's gap to the base over the stretches it shares with it.
786
797
  *
787
798
  * `reason`, why the row holds `cell`: `unjudged` (the default cell or the
788
799
  * base, or every untripped candidate, is under MIN_N merged PRs; `cell` is
@@ -791,31 +802,41 @@ const unjudged = () => ({ cell: null, reason: "unjudged", cells: {}, pairs: [] }
791
802
  * dropped), or what put it ahead of the next of the rest: `lower-fail-rate`,
792
803
  * `lower-usd` or `fewer-minutes`, or `name`.
793
804
  */
794
- function judge(objective, est = {}, pulls, cells, tripped, baseCell) {
805
+ function judge(objective, pulls = {}, cells, tripped, baseCell) {
795
806
  const { figure, metric, over, unreliable, better, reliably, ahead } = JUDGE[objective];
796
807
  const record = unjudged();
797
- const floor = est[POLICY_CELL];
798
- const base = est[baseCell];
799
- if (!floor || floor.merged < MIN_N || !base || base.merged < MIN_N) return record;
808
+ const pullsOf = (c) => pulls[c] ?? [];
809
+ const mergedOf = (c) => pullsOf(c).filter((u) => u.merged).length;
810
+ // A default cell or base short of MIN_N merged PRs has none to give any candidate, whichever stretches they share.
811
+ if (mergedOf(POLICY_CELL) < MIN_N || mergedOf(baseCell) < MIN_N) return record;
800
812
  // JSON writes −0 as 0, so a recorded end is 0 either way; `--check` compares the two.
801
- const units = (c) => pulls[c].map((u) => bootUnit(u, metric));
802
- const range = (a, b) => bootstrapDiffCI(units(a), units(b))?.map((x) => x + 0) ?? null;
813
+ const range = (m) => m.range(metric)?.map((x) => x + 0) ?? null;
803
814
  const reliablyBelow = (r) => r !== null && r[1] < 0;
804
- const bar = round4(floor.failed / floor.claims + TRIP_POINTS / 100);
815
+ // A matched figure as the table prints one, four places; none is unknown, past every figure that is known.
816
+ const printed = (side) => (side[figure] === null ? Infinity : round4(side[figure]));
817
+ const enough = (m) => m.cell.merged >= MIN_N && m.base.merged >= MIN_N;
818
+ const against = new Map();
805
819
  const qualifiers = [];
806
820
  let judged = false;
807
821
  for (const c of cells) {
808
822
  if (c === baseCell) continue;
809
- const e = est[c];
810
- if (tripped.has(c) || !e || e.merged < MIN_N) {
811
- record.cells[c] = { verdict: tripped.has(c) ? "tripped" : "too-few", under_floor: null, bar: null, range: null };
823
+ if (tripped.has(c)) {
824
+ record.cells[c] = { verdict: "tripped", under_floor: null, bar: null, range: null };
825
+ continue;
826
+ }
827
+ const vsBase = compareCells(pullsOf(c), pullsOf(baseCell));
828
+ const vsFloor = baseCell === POLICY_CELL ? vsBase : compareCells(pullsOf(c), pullsOf(POLICY_CELL));
829
+ if (!enough(vsBase) || !enough(vsFloor)) {
830
+ record.cells[c] = { verdict: "too-few", under_floor: null, bar: null, range: null };
812
831
  continue;
813
832
  }
814
833
  judged = true;
815
- const under = underFloor(e, floor);
816
- const r = range(c, baseCell);
834
+ against.set(c, vsBase);
835
+ const under = vsFloor.underFloor;
836
+ const bar = vsFloor.base.fail_rate === null ? null : round4(vsFloor.base.fail_rate + TRIP_POINTS / 100);
837
+ const r = range(vsBase);
817
838
  const verdict = under ? "under-floor"
818
- : e[figure] > ADOPT_RATIO * base[figure] ? over
839
+ : printed(vsBase.cell) > ADOPT_RATIO * printed(vsBase.base) ? over
819
840
  : reliablyBelow(r) ? "qualifies" : unreliable;
820
841
  record.cells[c] = { verdict, under_floor: under, bar, range: r };
821
842
  if (verdict === "qualifies") qualifiers.push(c);
@@ -823,36 +844,40 @@ function judge(objective, est = {}, pulls, cells, tripped, baseCell) {
823
844
  if (!judged) return record;
824
845
  if (qualifiers.length === 0) return { ...record, cell: baseCell, reason: "no-qualifier" };
825
846
 
826
- const of = (c) => est[c][figure];
827
847
  const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
828
- const failCmp = (a, b) => est[a].failed * est[b].claims - est[b].failed * est[a].claims;
848
+ // A qualifier's gap to the base in fail rate, and in the figure, over the stretches they share.
849
+ const failGap = (c) => against.get(c).cell.fail_rate - against.get(c).base.fail_rate;
850
+ const figureGap = (c) => printed(against.get(c).cell) - printed(against.get(c).base);
829
851
  const named = [...qualifiers].sort(byName);
830
852
  const dropped = new Set();
831
853
  for (let i = 0; i < named.length; i++) {
832
854
  for (let j = i + 1; j < named.length; j++) {
833
- const [win, other] = of(named[j]) < of(named[i]) ? [named[j], named[i]] : [named[i], named[j]];
834
- const r = range(win, other);
855
+ const pair = compareCells(pullsOf(named[i]), pullsOf(named[j]));
856
+ const flip = printed(pair.base) < printed(pair.cell);
857
+ const [win, other] = flip ? [named[j], named[i]] : [named[i], named[j]];
858
+ const r = range(flip ? compareCells(pullsOf(win), pullsOf(other)) : pair);
835
859
  record.pairs.push({ [better]: win, other, range: r });
836
860
  if (reliablyBelow(r)) dropped.add(other);
837
861
  }
838
862
  }
839
863
  // The best qualifier, by the figure then name, is never dropped, so the rest is never empty.
840
- const [win, next] = named.filter((c) => !dropped.has(c)).sort((a, b) => failCmp(a, b) || of(a) - of(b) || byName(a, b));
864
+ const [win, next] = named.filter((c) => !dropped.has(c))
865
+ .sort((a, b) => byName(failGap(a), failGap(b)) || byName(figureGap(a), figureGap(b)) || byName(a, b));
841
866
  const reason = qualifiers.length === 1 ? "sole-qualifier"
842
867
  : next === undefined ? reliably
843
- : failCmp(win, next) !== 0 ? "lower-fail-rate"
844
- : of(win) !== of(next) ? ahead : "name";
868
+ : failGap(win) !== failGap(next) ? "lower-fail-rate"
869
+ : figureGap(win) !== figureGap(next) ? ahead : "name";
845
870
  return { ...record, cell: win, reason };
846
871
  }
847
872
 
848
873
  /** A `cost` row: `judge()` from the default cell, by $ per merged PR. */
849
- function judgeRow(est, pulls, cells, tripped) {
850
- return judge("cost", est, pulls, cells, tripped, POLICY_CELL);
874
+ function judgeRow(pulls, cells, tripped) {
875
+ return judge("cost", pulls, cells, tripped, POLICY_CELL);
851
876
  }
852
877
 
853
878
  /** A `speed` row: `judge()` from the `cost` row's cell, by minutes of work time per merged PR. */
854
- function judgeSpeedRow(est, pulls, cells, tripped, costCell) {
855
- return judge("speed", est, pulls, cells, tripped, costCell);
879
+ function judgeSpeedRow(pulls, cells, tripped, costCell) {
880
+ return judge("speed", pulls, cells, tripped, costCell);
856
881
  }
857
882
 
858
883
  /**
@@ -884,10 +909,10 @@ export function fitTable({ prior, features, members, verdicts, guard, commit = n
884
909
  const reasons = { cost: {}, speed: {} };
885
910
  for (const s of nodes) {
886
911
  const up = parentOf(s);
887
- const cost = judgeRow(estimates[s], pulls[s], prior.cells, tripped);
912
+ const cost = judgeRow(pulls[s], prior.cells, tripped);
888
913
  const own = cost.cell !== null || up === null;
889
914
  const costCell = cost.cell ?? (up === null ? POLICY_CELL : rows.cost[up]);
890
- const speed = own ? judgeSpeedRow(estimates[s], pulls[s], prior.cells, tripped, costCell) : unjudged();
915
+ const speed = own ? judgeSpeedRow(pulls[s], prior.cells, tripped, costCell) : unjudged();
891
916
  const speedCell = speed.cell ?? (own ? costCell : rows.speed[up]);
892
917
  rows.cost[s] = costCell;
893
918
  rows.speed[s] = speedCell;