@sjawhar/pi-envoy 16.26.0 → 16.27.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.
package/README.md CHANGED
@@ -32,15 +32,41 @@ soft: it names the session it continues, which is a fork's or branch's parent, o
32
32
  this process last held the role under. The listener moves the role off that predecessor only
33
33
  when the predecessor has no live registration, when its live registration carries this extension
34
34
  instance's own client instance id, or when either side carries no instance id. A predecessor
35
- another process still runs keeps the role, and the claim is refused naming that holder. A refused
36
- session keeps running and stays registered, without the role: it does not claim again at each
37
- heartbeat, and it takes the role on its next session event once the holder is gone. Each
38
- extension instance mints its client instance id when it starts and sends it on every registration
39
- and on the deregistration at shutdown, where the listener removes the registration only while it
40
- carries the same id or none. The queues, deadlines and shared role state behind all of this are
41
- `src/registration-state.ts`, beside the extension's other `src/` modules: a queued task acts
42
- through a handle that refuses every step past the task's deadline, or once its session is no
43
- longer the open session.
35
+ another process still runs keeps the role, and the claim is refused naming that holder. A claim
36
+ of a role already held under this session's own id is decided on the standing claim rather than
37
+ on the registration: the listener grants it to the process that claim names, grants it once
38
+ nobody renewed the claim inside its live window, and otherwise refuses it naming this very
39
+ session. A session refused a role another live session holds keeps running and stays registered,
40
+ without the role: it does not claim again at each heartbeat, and it takes the role on its next
41
+ session event once the holder is gone. A refusal naming this session's own id is never recorded
42
+ as one of those, since it is that other process's standing claim, which the listener grants the
43
+ moment that process stops renewing it: nothing is said, and the next heartbeat claims again.
44
+ Each healthy heartbeat also re-asserts a role this session already holds, and confirms it only
45
+ when the lookup names this session and this process and reports no hand-back; a re-assertion the listener refuses naming
46
+ this session's own id is that same standing claim, so the role stays held here, nothing is
47
+ recorded, nothing is said, and the next heartbeat asks again, while a refusal naming a different
48
+ session ends the role here. A lookup that answers `handed_back` is a role this process does not
49
+ hold, however exactly it names this session and this process: a client built before a release
50
+ stated its process hands a role's lane topic back under this session id without being able to
51
+ free the claim, and the listener marks the claim rather than freeing it, after which no
52
+ registration renews it. The pass that reads the mark claims the role again at once, and that
53
+ grant writes a fresh record with no mark, so a hold marked this way is back before the role
54
+ claim reaper could free it. Each extension instance mints its client instance id when it starts
55
+ and sends it on every registration, on every claim and release, and on the deregistration at
56
+ shutdown, where the listener removes the registration only while it carries the same id or none.
57
+ A registration also renews every role claim this session holds that names this same instance,
58
+ whatever topics it carries and unless the listener has marked that claim handed back;
59
+ a release frees only the claims naming it, so a second process that resumed
60
+ this session's id neither ends this one's role nor outlasts it. A hand-back the listener could
61
+ not make — a release its own holder's renewal beat under each of its three conditional deletes,
62
+ which fails the route rather than reporting a release it did not make — is sent again by the
63
+ next heartbeat, so the role is not left standing while this process's registrations renew its
64
+ claim. The transcript's `envoy-role-claim` entry names the session claimed for and this process
65
+ too: a release another process wrote on the same transcript ends no role here, and a claim
66
+ another process wrote is pressed only while this process holds none. The queues, deadlines and
67
+ shared role state behind all of this are `src/registration-state.ts`, beside the extension's
68
+ other `src/` modules: a queued task acts through a handle that refuses every step past the
69
+ task's deadline, or once its session is no longer the open session.
44
70
 
45
71
  `envoy_list()` shows the union of the local subscriptions and the listener's persisted interest
46
72
  registry. Each reported interest identifies whether it is `live`, `registry`, or `both`, so
package/dist/dispatch.js CHANGED
@@ -26154,7 +26154,9 @@ var RoleWireSchema = object({
26154
26154
  host: string2().optional(),
26155
26155
  last_seen: number2().int(),
26156
26156
  state: WireStateSchema,
26157
- holder_state: SessionStateSchema.optional()
26157
+ holder_state: SessionStateSchema.optional(),
26158
+ client_instance_id: string2().optional(),
26159
+ handed_back: boolean2().optional()
26158
26160
  });
26159
26161
  var RoleHeldWireSchema = object({
26160
26162
  error: string2(),
@@ -26411,7 +26413,8 @@ function createEnvoyClient(config) {
26411
26413
  unsubscribe: async (input) => {
26412
26414
  await post("/v1/interests/unsubscribe", {
26413
26415
  session_id: input.sessionID,
26414
- topics: expandSubscriptionTopics(input.topics)
26416
+ topics: expandSubscriptionTopics(input.topics),
26417
+ ...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID }
26415
26418
  }, { actingSession: input.sessionID });
26416
26419
  },
26417
26420
  getInterest: async (sessionID) => InterestWireSchema.parse(JSON.parse(await request(`/v1/interests/${sessionID}`, {}))),
@@ -26481,7 +26484,8 @@ function createEnvoyClient(config) {
26481
26484
  session_id: input.sessionID,
26482
26485
  role: input.role,
26483
26486
  ...soft ? { soft: true } : {},
26484
- ...previous === "" ? {} : { previous_session_id: previous }
26487
+ ...previous === "" ? {} : { previous_session_id: previous },
26488
+ ...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID }
26485
26489
  };
26486
26490
  let raw;
26487
26491
  try {
package/dist/envoy.js CHANGED
@@ -37997,7 +37997,9 @@ var RoleWireSchema = object({
37997
37997
  host: string2().optional(),
37998
37998
  last_seen: number2().int(),
37999
37999
  state: WireStateSchema,
38000
- holder_state: SessionStateSchema.optional()
38000
+ holder_state: SessionStateSchema.optional(),
38001
+ client_instance_id: string2().optional(),
38002
+ handed_back: boolean2().optional()
38001
38003
  });
38002
38004
  var RoleHeldWireSchema = object({
38003
38005
  error: string2(),
@@ -38076,6 +38078,21 @@ function mergeInterestSources(registryTopics, liveTopics) {
38076
38078
  function holderStateOf(role) {
38077
38079
  return role.holder_state ?? role.state;
38078
38080
  }
38081
+ function namedProcess(id) {
38082
+ return id === "" ? undefined : id;
38083
+ }
38084
+ function roleHeldBy(info, sessionID, clientInstanceID) {
38085
+ if (info === undefined || info.holder !== sessionID || info.handed_back === true)
38086
+ return false;
38087
+ const holding = namedProcess(info.client_instance_id);
38088
+ return holding === undefined || holding === namedProcess(clientInstanceID);
38089
+ }
38090
+ function mayActOnRoleRecord(writer, clientInstanceID, holdsRole) {
38091
+ const wrote = namedProcess(writer);
38092
+ if (wrote === undefined || wrote === namedProcess(clientInstanceID))
38093
+ return true;
38094
+ return !holdsRole;
38095
+ }
38079
38096
  function newClientInstanceID() {
38080
38097
  return Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, "0")).join("");
38081
38098
  }
@@ -38271,7 +38288,8 @@ function createEnvoyClient(config) {
38271
38288
  unsubscribe: async (input) => {
38272
38289
  await post("/v1/interests/unsubscribe", {
38273
38290
  session_id: input.sessionID,
38274
- topics: expandSubscriptionTopics(input.topics)
38291
+ topics: expandSubscriptionTopics(input.topics),
38292
+ ...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID }
38275
38293
  }, { actingSession: input.sessionID });
38276
38294
  },
38277
38295
  getInterest: async (sessionID) => InterestWireSchema.parse(JSON.parse(await request(`/v1/interests/${sessionID}`, {}))),
@@ -38341,7 +38359,8 @@ function createEnvoyClient(config) {
38341
38359
  session_id: input.sessionID,
38342
38360
  role: input.role,
38343
38361
  ...soft ? { soft: true } : {},
38344
- ...previous === "" ? {} : { previous_session_id: previous }
38362
+ ...previous === "" ? {} : { previous_session_id: previous },
38363
+ ...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID }
38345
38364
  };
38346
38365
  let raw;
38347
38366
  try {
@@ -42136,7 +42155,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
42136
42155
 
42137
42156
  // package.json
42138
42157
  var name = "@sjawhar/pi-envoy";
42139
- var version2 = "16.26.0";
42158
+ var version2 = "16.27.0";
42140
42159
  var package_default = {
42141
42160
  name,
42142
42161
  version: version2,
@@ -43335,6 +43354,88 @@ function opensAsk({
43335
43354
  }
43336
43355
  }
43337
43356
 
43357
+ // src/hand-back-ledger.ts
43358
+ function createHandBackLedger(deps) {
43359
+ const pending = new Map;
43360
+ const abandoned = new Map;
43361
+ const keyOf = (topic, id) => `${topic}@${id}`;
43362
+ const handBack = async (topic, id) => {
43363
+ await deps.client().unsubscribe({ sessionID: id, topics: [topic], clientInstanceID: deps.clientInstanceID });
43364
+ };
43365
+ const warnRefused = (error, logFields) => {
43366
+ deps.warn("envoy: a role this process gave up was not handed back", {
43367
+ ...logFields,
43368
+ error: messageFor(error)
43369
+ });
43370
+ };
43371
+ return {
43372
+ handBackOrAbandon: (topic, id, logFields) => handBack(topic, id).catch((error) => {
43373
+ abandoned.set(keyOf(topic, id), { topic, id });
43374
+ warnRefused(error, logFields);
43375
+ }),
43376
+ settleEnded: async (acting, adopt) => {
43377
+ let restored = false;
43378
+ const failed = [];
43379
+ for (const [key, hold] of pending) {
43380
+ if (!acting())
43381
+ break;
43382
+ pending.delete(key);
43383
+ if (adopt(hold)) {
43384
+ restored = true;
43385
+ continue;
43386
+ }
43387
+ await handBack(hold.topic, hold.id).catch((error) => {
43388
+ failed.push(hold);
43389
+ warnRefused(error, { topic: hold.topic, sessionID: hold.id });
43390
+ });
43391
+ }
43392
+ for (const hold of failed)
43393
+ abandoned.set(keyOf(hold.topic, hold.id), hold);
43394
+ return restored;
43395
+ },
43396
+ adoptFor: (sessionID) => {
43397
+ for (const [key, hold] of abandoned) {
43398
+ if (hold.id !== sessionID)
43399
+ continue;
43400
+ abandoned.delete(key);
43401
+ pending.set(key, { topic: hold.topic, id: sessionID });
43402
+ }
43403
+ },
43404
+ recordEndedHold: (topic, id) => {
43405
+ pending.set(keyOf(topic, id), { topic, id });
43406
+ },
43407
+ forgetHoldsOf: (topic) => {
43408
+ for (const [key, hold] of abandoned) {
43409
+ if (hold.topic === topic)
43410
+ abandoned.delete(key);
43411
+ }
43412
+ for (const [key, hold] of pending) {
43413
+ if (hold.topic === topic)
43414
+ pending.delete(key);
43415
+ }
43416
+ },
43417
+ observeAbandonedHold: async (topic, role, holder, live) => {
43418
+ if (holder === undefined)
43419
+ return false;
43420
+ const key = keyOf(topic, holder);
43421
+ const hold = abandoned.get(key);
43422
+ if (hold === undefined)
43423
+ return false;
43424
+ const seen = await deps.client().getRole(role).then((info) => info.holder === holder ? info.last_seen : undefined, () => {
43425
+ return;
43426
+ });
43427
+ if (!live() || seen === undefined)
43428
+ return true;
43429
+ if (hold.lastSeen !== undefined && seen !== hold.lastSeen) {
43430
+ abandoned.delete(key);
43431
+ return false;
43432
+ }
43433
+ abandoned.set(key, { topic, id: hold.id, lastSeen: seen });
43434
+ return true;
43435
+ }
43436
+ };
43437
+ }
43438
+
43338
43439
  // src/registration-state.ts
43339
43440
  class AbandonedTaskError extends Error {
43340
43441
  }
@@ -43349,8 +43450,11 @@ function createRegistrationState(deps) {
43349
43450
  let claimedRoleTopic;
43350
43451
  let claimedRoleSessionID;
43351
43452
  let holdUnconfirmed = false;
43352
- const pendingHandBacks = new Map;
43353
- const abandonedHolds = new Map;
43453
+ const holds = createHandBackLedger({
43454
+ client: deps.client,
43455
+ clientInstanceID,
43456
+ warn: (message, context) => deps.log.warn(message, context)
43457
+ });
43354
43458
  const refusedRoles = new Map;
43355
43459
  let roleNoticesFor;
43356
43460
  const roleNoticeSubjects = new Set;
@@ -43371,25 +43475,14 @@ function createRegistrationState(deps) {
43371
43475
  deps.closeSubject(subject);
43372
43476
  roleNoticeSubjects.clear();
43373
43477
  };
43374
- const handBackAt = async (topic, sessionID) => {
43375
- await deps.client().unsubscribe({ sessionID, topics: [topic] });
43376
- };
43377
43478
  const refreshRegistration = (input) => {
43378
- for (const [key, hold] of abandonedHolds) {
43379
- if (hold.id !== input.sessionID)
43380
- continue;
43381
- abandonedHolds.delete(key);
43382
- pendingHandBacks.set(key, { topic: hold.topic, id: input.sessionID });
43383
- }
43479
+ holds.adoptFor(input.sessionID);
43384
43480
  return deps.client().subscribe({ ...input, clientInstanceID }).then((result) => {
43385
43481
  registeredFor = input.sessionID;
43386
43482
  registeredAt = Date.now();
43387
43483
  return result;
43388
43484
  });
43389
43485
  };
43390
- const recordClaimAfterDeadline = (topic, sessionID) => {
43391
- pendingHandBacks.set(`${topic}@${sessionID}`, { topic, id: sessionID });
43392
- };
43393
43486
  const moveHold = async (topic, sessionID, previousTopic, previousHoldID, recordClaim) => {
43394
43487
  const movedOff = previousTopic === topic ? undefined : previousTopic;
43395
43488
  if (movedOff !== undefined)
@@ -43397,25 +43490,12 @@ function createRegistrationState(deps) {
43397
43490
  claimedRoleTopic = topic;
43398
43491
  claimedRoleSessionID = sessionID;
43399
43492
  recordClaim?.();
43400
- if (movedOff !== undefined && previousHoldID)
43401
- await handBackAt(movedOff, previousHoldID);
43402
- };
43403
- const observeAbandonedHold = async (topic, role, holder, live) => {
43404
- const key = `${topic}@${holder}`;
43405
- const abandoned = abandonedHolds.get(key);
43406
- if (abandoned === undefined)
43407
- return false;
43408
- const seen = await deps.client().getRole(role).then((info) => info.holder === holder ? info.last_seen : undefined, () => {
43409
- return;
43410
- });
43411
- if (!live() || seen === undefined)
43412
- return true;
43413
- if (abandoned.lastSeen !== undefined && seen !== abandoned.lastSeen) {
43414
- abandonedHolds.delete(key);
43415
- return false;
43493
+ if (movedOff !== undefined && previousHoldID) {
43494
+ await holds.handBackOrAbandon(movedOff, previousHoldID, {
43495
+ topic: movedOff,
43496
+ sessionID: previousHoldID
43497
+ });
43416
43498
  }
43417
- abandonedHolds.set(key, { topic, id: abandoned.id, lastSeen: seen });
43418
- return true;
43419
43499
  };
43420
43500
  const createHandle = (live) => {
43421
43501
  let bound;
@@ -43454,11 +43534,7 @@ function createRegistrationState(deps) {
43454
43534
  const pluginHeld = roleNoticeSubjects.size > 0;
43455
43535
  endRole();
43456
43536
  if (holdID !== undefined && holdID !== "") {
43457
- await handBackAt(topic, holdID).catch((error) => deps.log.warn("envoy: a role this process gave up was not handed back", {
43458
- role,
43459
- sessionID: holdID,
43460
- error: messageFor(error)
43461
- }));
43537
+ await holds.handBackOrAbandon(topic, holdID, { role, sessionID: holdID });
43462
43538
  }
43463
43539
  if (tellUser) {
43464
43540
  const host = bound ?? "";
@@ -43472,30 +43548,15 @@ function createRegistrationState(deps) {
43472
43548
  };
43473
43549
  const settleEndedHolds = async (wanted) => {
43474
43550
  guard();
43475
- let restored = false;
43476
- const failed = [];
43477
- for (const [key, hold] of pendingHandBacks) {
43478
- if (!acting())
43479
- break;
43480
- pendingHandBacks.delete(key);
43481
- if (wanted !== undefined && hold.topic === ROLE_TOPIC_PREFIX + wanted && deps.sessionOpen(hold.id)) {
43482
- claimedRoleTopic = hold.topic;
43483
- claimedRoleSessionID = hold.id;
43484
- holdUnconfirmed = true;
43485
- restored = true;
43486
- continue;
43551
+ const restored = await holds.settleEnded(acting, (hold) => {
43552
+ if (wanted === undefined || hold.topic !== ROLE_TOPIC_PREFIX + wanted || !deps.sessionOpen(hold.id)) {
43553
+ return false;
43487
43554
  }
43488
- await handBackAt(hold.topic, hold.id).catch((error) => {
43489
- failed.push({ key, ...hold });
43490
- deps.log.warn("envoy: a role this process gave up was not handed back", {
43491
- topic: hold.topic,
43492
- sessionID: hold.id,
43493
- error: messageFor(error)
43494
- });
43495
- });
43496
- }
43497
- for (const { key, topic, id } of failed)
43498
- abandonedHolds.set(key, { topic, id });
43555
+ claimedRoleTopic = hold.topic;
43556
+ claimedRoleSessionID = hold.id;
43557
+ holdUnconfirmed = true;
43558
+ return true;
43559
+ });
43499
43560
  guard();
43500
43561
  return restored;
43501
43562
  };
@@ -43509,24 +43570,18 @@ function createRegistrationState(deps) {
43509
43570
  sessionID: id,
43510
43571
  role,
43511
43572
  soft: options.soft,
43512
- previousSessionID: options.previousSessionID
43573
+ previousSessionID: options.previousSessionID,
43574
+ clientInstanceID
43513
43575
  });
43514
43576
  if (!live()) {
43515
43577
  if (result.claimed)
43516
- recordClaimAfterDeadline(topic, id);
43578
+ holds.recordEndedHold(topic, id);
43517
43579
  refuse(`the role move that claimed ${role} for session ${id} was abandoned at its deadline while the claim was in flight`);
43518
43580
  }
43519
43581
  if (result.claimed) {
43520
43582
  refusedRoles.delete(id);
43521
43583
  holdUnconfirmed = false;
43522
- for (const [key, hold] of abandonedHolds) {
43523
- if (hold.topic === topic)
43524
- abandonedHolds.delete(key);
43525
- }
43526
- for (const [key, hold] of pendingHandBacks) {
43527
- if (hold.topic === topic)
43528
- pendingHandBacks.delete(key);
43529
- }
43584
+ holds.forgetHoldsOf(topic);
43530
43585
  }
43531
43586
  if (!deps.sessionOpen(id)) {
43532
43587
  if (result.claimed) {
@@ -43537,14 +43592,16 @@ function createRegistrationState(deps) {
43537
43592
  }
43538
43593
  if (!result.claimed) {
43539
43594
  endRole();
43540
- const waitingOnReap = await observeAbandonedHold(topic, role, result.holder, live);
43595
+ if (result.holder === id)
43596
+ return false;
43597
+ const waitingOnReap = await holds.observeAbandonedHold(topic, role, result.holder, live);
43541
43598
  const notRecorded = !live() ? "the move was abandoned at its deadline before the refusal was recorded" : deps.sessionOpen(id) ? undefined : "the session moved on before the refusal was recorded";
43542
43599
  if (notRecorded === undefined && !waitingOnReap)
43543
43600
  refusedRoles.set(id, role);
43544
43601
  deps.log.warn(notRecorded !== undefined ? `envoy: role held by another live session; ${notRecorded}` : waitingOnReap ? "envoy: role still held by a session this process left; claiming again once the listener reaps it" : "envoy: role held by another live session; not reclaimed", { role, sessionID: id, holder: result.holder });
43545
43602
  return false;
43546
43603
  }
43547
- await moveHold(topic, id, previousTopic, previousHoldID, () => deps.appendRoleClaimEntry(role));
43604
+ await moveHold(topic, id, previousTopic, previousHoldID, () => deps.appendRoleClaimEntry({ role, sessionID: id, clientInstanceID }));
43548
43605
  return true;
43549
43606
  };
43550
43607
  const reassertRole = async (role, afterOutage) => {
@@ -43553,7 +43610,7 @@ function createRegistrationState(deps) {
43553
43610
  const topic = ROLE_TOPIC_PREFIX + role;
43554
43611
  const client = deps.client();
43555
43612
  const stillHolds = () => claimedRoleTopic === topic;
43556
- const holder = await client.getRole(role).then((info) => info.holder, (error) => {
43613
+ const holding = await client.getRole(role).then((info) => info, (error) => {
43557
43614
  if (error instanceof EnvoyApiError && error.details.status === 404)
43558
43615
  return;
43559
43616
  throw error;
@@ -43561,14 +43618,17 @@ function createRegistrationState(deps) {
43561
43618
  guard();
43562
43619
  if (!stillHolds())
43563
43620
  return { decided: false };
43564
- if (holder === id) {
43621
+ if (roleHeldBy(holding, id, clientInstanceID)) {
43565
43622
  return afterOutage ? { decided: true, regain: "reregistered" } : { decided: true };
43566
43623
  }
43567
- const result = await client.setRole({ sessionID: id, role, soft: true });
43624
+ const result = await client.setRole({ sessionID: id, role, soft: true, clientInstanceID });
43568
43625
  guard();
43569
43626
  if (!stillHolds())
43570
43627
  return { decided: false };
43571
43628
  if (!result.claimed) {
43629
+ if (result.holder === id) {
43630
+ return { decided: true };
43631
+ }
43572
43632
  endRole();
43573
43633
  refusedRoles.set(id, role);
43574
43634
  deps.log.warn("envoy: role re-assertion refused; held by another live session", {
@@ -43582,7 +43642,7 @@ function createRegistrationState(deps) {
43582
43642
  deps.log.warn("envoy: role re-asserted after the listener lost the claim", {
43583
43643
  role,
43584
43644
  sessionID: id,
43585
- previousHolder: holder ?? null
43645
+ previousHolder: holding?.holder ?? null
43586
43646
  });
43587
43647
  return { decided: true, regain: "reclaimed" };
43588
43648
  };
@@ -43740,7 +43800,7 @@ function createRegistrationState(deps) {
43740
43800
  return;
43741
43801
  endRole();
43742
43802
  if (holdID !== "")
43743
- pendingHandBacks.set(`${topic}@${holdID}`, { topic, id: holdID });
43803
+ holds.recordEndedHold(topic, holdID);
43744
43804
  },
43745
43805
  markRoleBoundSubjects: (subjects, role) => {
43746
43806
  const marked = [];
@@ -43757,7 +43817,7 @@ function createRegistrationState(deps) {
43757
43817
  for (const subject of subjects)
43758
43818
  roleNoticeSubjects.delete(subject);
43759
43819
  },
43760
- recordClaimAfterDeadline,
43820
+ recordClaimAfterDeadline: holds.recordEndedHold,
43761
43821
  adoptClaimAfterSessionMoved: moveHold,
43762
43822
  heldRole,
43763
43823
  holdsRoleTopic: (topic) => claimedRoleTopic === topic,
@@ -47926,7 +47986,14 @@ function isRoleClaimEntry(entry) {
47926
47986
  return false;
47927
47987
  if (!("role" in entry.data))
47928
47988
  return false;
47929
- return entry.data.role === null || typeof entry.data.role === "string";
47989
+ if (!(entry.data.role === null || typeof entry.data.role === "string"))
47990
+ return false;
47991
+ if ("session_id" in entry.data && typeof entry.data.session_id !== "string")
47992
+ return false;
47993
+ if ("client_instance_id" in entry.data && typeof entry.data.client_instance_id !== "string") {
47994
+ return false;
47995
+ }
47996
+ return true;
47930
47997
  }
47931
47998
  function resolveSkillsDirectory() {
47932
47999
  const moduleDirectory = dirname2(fileURLToPath(import.meta.url));
@@ -49129,8 +49196,12 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
49129
49196
  deadlineMs: passDeadlineMs,
49130
49197
  notify: (message, level) => activeSessionContext?.ui.notify(message, level),
49131
49198
  log: logger3,
49132
- appendRoleClaimEntry: (role) => {
49133
- pi.appendEntry(ROLE_CLAIM_ENTRY, { role });
49199
+ appendRoleClaimEntry: ({ role, sessionID: claimedFor, clientInstanceID }) => {
49200
+ pi.appendEntry(ROLE_CLAIM_ENTRY, {
49201
+ role,
49202
+ session_id: claimedFor,
49203
+ client_instance_id: clientInstanceID
49204
+ });
49134
49205
  if (activeSessionContext !== undefined)
49135
49206
  ensureHeartbeat(activeSessionContext);
49136
49207
  },
@@ -49321,18 +49392,16 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
49321
49392
  await handle.subscribe(topic);
49322
49393
  }
49323
49394
  };
49324
- const transcriptClaimedRole = (branch) => {
49325
- let role;
49326
- for (const entry of branch) {
49327
- if (!isRoleClaimEntry(entry))
49328
- continue;
49329
- role = entry.data.role;
49330
- }
49331
- return role;
49395
+ const transcriptRoleRecord = (branch) => branch.findLast(isRoleClaimEntry)?.data;
49396
+ const recordedRole = (branch) => {
49397
+ const record = transcriptRoleRecord(branch);
49398
+ if (record === undefined)
49399
+ return;
49400
+ return mayActOnRoleRecord(record.client_instance_id, registrationState.clientInstanceID, registrationState.heldRole() !== undefined) ? record.role : undefined;
49332
49401
  };
49333
49402
  const desiredRole = async (handle, id, branch, readRows) => {
49334
49403
  const want = (role) => registrationState.refusalFor(id) === role ? undefined : role;
49335
- const recorded = transcriptClaimedRole(branch);
49404
+ const recorded = recordedRole(branch);
49336
49405
  if (recorded === null)
49337
49406
  return;
49338
49407
  if (recorded !== undefined)
@@ -49657,7 +49726,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
49657
49726
  registrationState.clearRefusal(host);
49658
49727
  if (sessionID !== host)
49659
49728
  restoreLocalSessionState(context);
49660
- registrationState.endUnwantedRole(host, transcriptClaimedRole(context.sessionManager.getBranch?.() ?? []), continuedBy(host));
49729
+ registrationState.endUnwantedRole(host, recordedRole(context.sessionManager.getBranch?.() ?? []), continuedBy(host));
49661
49730
  if (!inbound)
49662
49731
  return;
49663
49732
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-envoy",
3
- "version": "16.26.0",
3
+ "version": "16.27.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {