@kumiai/rpc 0.10.3 → 0.10.5

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.
@@ -37,6 +37,8 @@ export type EpochRuntime = {
37
37
  teardownEpoch: () => Promise<void>;
38
38
  /** Teardown then build; a teardown failure still builds, then rethrows. */
39
39
  rebuildEpoch: () => Promise<void>;
40
+ /** Resolves once no rebuild is in flight; never rejects. */
41
+ epochSettled: () => Promise<void>;
40
42
  surfaceFor: (name: string) => InternalSurface;
41
43
  sealForSegment: (name: string, bytes: Uint8Array, intent?: 'ephemeral' | 'log') => Promise<SegmentFrame>;
42
44
  hasInboxLane: () => boolean;
package/lib/peer-epoch.js CHANGED
@@ -346,7 +346,17 @@ import { inboxTopic, protocolTopic } from './topic.js';
346
346
  }
347
347
  };
348
348
  };
349
- const rebuildEpoch = async ()=>{
349
+ // Teardown empties the runtimes before build fills them, so `surfaceFor` must not run between.
350
+ const rebuilding = new Set();
351
+ const epochSettled = async ()=>{
352
+ while(rebuilding.size > 0)await Promise.allSettled(rebuilding);
353
+ };
354
+ const rebuildEpoch = ()=>{
355
+ const run = rebuildOnce().finally(()=>rebuilding.delete(run));
356
+ rebuilding.add(run);
357
+ return run;
358
+ };
359
+ const rebuildOnce = async ()=>{
350
360
  if (isDisposed()) return;
351
361
  // Teardown empties the runtimes before it reports a failed child, and a later walk sees the
352
362
  // advance as history. Build anyway, then report the failure.
@@ -366,6 +376,7 @@ import { inboxTopic, protocolTopic } from './topic.js';
366
376
  buildEpoch,
367
377
  teardownEpoch,
368
378
  rebuildEpoch,
379
+ epochSettled,
369
380
  surfaceFor,
370
381
  sealForSegment,
371
382
  hasInboxLane: ()=>inboxLane != null,
package/lib/peer.js CHANGED
@@ -387,7 +387,7 @@ export function createGroupPeer(input) {
387
387
  note: (name, topicID, message, failure)=>appLane.note(name, topicID, message, failure),
388
388
  requestAppPull
389
389
  });
390
- const { buildEpoch, teardownEpoch, rebuildEpoch, surfaceFor, sealForSegment } = epochRuntime;
390
+ const { buildEpoch, teardownEpoch, rebuildEpoch, epochSettled, surfaceFor, sealForSegment } = epochRuntime;
391
391
  const appOutboxAcceptance = mls == null ? undefined : createAppOutboxAcceptance({
392
392
  outbox: params.appOutbox,
393
393
  limit: params.appOutboxLimit,
@@ -1030,13 +1030,16 @@ export function createGroupPeer(input) {
1030
1030
  }));
1031
1031
  if (disposed) return false;
1032
1032
  const gap = result.gap || result.messages.length === 0 && result.head != null && pageAfter != null && result.head > pageAfter;
1033
- if (pageAfter == null) {
1033
+ // With no cursor the hub flags ANY log removal as a gap, so an unflagged read from the
1034
+ // oldest frame holds the whole log: a fresh member's floor stays covered, and its first
1035
+ // publication must not request a heal.
1036
+ if (pageAfter == null && result.gap) {
1034
1037
  covered = false;
1035
1038
  floor = {
1036
1039
  ...floor,
1037
1040
  covered: false
1038
1041
  };
1039
- } else if (gap) {
1042
+ } else if (pageAfter != null && gap) {
1040
1043
  floor = {
1041
1044
  ...floor,
1042
1045
  covered: false
@@ -2556,12 +2559,20 @@ export function createGroupPeer(input) {
2556
2559
  assertLive();
2557
2560
  return fn();
2558
2561
  };
2559
- const readyOrAbort = async (signal)=>{
2562
+ // Ready, and past any epoch rebuild in flight: the protocol surfaces are torn down mid-rebuild.
2563
+ const withEpoch = (fn)=>withReady(async ()=>{
2564
+ await epochSettled();
2565
+ assertLive();
2566
+ return fn();
2567
+ });
2568
+ /** {@link withEpoch}'s wait, abandoned when `signal` aborts. */ const epochOrAbort = async (signal)=>{
2560
2569
  if (signal == null) {
2561
2570
  await ready;
2571
+ await epochSettled();
2562
2572
  return 'ready';
2563
2573
  }
2564
2574
  if (signal.aborted) return 'aborted';
2575
+ const live = ready.then(()=>epochSettled());
2565
2576
  let onAbort;
2566
2577
  const aborted = new Promise((resolve)=>{
2567
2578
  onAbort = ()=>resolve('aborted');
@@ -2571,7 +2582,7 @@ export function createGroupPeer(input) {
2571
2582
  });
2572
2583
  try {
2573
2584
  return await Promise.race([
2574
- ready.then(()=>'ready'),
2585
+ live.then(()=>'ready'),
2575
2586
  aborted
2576
2587
  ]);
2577
2588
  } finally{
@@ -2599,16 +2610,16 @@ export function createGroupPeer(input) {
2599
2610
  logDelivery?.trigger();
2600
2611
  return;
2601
2612
  }
2602
- return withReady(()=>surfaceFor(key).dispatch(prc, config));
2613
+ return withEpoch(()=>surfaceFor(key).dispatch(prc, config));
2603
2614
  },
2604
- request: (prc, config)=>withReady(()=>surfaceFor(key).request(prc, config)),
2615
+ request: (prc, config)=>withEpoch(()=>surfaceFor(key).request(prc, config)),
2605
2616
  gather: async (prc, config)=>{
2606
- const outcome = await readyOrAbort(config?.signal);
2617
+ const outcome = await epochOrAbort(config?.signal);
2607
2618
  assertLive();
2608
2619
  if (outcome === 'aborted') return [];
2609
2620
  return surfaceFor(key).gather(prc, config);
2610
2621
  },
2611
- to: (memberDID)=>withReady(()=>surfaceFor(key).to(memberDID))
2622
+ to: (memberDID)=>withEpoch(()=>surfaceFor(key).to(memberDID))
2612
2623
  };
2613
2624
  };
2614
2625
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/rpc",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "description": "High-level MLS-aware group RPC for Enkaku: bus broadcast/anycast/gather plus directed RPC over the pub/sub hub",
5
5
  "keywords": [
6
6
  "rpc",