@feigi/fleet-ctl 3.158.11 → 3.158.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.158.11",
3
+ "version": "3.158.13",
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": {
@@ -21,12 +21,14 @@
21
21
  //
22
22
  // `--siblings` is the sibling pass, its own invocation: `--root` names the
23
23
  // live key, and the pass judges the other key-shaped directories beside it
24
- // (judgeSiblings below) by the checkout each records and by age, judging each
25
- // again just before `--apply` removes it. Under `--apply` it first writes the
26
- // live key's own `checkout-path`, and only that. Any other key passed as
27
- // `--root` would put the real live key among the judged siblings. It reads no
28
- // ledger, asks GitHub nothing, and is never combined with --pr or
29
- // --after-rotate.
24
+ // (judgeSiblings below) by the checkout each records and the device it was
25
+ // on, and by age, judging each again just before `--apply` removes it. A key
26
+ // whose checkout is gone is removed only while the directory that held it is
27
+ // still there on that device: a drive's mount folder left behind empty reads
28
+ // as another device. Under `--apply` it first writes the live key's own
29
+ // `checkout-path`, and only that. Any other key passed as `--root` would put
30
+ // the real live key among the judged siblings. It reads no ledger, asks
31
+ // GitHub nothing, and is never combined with --pr or --after-rotate.
30
32
  //
31
33
  // THE ROOT SWEEP judges every entry directly under `--root`:
32
34
  // pr<M>/, dispositions-fix-pr-<M>[-x].json
@@ -173,7 +175,8 @@ import { REVIEWS_DIR, reviewTargets } from "./run-records.mjs";
173
175
 
174
176
  const NAME = "reclaim-scratch";
175
177
  // The file at a key's top level naming the checkout the key's hash is taken
176
- // over: one line, an absolute path.
178
+ // over and the device that checkout was on: two lines, an absolute path, then
179
+ // lstat's `dev` in decimal.
177
180
  export const CHECKOUT_FILE = "checkout-path";
178
181
  const die = makeDie(NAME);
179
182
  const DAY_MS = 24 * 60 * 60 * 1000;
@@ -653,13 +656,14 @@ function judgeSiblings(root, cutoff) {
653
656
  // A read of `checkout-path` that leaves no file to judge, rather than an error.
654
657
  const NO_CHECKOUT_FILE = new Set(["ENOENT", "ENOTDIR", "EISDIR", "EACCES", "EPERM"]);
655
658
 
656
- // The checkout `key`'s `checkout-path` names, `{ checkout }`, or the `{ reason }`
657
- // the key is kept for instead: `no checkout file: …` when there is no valid
658
- // file — missing, unreadable, not a regular file, anything but one absolute
659
- // path, or a path whose sha256 does not start with the key's 8-hex suffix —
660
- // or the error any other failure to read it left. Only a regular file is read:
661
- // a FIFO there would block the pass and a link to a device such as /dev/zero
662
- // would never end.
659
+ // The checkout `key`'s `checkout-path` names and the device it was on,
660
+ // `{ checkout, device }`, or the `{ reason }` the key is kept for instead:
661
+ // `no checkout file: …` when there is no valid file — missing, unreadable,
662
+ // not a regular file, a path alone with no device, anything but an absolute
663
+ // path then a decimal device number on two lines, or a path whose sha256 does
664
+ // not start with the key's 8-hex suffix — or the error any other failure to
665
+ // read it left. Only a regular file is read: a FIFO there would block the pass
666
+ // and a link to a device such as /dev/zero would never end.
663
667
  function checkoutOf(key) {
664
668
  const file = join(key, CHECKOUT_FILE);
665
669
  const none = (why) => ({ reason: `no checkout file: ${why}` });
@@ -671,19 +675,20 @@ function checkoutOf(key) {
671
675
  if (NO_CHECKOUT_FILE.has(e.code)) return none(e.code === "ENOENT" ? `${CHECKOUT_FILE} is missing` : `${CHECKOUT_FILE} cannot be read (${e.code})`);
672
676
  return { reason: `its ${CHECKOUT_FILE} cannot be read: ${e.message}` };
673
677
  }
674
- const line = text.endsWith("\n") ? text.slice(0, -1) : text;
675
- if (line.includes("\n") || !isAbsolute(line)) return none(`${CHECKOUT_FILE} holds no single absolute path`);
678
+ const lines = (text.endsWith("\n") ? text.slice(0, -1) : text).split("\n");
679
+ if (lines.length === 1 && isAbsolute(lines[0])) return none(`${CHECKOUT_FILE} records no device`);
680
+ const [line, device] = lines;
681
+ if (lines.length !== 2 || !isAbsolute(line) || !isDigits(device)) return none(`${CHECKOUT_FILE} holds no absolute path and device number`);
676
682
  const suffix = basename(key).slice(-8);
677
683
  if (!createHash("sha256").update(line).digest("hex").startsWith(suffix)) return none(`${line} does not hash to the key's suffix ${suffix}`);
678
- return { checkout: line };
684
+ return { checkout: line, device };
679
685
  }
680
686
 
681
- // Whether anything exists at `p` (lstat): true, false, or the error that
682
- // leaves it unknown.
683
- function existsAt(p) {
687
+ // What lstat finds at `p`: its stats (bigint, so a device number is exact),
688
+ // false when nothing is there, or the error that leaves it unknown.
689
+ function lstatAt(p) {
684
690
  try {
685
- lstatSync(p);
686
- return true;
691
+ return lstatSync(p, { bigint: true });
687
692
  } catch (e) {
688
693
  if (e.code === "ENOENT" || e.code === "ENOTDIR") return false;
689
694
  return e;
@@ -693,44 +698,51 @@ function existsAt(p) {
693
698
  // One sibling key's verdict, `{remove, reason, idle}`. `idle` is whether
694
699
  // nothing under the key was found modified within the retention, searched for
695
700
  // every key. Removed only when its checkout file is valid, nothing exists at
696
- // the checkout it names, the directory that held that checkout does exist,
697
- // nothing under the key is fresh and every part of it could be read. A key
698
- // whose checkout still exists is its own phase 0's to reclaim; one whose
699
- // checkout's parent is gone too may sit on an unplugged drive.
701
+ // the checkout it names, the directory that held that checkout does exist and
702
+ // is on the device the checkout was on, nothing under the key is fresh and
703
+ // every part of it could be read. A key whose checkout still exists is its
704
+ // own phase 0's to reclaim; one whose checkout's parent is gone too, or is on
705
+ // another device now, may sit on an unplugged drive: a drive's mount folder
706
+ // can stay behind as an empty directory on the device underneath.
700
707
  function judgeSibling(path, cutoff) {
701
708
  const unreadable = [];
702
709
  const idle = freshUnder(path, cutoff, unreadable) === null;
703
710
  const keep = (reason) => ({ remove: false, reason, idle });
704
711
  const found = checkoutOf(path);
705
712
  if (found.reason !== undefined) return keep(found.reason);
706
- const { checkout } = found;
707
- const at = existsAt(checkout);
713
+ const { checkout, device } = found;
714
+ const at = lstatAt(checkout);
708
715
  if (at instanceof Error) return keep(`whether its checkout ${checkout} exists cannot be told: ${at.message}`);
709
716
  if (at) return keep(`its checkout ${checkout} still exists, so its own phase 0 reclaims it`);
710
717
  const held = dirname(checkout);
711
- const up = existsAt(held);
718
+ const up = lstatAt(held);
712
719
  if (up instanceof Error) return keep(`whether ${held}, the directory that held its checkout ${checkout}, exists cannot be told: ${up.message}`);
713
720
  if (!up) return keep(`neither its checkout ${checkout} nor ${held}, the directory that held it, exists`);
721
+ if (up.dev.toString() !== device) return keep(`its checkout ${checkout} is gone, but ${held}, the directory that held it, is on device ${up.dev} and the checkout was on device ${device}: its drive may not be mounted`);
714
722
  if (!idle) return keep("sibling key modified within 7 days");
715
723
  if (unreadable.length > 0) return keep(`sibling key could not be read whole (${unreadable[0]})`);
716
724
  return { remove: true, reason: `its checkout ${checkout} is gone and nothing under it changed in 7 days`, idle: true };
717
725
  }
718
726
 
719
727
  // The live key's own `checkout-path`, written when it is missing or says
720
- // anything but this workspace's canonical path: a temp file in the key,
721
- // renamed over it. A failure is returned as a failed[] entry, null otherwise.
728
+ // anything but this workspace's canonical path and the device that checkout
729
+ // is on now: a temp file in the key, renamed over it. A failure, reading the
730
+ // device included, is returned as a failed[] entry, null otherwise.
722
731
  function writeCheckout(root) {
723
732
  const file = join(root, CHECKOUT_FILE);
724
733
  let checkout;
734
+ let device;
725
735
  try {
726
736
  checkout = dirname(fleetFile(null, { canonicalise: true }));
737
+ device = lstatSync(checkout, { bigint: true }).dev.toString();
727
738
  } catch (e) {
728
739
  return { path: file, error: e.message };
729
740
  }
730
- if (checkoutOf(root).checkout === checkout) return null;
741
+ const saved = checkoutOf(root);
742
+ if (saved.checkout === checkout && saved.device === device) return null;
731
743
  const tmp = join(root, `.${CHECKOUT_FILE}.${process.pid}.tmp`);
732
744
  try {
733
- writeFileSync(tmp, `${checkout}\n`);
745
+ writeFileSync(tmp, `${checkout}\n${device}\n`);
734
746
  renameSync(tmp, file);
735
747
  } catch (e) {
736
748
  try {
@@ -454,10 +454,11 @@ ledger.
454
454
 
455
455
  Straight after that, the same step reclaims the other keys under the scratch parent:
456
456
  `~/.omp/plugins/node_modules/@feigi/fleet-ctl/scripts/fleet-run reclaim-scratch.mjs --siblings --root <scratch> --apply`. It
457
- first writes this key's `checkout-path`, the checkout the key was computed from. A
458
- sibling key goes whole only when the checkout its `checkout-path` names is gone, the
459
- directory that held it is still there, and nothing under the key has changed in 7 days;
460
- every other key stays whole, a key with no valid `checkout-path` included. The call asks
457
+ first writes this key's `checkout-path`, the checkout the key was computed from and its
458
+ device. A sibling key goes whole only when the checkout its `checkout-path` names is
459
+ gone, the directory that held it is still there on that device, and nothing under the key
460
+ has changed in 7 days; every other key stays whole, a key with no valid `checkout-path`
461
+ included. The call asks
461
462
  GitHub nothing, runs whatever the root sweep answered, and records nothing on the ledger.
462
463
  The step's output names each sibling key removed and each kept with nothing changed in 7
463
464
  days, with the reason. A non-zero exit, and each path its receipt's `failed[]` names, is