@bom-pi/core 0.2.5 → 0.2.6

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": "@bom-pi/core",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Core pairing machinery for Bom Pi: ceremonies, transports, durable stores",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -352,7 +352,12 @@ export type BootVerifyOutcome =
352
352
  | {
353
353
  outcome: "quarantined";
354
354
  reason: "removed" | "superseded" | "refused" | "unreachable" | "unsupported";
355
- };
355
+ }
356
+ /** ADR-19 hardening (fleet race): the entry this verify started with was REPLACED while
357
+ * the answer was in flight (a ceremony won the boot race). The verify is moot: nothing was
358
+ * erased, no cleanup was queued, and the connector now lives on the ceremony's credential —
359
+ * callers must treat the lane as owned by that ceremony and touch nothing. */
360
+ | { outcome: "overtaken" };
356
361
 
357
362
  export type BackoffOptions = {
358
363
  baseMs?: number;
@@ -1697,6 +1702,33 @@ export class CloudConnector {
1697
1702
 
1698
1703
  const entry = this.requireEntry();
1699
1704
 
1705
+ // ADR-19 hardening (fleet race 2026-11-15): every destructive decision below may act
1706
+ // ONLY on the exact entry this verify started with — same membership ref AND same
1707
+ // credential epoch. If a ceremony replaced the entry while an answer was in flight,
1708
+ // this verify is MOOT: no erase, no cleanup intent, no displacement, no adoption.
1709
+ // (The serialization chain makes the swap invisible to this body today; the guard
1710
+ // keeps the invariant local and true under any future refactor that splits it.)
1711
+ const verifiedRef: MemberRef = { ...entry.membership };
1712
+ const verifiedEpoch = entry.credentialEpoch;
1713
+
1714
+ const stillTheVerifiedEntry = (): boolean => {
1715
+ const current = this.snapshot.entry;
1716
+
1717
+ return (
1718
+ current !== null &&
1719
+ current.credentialEpoch === verifiedEpoch &&
1720
+ refsEqual(current.membership, verifiedRef)
1721
+ );
1722
+ };
1723
+
1724
+ const overtaken = (): { outcome: "overtaken" } => {
1725
+ this.lastFailure =
1726
+ "boot verify moot: the stored entry was replaced by a fresh ceremony while the answer was in flight";
1727
+ this.lastBootVerify = { outcome: "overtaken" };
1728
+
1729
+ return this.lastBootVerify;
1730
+ };
1731
+
1700
1732
  // R1: a pending intent for THIS exact ref wins over any anchor — the structural rule
1701
1733
  // "a credential and its own pending cleanup may not coexist" must hold here too.
1702
1734
  if (
@@ -1704,6 +1736,10 @@ export class CloudConnector {
1704
1736
  refsEqual(pending.membership, entry.membership),
1705
1737
  )
1706
1738
  ) {
1739
+ if (!stillTheVerifiedEntry()) {
1740
+ return overtaken();
1741
+ }
1742
+
1707
1743
  await this.quarantineStoredEntry();
1708
1744
  this.lastBootVerify = { outcome: "quarantined", reason: "refused" };
1709
1745
 
@@ -1711,6 +1747,10 @@ export class CloudConnector {
1711
1747
  }
1712
1748
 
1713
1749
  if (entry.credentialExpiresAt <= this.saneNow()) {
1750
+ if (!stillTheVerifiedEntry()) {
1751
+ return overtaken();
1752
+ }
1753
+
1714
1754
  await this.quarantineStoredEntry();
1715
1755
  this.lastBootVerify = { outcome: "quarantined", reason: "refused" };
1716
1756
 
@@ -1739,6 +1779,11 @@ export class CloudConnector {
1739
1779
  ),
1740
1780
  deadline,
1741
1781
  );
1782
+
1783
+ if (!stillTheVerifiedEntry()) {
1784
+ return overtaken();
1785
+ }
1786
+
1742
1787
  const outcome = await this.adoptVerifiedCredential(entry, verified);
1743
1788
 
1744
1789
  this.lastBootVerify = outcome;
@@ -1749,6 +1794,10 @@ export class CloudConnector {
1749
1794
  // already rotated the credential — the honest terminal state, NOT a quarantine
1750
1795
  // (queueing a cleanup here would delete the member row the REAL machine holds).
1751
1796
  if (error instanceof EndpointError && error.status === 409) {
1797
+ if (!stillTheVerifiedEntry()) {
1798
+ return overtaken();
1799
+ }
1800
+
1752
1801
  await this.markDisplaced();
1753
1802
  this.lastBootVerify = { outcome: "quarantined", reason: "superseded" };
1754
1803
 
@@ -1767,6 +1816,11 @@ export class CloudConnector {
1767
1816
  this.lastFailure = `boot verify failed (${reason}): ${
1768
1817
  error instanceof Error ? error.message : String(error)
1769
1818
  }`;
1819
+
1820
+ if (!stillTheVerifiedEntry()) {
1821
+ return overtaken();
1822
+ }
1823
+
1770
1824
  await this.quarantineStoredEntry();
1771
1825
  this.lastBootVerify = { outcome: "quarantined", reason };
1772
1826
 
@@ -1862,6 +1916,25 @@ export class CloudConnector {
1862
1916
  }
1863
1917
  : null;
1864
1918
 
1919
+ // ADR-19 hardening (review 2026-11-15): the receipt verifier above is an AWAIT — the
1920
+ // only reason the entry cannot change across it today is the outer serialize chain.
1921
+ // Keep the invariant LOCAL: re-check that the entry is still the exact one this verify
1922
+ // started with (same ref + credential epoch) immediately BEFORE the durable write. A
1923
+ // mismatch aborts the adoption — nothing written, nothing queued — and the throw lands
1924
+ // in the caller's fail-closed catch, whose own changed-entry guard maps it to a silent
1925
+ // "overtaken" (a ceremony owns the connector now).
1926
+ const current = this.snapshot.entry;
1927
+
1928
+ if (
1929
+ current === null ||
1930
+ current.credentialEpoch !== entry.credentialEpoch ||
1931
+ !refsEqual(current.membership, entry.membership)
1932
+ ) {
1933
+ throw new ConnectorStateError(
1934
+ "Boot verify moot: the stored entry changed while the rotation receipt was being verified; nothing adopted",
1935
+ );
1936
+ }
1937
+
1865
1938
  // R3: the anchored boot creates no intent, ever — and it adopts nothing else either: same
1866
1939
  // ref, same identity, only the credential material moves.
1867
1940
  const next: ConnectorSnapshot = {