@serfab/cadre-core 1.20.0 → 1.22.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.
Files changed (113) hide show
  1. package/README.md +294 -294
  2. package/dist/cadre-node.d.ts +329 -53
  3. package/dist/cadre-node.js +767 -85
  4. package/dist/cadre-node.js.map +1 -1
  5. package/dist/control-authorization.d.ts +32 -2
  6. package/dist/control-authorization.js +19 -0
  7. package/dist/control-authorization.js.map +1 -1
  8. package/dist/control-database.d.ts +236 -23
  9. package/dist/control-database.js +601 -178
  10. package/dist/control-database.js.map +1 -1
  11. package/dist/control-schema.d.ts +3 -3
  12. package/dist/control-schema.js +71 -7
  13. package/dist/control-schema.js.map +1 -1
  14. package/dist/ed25519-key.d.ts +8 -0
  15. package/dist/ed25519-key.js +11 -1
  16. package/dist/ed25519-key.js.map +1 -1
  17. package/dist/index.d.ts +5 -1
  18. package/dist/index.js +13 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/machine-removal.d.ts +51 -1
  21. package/dist/machine-removal.js +42 -1
  22. package/dist/machine-removal.js.map +1 -1
  23. package/dist/membership-connection-gater.d.ts +8 -0
  24. package/dist/membership-connection-gater.js +13 -1
  25. package/dist/membership-connection-gater.js.map +1 -1
  26. package/dist/owner-keys.js +2 -1
  27. package/dist/owner-keys.js.map +1 -1
  28. package/dist/owner-signer.js +3 -4
  29. package/dist/owner-signer.js.map +1 -1
  30. package/dist/peer-authorization.d.ts +14 -2
  31. package/dist/peer-authorization.js +24 -1
  32. package/dist/peer-authorization.js.map +1 -1
  33. package/dist/relay-reservation.js +20 -1
  34. package/dist/relay-reservation.js.map +1 -1
  35. package/dist/sealed-party-key.d.ts +32 -0
  36. package/dist/sealed-party-key.js +162 -0
  37. package/dist/sealed-party-key.js.map +1 -0
  38. package/dist/seed-bootstrap.d.ts +10 -3
  39. package/dist/seed-bootstrap.js +12 -0
  40. package/dist/seed-bootstrap.js.map +1 -1
  41. package/dist/strand-addr-protocol.d.ts +56 -6
  42. package/dist/strand-addr-protocol.js +57 -5
  43. package/dist/strand-addr-protocol.js.map +1 -1
  44. package/dist/strand-app-schema-report.d.ts +6 -3
  45. package/dist/strand-app-schema-report.js +13 -7
  46. package/dist/strand-app-schema-report.js.map +1 -1
  47. package/dist/strand-commit-durability.d.ts +33 -2
  48. package/dist/strand-commit-durability.js +44 -4
  49. package/dist/strand-commit-durability.js.map +1 -1
  50. package/dist/strand-database.d.ts +36 -6
  51. package/dist/strand-database.js +35 -11
  52. package/dist/strand-database.js.map +1 -1
  53. package/dist/strand-instance-manager.d.ts +133 -9
  54. package/dist/strand-instance-manager.js +266 -42
  55. package/dist/strand-instance-manager.js.map +1 -1
  56. package/dist/strand-membership-reconciler.d.ts +250 -51
  57. package/dist/strand-membership-reconciler.js +410 -66
  58. package/dist/strand-membership-reconciler.js.map +1 -1
  59. package/dist/strand-membership-writer.d.ts +7 -0
  60. package/dist/strand-membership-writer.js +9 -0
  61. package/dist/strand-membership-writer.js.map +1 -1
  62. package/dist/strand-party-key-rotation.d.ts +177 -0
  63. package/dist/strand-party-key-rotation.js +340 -0
  64. package/dist/strand-party-key-rotation.js.map +1 -0
  65. package/dist/strand-party-machines.d.ts +111 -0
  66. package/dist/strand-party-machines.js +258 -0
  67. package/dist/strand-party-machines.js.map +1 -0
  68. package/dist/strand-party-peers.d.ts +101 -0
  69. package/dist/strand-party-peers.js +49 -0
  70. package/dist/strand-party-peers.js.map +1 -0
  71. package/dist/strand-peer-redial.d.ts +34 -7
  72. package/dist/strand-peer-redial.js +46 -13
  73. package/dist/strand-peer-redial.js.map +1 -1
  74. package/dist/strand-revocation-enforcer.d.ts +15 -1
  75. package/dist/strand-revocation-enforcer.js +16 -9
  76. package/dist/strand-revocation-enforcer.js.map +1 -1
  77. package/dist/strand-transport-key.js +3 -0
  78. package/dist/strand-transport-key.js.map +1 -1
  79. package/dist/strand-watcher.d.ts +7 -4
  80. package/dist/strand-watcher.js +12 -7
  81. package/dist/strand-watcher.js.map +1 -1
  82. package/dist/types.d.ts +165 -17
  83. package/dist/types.js.map +1 -1
  84. package/package.json +9 -8
  85. package/src/cadre-node.ts +12252 -11528
  86. package/src/control-authorization.ts +41 -1
  87. package/src/control-database.ts +6123 -5594
  88. package/src/control-schema.ts +71 -7
  89. package/src/ed25519-key.ts +12 -1
  90. package/src/index.ts +957 -924
  91. package/src/machine-removal.ts +80 -1
  92. package/src/membership-connection-gater.ts +13 -1
  93. package/src/owner-keys.ts +2 -1
  94. package/src/owner-signer.ts +92 -94
  95. package/src/peer-authorization.ts +27 -3
  96. package/src/relay-reservation.ts +28 -1
  97. package/src/sealed-party-key.ts +190 -0
  98. package/src/seed-bootstrap.ts +17 -3
  99. package/src/strand-addr-protocol.ts +67 -6
  100. package/src/strand-app-schema-report.ts +17 -10
  101. package/src/strand-commit-durability.ts +54 -5
  102. package/src/strand-database.ts +48 -12
  103. package/src/strand-instance-manager.ts +330 -42
  104. package/src/strand-membership-reconciler.ts +1310 -942
  105. package/src/strand-membership-writer.ts +10 -0
  106. package/src/strand-party-key-rotation.ts +436 -0
  107. package/src/strand-party-machines.ts +293 -0
  108. package/src/strand-party-peers.ts +129 -0
  109. package/src/strand-peer-redial.ts +61 -14
  110. package/src/strand-revocation-enforcer.ts +27 -9
  111. package/src/strand-transport-key.ts +3 -0
  112. package/src/strand-watcher.ts +12 -7
  113. package/src/types.ts +3112 -2962
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Strand membership reconciliation: the per-instance background loop that finishes a
3
- * party's join at strand bring-up. Every machine of a party that runs a closed strand
4
- * ends up with (1) the party's `Strand.Member` row seated — redeeming the
5
- * formation-staged invitation if one is pending — and (2) its own durable
6
- * machine→party binding (`Strand.MemberPeer`) written, which is what revocation
7
- * enforcement and future admission control key on.
3
+ * party's join at strand bring-up and keeps the party's machine bindings whole. Every
4
+ * machine of a party that runs a closed strand ends up with (1) the party's `Strand.Member`
5
+ * row seated — redeeming the formation-staged invitation if one is pending — (2) its own
6
+ * durable machine→party binding (`Strand.MemberPeer`) written, which is what revocation
7
+ * enforcement and future admission control key on, and (3) every live sibling machine's
8
+ * binding written under the party's current key, with a removed machine's binding cleared —
9
+ * see "Binding the party's other machines" below.
8
10
  *
9
11
  * ## Contract
10
12
  *
@@ -26,10 +28,12 @@
26
28
  * for someone to admit this party — nothing this machine can do faster — so it re-arms on
27
29
  * the flat poll interval and resets the ladder. The loop stops on the done state.
28
30
  * - **Done state**: the party's member row is visible locally, this machine's own binding
29
- * is in place, AND no invitation is still staged — the loop stops. A LATER revocation is
30
- * the enforcer's business, not this loop's; a resume rebuilds the reconciler and
31
- * re-verifies from scratch (every write is idempotent, so re-running is free), and a
32
- * fresh invitation staged on a done loop re-arms it in place ({@link rearm}).
31
+ * is in place, every live sibling with a `StrandPeer` row is bound under the party's key
32
+ * (a pass that wrote a binding is not done; the next pass has to find nothing left), AND no
33
+ * invitation is still staged — the loop stops. A LATER revocation is the enforcer's
34
+ * business, not this loop's; a resume rebuilds the reconciler and re-verifies from scratch
35
+ * (every write is idempotent, so re-running is free), and a fresh invitation staged on a
36
+ * done loop, or a change to the party's machines, re-arms it in place ({@link rearm}).
33
37
  *
34
38
  * ## One pass
35
39
  *
@@ -38,28 +42,112 @@
38
42
  * a fresh formation, which re-arms the loop. With an invitation staged the loop reports
39
43
  * the dead end (below) and carries on: the redemption is attempted like any other, and a
40
44
  * manager's re-admission lets a later pass finish it.
41
- * 2. **Ensure membership.** Member row visible → done with this step; if a staged
42
- * invitation is still unspent, BURN it ({@link burnInvite} — the `ConsumedInvite` row
43
- * alone) so the bearer credential cannot be spent by anyone else. A burn refused by the
44
- * cohort keeps the invitation staged for the next pass (it is the same write gate a
45
- * redemption faces, and the local member row may be stale — see "Re-arming"); a dead
46
- * invitation is dropped. Member row absent + staged invitation → {@link consumeInvite}
47
- * under the party's own key, retried across passes until the `Invite` row has
48
- * replicated here and the write commits. Absent with no invitation (founder rows not
45
+ * 2. **Ensure membership.** Read first whether the party is moving to another key in this
46
+ * strand ({@link PartyStrandPeerSource.pendingKey}, one control read per pass); while it
47
+ * is, the step runs under that key instead — see "Redeeming under the pending key". Otherwise:
48
+ * member row visible → done with this step; if a staged invitation is still unspent, BURN it
49
+ * ({@link burnInvite} — the `ConsumedInvite` row alone) so the bearer credential cannot be
50
+ * spent by anyone else. A burn refused by the cohort keeps the invitation staged for the next
51
+ * pass (it is the same write gate a redemption faces, and the local member row may be stale —
52
+ * see "Re-arming"); a dead invitation is dropped. Member row absent + staged invitation →
53
+ * {@link consumeInvite} under the party's own key, retried across passes until the `Invite`
54
+ * row has replicated here and the write commits. Absent with no invitation (founder rows not
49
55
  * yet synced, or a machine whose party never joined) → keep waiting, escalating to one
50
56
  * visible warning after {@link IDLE_PASSES_BEFORE_ESCALATION} passes, never throwing.
51
57
  * 3. **Ensure the binding.** {@link registerMemberPeer} (insert-if-absent, restart-safe)
52
58
  * with this node's own strand transport peer id — only after step 2 sees the member
53
- * row locally (its deferred `MemberExists` reads the live local table). Done only once
54
- * the binding is in place AND nothing is staged; a binding written while a burn keeps
55
- * being refused leaves the loop live to settle the invitation later.
59
+ * row locally (its deferred `MemberExists` reads the live local table). A binding
60
+ * written while a burn keeps being refused leaves the loop live to settle the
61
+ * invitation later.
62
+ * 4. **Bind live siblings.** Every strand peer id the control database records for a live
63
+ * machine of this party ({@link PartyStrandPeerSource.read}) that has no binding under the
64
+ * party's key gets one, written here with the party key. See "Binding the party's other
65
+ * machines".
66
+ * 5. **Clear removed machines.** A binding under the party's key for a machine removed from
67
+ * the cadre is cleared through the self branch of {@link removeMemberPeer} — unless the
68
+ * pending-key read at step 2 found a party key rotation pending for the strand, or failed.
69
+ * 6. **Re-attempt this machine's own `StrandPeer` row** ({@link PartyStrandPeerSource.publishOwn}),
70
+ * the control-side statement step 4 on the siblings reads: a background write at bring-up
71
+ * that is deferred while alone or refused until this machine's own `CadrePeer` row arrives.
72
+ *
73
+ * ## Binding the party's other machines
74
+ *
75
+ * A `MemberPeer` binding is signed by the member key, which every machine of the party holds,
76
+ * so any machine can bind any peer id under the party's key: the party vouching for its own
77
+ * machine. Which peer ids are the party's machines comes from `CadreControl.StrandPeer`, each
78
+ * machine's own signed statement of its peer id in the strand, joined to the party's live
79
+ * machines and its `CadrePeer` tombstones (`strand-party-peers.ts`). The point is a party
80
+ * member key that changes (a machine removal rotates it: `strand-party-key-rotation.ts`):
81
+ * a sibling offline through the change returns to find itself bound under the new key by the
82
+ * machines that were there, and a machine bound by a sibling that had not yet heard of its
83
+ * removal is cleared once the tombstone arrives.
84
+ *
85
+ * Step 5 is gated on no rotation pending (the pending-key state step 2 read). While one is, the
86
+ * removed machine's binding under the current key is exactly the orphan the rotation is about to
87
+ * leave behind, and clearing it would hand the removed machine a clean slate the deny-list gate
88
+ * admits. A failed pending read clears nothing for the same reason. After the swap the pending row is gone, and the step
89
+ * clears a binding a lagging sibling wrote under the new key. The gate holds only because a
90
+ * removal writes the machine's tombstone and the pending row in ONE transaction
91
+ * (`ControlDatabase.removeMachine`): a tombstone that reaches this node without
92
+ * its pending row reads as "no rotation", and this step clears the binding the rotation
93
+ * meant to orphan, which leaves the removed machine admitted as a stranger rather than denied.
94
+ *
95
+ * The step reads the party's bindings once per pass (`listMemberPeers`) and compares in
96
+ * JavaScript, the scan-not-seek idiom. Two machines binding one sibling at once collide on the
97
+ * `MemberPeer` primary key; the loser's write is refused and its next pass finds the row. A
98
+ * sibling's row that cannot be read keeps the loop live on the flat poll interval, and a write
99
+ * that fails is retried on the ladder.
100
+ *
101
+ * ## Redeeming under the pending key
102
+ *
103
+ * A machine removal replaces the party's member key K in each closed strand with a fresh key K'
104
+ * (`strand-party-key-rotation.ts`), and in a strand the party does not manage K cannot seat K'
105
+ * itself: the strand's host has to re-invite the party, or its manager admit K' by hand
106
+ * (docs/strands.md → Replacing the party's key). The host's fresh invitation is staged here like
107
+ * any other and lands in step 2, which is why one rule governs that step: **while a
108
+ * `PendingStrandPartyKey` row exists for the strand, this loop never writes a `Strand.Member`
109
+ * row under K.** The removed machine holds K, and a seat written under K is a seat it keeps.
110
+ * Three cases, decided by what {@link PartyStrandPeerSource.pendingKey} answers at the head of
111
+ * the pass (a rejected read counts as pending with the key unreadable):
112
+ *
113
+ * - **No rotation pending**: the ordinary step 2 above.
114
+ * - **Pending, the key not readable here** (the row is sealed to other machines: this machine
115
+ * was admitted after the removal, or runs on an ephemeral identity; or the read failed): the
116
+ * step neither consumes nor burns. A staged invitation stays staged, with one debug line, for
117
+ * a machine that can read the key to redeem; the pass is idle, and it does not count toward
118
+ * the probable blocked re-join report below — it left the invitation staged on purpose.
119
+ * - **Pending, the key opened**: with K' already a member (admitted by hand, or seated by a
120
+ * sibling's redemption), a staged invitation is burned against K' and the rotation driver is
121
+ * kicked ({@link StrandMembershipReconcilerDeps.onPendingKeySeated}); with K' not yet a member
122
+ * and an invitation staged, it is redeemed under K' and the driver kicked; a refused
123
+ * redemption is classified as under K, except that a sealed strand is not terminal here (the
124
+ * party may still be a member under K) and only drops the dead invitation. With nothing staged
125
+ * the pass is idle: the driver has reported `needs-another-party`, and nothing happens until
126
+ * the host acts.
127
+ *
128
+ * Step 2 still answers whether K's member row is visible, which the binding steps that follow
129
+ * are under: K is the party's current key until the control swap, and a binding written under K
130
+ * after K has left (step 5 of the rotation, before the swap replicates here) is refused by
131
+ * `MemberPeer.MemberExists` and polled, until the swap re-keys this loop. The loop does not
132
+ * latch done while a rotation is pending, whatever else is in place, so a by-hand admission or a
133
+ * sibling's redemption is noticed on the next pass and the driver kicked; a pass that wrote
134
+ * nothing is idle, so the cadence is the flat poll interval. The pending state ends with the
135
+ * swap: `StrandInstanceManager.rekeyParty` rebuilds this loop under K', whose next pass finds no
136
+ * pending row, clears the removed machine's stale binding (step 5) and latches done as before.
137
+ * Whoever redeems the host's invitation seats a key of its choosing, so the invitation must reach
138
+ * the party's owner and not the removed machine, as with every invitation today.
56
139
  *
57
140
  * ## Stops, and re-arming
58
141
  *
59
- * Two kinds of stop. A RE-ARMABLE stop is one a fresh invitation should reopen:
142
+ * Two kinds of stop. A RE-ARMABLE stop is one a fresh invitation, or a change to the
143
+ * party's machines, should reopen:
60
144
  *
61
145
  * - **Done** (above).
62
- * - **Self-revoked with nothing staged** (step 1 above).
146
+ * - **Self-revoked with nothing staged** (step 1 above). A machine whose only binding is
147
+ * orphaned — its sibling rotated the key before this machine's `StrandPeer` row reached it —
148
+ * is denied by every other machine, so its own loop cannot write and stops here. The heal is
149
+ * a sibling binding it (step 4 there); its enforcer then drops its peer id from the deny set
150
+ * and reports `onSelfRestored`, which re-arms this loop.
63
151
  *
64
152
  * A PERMANENT stop is one a fresh invitation changes nothing about — {@link rearm} is a
65
153
  * no-op after it:
@@ -76,7 +164,10 @@
76
164
  * the instance manager, which calls {@link rearm}: a done loop reopens and runs one pass
77
165
  * at once; a running loop is merely kicked. This is what lets a party that was REMOVED
78
166
  * from the strand, and then handed a new invitation, actually attempt it — the loop
79
- * finished during its first join, long before the removal.
167
+ * finished during its first join, long before the removal. `CadreNode` also re-arms every
168
+ * strand's loop when `CadreControl.StrandPeer`, `CadrePeer` or `Revocation` changes
169
+ * (`StrandInstanceManager.notifyPartyPeersChanged`), so a sibling's row arriving binds it
170
+ * within the watch's coalescing window rather than at the next resume.
80
171
  *
81
172
  * On a removed party the local replica is usually stale: the cohort cut this machine off
82
173
  * at about the moment the removal was written, so `isStrandMember` still answers true and
@@ -145,6 +236,7 @@
145
236
  */
146
237
  import type { Database } from '@quereus/quereus';
147
238
  import type { StrandMembershipInvite } from './types.js';
239
+ import type { PartyStrandPeerSource } from './strand-party-peers.js';
148
240
  import { type TimeoutScheduler } from './timeout-scheduler.js';
149
241
  /**
150
242
  * Default poll interval, ms: the loop's idle cadence while nobody has admitted this party, and
@@ -267,6 +359,21 @@ export interface StrandMembershipReconcilerDeps {
267
359
  getOwnPeerId: () => string | undefined;
268
360
  /** The staged invitation seam. Absent for flows with no invitation (e.g. tests). */
269
361
  pendingInvite?: PendingMembershipInviteSource;
362
+ /**
363
+ * The control-database seam for steps 2 and 4 to 6 of the pass (see "Binding the party's other
364
+ * machines" and "Redeeming under the pending key" in the module doc): the party's pending key
365
+ * in this strand as this machine can read it, the party's machines' strand peer ids, and this
366
+ * machine's own `StrandPeer` row. Absent (tests, an embedder with no control database) means
367
+ * no rotation is ever pending and the loop binds only this machine.
368
+ */
369
+ partyPeers?: PartyStrandPeerSource;
370
+ /**
371
+ * Called when a pass finds the party's PENDING key seated as a member of the strand (see
372
+ * "Redeeming under the pending key"): it redeemed the staged invitation under that key, or found
373
+ * it seated already. On every such pass until the control swap re-keys the loop. `CadreNode`
374
+ * wires it to its party key rotation driver, which finishes the move on an owner machine.
375
+ */
376
+ onPendingKeySeated?: () => void;
270
377
  /**
271
378
  * Whether the revocation enforcer currently flags THIS node's own party as revoked.
272
379
  * When it does and nothing is staged, the loop stops rather than fight the enforcer;
@@ -335,15 +442,24 @@ export declare class StrandMembershipReconciler {
335
442
  /** Whether the blocked re-join was already reported this re-arm cycle (one report, either trigger). */
336
443
  private rejoinBlockedReported;
337
444
  /**
338
- * Whether the pass that just ran found nothing to act on — no member row and no staged
339
- * invitation. That is a wait to be admitted, not an unfinished join, so it re-arms on the
340
- * flat poll interval; every other unfinished outcome climbs the ladder.
445
+ * Whether the pass in flight left the staged invitation alone ON PURPOSE (a rotation is pending
446
+ * and this machine cannot read the key), which is not an attempt that failed and so does not
447
+ * count toward the probable blocked re-join report. Reset at the head of every pass.
448
+ */
449
+ private inviteLeftStagedDeliberately;
450
+ /** Whether this cycle has logged that the loop stays live for a pending rotation (one line per re-arm cycle). */
451
+ private pendingRotationLogged;
452
+ /**
453
+ * Whether the pass that just ran is waiting on something no faster retry can shorten — no
454
+ * member row and no staged invitation (a wait to be admitted, {@link noteIdlePass}), or the
455
+ * party's machines unreadable ({@link waitForPoll}). Such a pass re-arms on the flat poll
456
+ * interval; every other unfinished outcome climbs the ladder.
341
457
  *
342
458
  * NOTE: the ladder is therefore the DEFAULT for any outcome nobody classified — a new
343
459
  * early return added to {@link doPass} inherits the fast retry unless it calls
344
- * {@link noteIdlePass}. Right for every outcome that exists today (each is an unfinished
345
- * join this machine can make progress on). If an early return is ever added for a
346
- * condition retrying cannot resolve, classify it idle.
460
+ * {@link noteIdlePass} or {@link waitForPoll}. Right for every outcome that exists today
461
+ * (each is an unfinished join this machine can make progress on). If an early return is
462
+ * ever added for a condition retrying cannot resolve, classify it so.
347
463
  */
348
464
  private lastPassIdle;
349
465
  /** Current rung of the unfinished-join retry ladder, ms; unset before the first retry. */
@@ -376,14 +492,16 @@ export declare class StrandMembershipReconciler {
376
492
  */
377
493
  stop(): void;
378
494
  /**
379
- * A fresh invitation was staged: reopen a loop that stopped on a re-armable state (done,
380
- * or self-revoked with nothing staged) and run one pass at once; merely kick a loop that
381
- * is still running; do nothing after a permanent stop. Never rejects, and serialized
382
- * like {@link reconcile}: the reopen happens when the queued pass STARTS, after any pass
383
- * in flight has settled, so a `done` that pass latches cannot swallow the re-arm — and a
384
- * public {@link stop} that lands first still wins, because the queued pass re-checks it.
495
+ * Something changed that a stopped loop should look at — `cause` names it for the log: a
496
+ * fresh invitation was staged, the party's machines changed, or this machine is no longer
497
+ * revoked. Reopen a loop that stopped on a re-armable state (done, or self-revoked with
498
+ * nothing staged) and run one pass at once; merely kick a loop that is still running; do
499
+ * nothing after a permanent stop. Never rejects, and serialized like {@link reconcile}: the
500
+ * reopen happens when the queued pass STARTS, after any pass in flight has settled, so a
501
+ * `done` that pass latches cannot swallow the re-arm — and a public {@link stop} that lands
502
+ * first still wins, because the queued pass re-checks it.
385
503
  */
386
- rearm(): Promise<void>;
504
+ rearm(cause?: string): Promise<void>;
387
505
  /**
388
506
  * Run one pass now. Never rejects. Serialized: concurrent calls chain, so no two
389
507
  * passes overlap and each explicit call gets a pass that STARTS after the call. On a
@@ -404,10 +522,22 @@ export declare class StrandMembershipReconciler {
404
522
  /** One serialized pass; contains every failure (contract: never rejects). */
405
523
  private doPass;
406
524
  /**
407
- * Steps 2 and 3 against a live database, with the outcome counted toward the probable
525
+ * Steps 2 to 6 against a live database, with the outcome counted toward the probable
408
526
  * blocked re-join report whether the attempt returned or threw.
527
+ *
528
+ * NOTE: steps 4 to 6 cost one `StrandPeer` read, one fresh membership read and one
529
+ * `MemberPeer` scan per pass, per closed strand, and `CadreNode` re-arms every strand's loop
530
+ * on each change to the party's machines, their records included. Fine at party scale; if a
531
+ * party ever runs many strands on many machines, read `StrandPeer` once per control change
532
+ * rather than per pass.
409
533
  */
410
534
  private attempt;
535
+ /**
536
+ * The party's pending key in this strand, read once per pass. No seam means no rotation is
537
+ * ever pending; a rejected read is "pending, key unreadable", the posture under which nothing
538
+ * is seated under the current key and no removed machine's binding is cleared (module doc).
539
+ */
540
+ private readPendingKeyState;
411
541
  /**
412
542
  * Arm the next pass, now that this one has settled — so a slow pass never stacks ticks
413
543
  * behind it. Only a STARTED loop schedules: a caller driving {@link reconcile} by hand
@@ -416,8 +546,8 @@ export declare class StrandMembershipReconciler {
416
546
  */
417
547
  private scheduleNext;
418
548
  /**
419
- * The delay before the next pass: the flat poll interval while the loop is merely idling
420
- * (no member row, no staged invitation — {@link noteIdlePass}), otherwise the next rung
549
+ * The delay before the next pass: the flat poll interval while the loop is merely waiting
550
+ * ({@link lastPassIdle}), otherwise the next rung
421
551
  * of the doubling ladder from {@link INITIAL_JOIN_RETRY_INTERVAL_MS}, capped at the poll
422
552
  * interval. A pass that lands idle resets the ladder, so a later unfinished join starts
423
553
  * over at the bottom rung.
@@ -425,10 +555,40 @@ export declare class StrandMembershipReconciler {
425
555
  private nextDelayMs;
426
556
  private clearTimer;
427
557
  /**
428
- * Step 2 of the pass: `true` iff the party's member row is visible locally by the
429
- * time this returns (already present, or seated by redeeming the staged invitation).
558
+ * Step 2 of the pass: `true` iff the party's member row under its CURRENT key is visible
559
+ * locally by the time this returns (already present, or seated by redeeming the staged
560
+ * invitation). While a rotation is pending the staged invitation is spent under the pending
561
+ * key instead, or left alone ("Redeeming under the pending key" in the module doc), and the
562
+ * answer is only whether the current key is still a member.
430
563
  */
431
564
  private ensureMembership;
565
+ /** Step 2 with no rotation pending: the member row under the party's own key, seated from the staged invitation if need be. */
566
+ private ensureMembershipUnderOwnKey;
567
+ /**
568
+ * Step 2 while a rotation is pending whose key this machine cannot read: nothing is seated or
569
+ * burned, since the only key this machine could sign with is the one being retired. A staged
570
+ * invitation is left for a machine that can read the key, and the pass is idle.
571
+ */
572
+ private leaveInviteStaged;
573
+ /**
574
+ * Step 2 while a rotation is pending and this machine can read the pending key: see the
575
+ * pending-and-opened case of "Redeeming under the pending key" in the module doc. A pending
576
+ * key that does not decode throws to the pass's catch, which retries it.
577
+ */
578
+ private seatPendingKey;
579
+ /**
580
+ * Tell the rotation driver the pending key is seated. Once per pass that sees the seat, so a
581
+ * machine that cannot drive (no owner key here, or the swap deferred) hears it again on its
582
+ * next pass rather than never.
583
+ *
584
+ * NOTE: a non-owner machine that reads the key kicks on every pass between the seat and the
585
+ * swap, and `CadreNode.driveRotationIfPending` logs its refusal each time; bounded by the
586
+ * seconds the swap takes on the owner machine. The owner machine alone does the same while
587
+ * its swap is deferred (the only sibling offline): every pass kicks, the driver runs its
588
+ * reads and ends "swap deferred", for as long as that sibling stays away. If either log
589
+ * ever matters, kick once per seat (remember the pending stamp kicked for).
590
+ */
591
+ private kickRotationDriver;
432
592
  /**
433
593
  * The already-member arm: spend a still-staged invitation so nobody else can. The stage
434
594
  * is cleared once the burn lands or the invitation is known dead (already spent,
@@ -457,25 +617,64 @@ export declare class StrandMembershipReconciler {
457
617
  */
458
618
  private handleBurnFailure;
459
619
  /**
460
- * Step 3 of the pass: write this machine's own `MemberPeer` binding (insert-if-absent)
461
- * and, once it is in place with nothing staged, latch the done state and stop the loop.
462
- * A missing transport peer id (a quiesce racing the pass) defers to the next tick; a
463
- * write failure — a busy refusal included — is contained by the pass's outer catch and
464
- * retried. A binding written while an invitation is still staged (its burn keeps being
465
- * refused) is not done: the loop stays live so a later pass can settle the credential.
620
+ * Step 3 of the pass: write this machine's own `MemberPeer` binding (insert-if-absent);
621
+ * `true` once it is in place. A missing transport peer id (a quiesce racing the pass)
622
+ * defers to the next tick; a write failure — a busy refusal included — is contained by the
623
+ * pass's outer catch and retried.
466
624
  */
467
625
  private ensureBinding;
626
+ /**
627
+ * Steps 4 and 5 of the pass, against the party's machines as the control database records
628
+ * them: `true` when nothing was left to write — every live sibling was already bound and no
629
+ * removed machine's binding had to be cleared — so the pass may latch done. A pass that
630
+ * wrote is not settled: the next one re-reads and confirms. Rows that cannot be read settle
631
+ * nothing and move the next pass to the flat poll interval; nothing this machine can do
632
+ * sooner. No seam means no siblings to bind: settled.
633
+ */
634
+ private reconcileSiblings;
635
+ /**
636
+ * Step 4: bind each of `unbound` under the party's key. Each write is contained on its own,
637
+ * so one sibling's refusal (busy, or a collision with a sibling binding the same id) does
638
+ * not keep the others waiting. `true` iff there was nothing to bind.
639
+ */
640
+ private bindSiblings;
641
+ /**
642
+ * Step 5: clear the binding of each of `stale` (removed machines bound under the party's
643
+ * key), through the self branch of {@link removeMemberPeer} — signed by the party key, which
644
+ * is the row's own member key, so any peer id of the party's is reachable this way. Clears
645
+ * nothing while a key rotation is pending for the strand, or while whether one is could not be
646
+ * read, both of which `rotationPending` carries (see the module doc); that is settled, since
647
+ * the loop stays live until the swap re-keys it. `true` iff nothing was left to clear.
648
+ */
649
+ private clearRemovedMachines;
650
+ /** Step 6: re-attempt this machine's own `StrandPeer` row; the seam contains its failures and remembers success. */
651
+ private publishOwnStrandPeer;
652
+ /**
653
+ * The done decision, once the member row and the own binding are in place: not while a party
654
+ * key rotation is pending (the loop stays live to notice the pending key seated, and is
655
+ * rebuilt under that key by the swap; logged once per cycle), not while an invitation is still
656
+ * staged (its burn keeps being refused; the loop stays live so a later pass can settle the
657
+ * credential), and not while a sibling step wrote or could not read this pass. Otherwise latch
658
+ * done and stop.
659
+ */
660
+ private latchDone;
661
+ /** Re-arm the next pass on the flat poll interval, for a wait no faster retry can shorten. */
662
+ private waitForPoll;
468
663
  /**
469
664
  * Act on a `consumeInvite` rejection as {@link classifyConsumeFailure} routes it: busy → keep
470
- * the invitation and retry; half-committed → warn and drop; sealed → terminal; dead
471
- * invitation → drop; anything else → retry.
665
+ * the invitation and retry; half-committed → warn and drop; sealed → terminal under the party's
666
+ * own key, but under the pending key only a dead invitation (the party may still be a member
667
+ * under its current key, whose bindings this loop keeps whole, and the rotation stays pending
668
+ * for the life of the row); dead invitation → drop; anything else → retry.
472
669
  */
473
670
  private handleConsumeFailure;
474
671
  /**
475
672
  * Count an attempted pass that left the invitation staged (whatever stopped it — a
476
673
  * refused or busy write, or a read that threw on a cut-off machine); one that settled
477
- * it, or finished, ends the streak. At {@link UNFINISHED_PASSES_BEFORE_ESCALATION}
478
- * report the PROBABLE blocked re-join.
674
+ * it, or finished, ends the streak. A pass that left it staged on purpose (a rotation
675
+ * pending whose key this machine cannot read) is no attempt: it neither counts nor ends
676
+ * the streak. At {@link UNFINISHED_PASSES_BEFORE_ESCALATION} report the PROBABLE blocked
677
+ * re-join.
479
678
  */
480
679
  private noteAttemptOutcome;
481
680
  /**