@serfab/cadre-core 1.22.0 → 1.24.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 (314) hide show
  1. package/README.md +216 -294
  2. package/dist/arachnode-stub.d.ts +12 -4
  3. package/dist/arachnode-stub.js +15 -8
  4. package/dist/arachnode-stub.js.map +1 -1
  5. package/dist/cadre-invite-protocol.js +5 -4
  6. package/dist/cadre-invite-protocol.js.map +1 -1
  7. package/dist/cadre-node.d.ts +159 -53
  8. package/dist/cadre-node.js +276 -89
  9. package/dist/cadre-node.js.map +1 -1
  10. package/dist/control-authorization.d.ts +14 -2
  11. package/dist/control-authorization.js +8 -3
  12. package/dist/control-authorization.js.map +1 -1
  13. package/dist/control-cohort.d.ts +27 -13
  14. package/dist/control-cohort.js +21 -14
  15. package/dist/control-cohort.js.map +1 -1
  16. package/dist/control-database.d.ts +18 -16
  17. package/dist/control-database.js +57 -22
  18. package/dist/control-database.js.map +1 -1
  19. package/dist/control-protocol-guard.d.ts +1 -1
  20. package/dist/control-protocol-guard.js +7 -3
  21. package/dist/control-protocol-guard.js.map +1 -1
  22. package/dist/control-read-retry.d.ts +49 -11
  23. package/dist/control-read-retry.js +56 -15
  24. package/dist/control-read-retry.js.map +1 -1
  25. package/dist/control-retry.d.ts +32 -3
  26. package/dist/control-retry.js +35 -4
  27. package/dist/control-retry.js.map +1 -1
  28. package/dist/control-schema-version.d.ts +5 -5
  29. package/dist/control-schema-version.js +5 -5
  30. package/dist/control-schema-version.js.map +1 -1
  31. package/dist/control-schema.d.ts +5 -5
  32. package/dist/control-schema.js +1032 -1011
  33. package/dist/control-schema.js.map +1 -1
  34. package/dist/control-write-retry.d.ts +54 -65
  35. package/dist/control-write-retry.js +134 -158
  36. package/dist/control-write-retry.js.map +1 -1
  37. package/dist/delegate-admission.d.ts +1 -1
  38. package/dist/delegate-admission.js +1 -1
  39. package/dist/edge-node/config.d.ts +4 -3
  40. package/dist/edge-node/config.js +11 -9
  41. package/dist/edge-node/config.js.map +1 -1
  42. package/dist/edge-node/dissolve.d.ts +4 -4
  43. package/dist/edge-node/dissolve.js +4 -4
  44. package/dist/edge-node/edge-join.d.ts +1 -1
  45. package/dist/edge-node/edge-join.js +1 -1
  46. package/dist/edge-node/edge-node.js +2 -2
  47. package/dist/edge-node/edge-node.js.map +1 -1
  48. package/dist/edge-node/index.d.ts +1 -0
  49. package/dist/edge-node/index.js +1 -0
  50. package/dist/edge-node/index.js.map +1 -1
  51. package/dist/edge-node/join-credential.d.ts +1 -1
  52. package/dist/edge-node/join-credential.js +1 -1
  53. package/dist/edge-node/lazy-raw-storage.js +12 -0
  54. package/dist/edge-node/lazy-raw-storage.js.map +1 -1
  55. package/dist/edge-node/listen-addrs.d.ts +21 -0
  56. package/dist/edge-node/listen-addrs.js +25 -0
  57. package/dist/edge-node/listen-addrs.js.map +1 -0
  58. package/dist/edge-node/owner-grant.d.ts +1 -1
  59. package/dist/edge-node/owner-grant.js +1 -1
  60. package/dist/edge-node/platform.d.ts +5 -4
  61. package/dist/edge-node/platform.js.map +1 -1
  62. package/dist/edge-node/strand-move.d.ts +1 -1
  63. package/dist/edge-node/strand-move.js +1 -1
  64. package/dist/edge-node/strands.js +27 -11
  65. package/dist/edge-node/strands.js.map +1 -1
  66. package/dist/index.d.ts +7 -5
  67. package/dist/index.js +18 -7
  68. package/dist/index.js.map +1 -1
  69. package/dist/invitation-bootstrap.d.ts +28 -5
  70. package/dist/invitation-bootstrap.js +41 -8
  71. package/dist/invitation-bootstrap.js.map +1 -1
  72. package/dist/link-budget.d.ts +53 -4
  73. package/dist/link-budget.js +58 -5
  74. package/dist/link-budget.js.map +1 -1
  75. package/dist/machine-removal.d.ts +2 -2
  76. package/dist/machine-removal.js +4 -3
  77. package/dist/machine-removal.js.map +1 -1
  78. package/dist/membership-connection-gater.d.ts +2 -2
  79. package/dist/membership-connection-gater.js +2 -2
  80. package/dist/membership-view.d.ts +2 -2
  81. package/dist/membership-view.js +6 -3
  82. package/dist/membership-view.js.map +1 -1
  83. package/dist/node-claim-payload.d.ts +15 -7
  84. package/dist/node-claim-payload.js +25 -9
  85. package/dist/node-claim-payload.js.map +1 -1
  86. package/dist/node-class.d.ts +36 -0
  87. package/dist/node-class.js +26 -0
  88. package/dist/node-class.js.map +1 -0
  89. package/dist/node-default-transports.d.ts +50 -3
  90. package/dist/node-default-transports.js +48 -3
  91. package/dist/node-default-transports.js.map +1 -1
  92. package/dist/node-roles.d.ts +118 -0
  93. package/dist/node-roles.js +142 -0
  94. package/dist/node-roles.js.map +1 -0
  95. package/dist/node-transports.d.ts +6 -2
  96. package/dist/node-transports.js +39 -7
  97. package/dist/node-transports.js.map +1 -1
  98. package/dist/owner-anchor-sync.js +1 -1
  99. package/dist/owner-key-export.js +1 -1
  100. package/dist/owner-key-flows.d.ts +1 -1
  101. package/dist/owner-key-store.js +1 -1
  102. package/dist/owner-signer.js +1 -1
  103. package/dist/peer-authorization.d.ts +3 -1
  104. package/dist/peer-authorization.js +3 -1
  105. package/dist/peer-authorization.js.map +1 -1
  106. package/dist/peer-dial.d.ts +74 -10
  107. package/dist/peer-dial.js +89 -17
  108. package/dist/peer-dial.js.map +1 -1
  109. package/dist/peer-join-backfill.js +4 -4
  110. package/dist/peer-join-backfill.js.map +1 -1
  111. package/dist/peer-record.d.ts +34 -9
  112. package/dist/peer-record.js +66 -13
  113. package/dist/peer-record.js.map +1 -1
  114. package/dist/pending-join-runner.d.ts +1 -1
  115. package/dist/pending-join-runner.js +1 -1
  116. package/dist/provider/client.d.ts +6 -5
  117. package/dist/provider/client.js +3 -3
  118. package/dist/provider/client.js.map +1 -1
  119. package/dist/provider/descriptor.d.ts +1 -1
  120. package/dist/provider/descriptor.js +1 -1
  121. package/dist/provider/oauth.d.ts +1 -1
  122. package/dist/provider/oauth.js +1 -1
  123. package/dist/provider/rent-node.d.ts +4 -3
  124. package/dist/provider/rent-node.js +3 -3
  125. package/dist/provider/rent-node.js.map +1 -1
  126. package/dist/relay-addrs.d.ts +62 -7
  127. package/dist/relay-addrs.js +74 -11
  128. package/dist/relay-addrs.js.map +1 -1
  129. package/dist/relay-reservation.d.ts +1 -1
  130. package/dist/relay-reservation.js +1 -1
  131. package/dist/relay-server.d.ts +6 -5
  132. package/dist/relay-server.js +5 -5
  133. package/dist/relay-server.js.map +1 -1
  134. package/dist/schema-verification.d.ts +13 -10
  135. package/dist/schema-verification.js +32 -24
  136. package/dist/schema-verification.js.map +1 -1
  137. package/dist/sealed-party-key.js +1 -1
  138. package/dist/seed-bootstrap.d.ts +4 -3
  139. package/dist/seed-bootstrap.js +6 -7
  140. package/dist/seed-bootstrap.js.map +1 -1
  141. package/dist/strand-addr-protocol.d.ts +8 -6
  142. package/dist/strand-addr-protocol.js +12 -10
  143. package/dist/strand-addr-protocol.js.map +1 -1
  144. package/dist/strand-app-schema-report.d.ts +16 -2
  145. package/dist/strand-app-schema-report.js +15 -0
  146. package/dist/strand-app-schema-report.js.map +1 -1
  147. package/dist/strand-cohort.d.ts +1 -4
  148. package/dist/strand-cohort.js.map +1 -1
  149. package/dist/strand-commit-durability.d.ts +1 -1
  150. package/dist/strand-database.d.ts +13 -6
  151. package/dist/strand-database.js +17 -9
  152. package/dist/strand-database.js.map +1 -1
  153. package/dist/strand-first-sync-gate.d.ts +3 -2
  154. package/dist/strand-first-sync-gate.js +3 -2
  155. package/dist/strand-first-sync-gate.js.map +1 -1
  156. package/dist/strand-formation-deadlines.d.ts +2 -2
  157. package/dist/strand-formation-deadlines.js +2 -2
  158. package/dist/strand-formation-protocol.d.ts +1 -1
  159. package/dist/strand-formation-protocol.js +51 -16
  160. package/dist/strand-formation-protocol.js.map +1 -1
  161. package/dist/strand-instance-manager.d.ts +134 -42
  162. package/dist/strand-instance-manager.js +331 -76
  163. package/dist/strand-instance-manager.js.map +1 -1
  164. package/dist/strand-membership-reconciler.d.ts +8 -3
  165. package/dist/strand-membership-reconciler.js +8 -3
  166. package/dist/strand-membership-reconciler.js.map +1 -1
  167. package/dist/strand-membership-writer.d.ts +2 -2
  168. package/dist/strand-membership-writer.js +41 -39
  169. package/dist/strand-membership-writer.js.map +1 -1
  170. package/dist/strand-move.js +1 -1
  171. package/dist/strand-network-config.d.ts +15 -5
  172. package/dist/strand-network-config.js +7 -6
  173. package/dist/strand-network-config.js.map +1 -1
  174. package/dist/strand-party-key-rotation.d.ts +7 -3
  175. package/dist/strand-party-key-rotation.js +7 -3
  176. package/dist/strand-party-key-rotation.js.map +1 -1
  177. package/dist/strand-party-machines.d.ts +19 -8
  178. package/dist/strand-party-machines.js +26 -11
  179. package/dist/strand-party-machines.js.map +1 -1
  180. package/dist/strand-party-peers.d.ts +36 -14
  181. package/dist/strand-party-peers.js +24 -15
  182. package/dist/strand-party-peers.js.map +1 -1
  183. package/dist/strand-peer-redial.d.ts +1 -1
  184. package/dist/strand-peer-redial.js +1 -1
  185. package/dist/strand-reactivity.d.ts +20 -17
  186. package/dist/strand-reactivity.js +31 -18
  187. package/dist/strand-reactivity.js.map +1 -1
  188. package/dist/strand-revocation-enforcer.d.ts +3 -3
  189. package/dist/strand-revocation-enforcer.js +3 -3
  190. package/dist/strand-wake-protocol.d.ts +19 -7
  191. package/dist/strand-wake-protocol.js +22 -10
  192. package/dist/strand-wake-protocol.js.map +1 -1
  193. package/dist/strand-watcher.d.ts +1 -1
  194. package/dist/strand-watcher.js +1 -1
  195. package/dist/table-change-watch.js +1 -1
  196. package/dist/types.d.ts +127 -57
  197. package/dist/types.js.map +1 -1
  198. package/dist/webrtc-upgrade.d.ts +254 -0
  199. package/dist/webrtc-upgrade.js +355 -0
  200. package/dist/webrtc-upgrade.js.map +1 -0
  201. package/package.json +9 -9
  202. package/src/announce-addrs.ts +93 -93
  203. package/src/arachnode-stub.ts +18 -10
  204. package/src/bootstrap-peer-store-file.ts +44 -44
  205. package/src/bootstrap-peer-store.ts +214 -214
  206. package/src/cadre-invite-protocol.ts +741 -740
  207. package/src/cadre-node.ts +12462 -12252
  208. package/src/claim-proof.ts +147 -147
  209. package/src/control-authorization.ts +290 -276
  210. package/src/control-cohort.ts +223 -204
  211. package/src/control-database.ts +72 -28
  212. package/src/control-formation-recorder.ts +359 -359
  213. package/src/control-protocol-guard.ts +370 -366
  214. package/src/control-read-retry.ts +222 -180
  215. package/src/control-retry.ts +36 -4
  216. package/src/control-schema-version.ts +301 -301
  217. package/src/control-schema.ts +1108 -1087
  218. package/src/control-write-retry.ts +639 -669
  219. package/src/delegate-admission.ts +351 -351
  220. package/src/describe-thrown.ts +60 -60
  221. package/src/ed25519-key.ts +185 -185
  222. package/src/edge-node/config.ts +13 -10
  223. package/src/edge-node/dissolve.ts +252 -252
  224. package/src/edge-node/edge-join.ts +320 -320
  225. package/src/edge-node/edge-node.ts +1095 -1095
  226. package/src/edge-node/index.ts +60 -59
  227. package/src/edge-node/join-credential.ts +16 -16
  228. package/src/edge-node/lazy-raw-storage.ts +194 -178
  229. package/src/edge-node/listen-addrs.ts +26 -0
  230. package/src/edge-node/node-local.ts +84 -84
  231. package/src/edge-node/options.ts +195 -195
  232. package/src/edge-node/owner-grant.ts +63 -63
  233. package/src/edge-node/platform.ts +5 -4
  234. package/src/edge-node/strand-move.ts +266 -266
  235. package/src/edge-node/strands.ts +27 -12
  236. package/src/enrolled-machine-store-file.ts +43 -43
  237. package/src/enrolled-machine-store.ts +280 -280
  238. package/src/fetch-impl.ts +23 -23
  239. package/src/file-durable-slot.ts +64 -64
  240. package/src/file-safe-name.ts +32 -32
  241. package/src/formation-approval.ts +604 -604
  242. package/src/formation-token.ts +63 -63
  243. package/src/fs-atomic.ts +92 -92
  244. package/src/index.ts +987 -957
  245. package/src/invitation-bootstrap.ts +152 -118
  246. package/src/joined-strand-store.ts +553 -553
  247. package/src/key-store-file.ts +142 -142
  248. package/src/link-budget.ts +61 -5
  249. package/src/machine-removal.ts +211 -210
  250. package/src/member-redemption.ts +643 -643
  251. package/src/membership-connection-gater.ts +650 -650
  252. package/src/membership-view.ts +147 -144
  253. package/src/node-claim-payload.ts +34 -12
  254. package/src/node-class.ts +47 -0
  255. package/src/node-default-transports.ts +65 -3
  256. package/src/node-roles.ts +220 -0
  257. package/src/node-transports.ts +86 -49
  258. package/src/owner-anchor-sync.ts +172 -172
  259. package/src/owner-grant-protocol.ts +547 -547
  260. package/src/owner-key-export.ts +348 -348
  261. package/src/owner-key-flows.ts +109 -109
  262. package/src/owner-key-store.ts +1 -1
  263. package/src/owner-keys.ts +179 -179
  264. package/src/owner-signer.ts +92 -92
  265. package/src/peer-addr-book.ts +252 -252
  266. package/src/peer-authorization.ts +584 -582
  267. package/src/peer-dial.ts +698 -605
  268. package/src/peer-join-backfill.ts +961 -961
  269. package/src/peer-record.ts +71 -16
  270. package/src/pending-join-runner.ts +798 -798
  271. package/src/primary-lan-address.ts +47 -47
  272. package/src/provider/client.ts +327 -326
  273. package/src/provider/descriptor.ts +129 -129
  274. package/src/provider/index.ts +59 -59
  275. package/src/provider/oauth.ts +285 -285
  276. package/src/provider/rent-node.ts +276 -275
  277. package/src/relay-addrs.ts +90 -12
  278. package/src/relay-reservation.ts +1 -1
  279. package/src/relay-server.ts +99 -98
  280. package/src/schema-verification.ts +38 -23
  281. package/src/sealed-party-key.ts +190 -190
  282. package/src/seed-bootstrap.ts +8 -11
  283. package/src/seed-trust-policy.ts +353 -353
  284. package/src/self-address-update.ts +19 -19
  285. package/src/strand-addr-protocol.ts +17 -14
  286. package/src/strand-app-schema-report.ts +147 -122
  287. package/src/strand-cohort.ts +1 -5
  288. package/src/strand-commit-durability.ts +165 -165
  289. package/src/strand-database.ts +522 -510
  290. package/src/strand-first-sync-gate.ts +3 -2
  291. package/src/strand-formation-deadlines.ts +227 -227
  292. package/src/strand-formation-manager.ts +731 -731
  293. package/src/strand-formation-protocol.ts +1174 -1138
  294. package/src/strand-fret-addrs.ts +179 -179
  295. package/src/strand-instance-manager.ts +381 -85
  296. package/src/strand-membership-reconciler.ts +1315 -1310
  297. package/src/strand-membership-writer.ts +2152 -2150
  298. package/src/strand-move.ts +1 -1
  299. package/src/strand-network-config.ts +16 -6
  300. package/src/strand-offline.ts +178 -178
  301. package/src/strand-party-key-rotation.ts +440 -436
  302. package/src/strand-party-machines.ts +308 -293
  303. package/src/strand-party-peers.ts +151 -129
  304. package/src/strand-peer-redial.ts +1 -1
  305. package/src/strand-reactivity.ts +36 -19
  306. package/src/strand-revocation-enforcer.ts +758 -758
  307. package/src/strand-wake-protocol.ts +406 -394
  308. package/src/strand-watcher.ts +1 -1
  309. package/src/table-change-watch.ts +285 -285
  310. package/src/timed-step.ts +28 -28
  311. package/src/timeout-scheduler.ts +29 -29
  312. package/src/trusted-owner-store.ts +242 -242
  313. package/src/types.ts +3182 -3112
  314. package/src/webrtc-upgrade.ts +439 -0
@@ -32,17 +32,19 @@ import { StrandPartyKeyRotationDriver } from './strand-party-key-rotation.js';
32
32
  import { openPartyKey, partyKeyRecipients, sealPartyKey } from './sealed-party-key.js';
33
33
  import { describeOwnerKeys, namedOwnerKey, planOwnerKeyRemoval, revouchWithinPlan, OwnerKeyAddRefusedError, OwnerKeyRemovalRefusedError } from './owner-keys.js';
34
34
  import { ed25519PublicKeyB64FromPeerId } from './ed25519-key.js';
35
- import { signPeerRecord, verifyPeerRecordSignature, isPeerRecordFresh, orderSignalingFirst, isSignalingAddr, currentMemberTrustPolicy, DEFAULT_PEER_RECORD_MAX_AGE_MS, DEFAULT_PEER_RECORD_HEARTBEAT_MS } from './peer-record.js';
35
+ import { signPeerRecord, verifyPeerRecordSignature, isPeerRecordFresh, orderRelayedFirst, isSignalingAddr, firstRelayedAddr, currentMemberTrustPolicy, DEFAULT_PEER_RECORD_MAX_AGE_MS, DEFAULT_PEER_RECORD_HEARTBEAT_MS } from './peer-record.js';
36
36
  import { signDeviceTokenRecord, verifyDeviceTokenSignature, isPushPlatform } from './device-token.js';
37
37
  import { StrandWatcher, DEFAULT_STRAND_WATCH_BACKSTOP_MS } from './strand-watcher.js';
38
38
  import { StrandInstanceManager, liveStrandStatus } from './strand-instance-manager.js';
39
39
  import { PeerJoinBackfill } from './peer-join-backfill.js';
40
+ import { WebrtcUpgradeService } from './webrtc-upgrade.js';
40
41
  import { deriveCohortMembers } from './strand-cohort.js';
41
- import { selectControlCohortDials, nextReconcileWakeMs, CLAIM_RESTART_REDIAL_STEP_MS, CONTROL_COHORT_REDIAL_MS, DEFAULT_CONTROL_COHORT_RECONCILE_MS, DEFAULT_CONTROL_COHORT_TARGET_DEGREE } from './control-cohort.js';
42
+ import { encodeAlwaysOn } from './node-class.js';
43
+ import { controlCohortSiblingsOf, selectControlCohortDials, nextReconcileWakeMs, CLAIM_RESTART_REDIAL_STEP_MS, CONTROL_COHORT_REDIAL_MS, DEFAULT_CONTROL_COHORT_RECONCILE_MS, DEFAULT_CONTROL_COHORT_TARGET_DEGREE } from './control-cohort.js';
42
44
  import { scheduleRuns } from './table-change-watch.js';
43
45
  import { MEMBERSHIP_VIEW_RECONNECT_RELOAD_MS } from './membership-view.js';
44
46
  import { dialPeerAddrs, SelfRelayOnlyError, CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS, trailingPeerId, withTrailingPeerId } from './peer-dial.js';
45
- import { ADMISSION_DECISION_TIMEOUT_MS, declaredCohortReadDeadlineMs, optimysticDialLimits, peerJoinPushBudget, relayReservationBudgetMs, relayedDialBudgetMs, relayedRequestBudgetMs, resolveLinkRoundTripMs } from './link-budget.js';
47
+ import { ADMISSION_DECISION_TIMEOUT_MS, declaredCohortReadDeadlineMs, optimysticDialLimits, peerJoinPushBudget, relayReservationBudgetMs, relayedDialBudgetMs, relayedRequestBudgetMs, resolveLinkRoundTripMs, webrtcUpgradeDialBudgetMs } from './link-budget.js';
46
48
  import { EnrollmentService } from './enrollment.js';
47
49
  import { HibernationManager } from './hibernation-manager.js';
48
50
  import { ControlDatabase, generateStampId, isPendingJoinConflict, isStrandIdConflict, IssuedRowNotHereYetError, pendingJoinId } from './control-database.js';
@@ -61,10 +63,11 @@ import { controlNetworkName, installControlProtocolGuard, servesControlDatabase
61
63
  import { StrandWakeService, dialWake } from './strand-wake-protocol.js';
62
64
  import { StrandAddrService, collectStrandAddrs, nextStrandAddrAsk } from './strand-addr-protocol.js';
63
65
  import { DelegateAdmissionStore, extractCircuitRelayTargets, dueRelayAnnounces, prunePeerStrandKeys, peerStrandKey, recordRelayRefusals, relaysNotRefusing } from './delegate-admission.js';
64
- import { relayCircuitAddrs, resolveListenAddrs, resolveTransportOptions, RelayReservationFailedError } from './relay-addrs.js';
66
+ import { relayCircuitAddrs, resolveListenAddrs, resolveTransportOptions, listenTransportNodeOptions, RelayReservationFailedError } from './relay-addrs.js';
65
67
  import { selfAddressesChanged } from './self-address-update.js';
66
68
  import { nodeTransportsOption } from './node-transports.js';
67
69
  import { resolveRelayServer } from './relay-server.js';
70
+ import { resolveHostUnclaimedStrands, resolveNodeRoles } from './node-roles.js';
68
71
  import { replacesAdvertisedAddrs, resolveAnnounceAddrs } from './announce-addrs.js';
69
72
  import { superviseRelayReservation, resolveRelayReservationState } from './relay-reservation.js';
70
73
  import { PushFanoutService } from './push-fanout.js';
@@ -161,7 +164,7 @@ function addressesOfFirst(members, peerId) {
161
164
  * freshly-RPC'd sibling answers and the addresses the strand's formation carried. The
162
165
  * caller passes the FRESHER source as `primary`, so a stale entry can only ever be
163
166
  * appended, never promoted ahead of a current one, and each source keeps whatever
164
- * signaling-first ordering it arrived with.
167
+ * relayed-first ordering it arrived with.
165
168
  */
166
169
  function unionAddrs(primary, extra) {
167
170
  if (extra.length === 0) {
@@ -305,6 +308,13 @@ export class CadreNode {
305
308
  * start() cycle rebuilds it with a fresh caught-up-peer memo.
306
309
  */
307
310
  this.controlBackfill = null;
311
+ /**
312
+ * The control node's background WebRTC upgrade of its relayed connections
313
+ * ({@link startWebrtcUpgrade}). Created in {@link start} and stopped in {@link cleanup}
314
+ * beside the backfill, so a stop()→start() cycle starts over with no backoff state from the
315
+ * previous session.
316
+ */
317
+ this.webrtcUpgrade = null;
308
318
  /**
309
319
  * Devices whose invitation redemption this member has verified and is admitting right now,
310
320
  * each with its count of overlapping redemptions. The control backfill's gate and the
@@ -690,6 +700,8 @@ export class CadreNode {
690
700
  * is up — only a strand with no runtime at all answers retryably meanwhile.
691
701
  */
692
702
  this.strandLaunchRefusals = new Map();
703
+ /** {@link stopAppSchemaRefusedStrand} runs in flight, keyed by strandId, so a second report joins the first. */
704
+ this.appSchemaStops = new Map();
693
705
  /**
694
706
  * Dial targets learned out of band, keyed by peer id, valued by the multiaddr
695
707
  * strings this node was handed (parsed lazily, at dial time). Two writers:
@@ -959,10 +971,11 @@ export class CadreNode {
959
971
  /** `connection:close` listener: {@link onControlConnectionClosed} (teardown in {@link stopRecordRefresh}). */
960
972
  this.controlConnectionCloseHandler = null;
961
973
  this.config = config;
962
- this.hostUnclaimedStrands = config.hostUnclaimedStrands ?? config.profile === 'storage';
974
+ this.roles = resolveNodeRoles(config.nodeClass, config.roles);
975
+ this.hostUnclaimedStrands = resolveHostUnclaimedStrands(config.hostUnclaimedStrands, this.roles);
963
976
  this.strandManager = new StrandInstanceManager();
964
977
  this.enrollmentService = new EnrollmentService();
965
- this.relayServer = resolveRelayServer(config.network, config.profile);
978
+ this.relayServer = resolveRelayServer(config.network, this.roles);
966
979
  this.unauthorizedRelayReservations = new UnauthorizedReservationBudget(config.network?.unauthorizedRelayReservationCap, this.relayServer.init.reservations.reservationTtl);
967
980
  // Create hibernation manager with callbacks
968
981
  const hibernationCallbacks = {
@@ -1227,8 +1240,8 @@ export class CadreNode {
1227
1240
  // strand's loop runs one confirming pass per heartbeat of any party machine, and on a
1228
1241
  // node offering offline mode each running strand's machine tracker one control read
1229
1242
  // (`readPartyStrandPeers`: the strand's rows and the machine rows read fresh); the
1230
- // reconciler's pass NOTE says what the pass costs. If that read ever shows in a phone's
1231
- // profile, refresh the trackers only on a `StrandPeer` or `Revocation` change and on a
1243
+ // reconciler's pass NOTE says what the pass costs. If that read ever shows up in a phone's
1244
+ // CPU profile, refresh the trackers only on a `StrandPeer` or `Revocation` change and on a
1232
1245
  // `CadrePeer` row's appearance or disappearance, not on every heartbeat. A table this
1233
1246
  // `Database` has not yet touched hears local commits only (`table-change-watch.ts`):
1234
1247
  // `StrandPeer` is first read by the publish every strand launch makes, by the tracker's
@@ -1337,6 +1350,10 @@ export class CadreNode {
1337
1350
  // control libp2p node reports a peer connection, and arming it at start is
1338
1351
  // what closes the "genesised alone, headers never replicate" hole.
1339
1352
  this.startControlBackfill();
1353
+ // Try a direct WebRTC connection in the background wherever this node ends up talking to
1354
+ // a machine through a relay. Nothing in libp2p does this, and since every dial a caller
1355
+ // waits on now goes relayed-first, nothing else opens a WebRTC connection at all.
1356
+ this.startWebrtcUpgrade();
1340
1357
  // Seed the per-stream gate's materialized authorized set now that the
1341
1358
  // control DB is up (non-blocking; the helper never rejects). Until it
1342
1359
  // lands the snapshot is empty, which the stream gate treats as cold
@@ -1901,6 +1918,40 @@ export class CadreNode {
1901
1918
  });
1902
1919
  this.controlBackfill.start();
1903
1920
  }
1921
+ /**
1922
+ * Arm the control node's background WebRTC upgrade: whenever a machine identifies over a
1923
+ * relayed connection and publishes a WebRTC address, dial it once and let new streams move to
1924
+ * the direct connection (`webrtc-upgrade.ts`). The service is inert on a node whose embedder
1925
+ * passed no WebRTC transport: the phones and browser tabs always have one, and a Node host
1926
+ * has one when it asked for it (`cadre-cli`'s `network.webrtc`, which resolves to a `/webrtc`
1927
+ * listen entry — see `node-default-transports.ts`).
1928
+ *
1929
+ * Who this can reach is narrower than the connection gate, and not by anything here: the
1930
+ * trigger is `peer:identify`, and Optimystic gives each control node an identify protocol id
1931
+ * naming its own party (`/optimystic/control-<partyId>/id/1.0.0`, the table in
1932
+ * `control-protocol-guard.ts`). Another party's control node never completes identify with this
1933
+ * one, so a formation joiner or a stranger dialing through this node's relay is never a
1934
+ * candidate however long its connection stays open. What is left is this party's own machines
1935
+ * and a device redeeming an invitation INTO this party.
1936
+ *
1937
+ * NOTE: that device is the one case where an upgrade is attempted against a peer this node has
1938
+ * not yet admitted, and ICE tells it this machine's own interface addresses and the address a
1939
+ * STUN server sees it at, which the relayed connection did not. Accepted: it is a machine in
1940
+ * the act of becoming a member, and the same connection already carries the redemption. If
1941
+ * that exposure ever matters, gate this service's attempts on {@link isAuthorizedMember}
1942
+ * rather than narrowing the gate.
1943
+ */
1944
+ startWebrtcUpgrade() {
1945
+ if (!this.controlNode) {
1946
+ return;
1947
+ }
1948
+ this.webrtcUpgrade = new WebrtcUpgradeService({
1949
+ label: this.controlNetworkName(),
1950
+ node: this.controlNode,
1951
+ dialTimeoutMs: webrtcUpgradeDialBudgetMs(this.config.network?.linkRoundTripMs)
1952
+ });
1953
+ this.webrtcUpgrade.start();
1954
+ }
1904
1955
  /**
1905
1956
  * Admit a device whose invitation redemption has verified to this member's control
1906
1957
  * replication until the returned release is called (the handler's `admitDevice`;
@@ -2055,7 +2106,7 @@ export class CadreNode {
2055
2106
  * only caller in production is `createControlNode`.
2056
2107
  */
2057
2108
  buildControlNodeOptions() {
2058
- const { network, profile } = this.config;
2109
+ const { network } = this.config;
2059
2110
  const identityKey = this.identityKey;
2060
2111
  // `network.relayAddrs` contributes the bare `/p2p-circuit` SEARCH entry, which
2061
2112
  // opens no connection — the reservation is driven explicitly at the END of
@@ -2079,7 +2130,7 @@ export class CadreNode {
2079
2130
  bootstrapNodes: [],
2080
2131
  networkName: this.controlNetworkName(),
2081
2132
  storage: controlStorageProvider,
2082
- fretProfile: profile === 'storage' ? 'core' : 'edge',
2133
+ fretProfile: this.roles.overlayTier,
2083
2134
  relay: this.relayServer.enabled,
2084
2135
  // Merged party-run defaults: no per-connection data/duration cap, a store sized for
2085
2136
  // one party's NAT'd machines. Strand nodes get the same init (`relay-server.ts`).
@@ -2108,7 +2159,10 @@ export class CadreNode {
2108
2159
  enrolledMachines: this.declaredEnrolledMachines,
2109
2160
  cohortQueryTimeoutMs: declaredCohortReadDeadlineMs(network)
2110
2161
  }),
2111
- arachnode: { enableRingZulu: profile === 'storage' },
2162
+ // Ring Zulu follows `alwaysOn` rather than being a role of its own: the storage rings it
2163
+ // hints at are unimplemented, so there is nothing else to configure yet
2164
+ // (`backlog/later/5-ring-zulu-storage-rings`).
2165
+ arachnode: { enableRingZulu: this.roles.alwaysOn },
2112
2166
  // One join catch-up per node, for the strand node's reason (`strand-instance-manager.ts`,
2113
2167
  // at its `rebalance` option): Optimystic's rebalance growth arm would push a joining
2114
2168
  // member each control block again, one request per block. Every peer the growth arm
@@ -2150,8 +2204,10 @@ export class CadreNode {
2150
2204
  // `{}` when `network.transports` is set, since the embedder owns transport policy
2151
2205
  // then. Spread NEXT to `transports` because the two answer the same question, and a
2152
2206
  // no-op whenever a list is passed there — with `relayAddrs` set that list comes from
2153
- // `network.defaultTransports` when the embedder gave none, on the same switch.
2154
- ...transportOptions,
2207
+ // `network.defaultTransports` when the embedder gave none, on the same switch. The
2208
+ // resolution's WebRTC half is not a db-p2p option and is dropped here
2209
+ // (`listenTransportNodeOptions`); `nodeTransportsOption` above is what reads it.
2210
+ ...listenTransportNodeOptions(transportOptions),
2155
2211
  // Configured `listenAddrs`, plus the bare `/p2p-circuit` search listener when
2156
2212
  // `network.relayAddrs` is set — that listener registers the pending reservation
2157
2213
  // `driveControlRelayReservation` fills after bring-up.
@@ -2173,11 +2229,11 @@ export class CadreNode {
2173
2229
  admitRelayReservation: (remotePeerId) => this.admitControlRelayReservation(remotePeerId),
2174
2230
  bringUpInFlight: () => this.controlBringUpInFlight
2175
2231
  }, network?.connectionGater, ADMISSION_DECISION_TIMEOUT_MS, relayedRequestBudgetMs(network?.linkRoundTripMs)),
2176
- // Fail-closed per-stream authorization for the four Optimystic control-DB
2232
+ // Fail-closed per-stream authorization for the five Optimystic control-DB
2177
2233
  // protocols — the members-only layer the connection gater's stranger
2178
2234
  // carve-outs cannot express (see authorizeInboundControlStream). Control
2179
2235
  // node only: strand cohort nodes serve cross-party peers. The protocol guard
2180
- // (installControlProtocolGuard) checks these four with this same predicate
2236
+ // (installControlProtocolGuard) checks these five with this same predicate
2181
2237
  // first; Optimystic's own check is kept because it is a working, supported
2182
2238
  // upstream defence, not a second policy.
2183
2239
  authorizeInboundStream: (remotePeerId, protocol) => this.authorizeInboundControlStream(remotePeerId, protocol),
@@ -2326,7 +2382,7 @@ export class CadreNode {
2326
2382
  * RESERVE request, so it is never called on a node whose relay server is off.
2327
2383
  *
2328
2384
  * Refuses everyone, ahead of every admission below, while this node is waiting to be
2329
- * claimed ({@link isAwaitingClaim}): a storage-profile node runs the relay server by
2385
+ * claimed ({@link isAwaitingClaim}): a `'server'` node runs the relay server by
2330
2386
  * default, and an unclaimed node on a public address must not become anyone's relay.
2331
2387
  * The empty-anchor admission in check 1 exists for a node that will be enrolled by
2332
2388
  * its siblings, which an unclaimed node has none of.
@@ -2503,10 +2559,10 @@ export class CadreNode {
2503
2559
  }
2504
2560
  /**
2505
2561
  * Per-stream authorization for the protocol guard's `members-snapshot` class
2506
- * (`control-protocol-guard.ts`): the four Optimystic control-DB protocols
2507
- * (`/optimystic/control-<party>/{repo,cluster,sync,block-transfer}/…`), FRET's
2562
+ * (`control-protocol-guard.ts`): the five Optimystic control-DB protocols
2563
+ * (`/optimystic/control-<party>/{repo,cluster,sync,block-transfer,blob}/…`), FRET's
2508
2564
  * five, and any protocol nobody classed. Also wired as Optimystic's
2509
- * `authorizeInboundStream` in {@link createControlNode} for the four DB
2565
+ * `authorizeInboundStream` in {@link createControlNode} for the five DB
2510
2566
  * protocols. The fail-closed layer behind the fail-open connection gater.
2511
2567
  * Control node ONLY: strand cohort nodes legitimately serve cross-party peers.
2512
2568
  *
@@ -2571,7 +2627,7 @@ export class CadreNode {
2571
2627
  // the count of machines serving the network — the quantity
2572
2628
  // `resolveRepairYardstick` asks for. It is NOT that quantity for a strand, which
2573
2629
  // launches only on machines whose embedder registered its sApp config (see
2574
- // {@link addStrand}) plus storage-profile machines hosting it as a storage replica
2630
+ // {@link addStrand}) plus always-on machines hosting it as a storage replica
2575
2631
  // ({@link CadreNodeConfig.hostUnclaimedStrands}) whose filter admits it — phones
2576
2632
  // serve only what their app claims — so this number must never be routed to a strand node:
2577
2633
  // over-declaring pins Optimystic's repair corroboration floor at two peers and a
@@ -2765,6 +2821,15 @@ export class CadreNode {
2765
2821
  * and dial each peer once — what `@libp2p/bootstrap` would have done had the node been
2766
2822
  * built with them. Best-effort: a failed dial is logged, and the connection manager and
2767
2823
  * FRET reconnect from the address book as they do for any known peer.
2824
+ *
2825
+ * NOTE: this dials by peer id, so libp2p's own address sorter picks the order rather than
2826
+ * `peer-dial.ts` → `directBeforeRelayed`. A `/p2p-circuit/webrtc` address in a bootstrap
2827
+ * peer's record therefore sorts AHEAD of the plain relayed one (libp2p's
2828
+ * `circuitRelayAddressesLast` counts only an exact `Circuit` match as relayed) and can cost
2829
+ * this peer one ICE timeout, about 23 s, before the relayed address is tried. Left as it is
2830
+ * because nothing waits on this pass — `start()` voids it, and a peer it misses is reconnected
2831
+ * from the address book. Dial by address (`dialPeerAddrs`) if bootstrap peers ever start
2832
+ * publishing WebRTC addresses and the timing of their first connection matters.
2768
2833
  */
2769
2834
  async dialControlBootstrapPeers() {
2770
2835
  const node = this.controlNode;
@@ -2992,12 +3057,13 @@ export class CadreNode {
2992
3057
  }
2993
3058
  /**
2994
3059
  * Publish (or refresh) this node's own signed `CadrePeer` address record so
2995
- * other members can resolve its current signaling/relay multiaddrs from its
3060
+ * other members can resolve its current relayed and direct multiaddrs from its
2996
3061
  * PeerId alone. Public, awaitable, and idempotent.
2997
3062
  *
2998
3063
  * - Builds a `PeerAddressRecord` from the node's current dialable addrs
2999
- * (signaling/`p2p-circuit` first), signed with the ed25519 key behind its
3000
- * PeerId (the resolved node identity from `keyStore`/`config.privateKey`).
3064
+ * ({@link collectSelfAddrs}: relayed first, WebRTC last), signed with the
3065
+ * ed25519 key behind its PeerId (the resolved node identity from
3066
+ * `keyStore`/`config.privateKey`).
3001
3067
  * - If the row already exists: a self-signed UPDATE bumping `UpdatedAt`.
3002
3068
  * - If not, and the node is its own owner: an owner-signed INSERT that
3003
3069
  * also carries the self-signature. That INSERT is idempotent, so if an owner
@@ -3149,14 +3215,14 @@ export class CadreNode {
3149
3215
  }
3150
3216
  /**
3151
3217
  * Is `record` still the one to publish: signed less than half a heartbeat ago, with this
3152
- * node's profile, over the addresses it would publish now, and the signature the own row
3218
+ * node's own always-on claim, over the addresses it would publish now, and the signature the own row
3153
3219
  * holds? The age bound keeps a record that is not re-written fresh for resolvers: at most half
3154
3220
  * a heartbeat old here and re-stamped by the heartbeat within one more, so never older than
3155
3221
  * 1.5 heartbeats (11.25 min) against {@link DEFAULT_PEER_RECORD_MAX_AGE_MS}. Cheap checks
3156
3222
  * first: the row comes from the membership view, the addresses from the app's resolver.
3157
3223
  */
3158
3224
  async isCurrentSelfRecord(record) {
3159
- if (Date.now() - record.updatedAt >= DEFAULT_PEER_RECORD_HEARTBEAT_MS / 2 || record.profile !== this.config.profile) {
3225
+ if (Date.now() - record.updatedAt >= DEFAULT_PEER_RECORD_HEARTBEAT_MS / 2 || record.profile !== this.publishedProfile()) {
3160
3226
  return false;
3161
3227
  }
3162
3228
  const row = await this.controlDatabase?.queryPeerRecord(record.peerId);
@@ -3239,7 +3305,19 @@ export class CadreNode {
3239
3305
  */
3240
3306
  signSelfRecord(peerId, signingKey, addrs, existing) {
3241
3307
  const updatedAt = Math.max(Date.now(), (existing?.updatedAt ?? 0) + 1);
3242
- return signPeerRecord(this.partyId, { peerId, publicKey: signingKey.publicKeyB64, addrs, updatedAt, profile: this.config.profile }, signingKey.privateKeyB64);
3308
+ return signPeerRecord(this.partyId, { peerId, publicKey: signingKey.publicKeyB64, addrs, updatedAt, profile: this.publishedProfile() }, signingKey.privateKeyB64);
3309
+ }
3310
+ /**
3311
+ * What this node publishes in its own `CadrePeer.Profile`: the `alwaysOn` role, in the stored
3312
+ * form (`node-class.ts`). The column is the one place the old codes survive, because the
3313
+ * control store is the one place backwards compatibility applies
3314
+ * (`docs/cadre/control-schema.md` → "Schema versions and migrations").
3315
+ *
3316
+ * ONE method for both uses on purpose: the heartbeat republishes when the stored row differs
3317
+ * from this, so a second derivation that disagreed would republish on every heartbeat forever.
3318
+ */
3319
+ publishedProfile() {
3320
+ return encodeAlwaysOn(this.roles.alwaysOn);
3243
3321
  }
3244
3322
  /**
3245
3323
  * The ed25519 keypair (base64url) the node signs its own record with — the key
@@ -3320,16 +3398,17 @@ export class CadreNode {
3320
3398
  log('reconcileControlCohort: first self-record publish: %s', outcome);
3321
3399
  }
3322
3400
  /**
3323
- * Collect this node's current dialable addresses for publication, signaling
3324
- * (`/p2p-circuit`) first. Prefers the best invite/NAT-resolved set and folds
3325
- * in the relay/signaling address (the WebRTC dial input) when not already
3326
- * present.
3401
+ * Collect this node's current dialable addresses for publication, ranked by
3402
+ * {@link orderRelayedFirst}: the plain relayed addresses, then the direct ones,
3403
+ * then any that needs ICE after its relay hop. Prefers the best
3404
+ * invite/NAT-resolved set and folds in this node's relayed address
3405
+ * ({@link getRelayAddress}) when not already present.
3327
3406
  */
3328
3407
  async collectSelfAddrs() {
3329
3408
  const resolved = await this.resolveInviteAddresses();
3330
3409
  const relay = await this.getRelayAddress();
3331
3410
  const merged = relay && !resolved.includes(relay) ? [...resolved, relay] : resolved;
3332
- return orderSignalingFirst([...new Set(merged)]);
3411
+ return orderRelayedFirst([...new Set(merged)]);
3333
3412
  }
3334
3413
  /**
3335
3414
  * Wire the ongoing self-record refresh: re-publish whenever libp2p reports an
@@ -3477,8 +3556,9 @@ export class CadreNode {
3477
3556
  * 4. freshness — rejected once older than `maxAgeMs` (never a dead relay
3478
3557
  * reservation),
3479
3558
  * 5. the pluggable trust gate (`opts.trustPolicy`).
3480
- * Survivors are returned signaling (`/p2p-circuit`) first, filtered to
3481
- * signaling-only when requested, as parsed `Multiaddr`s (unparsable addrs
3559
+ * Survivors are returned in {@link orderRelayedFirst} order — plain relayed,
3560
+ * then direct, then WebRTC — filtered to the addresses reaching through a relay
3561
+ * when `signalingOnly` is set, as parsed `Multiaddr`s (unparsable addrs
3482
3562
  * dropped). Any gate failure yields an empty array rather than throwing.
3483
3563
  *
3484
3564
  * Every returned address is normalized to terminate in `/p2p/<peerId>` — see
@@ -3534,11 +3614,11 @@ export class CadreNode {
3534
3614
  log('resolvePeerAddrs: trust policy rejected %s', peerId);
3535
3615
  return null;
3536
3616
  }
3537
- // Order signaling-first (the on-record order was what we verified above),
3538
- // optionally restrict to signaling addrs, then parse — dropping any addr
3539
- // that does not parse as a multiaddr — and finally normalize every survivor
3540
- // onto `/p2p/<peerId>` so no caller ever sees a mixed list.
3541
- let addrs = orderSignalingFirst(record.addrs);
3617
+ // Order relayed-first, WebRTC last (the on-record order was what we verified
3618
+ // above), optionally restrict to the addresses that reach through a relay, then
3619
+ // parse — dropping any addr that does not parse as a multiaddr — and finally
3620
+ // normalize every survivor onto `/p2p/<peerId>` so no caller ever sees a mixed list.
3621
+ let addrs = orderRelayedFirst(record.addrs);
3542
3622
  if (opts.signalingOnly) {
3543
3623
  addrs = addrs.filter(isSignalingAddr);
3544
3624
  }
@@ -3631,8 +3711,8 @@ export class CadreNode {
3631
3711
  // the convergence test does it by hand with a manual dial(). reconcileControlCohort
3632
3712
  // productionizes that: each node resolves its known siblings' control addresses
3633
3713
  // and proactively dials a bounded, backbone-preferential set, re-observing and
3634
- // re-dialing dropped connections on each pass. See docs/architecture.md (Control
3635
- // Network) and control-cohort.ts for the selection policy.
3714
+ // re-dialing dropped connections on each pass. See docs/cadre/control-convergence.md
3715
+ // ("Cohort auto-connect") and control-cohort.ts for the selection policy.
3636
3716
  // ============================================================================
3637
3717
  /**
3638
3718
  * Run one proactive control-cohort dial pass to keep this node connected to its
@@ -3842,7 +3922,7 @@ export class CadreNode {
3842
3922
  // 2. Classify backbone (always-on) members and select a bounded dial set.
3843
3923
  const targetDegree = this.config.network?.controlCohort?.targetDegree
3844
3924
  ?? DEFAULT_CONTROL_COHORT_TARGET_DEGREE;
3845
- const { dials, cappedNonBackbone } = selectControlCohortDials(siblings, targetDegree);
3925
+ const { dials, cappedNonBackbone } = selectControlCohortDials(controlCohortSiblingsOf(siblings), targetDegree);
3846
3926
  if (cappedNonBackbone > 0) {
3847
3927
  // Don't silently bound coverage — surface what the out-degree cap dropped.
3848
3928
  log('reconcileControlCohort: capped %d non-backbone sibling(s) at targetDegree=%d', cappedNonBackbone, targetDegree);
@@ -4339,7 +4419,7 @@ export class CadreNode {
4339
4419
  // local-only). The remedy: detect "wrote while alone" (no identified sibling the
4340
4420
  // cohort would admit: committedAlone), queue the affected row, and RE-ISSUE the write
4341
4421
  // once one is reachable, as an idempotent monotonic update that now broadcasts.
4342
- // See docs/architecture.md (Control Network Convergence → "Writes made while alone").
4422
+ // See docs/cadre/control-convergence.md ("Writes made while alone").
4343
4423
  // ============================================================================
4344
4424
  /**
4345
4425
  * Whether a control write happening now would commit local-only: no sibling is reachable
@@ -5170,6 +5250,64 @@ export class CadreNode {
5170
5250
  this.strandWatcher?.suppressStrand(strandId);
5171
5251
  return true;
5172
5252
  }
5253
+ /**
5254
+ * Stop a running strand whose `App` schema can no longer be used here: another member recorded a
5255
+ * higher App schema version than the one its database runs (`onAppSchemaSuperseded`), so its writes
5256
+ * would erase what the newer version added, or a rebuild after hibernation was refused the schema
5257
+ * (`AppSchemaRefusedError`), which every later rebuild would be too. Leaves what a refused launch
5258
+ * leaves (docs/strands/app-schema.md → "A running member stops"): no instance, the sApp config registered, the
5259
+ * strand suppressed in the watcher until the next {@link addStrand}, which launches through the
5260
+ * connect's version gate. Storage, saved network state and control rows stay. Emits
5261
+ * `strand:stopped`, then `strand:error` with the refusal, so an app tells its user to update on
5262
+ * `error instanceof AppSchemaOutdatedError`.
5263
+ *
5264
+ * Through the manager's stop rather than {@link detachStrand}, which drops the sApp config the next
5265
+ * claim replaces. A claim that registered another config meanwhile is not suppressed but handed to the
5266
+ * watcher's relaunch, since its schema has not been tried ({@link suppressIfAppSchemaRefused}).
5267
+ * A second report for the strand while one stop runs joins it. Never rejects.
5268
+ */
5269
+ stopAppSchemaRefusedStrand(strandId, error) {
5270
+ const running = this.appSchemaStops.get(strandId);
5271
+ if (running) {
5272
+ return running;
5273
+ }
5274
+ const stop = this.runAppSchemaRefusedStop(strandId, error).finally(() => this.appSchemaStops.delete(strandId));
5275
+ this.appSchemaStops.set(strandId, stop);
5276
+ return stop;
5277
+ }
5278
+ async runAppSchemaRefusedStop(strandId, error) {
5279
+ if (!this._running || !this.strandManager.hasStrand(strandId)) {
5280
+ log('Strand %s: app schema refused, and the strand is already down: %s', strandId, error.message);
5281
+ return;
5282
+ }
5283
+ log('Strand %s: stopping it, its app schema is refused: %s', strandId, error.message);
5284
+ const launchedWith = this.strandManager.launchedSAppConfig(strandId);
5285
+ this.hibernationManager.untrackStrand(strandId);
5286
+ try {
5287
+ await this.strandManager.stopStrand(strandId);
5288
+ }
5289
+ catch (stopError) {
5290
+ log('Strand %s: stopping it after its app schema was refused failed: %o', strandId, stopError);
5291
+ }
5292
+ if (!this.suppressIfAppSchemaRefused(strandId, launchedWith, error)) {
5293
+ this.strandWatcher?.forgetStrand(strandId);
5294
+ }
5295
+ this.emit('strand:stopped', { strandId });
5296
+ this.emit('strand:error', { strandId, error });
5297
+ }
5298
+ /**
5299
+ * {@link stopAppSchemaRefusedStrand} for a wake or check-in whose rebuild was refused the strand's
5300
+ * `App` schema, in place of re-hibernating it for a later wake to be refused again. Returns whether it
5301
+ * stopped the strand.
5302
+ */
5303
+ async stopIfRebuildRefusedAppSchema(instance, error) {
5304
+ const refusal = appSchemaRefusalOf(error);
5305
+ if (!refusal || instance.status !== 'error') {
5306
+ return false;
5307
+ }
5308
+ await this.stopAppSchemaRefusedStrand(instance.strandId, refusal);
5309
+ return true;
5310
+ }
5173
5311
  /**
5174
5312
  * Offer a strand no local config claims to the hosting app as `strand:discovered`, so
5175
5313
  * it can decide whether to join (register a config + addStrand); the strand-agnostic
@@ -5343,6 +5481,13 @@ export class CadreNode {
5343
5481
  this.controlBackfill.stop();
5344
5482
  this.controlBackfill = null;
5345
5483
  }
5484
+ // The WebRTC upgrade service with it, and for the same reason: no new upgrade dial against a
5485
+ // transport being torn down. Its stop() also aborts the attempt in flight, which otherwise
5486
+ // holds an ICE negotiation — and the timer bounding it — past the node's own stop.
5487
+ if (this.webrtcUpgrade) {
5488
+ this.webrtcUpgrade.stop();
5489
+ this.webrtcUpgrade = null;
5490
+ }
5346
5491
  // Close control database (this also shuts down the collection factory).
5347
5492
  // Detach the membership hub first: nothing this teardown does should drive a
5348
5493
  // gate refresh, and a notification arriving after this point is a no-op.
@@ -5471,7 +5616,8 @@ export class CadreNode {
5471
5616
  * triggers are coalesced upstream by `HibernationManager`, so this runs once
5472
5617
  * per wake; a wake racing a check-in joins the check-in's rebuild in `resumeStrand`.
5473
5618
  *
5474
- * A failed rebuild re-hibernates the strand (see {@link rehibernateIfResumeFailed});
5619
+ * A failed rebuild re-hibernates the strand (see {@link rehibernateIfResumeFailed}), except one
5620
+ * refused the strand's `App` schema, which stops it ({@link stopIfRebuildRefusedAppSchema});
5475
5621
  * every failure rethrows, so the waker still sees the error.
5476
5622
  *
5477
5623
  * Records no activity itself: whoever asked for the wake did ({@link wakeStrand},
@@ -5503,7 +5649,9 @@ export class CadreNode {
5503
5649
  await this.resumeStrandRuntime(strandId);
5504
5650
  }
5505
5651
  catch (error) {
5506
- await this.rehibernateIfResumeFailed(instance, 'Wake', error);
5652
+ if (!await this.stopIfRebuildRefusedAppSchema(instance, error)) {
5653
+ await this.rehibernateIfResumeFailed(instance, 'Wake', error);
5654
+ }
5507
5655
  throw error;
5508
5656
  }
5509
5657
  this.emit('strand:waking', { strandId });
@@ -5566,7 +5714,7 @@ export class CadreNode {
5566
5714
  /**
5567
5715
  * Replace a running strand node whose launch seed names a machine removed from the cadre with one
5568
5716
  * built from a fresh seed, which a removed machine is not in, so an offline queue stops waiting
5569
- * for it (`docs/strands.md` → Waiting for the party's own machines). The same pair hibernation
5717
+ * for it (`docs/strands/writes.md` → Waiting for the party's own machines). The same pair hibernation
5570
5718
  * runs, so the app sees what it sees on a wake, and a queue is restored from its journal; the
5571
5719
  * quiesce waits for a build in flight. A strand that went down meanwhile takes a fresh seed at its
5572
5720
  * next wake, so it is left down.
@@ -5685,7 +5833,9 @@ export class CadreNode {
5685
5833
  // before the rebuild (the seed read) built nothing: the strand is still `hibernating`
5686
5834
  // (the manager escalates), or a wake that began meanwhile is building or holding it,
5687
5835
  // and the manager hands the chain to that wake, whose outcome restores or ends it.
5688
- await this.rehibernateIfResumeFailed(instance, 'Check-in', err);
5836
+ if (!await this.stopIfRebuildRefusedAppSchema(instance, err)) {
5837
+ await this.rehibernateIfResumeFailed(instance, 'Check-in', err);
5838
+ }
5689
5839
  return;
5690
5840
  }
5691
5841
  // 2-3. Bounded window for the strand network to connect + the app to act,
@@ -5920,7 +6070,7 @@ export class CadreNode {
5920
6070
  }
5921
6071
  /**
5922
6072
  * Switch a strand between offline mode, where a commit resolves once the transaction is queued on
5923
- * this machine, and online mode (docs/strands.md → "Offline mode"). Affects transactions begun from
6073
+ * this machine, and online mode (docs/strands/writes.md → "Offline mode"). Affects transactions begun from
5924
6074
  * now on; one already open keeps the acknowledgement it began with. The mode belongs to the strand:
5925
6075
  * a hibernating strand takes it at its next build, and it lasts across hibernation and every
5926
6076
  * rebuild until the process exits, after which the strand starts in `strandOffline.initialMode`.
@@ -5944,10 +6094,11 @@ export class CadreNode {
5944
6094
  return this.strandManager.offlineMode(strandId);
5945
6095
  }
5946
6096
  /**
5947
- * The party's other machines known to hold `strandId` (each has written its `StrandPeer` row for
5948
- * it) with no open connection from this node's strand node: what a queued transaction reporting
6097
+ * The party's other machines known to STORE `strandId` (each has a `StrandPeer` row for it whose
6098
+ * role says it serves; a client's row is read and skipped) with no open connection from this
6099
+ * node's strand node: what a queued transaction reporting
5949
6100
  * `waitingFor: 'cohort'` may be waiting for, by control peer id (`listMachines`, `removeMachine`)
5950
- * and strand peer id (docs/strands.md → "Waiting for the party's own machines"). Empty on a
6101
+ * and strand peer id (docs/strands/writes.md → "Waiting for the party's own machines"). Empty on a
5951
6102
  * strand not running here, and on a node offering no offline mode. Nothing releases the wait on
5952
6103
  * its own: the transaction is safe in the journal, and removing the machine is the user's call.
5953
6104
  */
@@ -6033,7 +6184,7 @@ export class CadreNode {
6033
6184
  if (existing) {
6034
6185
  // NOTE: reads local converged state, and `queryStrand` does not filter rows whose
6035
6186
  // StampId a Revocation has retired. So on a sibling that still physically holds a row
6036
- // deleted elsewhere while ALONE (the delete-while-alone gap in docs/architecture.md),
6187
+ // deleted elsewhere while ALONE (the delete-while-alone gap in docs/cadre/control-convergence.md),
6037
6188
  // an owner-signed republish now no-ops onto that doomed row instead of re-seating the
6038
6189
  // id under a fresh stamp. Harmless while that gap is itself unresolved — both
6039
6190
  // behaviours end at the same unconverged state — but if delete-while-alone ever gains
@@ -6311,7 +6462,7 @@ export class CadreNode {
6311
6462
  * deletion cannot be replayed, and `queryStrands` reads raw (no retired-stamp filter),
6312
6463
  * so siblings that already hold the row keep running the strand until the collection
6313
6464
  * itself converges (logged loudly; see "Deletes made while alone" in
6314
- * docs/architecture.md).
6465
+ * docs/cadre/control-convergence.md).
6315
6466
  *
6316
6467
  * A no-op (no throw, no tombstone) when the row is already absent — but a
6317
6468
  * locally-running instance of that id is still stopped.
@@ -6323,7 +6474,7 @@ export class CadreNode {
6323
6474
  * step, not a widening of this method.
6324
6475
  *
6325
6476
  * Refuses while the strand's offline queue on this machine holds transactions, unless
6326
- * `options.discardQueued` (docs/strands.md → "Leaving a strand with unsent transactions"). The
6477
+ * `options.discardQueued` (docs/strands/writes.md → "Leaving a strand with unsent transactions"). The
6327
6478
  * check and the discard run before the control-plane delete, so a delete refused afterwards
6328
6479
  * leaves the discarded transactions discarded.
6329
6480
  *
@@ -6403,7 +6554,7 @@ export class CadreNode {
6403
6554
  * NOT the strand row's shared `MemberPrivateKey`, which formation hands to every
6404
6555
  * joining party — is what the founder bootstrap derives `Member.Key`/`Manager.MemberKey`
6405
6556
  * from. It replicates to every machine this party owns (same plaintext-at-rest stance
6406
- * as `MemberPrivateKey`; docs/strands.md → "Closed-Strand Member Key Handling") and is
6557
+ * as `MemberPrivateKey`; docs/strands/keys.md → "Closed-strand member key handling") and is
6407
6558
  * never put on the formation wire.
6408
6559
  *
6409
6560
  * A founding seats the key in the same transaction as the strand row, not through here.
@@ -6748,7 +6899,7 @@ export class CadreNode {
6748
6899
  sAppConfig,
6749
6900
  storage: this.config.storage,
6750
6901
  network: this.config.network,
6751
- profile: this.config.profile,
6902
+ roles: this.roles,
6752
6903
  defaultLatencyHint: this.config.hibernation?.defaultLatencyHint ?? 'interactive',
6753
6904
  privateKey: transportKey,
6754
6905
  bootstrapNodes,
@@ -6790,7 +6941,8 @@ export class CadreNode {
6790
6941
  appSchema: {
6791
6942
  onAppSchemaDeferred: (event) => this.emit('strand:app-schema-deferred', event),
6792
6943
  onAppSchemaApplied: (event) => this.emit('strand:app-schema-applied', event),
6793
- onAppSchemaFailed: (event) => this.emit('strand:error', event)
6944
+ onAppSchemaFailed: (event) => this.emit('strand:error', event),
6945
+ onAppSchemaSuperseded: (event) => void this.stopAppSchemaRefusedStrand(event.strandId, event.error)
6794
6946
  },
6795
6947
  // Re-announce the delegate to ONE relay before the strand node's reservation
6796
6948
  // supervisor re-drives it (see announceDelegateToRelay). Retained with the
@@ -7431,8 +7583,8 @@ export class CadreNode {
7431
7583
  }
7432
7584
  /**
7433
7585
  * The local strand instance's dialable strand-network multiaddrs for the
7434
- * strand-addr RPC, ordered signaling-first (reusing the control node's
7435
- * {@link orderSignalingFirst}). Returns `[]` when the strand is not running
7586
+ * strand-addr RPC, ordered relayed-first and WebRTC last (reusing the control
7587
+ * node's {@link orderRelayedFirst}). Returns `[]` when the strand is not running
7436
7588
  * locally or has no live libp2p node (hibernating / quiescing / never
7437
7589
  * participated) — a node only answers for a strand it is actively meshing,
7438
7590
  * regardless of the strand's mode. A `bootstrap`-mode first node still has a
@@ -7465,7 +7617,7 @@ export class CadreNode {
7465
7617
  addrs.push(bound.toString());
7466
7618
  }
7467
7619
  }
7468
- return orderSignalingFirst(addrs);
7620
+ return orderRelayedFirst(addrs);
7469
7621
  }
7470
7622
  /**
7471
7623
  * Leave a strand joined from another party, for the whole party: remove its party-wide
@@ -7483,7 +7635,7 @@ export class CadreNode {
7483
7635
  * strand stays, so a later re-formation reuses the same identity.
7484
7636
  *
7485
7637
  * Refuses while the strand's offline queue on this machine holds transactions, unless
7486
- * `options.discardQueued` (docs/strands.md → "Leaving a strand with unsent transactions"). The
7638
+ * `options.discardQueued` (docs/strands/writes.md → "Leaving a strand with unsent transactions"). The
7487
7639
  * check and the discard run before the party-wide row is removed, so a removal refused
7488
7640
  * afterwards leaves the discarded transactions discarded.
7489
7641
  *
@@ -7505,7 +7657,7 @@ export class CadreNode {
7505
7657
  }
7506
7658
  /**
7507
7659
  * Before a leave changes anything: refuse while the strand's offline queue holds transactions,
7508
- * unless the app asked to discard them (docs/strands.md → "Leaving a strand with unsent
7660
+ * unless the app asked to discard them (docs/strands/writes.md → "Leaving a strand with unsent
7509
7661
  * transactions"). Transactions Optimystic will not withdraw stay in the journal, named in one
7510
7662
  * warning, and the leave goes on: they may already be saved, and a cohort that never returns
7511
7663
  * would otherwise block the leave forever.
@@ -8048,7 +8200,7 @@ export class CadreNode {
8048
8200
  * as serving the control database and is one this node sends control writes to (an
8049
8201
  * authorized member, or a device whose admission it is writing). Optimystic counts a peer
8050
8202
  * into a control block's cohort on those same terms; with none, a write commits on this node
8051
- * alone and is queued for re-issue once one is reachable (docs/architecture.md → "Writes made
8203
+ * alone and is queued for re-issue once one is reachable (docs/cadre/control-convergence.md → "Writes made
8052
8204
  * while alone").
8053
8205
  *
8054
8206
  * It exists so an embedder can warn an owner before a control write that this machine
@@ -8229,10 +8381,10 @@ export class CadreNode {
8229
8381
  * never reach here: {@link ControlDatabase.queryCadrePeers} excludes them, so a
8230
8382
  * revoked peer is not addressable either.
8231
8383
  *
8232
- * NOTE: answers the whole `CadrePeerRow`, past the fields declared; the integration
8233
- * harness (`owner-cli-node.ts`, `OwnerCliMemberRow.sig`) reads `sig` off it through the admin
8234
- * channel to tell a row another member seated from one the subject published itself. Narrow
8235
- * this to the declared fields only together with that reader.
8384
+ * NOTE: answers the whole row. The integration harness (`owner-cli-node.ts`,
8385
+ * `OwnerCliMemberRow.sig`) reads `sig` off it through the admin channel to tell a row
8386
+ * another member seated from one the subject published itself. Narrow this to fewer fields
8387
+ * only together with that reader.
8236
8388
  */
8237
8389
  async listMembers() {
8238
8390
  if (!this.controlDatabase) {
@@ -8546,7 +8698,7 @@ export class CadreNode {
8546
8698
  * Push-wake a hibernating cadre peer over the control network.
8547
8699
  *
8548
8700
  * Resolves the target's signed control-network address from its `CadrePeer`
8549
- * record (via {@link resolvePeerAddrs}, signaling/relay first — so a NAT'd peer
8701
+ * record (via {@link resolvePeerAddrs}, relayed first — so a NAT'd peer
8550
8702
  * is reachable through its circuit-relay address), dials `WAKE_PROTOCOL`, sends
8551
8703
  * the {@link WakeRequest}, and returns the peer's {@link WakeAck}. The receiver
8552
8704
  * only resumes a strand it already participates in; it acks once it has decided,
@@ -8860,7 +9012,7 @@ export class CadreNode {
8860
9012
  * Whether a control write made now could fork the party's history: no sibling is reachable
8861
9013
  * ({@link committedAlone}) while the party has other members. Such a write commits on this
8862
9014
  * node alone, and if another member writes the same collection meanwhile, both take it to the
8863
- * same revision with different content, which no re-issue heals (docs/architecture.md →
9015
+ * same revision with different content, which no re-issue heals (docs/cadre/control-convergence.md →
8864
9016
  * "Writes made while alone"). A party with no other members cannot fork.
8865
9017
  *
8866
9018
  * What a caller does on `true` depends on the write. An `OwnerKey` add has no re-issue path at
@@ -9110,17 +9262,13 @@ export class CadreNode {
9110
9262
  * the party still holds, own or joined. A row left behind by a joined strand the party has left
9111
9263
  * waits for a re-formation and is not listed. Public columns only, so a row sealed to other
9112
9264
  * machines lists too. Empty on a machine removed from the cadre, which cannot act on what it holds.
9265
+ * A recipient the party lost but has not removed stays in `sealedTo`; removing it writes a
9266
+ * replacement sealed to the machines present (`ControlDatabase.removeMachine`).
9113
9267
  *
9114
9268
  * NOTE: no event announces a change here; an app reads this on `strand:party-key-rotation-blocked`,
9115
9269
  * `strand:party-key-rotated` and after its own {@link removeMachine}, so a second device of the
9116
9270
  * party sees a row replicated to it on its next read. If an app ever needs a push, emit from
9117
9271
  * {@link onPartyKeyTablesChanged}.
9118
- *
9119
- * NOTE: `waitingOn` does not look at who the key is sealed to. If the party loses every machine a
9120
- * row is sealed to and recovers as docs/strands.md describes (deleting its `StrandPartyKey` row,
9121
- * re-joining under a fresh key), the row stays listed as `owner-machine`, then `another-party`,
9122
- * though no machine can open it; only a later removal replaces it. If an app ever reaches this,
9123
- * compare `partyKeyRecipients(row.sealedKey)` with the live machines and add a state for it.
9124
9272
  */
9125
9273
  async listPendingPartyKeyRotations() {
9126
9274
  if (!this.controlDatabase) {
@@ -9135,16 +9283,45 @@ export class CadreNode {
9135
9283
  return [];
9136
9284
  }
9137
9285
  const held = new Set((await this.heldStrandRows(controlDatabase)).map((row) => row.Id));
9286
+ const present = await this.presentMachinePeerIds(controlDatabase);
9138
9287
  const rotations = [];
9139
9288
  for (const [strandId, row] of pending) {
9140
9289
  if (held.has(strandId)) {
9141
9290
  const partyKey = await controlDatabase.queryStrandPartyKey(strandId);
9142
9291
  const strand = await this.pendingRotationStrandState(strandId, partyKey, row.publicKey);
9143
- rotations.push({ strandId, publicKey: row.publicKey, superseded: row.superseded, waitingOn: pendingRotationWaitingOn(strand) });
9292
+ rotations.push({
9293
+ strandId,
9294
+ publicKey: row.publicKey,
9295
+ superseded: row.superseded,
9296
+ waitingOn: pendingRotationWaitingOn(strand),
9297
+ sealedTo: this.pendingKeyRecipientsPresent(strandId, row, present),
9298
+ });
9144
9299
  }
9145
9300
  }
9146
9301
  return rotations;
9147
9302
  }
9303
+ /** The peer ids {@link listMachines} lists, and this node's own, which is a machine of the cadre before its `CadrePeer` row lands. */
9304
+ async presentMachinePeerIds(controlDatabase) {
9305
+ const present = new Set((await controlDatabase.queryCadrePeers()).map((row) => row.peerId));
9306
+ const self = this.peerId?.toString();
9307
+ if (self !== undefined) {
9308
+ present.add(self);
9309
+ }
9310
+ return present;
9311
+ }
9312
+ /**
9313
+ * {@link PendingPartyKeyRotation.sealedTo}: the row's recipients still in the cadre. An envelope
9314
+ * that does not decode opens for nobody, so it lists none, logged; the rest of the listing stands.
9315
+ */
9316
+ pendingKeyRecipientsPresent(strandId, row, present) {
9317
+ try {
9318
+ return partyKeyRecipients(row.sealedKey).filter((peerId) => present.has(peerId));
9319
+ }
9320
+ catch (error) {
9321
+ log('The pending party key of strand %s does not decode, so no machine can open it: %o', strandId, error);
9322
+ return [];
9323
+ }
9324
+ }
9148
9325
  /** {@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. */
9149
9326
  async pendingRotationStrandState(strandId, partyKey, pendingPublicKey) {
9150
9327
  const closed = await this.closedStrandState(strandId, partyKey);
@@ -9166,7 +9343,7 @@ export class CadreNode {
9166
9343
  * withdrawal of every live invitation it could redeem to come back, and a
9167
9344
  * `PendingStrandPartyKey` row per closed strand the party holds a key for, in ONE transaction
9168
9345
  * ({@link ControlDatabase.removeMachine}), with a `Revocation` tombstone per removed row so the
9169
- * removal holds on every machine ("Deletes made while alone" in docs/architecture.md), under
9346
+ * removal holds on every machine ("Deletes made while alone" in docs/cadre/control-convergence.md), under
9170
9347
  * one owner approval. The pending row reaches the removed machine in that same transaction, so
9171
9348
  * the fresh key rides in it sealed to the machines that remain
9172
9349
  * ({@link pendingPartyKeyRecipients}): the removed machine holds the row and cannot open it. Afterwards this node forgets the machine as a dial target, and the
@@ -9264,9 +9441,11 @@ export class CadreNode {
9264
9441
  * key to seal to.
9265
9442
  *
9266
9443
  * NOTE: a machine admitted after the removal is not a recipient, so an owner machine enrolled
9267
- * while a rotation is pending cannot drive it; a recipient owner machine has to finish it. If a
9268
- * party is seen stuck that way, the remedy is the replacement a second removal already writes
9269
- * (`ControlDatabase.removeMachine`), minted for the machines present then.
9444
+ * while a rotation is pending cannot drive it or redeem the host's invitation under the new key;
9445
+ * a recipient owner machine has to. The app learns which machines those are from
9446
+ * {@link PendingPartyKeyRotation.sealedTo}. If a party is seen stuck that way, the remedy is the
9447
+ * replacement a second removal already writes (`ControlDatabase.removeMachine`), minted for the
9448
+ * machines present then.
9270
9449
  */
9271
9450
  pendingPartyKeyRecipients(machines, removedPeerId) {
9272
9451
  const recipients = new Map();
@@ -9510,6 +9689,14 @@ export class CadreNode {
9510
9689
  * the party-machine watch and the next reconciler pass. Written regardless of whether this machine holds the party's
9511
9690
  * member key: a storage replica is bound by its siblings. A node on an ephemeral identity
9512
9691
  * cannot sign the row and writes nothing. Never rejects.
9692
+ *
9693
+ * The row's role is this node's own: null when it serves the blocks of the strands it runs,
9694
+ * `'client'` when it runs them without storing any (`NodeRoles.strandCohortMember`). Read here
9695
+ * rather than carried through {@link deferredStrandPeerWrites}, which stores the strand peer id
9696
+ * alone, because the role cannot change while the node runs. A row already in the party keeps
9697
+ * the role it was written with, since the row is immutable; `ControlDatabase.insertStrandPeer`
9698
+ * logs the mismatch when a reconfigured machine publishes a different one
9699
+ * (`docs/strands/membership.md` → "Limits and accepted tradeoffs").
9513
9700
  */
9514
9701
  async publishStrandPeer(strandId, strandPeerId) {
9515
9702
  if (this.strandPeerRowsHeld.has(strandId) || !this._running || !this.controlDatabase) {
@@ -9526,10 +9713,11 @@ export class CadreNode {
9526
9713
  return;
9527
9714
  }
9528
9715
  try {
9529
- const written = await this.controlDatabase.insertStrandPeer({ strandId, strandPeerId }, ed25519MessageSigner(signingKey.privateKeyB64));
9716
+ const role = this.roles.strandCohortMember ? null : 'client';
9717
+ const written = await this.controlDatabase.insertStrandPeer({ strandId, strandPeerId, role }, ed25519MessageSigner(signingKey.privateKeyB64));
9530
9718
  this.strandPeerRowsHeld.add(strandId);
9531
9719
  this.deferredStrandPeerWrites.delete(strandId);
9532
- log('StrandPeer row for strand %s %s (this machine is %s there)', strandId, written ? 'written' : 'already present', strandPeerId);
9720
+ log('StrandPeer row for strand %s %s (this machine is %s there, %s)', strandId, written ? 'written' : 'already present', strandPeerId, role ?? 'serving');
9533
9721
  }
9534
9722
  catch (error) {
9535
9723
  this.deferredStrandPeerWrites.set(strandId, strandPeerId);
@@ -9668,16 +9856,15 @@ export class CadreNode {
9668
9856
  return JSON.parse(json);
9669
9857
  }
9670
9858
  /**
9671
- * Get this node's circuit relay address for inclusion in seeds.
9672
- * Returns null if no relay address is available.
9859
+ * This node's one relayed address for a seed, or null when it holds no reservation:
9860
+ * {@link firstRelayedAddr} of its announced addresses, so the plain relayed address
9861
+ * is named ahead of a WebRTC one that needs ICE after the same relay hop.
9673
9862
  */
9674
9863
  async getRelayAddress() {
9675
9864
  if (!this.controlNode) {
9676
9865
  return null;
9677
9866
  }
9678
- const addrs = this.controlNode.getMultiaddrs();
9679
- const relayAddr = addrs.find(addr => addr.toString().includes('/p2p-circuit/'));
9680
- return relayAddr?.toString() ?? null;
9867
+ return firstRelayedAddr(this.controlNode.getMultiaddrs().map(addr => addr.toString()));
9681
9868
  }
9682
9869
  // ============================================================================
9683
9870
  // Seed Bootstrap Helper Methods
@@ -9719,7 +9906,7 @@ export class CadreNode {
9719
9906
  * the peer id, addresses and secret its host showed (the QR code): mint a seed, prove
9720
9907
  * possession of the secret beside it (`claim-proof.ts`), deliver it, and on acceptance
9721
9908
  * vouch the node into this cadre and keep its addresses as a dial target. The owner
9722
- * side of the claim-secret entry in the Seed Delivery Protocol (`docs/architecture.md`).
9909
+ * side of "Claiming a node" (`docs/cadre/membership.md`).
9723
9910
  *
9724
9911
  * Requires the seed service with an owner key ({@link useOwnerSigner}), as
9725
9912
  * {@link addDrone} does, and like it is one owner approval (the seed and the vouch). The
@@ -10632,7 +10819,7 @@ export class CadreNode {
10632
10819
  /**
10633
10820
  * Ask to join through `invitation` and have the party keep trying until the join works, the
10634
10821
  * invitation is used up or expires, or the request is dismissed: across restarts, and from
10635
- * any owner machine of the party (`docs/strands.md` → "Joining while the inviter is
10822
+ * any owner machine of the party (`docs/strands/formation.md` → "Joining while the inviter is
10636
10823
  * offline"). Records a party-wide `JoinRequest` row, runs one attempt on this machine at
10637
10824
  * once, and returns the status after it: `'joined'` when the inviter answered yes, `'waiting'`
10638
10825
  * when it was unreachable or not ready, `'failed'` when it refused for good.