@feigi/fleet-ctl 3.64.0 → 3.64.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -256,7 +256,7 @@ For each labeled PR clearing the hold rule, lowest first:
256
256
 
257
257
  **No rebase happened because the PR was already current? Pass the head twice.** That is the normal case in a pass, not an edge case, and `pre == post` selects a proof path built for it. Never invent a plausible-looking `pre` to make the arguments differ — a `pre` that never landed satisfies the pre-rebase leg by construction, and passing one is the single easiest way to turn a stale merge into `proved=true`.
258
258
 
259
- **Read `gates`, not the flat fields.** The payload's flat fields are observations, and one of them being true or false says nothing about the verdict on its own. `gates` is the verdict's own working: `proved` is true exactly when every value in it is true. Membership is per-invocation — on the rebase path it carries `preDidNotLand` (leg 1), on the merge-commit path it carries `preIsParentOfHead` (leg 1 replaced), and on the no-rebase path it carries neither because leg 1 is dropped. That is why `preIsAncestor:true` sits next to `proved:true` on the no-rebase path and is **not** a contradiction: leg 1 wants it false, and leg 1 is not a gate on that path. A sanity check written against `preIsAncestor === false` rejects correct merges; write it against `gates` instead.
259
+ **Read `gates`, not the flat fields.** The payload's flat fields are observations, and one of them being true or false says nothing about the verdict on its own. `gates` is the verdict's own working: `proved` is true exactly when every value in it is true. Membership is per-invocation — on the rebase path it carries `preDidNotLand` (leg 1), on the merge-commit path it carries `preIsParentOfHead` (leg 1 replaced: true only when `pre` is a parent of `post` and is not an ancestor of `<merge>^1`, so a parent of `post` that was already on main fails it), and on the no-rebase path it carries neither because leg 1 is dropped. That is why `preIsAncestor:true` sits next to `proved:true` on the no-rebase path and is **not** a contradiction: leg 1 wants it false, and leg 1 is not a gate on that path. A sanity check written against `preIsAncestor === false` rejects correct merges; write it against `gates` instead.
260
260
 
261
261
  Exit **0** proved, **1** disproved, **2** the script could not evaluate the claim at all — the merge is unreachable from `origin/main`, is not a merge commit, or an argument does not resolve. Treat 2 as "ask a human", not as a disproof.
262
262
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.64.0",
3
+ "version": "3.64.2",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -45,6 +45,15 @@
45
45
  // the PR once it exists, are kept in the receipt: a re-run
46
46
  // after a failed push or PR resumes on that branch and never
47
47
  // opens a second PR.
48
+ // phase0-receipt moves `.fleet/phase0.json` to `.fleet/phase0.previous.json`,
49
+ // the name `phase0.mjs` holds a previous run's receipt under,
50
+ // so a run that ended here leaves no phase-0 receipt for the
51
+ // next run in this session to resume, and that run's rotation
52
+ // files it as `phase0.<UTC stamp>.json` beside the ledger
53
+ // archive. After the tick, which reads the caps from it, and
54
+ // before the stop. No `phase0.json` is nothing to move and is
55
+ // `ok`; a held receipt already there that is not this one is
56
+ // a failed step.
48
57
  // heartbeat-stop `fleet-heartbeat.mjs --stop "<reason>"`, last, because
49
58
  // every reader takes a recorded stop as the end of the run.
50
59
  //
@@ -70,7 +79,7 @@
70
79
  // Zero deps: node builtins and sibling scripts only.
71
80
 
72
81
  import { spawnSync } from "node:child_process";
73
- import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
82
+ import { existsSync, linkSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
74
83
  import { homedir } from "node:os";
75
84
  import { dirname, join } from "node:path";
76
85
  import { fileURLToPath } from "node:url";
@@ -78,7 +87,7 @@ import { makeDie, defineFlags } from "./arg.mjs";
78
87
  import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
79
88
  import { gitEnv } from "./git-env.mjs";
80
89
  import { isCLI } from "./is-cli.mjs";
81
- import { CLOSEOUT_RECEIPT, memberTokens, rowPr } from "./ledger-grammar.mjs";
90
+ import { CLOSEOUT_RECEIPT, RECEIPT, RECEIPT_HELD, memberTokens, rowPr } from "./ledger-grammar.mjs";
82
91
  import { encodeProjectDir, isOmpSessionDirName } from "./member-record.mjs";
83
92
  import { tickCaps } from "./phase0-receipt.mjs";
84
93
 
@@ -334,6 +343,31 @@ function stepCommitAndPR({ reason, branch, receipt, save }) {
334
343
  return result;
335
344
  }
336
345
 
346
+ // The receipt `phase0.mjs` resumes would otherwise outlive the run it describes.
347
+ // It is set aside under the name `phase0.mjs` holds a previous run's receipt
348
+ // under, which the next run's rotation restores and archives with the ledger.
349
+ // Linked, then unlinked, so a held receipt already there is refused rather than
350
+ // overwritten; one that is this very file, left by a crash between the two, is
351
+ // finished off.
352
+ function stepPhase0Receipt({ fleetDir }) {
353
+ const from = join(fleetDir, RECEIPT);
354
+ if (!existsSync(from)) return ok(`no ${RECEIPT} to move`);
355
+ const to = join(fleetDir, RECEIPT_HELD);
356
+ try {
357
+ linkSync(from, to);
358
+ } catch (e) {
359
+ if (e.code !== "EEXIST") return failed(`cannot move ${from} to ${to}: ${e.message}`);
360
+ const [a, b] = [statSync(from), statSync(to)];
361
+ if (a.dev !== b.dev || a.ino !== b.ino) return failed(`${to} already holds another receipt — move it out of the way, then run finish again`);
362
+ }
363
+ try {
364
+ unlinkSync(from);
365
+ } catch (e) {
366
+ return failed(`moved ${from} to ${to} but could not remove it: ${e.message} — remove it by hand before the next run`);
367
+ }
368
+ return ok(`${from} -> ${to}`);
369
+ }
370
+
337
371
  function stepHeartbeatStop({ cwd, reason }) {
338
372
  const r = node("fleet-heartbeat.mjs", ["--stop", reason], { cwd });
339
373
  return r.status === 0 ? ok(r.stdout) : failed(`fleet-heartbeat.mjs --stop failed: ${detail(r)}`);
@@ -348,6 +382,7 @@ const FINISH = {
348
382
  "tier-outcomes": stepTierOutcomes,
349
383
  metrics: stepMetrics,
350
384
  "commit-and-pr": stepCommitAndPR,
385
+ "phase0-receipt": stepPhase0Receipt,
351
386
  "heartbeat-stop": stepHeartbeatStop,
352
387
  };
353
388
  const STEP_NAMES = [...Object.keys(BEGIN), ...Object.keys(FINISH)];
@@ -29,6 +29,11 @@ import { createHash } from "node:crypto";
29
29
  // way, so the format lives here once.
30
30
  const RECEIPT_STEM = "phase0";
31
31
  export const RECEIPT = `${RECEIPT_STEM}.json`;
32
+ // Where a previous run's receipt waits, beside the ledger, until the next run's
33
+ // rotation files it: `phase0.mjs` holds a receipt there at startup, and
34
+ // `closeout.mjs finish` sets the run's own there, so a run that ended cleanly
35
+ // leaves no receipt for the next run to resume.
36
+ export const RECEIPT_HELD = `${RECEIPT_STEM}.previous.json`;
32
37
  export const archiveStamp = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z").replaceAll(":", "");
33
38
  export const receiptArchiveName = (stamp) => `${RECEIPT_STEM}.${stamp}.json`;
34
39
  const CLOSEOUT_STEM = "closeout";
@@ -76,7 +76,8 @@
76
76
  // writes the next, so the previous run's receipt still matches it, and a
77
77
  // re-run that trusted `run` alone would skip `rotate`. The session rule closes
78
78
  // a new session. A receipt of any other run (a `run` that is set and does not
79
- // match, or a different session) is held as `phase0.previous.json` and the
79
+ // match, or a different session) is held as `phase0.previous.json`, where
80
+ // `closeout.mjs finish` also leaves a finished run's receipt, and the
80
81
  // script starts at `branch`; this run's own receipt is written at
81
82
  // `phase0.json` after every step. A receipt whose rotation has not run is
82
83
  // simply overwritten: every step before `rotate` is idempotent and is re-run
@@ -122,7 +123,7 @@ import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
122
123
  import { readState, stateFileIn } from "./fleet-state.mjs";
123
124
  import { gitEnv } from "./git-env.mjs";
124
125
  import { isCLI } from "./is-cli.mjs";
125
- import { RECEIPT, archiveStamp, receiptArchiveName, rowNums } from "./ledger-grammar.mjs";
126
+ import { RECEIPT, RECEIPT_HELD, archiveStamp, receiptArchiveName, rowNums } from "./ledger-grammar.mjs";
126
127
 
127
128
  const NAME = "phase0";
128
129
  const SCRIPTS = dirname(fileURLToPath(import.meta.url));
@@ -131,8 +132,6 @@ const NETWORK_TIMEOUT_MS = 120_000;
131
132
  const PR_LIMIT = 1000;
132
133
  // The tail of a child's output is the part that says why it stopped.
133
134
  const OUTPUT_MAX = 16_000;
134
- // The previous run's receipt, set aside at startup until the rotation files it.
135
- const HELD = "phase0.previous.json";
136
135
  const RULESET_SPEC = join(".github", "rulesets", "main.json");
137
136
  const RULESET_CHECK = join(".github", "scripts", "apply-ruleset.sh");
138
137
 
@@ -479,7 +478,7 @@ function main() {
479
478
  const scratch = root.stdout;
480
479
 
481
480
  const receiptPath = join(fleetDir, RECEIPT);
482
- const held = join(fleetDir, HELD);
481
+ const held = join(fleetDir, RECEIPT_HELD);
483
482
  const state = readState(stateFileIn(fleetDir), NAME);
484
483
  if (state.degraded) {
485
484
  // The record decides whether a receipt is the previous run's, and a record
@@ -15,7 +15,8 @@
15
15
  # 3. the merge commit's second parent IS the rebased head
16
16
  #
17
17
  # merge-commit path (pre != post, post has exactly two parents, and pre is one of them) — one gate replaces leg 1:
18
- # 1. pre IS a parent of post (the old version survives as an ancestor of the new)
18
+ # 1. pre IS a parent of post, and pre is NOT an ancestor of the merge's first
19
+ # parent (the old version survives in the new, and was not already on main)
19
20
  # 2. the rebased head IS an ancestor of main (the new version did)
20
21
  # 3. the merge commit's second parent IS the rebased head
21
22
  #
@@ -38,9 +39,9 @@
38
39
  # What stands in for leg 1 on each path:
39
40
  # no-rebase path — leg 1 is dropped (impossible by construction)
40
41
  # rebase path — preDidNotLand: the pre-rebase head is NOT an ancestor of main
41
- # merge-commit path — preIsParentOfHead: the pre-rebase head IS a parent of post;
42
- # the path selection already established that, so the gate
43
- # records which path ran rather than testing anything new
42
+ # merge-commit path — preIsParentOfHead: the pre-rebase head IS a parent of post
43
+ # and is NOT an ancestor of <merge>^1, so a parent of post
44
+ # that was already on main before the merge fails it
44
45
  #
45
46
  # The payload splits the checks into three kinds, because a flat object could not
46
47
  # say which of its fields were load-bearing for the verdict it sits next to:
@@ -212,7 +213,13 @@ elif [ "$post_parents" -eq 2 ] && { [ "$post_first" = "$pre_full" ] || [ "$post_
212
213
  else
213
214
  echo " merge-commit (pre != post, pre is second parent of post) — pre is a parent of post" >&2
214
215
  fi
215
- teeth=true
216
+ # Being a parent of post does not tell the PR head from main's side of the
217
+ # merge-in: both are parents. The side that was already on main is an
218
+ # ancestor of the merge's first parent, the main this merge was built on.
219
+ echo "\$ git merge-base --is-ancestor $pre $first" >&2
220
+ pre_landed=$(is_ancestor "$pre_full" "$first")
221
+ if [ "$pre_landed" = false ]; then teeth=true; else teeth=false; fi
222
+ echo " pre is-ancestor of ${merge}^1 = $pre_landed, so preIsParentOfHead = $teeth (wants pre not already on main)" >&2
216
223
  else
217
224
  proof_path="rebase"
218
225
  if [ "$pre_anc" = false ]; then teeth=true; else teeth=false; fi
@@ -228,13 +235,13 @@ if [ "$parents" -eq 2 ]; then two_parents=true; else two_parents=false; fi
228
235
  # `$teeth` is a constant true on the no-rebase path, and it is left OUT of the
229
236
  # object there rather than emitted as one: leg 1 is dropped on that path, and a
230
237
  # gate that cannot fail is not a gate. Its absence is the machine-readable form
231
- # of "leg 1 did not carry this proof". On the merge-commit path `$teeth` is a
232
- # constant true too — the elif that selects the path is itself the check that pre
233
- # is a parent of post — and it is emitted anyway, as `preIsParentOfHead`, because
234
- # the payload contract names it: it records which leg-1 replacement the proof ran
235
- # under. It cannot fail, so nothing rests on it; the four shared gates carry the
236
- # verdict there, and any parent of a two-parent post, the main side included,
237
- # satisfies it.
238
+ # of "leg 1 did not carry this proof". On the merge-commit path `$teeth` is
239
+ # emitted as `preIsParentOfHead` and is a real test: the elif that selects the
240
+ # path already established that pre is a parent of post, and on top of that
241
+ # `$teeth` is false when pre is an ancestor of the merge's first parent — main's
242
+ # side of the merge-in, a commit that landed before this merge did. The test does
243
+ # not depend on which parent position pre holds, so either merge direction is
244
+ # covered.
238
245
  gates="\"postIsAncestor\":$post_anc,\"secondParentIsHead\":$second_is_head,\"exactlyTwoParents\":$two_parents,\"headWasCurrent\":$head_current"
239
246
  if [ "$proof_path" = rebase ]; then
240
247
  gates="\"preDidNotLand\":$teeth,$gates"