@serfab/cadre-core 1.21.0 → 1.23.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 (109) hide show
  1. package/README.md +294 -294
  2. package/dist/cadre-node.d.ts +334 -53
  3. package/dist/cadre-node.js +794 -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 +587 -173
  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/membership-view.js +4 -1
  27. package/dist/membership-view.js.map +1 -1
  28. package/dist/owner-keys.js +2 -1
  29. package/dist/owner-keys.js.map +1 -1
  30. package/dist/owner-signer.js +3 -4
  31. package/dist/owner-signer.js.map +1 -1
  32. package/dist/peer-authorization.d.ts +14 -2
  33. package/dist/peer-authorization.js +24 -1
  34. package/dist/peer-authorization.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-commit-durability.d.ts +33 -2
  45. package/dist/strand-commit-durability.js +44 -4
  46. package/dist/strand-commit-durability.js.map +1 -1
  47. package/dist/strand-database.d.ts +35 -5
  48. package/dist/strand-database.js +34 -10
  49. package/dist/strand-database.js.map +1 -1
  50. package/dist/strand-instance-manager.d.ts +200 -18
  51. package/dist/strand-instance-manager.js +434 -64
  52. package/dist/strand-instance-manager.js.map +1 -1
  53. package/dist/strand-membership-reconciler.d.ts +250 -51
  54. package/dist/strand-membership-reconciler.js +410 -66
  55. package/dist/strand-membership-reconciler.js.map +1 -1
  56. package/dist/strand-membership-writer.d.ts +7 -0
  57. package/dist/strand-membership-writer.js +9 -0
  58. package/dist/strand-membership-writer.js.map +1 -1
  59. package/dist/strand-party-key-rotation.d.ts +177 -0
  60. package/dist/strand-party-key-rotation.js +340 -0
  61. package/dist/strand-party-key-rotation.js.map +1 -0
  62. package/dist/strand-party-machines.d.ts +111 -0
  63. package/dist/strand-party-machines.js +258 -0
  64. package/dist/strand-party-machines.js.map +1 -0
  65. package/dist/strand-party-peers.d.ts +101 -0
  66. package/dist/strand-party-peers.js +49 -0
  67. package/dist/strand-party-peers.js.map +1 -0
  68. package/dist/strand-peer-redial.d.ts +34 -7
  69. package/dist/strand-peer-redial.js +46 -13
  70. package/dist/strand-peer-redial.js.map +1 -1
  71. package/dist/strand-revocation-enforcer.d.ts +15 -1
  72. package/dist/strand-revocation-enforcer.js +16 -9
  73. package/dist/strand-revocation-enforcer.js.map +1 -1
  74. package/dist/strand-transport-key.js +3 -0
  75. package/dist/strand-transport-key.js.map +1 -1
  76. package/dist/strand-watcher.d.ts +7 -4
  77. package/dist/strand-watcher.js +12 -7
  78. package/dist/strand-watcher.js.map +1 -1
  79. package/dist/types.d.ts +169 -13
  80. package/dist/types.js.map +1 -1
  81. package/package.json +9 -8
  82. package/src/cadre-node.ts +12280 -11528
  83. package/src/control-authorization.ts +41 -1
  84. package/src/control-database.ts +6123 -5603
  85. package/src/control-schema.ts +71 -7
  86. package/src/ed25519-key.ts +12 -1
  87. package/src/index.ts +957 -924
  88. package/src/machine-removal.ts +80 -1
  89. package/src/membership-connection-gater.ts +13 -1
  90. package/src/membership-view.ts +4 -1
  91. package/src/owner-keys.ts +2 -1
  92. package/src/owner-signer.ts +92 -94
  93. package/src/peer-authorization.ts +27 -3
  94. package/src/sealed-party-key.ts +190 -0
  95. package/src/seed-bootstrap.ts +17 -3
  96. package/src/strand-addr-protocol.ts +67 -6
  97. package/src/strand-commit-durability.ts +54 -5
  98. package/src/strand-database.ts +47 -11
  99. package/src/strand-instance-manager.ts +524 -65
  100. package/src/strand-membership-reconciler.ts +1310 -942
  101. package/src/strand-membership-writer.ts +10 -0
  102. package/src/strand-party-key-rotation.ts +436 -0
  103. package/src/strand-party-machines.ts +293 -0
  104. package/src/strand-party-peers.ts +129 -0
  105. package/src/strand-peer-redial.ts +61 -14
  106. package/src/strand-revocation-enforcer.ts +27 -9
  107. package/src/strand-transport-key.ts +3 -0
  108. package/src/strand-watcher.ts +12 -7
  109. package/src/types.ts +3121 -2963
@@ -1,6 +1,6 @@
1
1
  import type { Libp2p, PeerId } from '@libp2p/interface';
2
2
  import type { Multiaddr } from '@multiformats/multiaddr';
3
- import type { CadreNodeConfig, StrandInstance, StrandRow, StrandConfig, FoundStrandConfig, FoundStrandResult, FoundStrandOptions, FoundStrandBackgroundResult, SAppConfig, CadreNodeEvents, ControlNetworkSeed, ApplySeedResult, SeedAckMessage, SeedDeliveryTarget, AddDroneOptions, DroneInitResult, OpenInvitation, FormStrandResult, StrandFormationDisclosure, StrandMembershipInvite, ResolveOpts, SelfRegistrationOutcome, ServiceWakeResult, PushPlatform, DeviceTokenRecord, CadreInviteStatus, CadreMachine, CadreOwnerKey, MachineRemovalPlan, MachineRemovalResult, OwnerKeyRemovalPlan, OwnerKeyRemovalResult, RemoveOwnerOptions, CadreRemoval, CadreInvitationReach, CreateCadreInvitationOptions, CreateCadreInvitationResult, RedeemCadreInvitationOptions, RedeemCadreInvitationResult, CreateOwnerGrantOptions, CreateOwnerGrantResult, OwnerGrantStatus, RedeemOwnerGrantOptions, RedeemOwnerGrantResult, JoinWithOwnerGrantResult, ResolveDeviceTokenOpts, PendingJoinStatus } from './types.js';
3
+ import type { CadreNodeConfig, StrandInstance, StrandRow, StrandConfig, FoundStrandConfig, FoundStrandResult, FoundStrandOptions, FoundStrandBackgroundResult, SAppConfig, CadreNodeEvents, ControlNetworkSeed, ApplySeedResult, SeedAckMessage, SeedDeliveryTarget, AddDroneOptions, DroneInitResult, OpenInvitation, FormStrandResult, StrandFormationDisclosure, StrandMembershipInvite, ResolveOpts, SelfRegistrationOutcome, ServiceWakeResult, PushPlatform, DeviceTokenRecord, CadreInviteStatus, CadreMachine, CadreOwnerKey, MachineRemovalPlan, MachineRemovalResult, PendingPartyKeyRotation, OwnerKeyRemovalPlan, OwnerKeyRemovalResult, RemoveOwnerOptions, CadreRemoval, CadreInvitationReach, CreateCadreInvitationOptions, CreateCadreInvitationResult, RedeemCadreInvitationOptions, RedeemCadreInvitationResult, CreateOwnerGrantOptions, CreateOwnerGrantResult, OwnerGrantStatus, RedeemOwnerGrantOptions, RedeemOwnerGrantResult, JoinWithOwnerGrantResult, ResolveDeviceTokenOpts, PendingJoinStatus } from './types.js';
4
4
  import { type StrandLeaveOptions, type StrandOfflineMode } from './strand-offline.js';
5
5
  import { type TrustedOwnerStore, type TrustSource } from './trusted-owner-store.js';
6
6
  import { type OwnerSign, type OwnerSigner } from './owner-signer.js';
@@ -8,6 +8,7 @@ import { type BootstrapPeerStore } from './bootstrap-peer-store.js';
8
8
  import { type StrandNetworkStateStore } from './strand-network-state.js';
9
9
  import { type EnrolledMachineStore } from './enrolled-machine-store.js';
10
10
  import { type JoinedStrandRecord } from './joined-strand-store.js';
11
+ import { type PartyStrandPeer } from './strand-party-peers.js';
11
12
  import { type SAppIdLookup } from './strand-watcher.js';
12
13
  import type { CohortPeerRow } from './strand-cohort.js';
13
14
  import { type ControlCohortReconcileResult } from './control-cohort.js';
@@ -22,9 +23,10 @@ import { type RelayReservationState, type RelayReservationSupervisorOptions } fr
22
23
  import type { WakeAck } from './types.js';
23
24
  import { type ConnectionPathSummary } from './diagnostics/connection-path.js';
24
25
  /**
25
- * How often a running strand re-asks each connected sibling that last ANSWERED
26
- * (even with nothing) for its strand-network addresses, and re-merges them into
27
- * its own libp2p address book ({@link CadreNode.refreshStrandPeerAddrs}).
26
+ * How often a running strand re-asks each connected sibling that last answered WITH
27
+ * addresses for its strand-network addresses, and re-merges them into its own libp2p
28
+ * address book ({@link CadreNode.refreshStrandPeerAddrs}); also the longest wait
29
+ * after an answer with none ({@link nextStrandAddrAsk}).
28
30
  * Overridable per node via `network.controlCohort.strandAddrRefreshMs`.
29
31
  *
30
32
  * Ten minutes sits comfortably inside the peerStore's one-hour address expiry
@@ -33,17 +35,6 @@ import { type ConnectionPathSummary } from './diagnostics/connection-path.js';
33
35
  * on, so the strand-addr RPC fan-out stays cheap.
34
36
  */
35
37
  export declare const STRAND_PEER_ADDR_REFRESH_MS: number;
36
- /**
37
- * How soon {@link CadreNode.refreshStrandPeerAddrs} re-asks a sibling that did NOT
38
- * answer — unreachable, `unavailable`, or `refused`. A refusal matters most: a
39
- * phone asking before its `CadrePeer` row has replicated to the sibling is refused
40
- * and its delegate grant goes unrecorded, and waiting the full
41
- * {@link STRAND_PEER_ADDR_REFRESH_MS} for the next try is the delay this bounds.
42
- * A pass arms its own wake for the earliest due time it leaves behind
43
- * (`nextReconcileWakeMs`), so a sibling that keeps failing costs one timed-out
44
- * RPC a minute, with no pass in between.
45
- */
46
- export declare const STRAND_PEER_ADDR_RETRY_MS: number;
47
38
  /**
48
39
  * Default lifetime of an owner grant ({@link CadreNode.createOwnerGrant}): whoever holds the
49
40
  * bundle can become an owner, so it is a bearer credential for admin rights and lives only
@@ -376,14 +367,19 @@ export declare class CadreNode implements SAppIdLookup {
376
367
  * missing key is due. Bounds {@link refreshStrandPeerAddrs}'s fan-out per
377
368
  * (sibling, strand) rather than per strand, so a sibling that connects after a
378
369
  * pass is asked on the pass its connection starts instead of waiting out a stamp
379
- * another sibling's answer set. An answer (even an empty one) makes the sibling
380
- * due again in {@link STRAND_PEER_ADDR_REFRESH_MS}; no answer, in
381
- * {@link STRAND_PEER_ADDR_RETRY_MS}, and each pass arms its own wake for the
382
- * earliest due time it leaves behind (`nextReconcileWakeMs`). Keys whose strand
383
- * stopped running or whose sibling is no longer connected are pruned every pass,
384
- * so a resumed strand and a reconnected sibling are both asked at once.
370
+ * another sibling's answer set. {@link nextStrandAddrAsk} sets each due time from the
371
+ * ask's outcome, and each pass arms its own wake for the earliest due time it leaves
372
+ * behind (`nextReconcileWakeMs`). Keys whose strand stopped running or whose sibling
373
+ * is no longer connected are pruned every pass, so a resumed strand and a reconnected
374
+ * sibling are both asked at once.
385
375
  */
386
376
  private readonly strandAddrAskDueAt;
377
+ /**
378
+ * How far each (sibling, strand) has climbed {@link nextStrandAddrAsk}'s wait, keyed like
379
+ * {@link strandAddrAskDueAt} and pruned with it: a reconnected sibling may be a new
380
+ * incarnation, so it starts again at the first step.
381
+ */
382
+ private readonly strandAddrAskStreak;
387
383
  /**
388
384
  * The strand-network addresses a formation carried back
389
385
  * (`FormationResultMessage.strandAddrs`), by strand id: the responder's live strand
@@ -710,6 +706,45 @@ export declare class CadreNode implements SAppIdLookup {
710
706
  private selfPeerPublishDeferred;
711
707
  /** This node's own `DeviceToken` self-write committed local-only (re-touched on growth). */
712
708
  private pendingSelfDeviceWrite;
709
+ /**
710
+ * This machine's `StrandPeer` rows ({@link publishStrandPeer}) that could not be written
711
+ * yet, by strand id → this machine's peer id in that strand: deferred while a write could
712
+ * fork the party, or refused because this machine's own `CadrePeer` row has not reached
713
+ * this node. Re-attempted by the growth drain ({@link publishDeferredStrandPeers}), by the
714
+ * party-machine watch when a `CadrePeer` row arrives (this machine's own included: a
715
+ * replica with no party key runs no reconciler, so that is its retry), and by each
716
+ * membership reconciler pass of the strand. Cleared on stop with the queues above: the next
717
+ * start's launches publish again.
718
+ */
719
+ private readonly deferredStrandPeerWrites;
720
+ /** The latest rebuild queued per strand for a removed machine in its seed ({@link queueSeedRemovalRebuild}). */
721
+ private readonly seedRemovalRebuilds;
722
+ /**
723
+ * Strands whose `StrandPeer` row for this machine this process has found present (written
724
+ * by it, or already stored). Rows are never updated or deleted, so once present the row
725
+ * stays, and a later publish for the strand costs nothing. Per session.
726
+ */
727
+ private readonly strandPeerRowsHeld;
728
+ /**
729
+ * The watch that wakes every closed strand's membership reconciler when the party's
730
+ * machines change ({@link StrandInstanceManager.notifyPartyPeersChanged}); taken in
731
+ * `start()` beside the gate watch, disposed in `stop()`.
732
+ */
733
+ private strandPartyPeersWatch;
734
+ /**
735
+ * The watch on `StrandPartyKey` and `PendingStrandPartyKey` ({@link onPartyKeyTablesChanged}):
736
+ * a swapped key replicated from the machine that finished a rotation re-keys the running
737
+ * strand here, and a pending row drives a rotation here when this is an owner machine running
738
+ * the strand. Taken in `start()`, disposed in `stop()`.
739
+ */
740
+ private strandPartyKeyWatch;
741
+ /**
742
+ * The party key rotation driver (`strand-party-key-rotation.ts`) over this node's control
743
+ * database and strand manager; one run per strand at a time. Driven by {@link removeMachine},
744
+ * a closed strand becoming writable here, an offline queue draining, the party key watch and
745
+ * the growth drain.
746
+ */
747
+ private readonly partyKeyRotation;
713
748
  /**
714
749
  * Guards the one-shot, first-cohort-growth reconstruction: an owner re-touches
715
750
  * every membership row it may have authored that could be unreplicated (covering
@@ -2423,6 +2458,19 @@ export declare class CadreNode implements SAppIdLookup {
2423
2458
  */
2424
2459
  expireDeviceToken(peerId: string): Promise<void>;
2425
2460
  private handleStrandAdded;
2461
+ /**
2462
+ * Stop the watcher relaunching a strand whose launch failed on an app schema that can never apply
2463
+ * to its tables (`AppSchemaRefusedError`, e.g. a `not null` column with no default added to a table
2464
+ * with rows): every relaunch would build the strand node and compose the database only to fail at the
2465
+ * same statement (gotchoices/sereus#57). The next {@link addStrand} lifts it, since a claim is the only
2466
+ * way the registered schema changes. Any other failure is left to the retry ladder.
2467
+ *
2468
+ * Not suppressed when a claim registered another config while this launch ran (`launchedWith` is
2469
+ * no longer the registered one): that claim already lifted any suppression, and its own call only
2470
+ * waited on this launch, so its schema has not been tried yet and the ladder must try it.
2471
+ * Returns whether it suppressed.
2472
+ */
2473
+ private suppressIfAppSchemaRefused;
2426
2474
  /**
2427
2475
  * Offer a strand no local config claims to the hosting app as `strand:discovered`, so
2428
2476
  * it can decide whether to join (register a config + addStrand); the strand-agnostic
@@ -2482,6 +2530,18 @@ export declare class CadreNode implements SAppIdLookup {
2482
2530
  * journaled before it went out, and the next build's restore re-sends it under the same action id.
2483
2531
  */
2484
2532
  private handleOfflineStatus;
2533
+ /**
2534
+ * The state of a strand's offline queue. An empty queue is when a party key rotation it held up
2535
+ * can run: every membership write is refused while it lists a transaction
2536
+ * (`StrandOfflineQueueBusyError`), which is how a machine removal made on a held queue leaves its
2537
+ * strand `pending`.
2538
+ *
2539
+ * NOTE: a queue held for another reason (a second machine still unreachable) keeps the removed
2540
+ * machine a member of a closed strand until it drains, unless another owner machine drives the
2541
+ * rotation. If a lost phone's removal must not wait on that, let the rotation's writes past the
2542
+ * refusal, with the bounded wait the refusal exists to avoid.
2543
+ */
2544
+ private handleQueueState;
2485
2545
  private handleStrandIdle;
2486
2546
  /**
2487
2547
  * Hibernate a strand: release its strand-network resources via the strand
@@ -2527,6 +2587,29 @@ export declare class CadreNode implements SAppIdLookup {
2527
2587
  * alone.
2528
2588
  */
2529
2589
  private rehibernateAfterFailedResume;
2590
+ /**
2591
+ * Run {@link rebuildWithoutRemovedMachine} after any rebuild already queued for `strandId`, so
2592
+ * two removals give two rebuilds in turn. A later removal needs its own: the first may have
2593
+ * resolved its seed before the second's row was written. Never rejects.
2594
+ */
2595
+ private queueSeedRemovalRebuild;
2596
+ /**
2597
+ * Replace a running strand node whose launch seed names a machine removed from the cadre with one
2598
+ * built from a fresh seed, which a removed machine is not in, so an offline queue stops waiting
2599
+ * for it (`docs/strands.md` → Waiting for the party's own machines). The same pair hibernation
2600
+ * runs, so the app sees what it sees on a wake, and a queue is restored from its journal; the
2601
+ * quiesce waits for a build in flight. A strand that went down meanwhile takes a fresh seed at its
2602
+ * next wake, so it is left down.
2603
+ *
2604
+ * NOTE: accepted tradeoff — the rebuild drops the running database's in-memory followed commits.
2605
+ * An upstream "forget this peer" call would avoid the rebuild, but needs an Optimystic change for
2606
+ * a case a removal hits rarely. If rebuilds prove disruptive, ask for that call.
2607
+ *
2608
+ * NOTE: a force-hibernate landing between the quiesce and the resume is undone by the resume, and
2609
+ * its cancelled timers leave the strand up until the next activity. If a backgrounded phone is
2610
+ * seen holding a strand up after a removal, make the two steps one transition in the manager.
2611
+ */
2612
+ private rebuildWithoutRemovedMachine;
2530
2613
  /**
2531
2614
  * Rebuild a quiesced strand's runtime, re-resolving the volatile cohort input
2532
2615
  * first: the discovery seed may have grown since the strand last ran. Shared by
@@ -2535,6 +2618,11 @@ export declare class CadreNode implements SAppIdLookup {
2535
2618
  * and joins a rebuild already in flight, so the two paths never build twice.
2536
2619
  */
2537
2620
  private resumeStrandRuntime;
2621
+ /**
2622
+ * The party's `StrandPartyKey.PrivateKey` for `strandId` as stored now, for a resume;
2623
+ * `undefined` when there is none or the read fails (logged), so the caller keeps what it has.
2624
+ */
2625
+ private storedStrandPartyKey;
2538
2626
  /**
2539
2627
  * Real cohort check-in for a hibernating strand (the `onCheckIn` callback).
2540
2628
  *
@@ -2621,6 +2709,15 @@ export declare class CadreNode implements SAppIdLookup {
2621
2709
  * strand in the watcher so this retry cannot resurrect it — a call to THIS method lifts
2622
2710
  * that suppression again, since an explicit claim is a deliberate reversal of the
2623
2711
  * deliberate stop.
2712
+ *
2713
+ * A launch refused on its app schema (`AppSchemaRefusedError`: the schema can never apply
2714
+ * to the tables the strand holds, such as a `not null` column with no default added to a
2715
+ * table with rows) is not handed to the relaunch, since every relaunch would fail the same
2716
+ * way after a full start-up. The strand is suppressed in the watcher instead, and the next
2717
+ * call to this method lifts that: a claim is the only way the registered schema changes,
2718
+ * so a different schema launches, and the same one makes one more attempt. A storage
2719
+ * replica this claim tried to give the schema in place keeps running and stays known to
2720
+ * the watcher.
2624
2721
  */
2625
2722
  addStrand(config: StrandConfig): Promise<StrandInstance>;
2626
2723
  /**
@@ -2654,6 +2751,15 @@ export declare class CadreNode implements SAppIdLookup {
2654
2751
  * @throws when this node does not run the strand.
2655
2752
  */
2656
2753
  getStrandOfflineMode(strandId: string): StrandOfflineMode;
2754
+ /**
2755
+ * The party's other machines known to hold `strandId` (each has written its `StrandPeer` row for
2756
+ * it) with no open connection from this node's strand node: what a queued transaction reporting
2757
+ * `waitingFor: 'cohort'` may be waiting for, by control peer id (`listMachines`, `removeMachine`)
2758
+ * and strand peer id (docs/strands.md → "Waiting for the party's own machines"). Empty on a
2759
+ * strand not running here, and on a node offering no offline mode. Nothing releases the wait on
2760
+ * its own: the transaction is safe in the journal, and removing the machine is the user's call.
2761
+ */
2762
+ getUnreachedStrandMachines(strandId: string): readonly PartyStrandPeer[];
2657
2763
  /**
2658
2764
  * Publish a strand row to the shared control database under this node's own
2659
2765
  * owner identity, so other cadre members discover it via control-network
@@ -3308,11 +3414,11 @@ export declare class CadreNode implements SAppIdLookup {
3308
3414
  *
3309
3415
  * Due times are per (sibling, strand) and set from each sibling's own outcome, so
3310
3416
  * a sibling that connects late — a phone joining after the party's always-on
3311
- * machines — is asked on the pass its connection starts, and one that could not
3312
- * answer or refused (its view of the membership may not include us yet) is retried
3313
- * within {@link STRAND_PEER_ADDR_RETRY_MS} rather than
3314
- * {@link STRAND_PEER_ADDR_REFRESH_MS}; the pass that stamped the retry arms a wake
3315
- * for it ({@link armReconcileWake}).
3417
+ * machines — is asked on the pass its connection starts, and one that gave no
3418
+ * address (it is restarting, its strand has not launched, or its view of the
3419
+ * membership does not include us yet) is retried within seconds, on the climbing
3420
+ * wait of {@link nextStrandAddrAsk}; the pass that stamped the retry arms a wake for
3421
+ * it ({@link armReconcileWake}).
3316
3422
  *
3317
3423
  * Distinct from {@link refreshDelegateGrants}, deliberately: that pass covers
3318
3424
  * RELAYS on a `DELEGATE_GRANT_TTL_MS / 2` throttle to keep circuit-relay
@@ -3407,11 +3513,11 @@ export declare class CadreNode implements SAppIdLookup {
3407
3513
  private remergeUnrecordedFormationAddrs;
3408
3514
  /**
3409
3515
  * RPC `due` siblings for `strandId` and set each one's next due time from its own
3410
- * outcome: an answer, even an empty one, waits the full refresh interval; anything
3411
- * else retries in {@link STRAND_PEER_ADDR_RETRY_MS} (or the refresh interval, if
3412
- * configured shorter). Stamped before the caller
3413
- * re-checks that the strand is still running, so a strand torn down mid-pass still
3414
- * records who was asked.
3516
+ * outcome ({@link nextStrandAddrAsk}). Stamped before the caller re-checks that the
3517
+ * strand is still running, so a strand torn down mid-pass still records who was asked.
3518
+ * Stamped from the pass's `now`, taken before the ask, so an ask that outlasted its wait
3519
+ * is due at once; that cannot spin, because the next ask has to outlast a wait at least as
3520
+ * long.
3415
3521
  */
3416
3522
  private askSiblingsForStrandAddrs;
3417
3523
  /**
@@ -4227,8 +4333,10 @@ export declare class CadreNode implements SAppIdLookup {
4227
4333
  * "Writes made while alone"). A party with no other members cannot fork.
4228
4334
  *
4229
4335
  * What a caller does on `true` depends on the write. An `OwnerKey` add has no re-issue path at
4230
- * all, so {@link addOwner}, {@link removeOwner}'s re-vouch and a local owner grant redemption
4231
- * refuse it `alone`. A background write nothing waits on (the self-record publishes
4336
+ * all, so {@link addOwner} and a local owner grant redemption refuse it `alone`.
4337
+ * {@link removeOwner} refuses any re-vouch `alone`: an owner row's re-add has no re-issue path,
4338
+ * and a peer row's new voucher is lost to the fork above while the removal's tombstone, in
4339
+ * another collection, still arrives. A background write nothing waits on (the self-record publishes
4232
4340
  * {@link publishSelfRecordInBackground} makes, the pending-join runner's background attempts)
4233
4341
  * waits for a reachable sibling.
4234
4342
  *
@@ -4265,9 +4373,9 @@ export declare class CadreNode implements SAppIdLookup {
4265
4373
  *
4266
4374
  * Steps: re-plan ({@link planOwnerKeyRemoval}) and throw {@link OwnerKeyRemovalRefusedError}
4267
4375
  * on a refusal; check `options.revouch` against the plan's dependents and throw before any
4268
- * write when it names anything else; refuse `alone` ({@link controlWriteCouldFork}) when an
4269
- * `OwnerKey` row is to be re-vouched, since that re-add has no re-issue path; **re-vouch
4270
- * first**, under this node's key, the dependents the caller chose to keep and this node's own
4376
+ * write when it names anything else; refuse `alone` ({@link controlWriteCouldFork}) when any
4377
+ * row is to be re-vouched, this node's own included, since the new voucher might never reach
4378
+ * the other machines; **re-vouch first**, under this node's key, the dependents the caller chose to keep and this node's own
4271
4379
  * row when the key vouched it (`ControlDatabase.revouchOwnerKey`, `reauthorizePeer`), so they
4272
4380
  * are never untrusted in between, and stop before the removal if one fails (re-vouches
4273
4381
  * already made stay, harmlessly); then the removal. The re-vouches and the removal are one owner approval. The
@@ -4299,13 +4407,9 @@ export declare class CadreNode implements SAppIdLookup {
4299
4407
  * skipped.
4300
4408
  *
4301
4409
  * A failure rethrows and stops the call before the removal; re-vouches already made stay
4302
- * (the row is only re-signed by a current owner) and the caller retries. An owner re-vouch
4303
- * is refused alone before this runs; one whose last connection drops while it runs is logged,
4410
+ * (the row is only re-signed by a current owner) and the caller retries. Any re-vouch is
4411
+ * refused alone before this runs; one whose last connection drops while it runs is logged,
4304
4412
  * as {@link addOwner}'s add is.
4305
- *
4306
- * NOTE: a peer re-touch committed alone is not queued, and the drain skips self-published
4307
- * rows anyway, so the other machines may get the removal's tombstone without the new voucher
4308
- * (`tickets/backlog/bug-owner-key-removal-revouch-made-alone-is-not-reissued`).
4309
4413
  */
4310
4414
  private revouchDependents;
4311
4415
  /**
@@ -4317,38 +4421,215 @@ export declare class CadreNode implements SAppIdLookup {
4317
4421
  listMachines(): Promise<CadreMachine[]>;
4318
4422
  /**
4319
4423
  * What {@link removeMachine} would do for `peerId`, read without writing, for an app's
4320
- * confirmation step ({@link MachineRemovalPlan}): whether this node may remove it and which
4321
- * invitations it could come back through (`planMachineRemoval` in `machine-removal.ts`).
4424
+ * confirmation step ({@link MachineRemovalPlan}): whether this node may remove it, which
4425
+ * invitations it could come back through, and where the party's key in each closed strand is
4426
+ * replaced (`planMachineRemoval` in `machine-removal.ts`).
4322
4427
  */
4323
4428
  planMachineRemoval(peerId: string): Promise<MachineRemovalPlan>;
4429
+ /** {@link planMachineRemoval} over `machines` already read, for {@link removeMachine}, which also seals the pending keys to them. */
4430
+ private planRemovalAmong;
4431
+ /** Every strand the party holds, own and joined. */
4432
+ private heldStrandRows;
4433
+ /**
4434
+ * Every closed strand the party holds a membership key for, own and joined, as this node runs
4435
+ * it ({@link ClosedStrandState}): the input to the plan's per-strand rotation site.
4436
+ */
4437
+ private readClosedStrandStates;
4438
+ /**
4439
+ * {@link readClosedStrandStates} for one strand: its runtime here, and the party's manager seat
4440
+ * when a database is live and the party's key is known. A seat that cannot be read is `unknown`;
4441
+ * what acts on the strand finds out for itself.
4442
+ */
4443
+ private closedStrandState;
4444
+ /**
4445
+ * The party key replacements still waiting, for an app to list until each one finishes
4446
+ * ({@link PendingPartyKeyRotation}): one entry per live `PendingStrandPartyKey` row whose strand
4447
+ * the party still holds, own or joined. A row left behind by a joined strand the party has left
4448
+ * waits for a re-formation and is not listed. Public columns only, so a row sealed to other
4449
+ * machines lists too. Empty on a machine removed from the cadre, which cannot act on what it holds.
4450
+ * A recipient the party lost but has not removed stays in `sealedTo`; removing it writes a
4451
+ * replacement sealed to the machines present (`ControlDatabase.removeMachine`).
4452
+ *
4453
+ * NOTE: no event announces a change here; an app reads this on `strand:party-key-rotation-blocked`,
4454
+ * `strand:party-key-rotated` and after its own {@link removeMachine}, so a second device of the
4455
+ * party sees a row replicated to it on its next read. If an app ever needs a push, emit from
4456
+ * {@link onPartyKeyTablesChanged}.
4457
+ */
4458
+ listPendingPartyKeyRotations(): Promise<PendingPartyKeyRotation[]>;
4459
+ /** The peer ids {@link listMachines} lists, and this node's own, which is a machine of the cadre before its `CadrePeer` row lands. */
4460
+ private presentMachinePeerIds;
4461
+ /**
4462
+ * {@link PendingPartyKeyRotation.sealedTo}: the row's recipients still in the cadre. An envelope
4463
+ * that does not decode opens for nobody, so it lists none, logged; the rest of the listing stands.
4464
+ */
4465
+ private pendingKeyRecipientsPresent;
4466
+ /** {@link closedStrandState} plus the strand reads only a pending replacement asks about; a read that fails is `unknown`, so one strand mid-teardown leaves the rest of the listing standing. */
4467
+ private pendingRotationStrandState;
4324
4468
  /**
4325
4469
  * Remove a machine from the cadre completely, signed by this node's owner key: its
4326
- * `CadrePeer` row, its `DeviceToken` row (a removed phone must not be push-woken) and a
4327
- * withdrawal of every live invitation it could redeem to come back, in ONE transaction
4328
- * ({@link ControlDatabase.removeMachine}), with a `Revocation` tombstone per row so the
4470
+ * `CadrePeer` row, its `DeviceToken` row (a removed phone must not be push-woken), a
4471
+ * withdrawal of every live invitation it could redeem to come back, and a
4472
+ * `PendingStrandPartyKey` row per closed strand the party holds a key for, in ONE transaction
4473
+ * ({@link ControlDatabase.removeMachine}), with a `Revocation` tombstone per removed row so the
4329
4474
  * removal holds on every machine ("Deletes made while alone" in docs/architecture.md), under
4330
- * one owner approval. Afterwards this node forgets the machine as a dial target, and the
4475
+ * one owner approval. The pending row reaches the removed machine in that same transaction, so
4476
+ * the fresh key rides in it sealed to the machines that remain
4477
+ * ({@link pendingPartyKeyRecipients}): the removed machine holds the row and cannot open it. Afterwards this node forgets the machine as a dial target, and the
4331
4478
  * refresh the write notifies hangs up its control connection ({@link hangUpRevokedControlPeers})
4332
4479
  * before this resolves.
4333
4480
  *
4481
+ * Then, for each closed strand that runs here (a hibernating one is woken first), the party
4482
+ * moves onto the fresh key in the strand's own rows and the control record
4483
+ * (`strand-party-key-rotation.ts`; a second owner approval for the swap), so the removed
4484
+ * machine is left holding a key that is no longer a member there and every machine's
4485
+ * revoked-peer gate denies it. The result says per strand whether that happened here
4486
+ * ({@link MachineRemovalResult.strands}): a strand not running here is finished by any owner
4487
+ * machine that runs it, and a strand the party does not manage waits for the other party's
4488
+ * manager.
4489
+ *
4334
4490
  * Owner keys stay: they are the person's, not the machine's. A lost phone that held one can
4335
4491
  * still sign, a fresh machine invitation it could redeem included, so removing that key
4336
4492
  * ({@link removeOwner}) is the step that locks it out.
4337
4493
  *
4338
- * Not undone by this call: the machine keeps every row and strand block it already synced
4339
- * and the party's strand member keys (`tickets/blocked/decide-removed-machine-strand-access`).
4340
- * A fresh invitation re-admits it later under fresh stamps.
4494
+ * Not undone by this call: the machine keeps every row and strand block it already synced,
4495
+ * and each strand's read secret, so it can still read the blocks it holds. A fresh invitation
4496
+ * re-admits it later under fresh stamps.
4341
4497
  *
4342
- * @returns what was written ({@link MachineRemovalResult}); all false when no live row names
4343
- * the machine here (already removed elsewhere).
4498
+ * @returns what was written and rotated ({@link MachineRemovalResult}); all false and empty when
4499
+ * no live row names the machine here (already removed elsewhere).
4344
4500
  * @throws {MachineRemovalRefusedError} `'not-an-owner'` or `'self'`, before any write.
4345
4501
  */
4346
4502
  removeMachine(peerId: string): Promise<MachineRemovalResult>;
4503
+ /**
4504
+ * The strand side of {@link removeMachine}: every strand the plan placed here is woken if it
4505
+ * hibernates, then driven through the rotation; a strand placed `later` is reported `pending`
4506
+ * without being touched. Never rejects: a wake that fails leaves its strand `pending`, as does an
4507
+ * offline queue holding transactions, whose drain drives it ({@link handleQueueState}).
4508
+ */
4509
+ private rotateAfterRemoval;
4510
+ /** Wake a hibernating strand so a rotation can run against its database; a failure is logged, and the strand stays pending. */
4511
+ private wakeForRotation;
4512
+ /**
4513
+ * Who may open the pending keys a removal of `removedPeerId` writes: every live machine this
4514
+ * node trusts, and this node itself, the removed machine left out, each under the identity key
4515
+ * its peer id carries (`CadreMachine.publicKey`, derived from the id, never a stored column).
4516
+ * Which machines hold an owner key is recorded nowhere, so every one of them is a recipient.
4517
+ * This node is added from its own identity key, so it is a recipient before its own `CadrePeer`
4518
+ * row has landed.
4519
+ * NOTE: a node on an ephemeral identity (tests only; see {@link isControlNetworkMember}) seals to
4520
+ * the others alone and cannot drive what it wrote: logged, never a refusal, since locking out a
4521
+ * lost phone must not fail on it. If such a node ever becomes a supported deployment, it needs a
4522
+ * key to seal to.
4523
+ *
4524
+ * NOTE: a machine admitted after the removal is not a recipient, so an owner machine enrolled
4525
+ * while a rotation is pending cannot drive it or redeem the host's invitation under the new key;
4526
+ * a recipient owner machine has to. The app learns which machines those are from
4527
+ * {@link PendingPartyKeyRotation.sealedTo}. If a party is seen stuck that way, the remedy is the
4528
+ * replacement a second removal already writes (`ControlDatabase.removeMachine`), minted for the
4529
+ * machines present then.
4530
+ */
4531
+ private pendingPartyKeyRecipients;
4532
+ /** This machine as a sealed party key sees it: its control peer id with the identity key behind it ({@link getSelfSigningKey}), or null on an ephemeral identity. */
4533
+ private selfPartyKeyIdentity;
4534
+ /** The `PendingStrandPartyKey` row a removal writes for one strand: a fresh key, its public half in the clear and its private half sealed to `recipients`. */
4535
+ private mintPendingPartyKey;
4536
+ /**
4537
+ * {@link StrandPartyKeyRotationDeps.readPending}: the strand's pending row with its key opened
4538
+ * under this machine's identity key, or null when none is pending. Rejects when the row is not
4539
+ * sealed to this machine, or this node runs on an ephemeral identity and can open nothing; the
4540
+ * driver then reports the strand `pending` with a log, and a recipient owner machine finishes
4541
+ * it. The background triggers ask {@link isPendingPartyKeyRecipient} first, so only the
4542
+ * removal's own drive reaches that rejection.
4543
+ */
4544
+ private openPendingPartyKey;
4545
+ /**
4546
+ * {@link PartyStrandPeerSource.pendingKey} for one strand: the same read as
4547
+ * {@link openPendingPartyKey}, answering a null key rather than rejecting when the row does not
4548
+ * open here, so the membership reconciler can tell "no rotation" from "a rotation this machine
4549
+ * cannot take part in" and neither consume nor burn an invitation in the latter case.
4550
+ */
4551
+ private readPendingPartyKeyState;
4552
+ /**
4553
+ * One strand's `PendingStrandPartyKey` row as this machine can read it, shared by the driver's
4554
+ * seam and the reconciler's. Rejects when the row cannot be read, or carries an envelope that
4555
+ * does not decode or was sealed for another strand (`openPartyKey` throws on both).
4556
+ */
4557
+ private readPendingPartyKey;
4558
+ /**
4559
+ * Whether `row`'s key is sealed to this machine. The background triggers ask before driving, so
4560
+ * a machine the key was not sealed to (admitted after the removal, or on an ephemeral identity)
4561
+ * logs one line rather than a failed run on every change of the table.
4562
+ */
4563
+ private isPendingPartyKeyRecipient;
4564
+ /**
4565
+ * Drive the rotation pending for `strandId`, if one is, when this is an owner machine with the
4566
+ * strand's database live (`strand-party-key-rotation.ts`) and the pending key is sealed to it.
4567
+ * Called in the background from the strand lifecycle (launch, resume, writable, queue drained); a strand with
4568
+ * nothing pending costs one control read. Never on a machine removed from the cadre
4569
+ * ({@link removedFromCadre}): it may hold an owner key and a key an earlier removal sealed to
4570
+ * it, and it is no longer a member whatever it holds, as the owner re-issue drains already
4571
+ * stop. Never rejects.
4572
+ */
4573
+ private driveRotationIfPending;
4574
+ /** {@link driveRotationIfPending} for every closed strand running here, one run; for the watch and the growth drain. */
4575
+ private driveTrackedPendingRotations;
4576
+ /**
4577
+ * The party key watch's run: for every tracked closed strand, re-key the instance when the
4578
+ * `StrandPartyKey` row names a key other than the one it runs under (a rotation finished on
4579
+ * another machine), then drive whatever rotation is pending here.
4580
+ */
4581
+ private onPartyKeyTablesChanged;
4582
+ /**
4583
+ * Step 6 of a party key rotation ({@link StrandPartyKeyRotationDeps.swapKeys}): the control
4584
+ * swap for every entry under one owner approval, deferred while a control write could fork the
4585
+ * party ({@link controlWriteCouldFork}); the growth drain re-drives it. The tombstones it files
4586
+ * ride the committed-delete seam like every other removal's.
4587
+ */
4588
+ private swapStrandPartyKeys;
4347
4589
  /**
4348
4590
  * The read behind {@link listMachines}: the live `CadrePeer` rows projected as machines, with
4349
4591
  * this node's membership predicate as the `trusted` test.
4350
4592
  */
4351
4593
  private readMachines;
4594
+ /** {@link readMachines} over `rows` already read, for a caller that read them fresh. */
4595
+ private describeMachineRows;
4596
+ /**
4597
+ * The control-database seam of one strand's launch for the party's machines in it
4598
+ * (`StartStrandConfig.partyPeers`, `strand-party-peers.ts`): this machine's own `StrandPeer`
4599
+ * row, the party's other machines' peer ids, and the party's pending key in the strand as this
4600
+ * machine can read it. The reads reject rather than answer "nothing" when the control database
4601
+ * is gone, which the reconciler and the offline queue's machine tracker treat as "unknown".
4602
+ */
4603
+ private partyStrandPeerSource;
4604
+ /** The control database, or a throw naming what `purpose` needed it for, for a seam whose caller contains the throw. */
4605
+ private requireControlDatabase;
4606
+ /**
4607
+ * Publish this machine's peer id in `strandId` to the party's control database — its
4608
+ * `StrandPeer` row, signed by the identity key as the self record is
4609
+ * ({@link ControlDatabase.insertStrandPeer}). Insert-if-absent, and remembered once present
4610
+ * ({@link strandPeerRowsHeld}), so the per-pass re-attempt the membership reconciler makes
4611
+ * costs nothing after the first. A background write like the self-record publish: nothing is
4612
+ * written while a write could fork the party ({@link controlWriteCouldFork}), and a refusal —
4613
+ * the schema wants this machine's own `CadrePeer` row, which may not have reached this node —
4614
+ * is logged; either leaves the row in {@link deferredStrandPeerWrites} for the growth drain,
4615
+ * the party-machine watch and the next reconciler pass. Written regardless of whether this machine holds the party's
4616
+ * member key: a storage replica is bound by its siblings. A node on an ephemeral identity
4617
+ * cannot sign the row and writes nothing. Never rejects.
4618
+ */
4619
+ private publishStrandPeer;
4620
+ /** The re-attempt of every `StrandPeer` row in {@link deferredStrandPeerWrites} (growth drain, party-machine watch); each contains its own failure. */
4621
+ private publishDeferredStrandPeers;
4622
+ /**
4623
+ * The party's machines' peer ids in `strandId` ({@link PartyStrandPeers}): the strand's
4624
+ * `StrandPeer` rows joined to the party's live machines and its `CadrePeer` tombstones
4625
+ * (`partitionPartyStrandPeers`). The membership rows are read FRESH
4626
+ * ({@link ControlDatabase.queryMachineRowsFresh}), not from the membership views: a
4627
+ * sibling that binds a machine under the party's new key from a view that has not heard
4628
+ * of the machine's removal would bind the machine the rotation exists to shut out, and
4629
+ * the views' lag is exactly that window. Rejects when any read fails; never answers
4630
+ * "no machines" for a failed read.
4631
+ */
4632
+ private readPartyStrandPeers;
4352
4633
  /**
4353
4634
  * Create a seed from the current control network state.
4354
4635
  * The seed contains peer information and is signed by an owner.