@sjawhar/claude-envoy 6.12.3 → 6.12.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.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "6.12.3"
5
+ "version": "6.12.5"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "6.12.3",
3
+ "version": "6.12.5",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
package/README.md CHANGED
@@ -150,7 +150,11 @@ message from Dispatch's Agents page as that person's own turn.
150
150
  decided on the standing claim: the listener grants it to the process that claim names, grants
151
151
  it once nobody renewed that claim inside its live window, and otherwise refuses it naming this
152
152
  very session, which keeps the role and the record here and asks again on the next heartbeat.
153
- Only a refusal naming a different session ends the role and removes the record. Every healthy
153
+ Only a refusal naming a different session ends the role and removes the record. Every claim
154
+ that lands, the tool's, a restore's, a heartbeat's or a Legion pane's, writes each warning the
155
+ listener answers it with to stderr, naming the role and the session, such as that it handed over
156
+ no message of the replaced session and why; `envoy_role_set` also returns them beside the
157
+ interest row, as `warnings`. Every healthy
154
158
  registration heartbeat checks and reasserts the role if the listener lost it, and it confirms
155
159
  the role only when the lookup names this session *and* this process and reports no hand-back
156
160
  (`handed_back`); each heartbeat also renews the claims this process holds, whatever topics
@@ -15837,6 +15837,7 @@ var EVENT_TYPE_MEMBERS = {
15837
15837
  "project.updated": true,
15838
15838
  "result.recorded": true,
15839
15839
  "result.retracted": true,
15840
+ "role.undelivered": true,
15840
15841
  "settings.architecture_source.updated": true,
15841
15842
  "settings.project_default_assignee.updated": true,
15842
15843
  "settings.repo_project.updated": true,
@@ -16025,6 +16026,15 @@ var SubscriptionRemovedEventPayloadSchema = object({
16025
16026
  pending: subscriptionRemovedEventPayloadFields.pending,
16026
16027
  request_event_id: subscriptionRemovedEventPayloadFields.request_event_id
16027
16028
  });
16029
+ var RoleUndeliveredEventPayloadSchema = strictObject({
16030
+ event_id: number2().int().positive(),
16031
+ event_type: string2(),
16032
+ role: string2(),
16033
+ keeps: number2().int().positive(),
16034
+ kept_at: string2(),
16035
+ dropped_at: string2(),
16036
+ reason: _enum2(["expired", "copy_gone"])
16037
+ }).readonly();
16028
16038
  // ../contracts/src/dispatch-api-targeted.ts
16029
16039
  var DispatchTargetedResourceIDSchema = uuid2();
16030
16040
  var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
package/dist/dispatch.js CHANGED
@@ -16437,6 +16437,7 @@ var EVENT_TYPE_MEMBERS = {
16437
16437
  "project.updated": true,
16438
16438
  "result.recorded": true,
16439
16439
  "result.retracted": true,
16440
+ "role.undelivered": true,
16440
16441
  "settings.architecture_source.updated": true,
16441
16442
  "settings.project_default_assignee.updated": true,
16442
16443
  "settings.repo_project.updated": true,
@@ -16625,6 +16626,15 @@ var SubscriptionRemovedEventPayloadSchema = object({
16625
16626
  pending: subscriptionRemovedEventPayloadFields.pending,
16626
16627
  request_event_id: subscriptionRemovedEventPayloadFields.request_event_id
16627
16628
  });
16629
+ var RoleUndeliveredEventPayloadSchema = strictObject({
16630
+ event_id: number2().int().positive(),
16631
+ event_type: string2(),
16632
+ role: string2(),
16633
+ keeps: number2().int().positive(),
16634
+ kept_at: string2(),
16635
+ dropped_at: string2(),
16636
+ reason: _enum2(["expired", "copy_gone"])
16637
+ }).readonly();
16628
16638
  // ../contracts/src/dispatch-api-targeted.ts
16629
16639
  var DispatchTargetedResourceIDSchema = uuid2();
16630
16640
  var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
@@ -39946,6 +39956,7 @@ var DeliveryAnswerWireSchema = object({
39946
39956
  consumer_start: number2().int().nonnegative().optional()
39947
39957
  });
39948
39958
  var StringListWireSchema = array(string2()).nullish().transform((list) => list ?? []);
39959
+ var RoleSetWireSchema = InterestWireSchema.extend({ warnings: StringListWireSchema });
39949
39960
  var SessionWireSchema = object({
39950
39961
  session_id: string2(),
39951
39962
  machine_id: string2(),
@@ -40406,7 +40417,7 @@ function createEnvoyClient(config) {
40406
40417
  },
40407
40418
  setRole: async (input) => {
40408
40419
  const soft = input.soft === true;
40409
- const previous = soft ? input.previousSessionID ?? "" : "";
40420
+ const previous = input.previousSessionID ?? "";
40410
40421
  const body = {
40411
40422
  session_id: input.sessionID,
40412
40423
  role: input.role,
@@ -40431,10 +40442,8 @@ function createEnvoyClient(config) {
40431
40442
  }
40432
40443
  throw error;
40433
40444
  }
40434
- return {
40435
- claimed: true,
40436
- interest: InterestWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"))
40437
- };
40445
+ const { warnings, ...interest } = RoleSetWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"));
40446
+ return { claimed: true, interest, warnings };
40438
40447
  },
40439
40448
  getRole: async (role) => RoleWireSchema.parse(answerJson(await request(`/v1/roles/${encodeURIComponent(role)}`, { method: "GET" }), "GET", `/v1/roles/${encodeURIComponent(role)}`)),
40440
40449
  listSessions: async (input = {}) => {
@@ -38637,6 +38637,7 @@ var EVENT_TYPE_MEMBERS = {
38637
38637
  "project.updated": true,
38638
38638
  "result.recorded": true,
38639
38639
  "result.retracted": true,
38640
+ "role.undelivered": true,
38640
38641
  "settings.architecture_source.updated": true,
38641
38642
  "settings.project_default_assignee.updated": true,
38642
38643
  "settings.repo_project.updated": true,
@@ -38825,6 +38826,15 @@ var SubscriptionRemovedEventPayloadSchema = object({
38825
38826
  pending: subscriptionRemovedEventPayloadFields.pending,
38826
38827
  request_event_id: subscriptionRemovedEventPayloadFields.request_event_id
38827
38828
  });
38829
+ var RoleUndeliveredEventPayloadSchema = strictObject({
38830
+ event_id: number2().int().positive(),
38831
+ event_type: string2(),
38832
+ role: string2(),
38833
+ keeps: number2().int().positive(),
38834
+ kept_at: string2(),
38835
+ dropped_at: string2(),
38836
+ reason: _enum2(["expired", "copy_gone"])
38837
+ }).readonly();
38828
38838
  // ../contracts/src/dispatch-api-targeted.ts
38829
38839
  var DispatchTargetedResourceIDSchema = uuid2();
38830
38840
  var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
@@ -61385,6 +61395,7 @@ var DeliveryAnswerWireSchema = object({
61385
61395
  consumer_start: number2().int().nonnegative().optional()
61386
61396
  });
61387
61397
  var StringListWireSchema = array(string2()).nullish().transform((list) => list ?? []);
61398
+ var RoleSetWireSchema = InterestWireSchema.extend({ warnings: StringListWireSchema });
61388
61399
  var SessionWireSchema = object({
61389
61400
  session_id: string2(),
61390
61401
  machine_id: string2(),
@@ -61845,7 +61856,7 @@ function createEnvoyClient(config) {
61845
61856
  },
61846
61857
  setRole: async (input) => {
61847
61858
  const soft = input.soft === true;
61848
- const previous = soft ? input.previousSessionID ?? "" : "";
61859
+ const previous = input.previousSessionID ?? "";
61849
61860
  const body = {
61850
61861
  session_id: input.sessionID,
61851
61862
  role: input.role,
@@ -61870,10 +61881,8 @@ function createEnvoyClient(config) {
61870
61881
  }
61871
61882
  throw error;
61872
61883
  }
61873
- return {
61874
- claimed: true,
61875
- interest: InterestWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"))
61876
- };
61884
+ const { warnings, ...interest } = RoleSetWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"));
61885
+ return { claimed: true, interest, warnings };
61877
61886
  },
61878
61887
  getRole: async (role) => RoleWireSchema.parse(answerJson(await request(`/v1/roles/${encodeURIComponent(role)}`, { method: "GET" }), "GET", `/v1/roles/${encodeURIComponent(role)}`)),
61879
61888
  listSessions: async (input = {}) => {
@@ -66845,7 +66854,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
66845
66854
 
66846
66855
  // package.json
66847
66856
  var name2 = "@sjawhar/claude-envoy";
66848
- var version2 = "6.12.3";
66857
+ var version2 = "6.12.5";
66849
66858
  var package_default = {
66850
66859
  name: name2,
66851
66860
  version: version2,
@@ -66856,7 +66865,7 @@ var package_default = {
66856
66865
  repository: { type: "git", url: "https://github.com/cybermonklabs/legion" },
66857
66866
  scripts: { channel: "bun bin/envoy-channel.ts", "verify-build": "bash scripts/verify-build.sh", prepack: "bash scripts/pack-skills.sh", postpack: "bash scripts/pack-skills.sh --restore", typecheck: "bun ../contracts/scripts/gen-api.ts && bunx tsc --noEmit", test: "bun test --timeout=60000", lint: "bunx biome check src/ hooks/ scripts/" },
66858
66867
  devDependencies: { "@biomejs/biome": "^2.3.14", "@legion/cipher-client": "workspace:*", "@legion/contracts": "workspace:*", "@legion/envoy-client": "workspace:*", "@legion/pi-shared": "workspace:*", "@legion/test-fixtures": "workspace:*", "@modelcontextprotocol/sdk": "^1.30.0", "bun-types": "latest", nats: "^2.29.2", typescript: "^5.3.0", zod: "4.3.6" },
66859
- legion: { daemonApiVersion: 283 }
66868
+ legion: { daemonApiVersion: 284 }
66860
66869
  };
66861
66870
 
66862
66871
  // ../envoy-client/src/inbound-card.ts
@@ -68926,7 +68935,8 @@ var LegionRegisterResponse = object({
68926
68935
  role: _enum2(LEGION_ROLES),
68927
68936
  generation: number2().int().positive(),
68928
68937
  secret: nonEmptyString2,
68929
- promptAgents: array(nonEmptyString2)
68938
+ promptAgents: array(nonEmptyString2),
68939
+ replaces: nonEmptyString2.optional()
68930
68940
  });
68931
68941
  var LegionCapabilityReport = strictObject({
68932
68942
  measuredAt: timestamp,
@@ -69029,7 +69039,8 @@ var LegionControllerRegisterResponse = object({
69029
69039
  claimToken: nonEmptyString2,
69030
69040
  role: literal("controller").optional(),
69031
69041
  generation: number2().int().positive(),
69032
- secret: nonEmptyString2
69042
+ secret: nonEmptyString2,
69043
+ replaces: nonEmptyString2.optional()
69033
69044
  });
69034
69045
  var LegionControllerSecretResponse = object({
69035
69046
  secret: nonEmptyString2,
@@ -69441,9 +69452,10 @@ var LEGION_ANSWER_READS = {
69441
69452
  "role",
69442
69453
  "generation",
69443
69454
  "secret",
69444
- "promptAgents"
69455
+ "promptAgents",
69456
+ "replaces"
69445
69457
  ],
69446
- LegionControllerRegisterResponse: ["claimToken", "generation", "secret"],
69458
+ LegionControllerRegisterResponse: ["claimToken", "generation", "secret", "replaces"],
69447
69459
  LegionGrantResponse: ["grantId"],
69448
69460
  LegionErrorResponse: ["error", "code"],
69449
69461
  LegionReleaseRecordsResponse: [
@@ -69812,7 +69824,7 @@ async function bootLegionClaim(host) {
69812
69824
  stopAfterRegistration(host, claim.claimToken, error);
69813
69825
  return { claimed: Promise.resolve() };
69814
69826
  }
69815
- return { claimed: claimRoleAtFirstTurn(host, claim.claimToken, firstTurn) };
69827
+ return { claimed: claimRoleAtFirstTurn(host, claim.claimToken, claim.replaces, firstTurn) };
69816
69828
  }
69817
69829
  function stopAfterRegistration(host, role, error) {
69818
69830
  host.log(`claim boot failed after claims/register registered ${role}; ${host.stopping}: ${messageFor(error)}`);
@@ -69831,7 +69843,7 @@ function listenForFirstTurn(host) {
69831
69843
  step();
69832
69844
  };
69833
69845
  }
69834
- function claimRoleAtFirstTurn(host, role, firstTurn) {
69846
+ function claimRoleAtFirstTurn(host, role, replaces, firstTurn) {
69835
69847
  const done = Promise.withResolvers();
69836
69848
  let ran = false;
69837
69849
  const claim = () => {
@@ -69841,7 +69853,7 @@ function claimRoleAtFirstTurn(host, role, firstTurn) {
69841
69853
  clearTimeout(bound);
69842
69854
  (async () => {
69843
69855
  try {
69844
- await claimRoleAgainOnBusy(() => host.claimRole(role), role, {
69856
+ await claimRoleAgainOnBusy(() => host.claimRole(role, replaces), role, {
69845
69857
  log: host.log,
69846
69858
  firstDelayMs: host.roleClaimRetryFirstDelayMs,
69847
69859
  signal: host.signal
@@ -69871,7 +69883,7 @@ async function claimRoleAgainOnBusy(claim, role, options) {
69871
69883
  throw error;
69872
69884
  if (options.maxAttempts !== undefined && attempt >= options.maxAttempts)
69873
69885
  throw error;
69874
- options.log(`claim of Envoy role ${role} was answered 503 at attempt ${attempt}, so nothing was claimed; claiming it again in ${wait} ms: ${messageFor(error)}`);
69886
+ options.log(`claim of Envoy role ${role} was answered 503 at attempt ${attempt}; claiming it again in ${wait} ms: ${messageFor(error)}`, error);
69875
69887
  const waited = Promise.withResolvers();
69876
69888
  const timer = setTimeout(waited.resolve, wait);
69877
69889
  timer.unref?.();
@@ -70590,6 +70602,13 @@ function createPhaseHookEndpoint(deps) {
70590
70602
  };
70591
70603
  }
70592
70604
 
70605
+ // src/role-claim-warnings.ts
70606
+ function logRoleClaimWarnings(log, role, sessionID, warnings) {
70607
+ for (const warning of warnings) {
70608
+ log(`the Envoy listener warned about the claim of role ${role} for session ${sessionID}: ${warning}`);
70609
+ }
70610
+ }
70611
+
70593
70612
  // src/legion-claim.ts
70594
70613
  var PLUGIN_CONTRACT = daemonContract(package_default, import.meta.dir);
70595
70614
  async function legionPane(env) {
@@ -70675,7 +70694,7 @@ function startLegionClaim(deps) {
70675
70694
  setCapability: (registered) => {
70676
70695
  capability = registered;
70677
70696
  },
70678
- claimRole: async (role) => {
70697
+ claimRole: async (role, replaces) => {
70679
70698
  const deadline = Date.now() + roleWaitMs;
70680
70699
  let waited = false;
70681
70700
  for (;; ) {
@@ -70683,10 +70702,13 @@ function startLegionClaim(deps) {
70683
70702
  sessionID,
70684
70703
  role,
70685
70704
  soft: true,
70686
- clientInstanceID: deps.clientInstanceID
70705
+ clientInstanceID: deps.clientInstanceID,
70706
+ ...replaces ? { previousSessionID: replaces } : {}
70687
70707
  });
70688
- if (claimed.claimed)
70708
+ if (claimed.claimed) {
70709
+ logRoleClaimWarnings(deps.log, role, sessionID, claimed.warnings);
70689
70710
  break;
70711
+ }
70690
70712
  if (claimed.holder !== sessionID) {
70691
70713
  throw new Error(`Envoy role ${role} is held by live session ${claimed.holder}`);
70692
70714
  }
@@ -72515,6 +72537,10 @@ function parseArguments(spec, input) {
72515
72537
  function mcpResult(value) {
72516
72538
  return { content: [{ type: "text", text: JSON.stringify(value) }] };
72517
72539
  }
72540
+ function warnOnStderr(line) {
72541
+ process.stderr.write(`envoy-channel: ${line}
72542
+ `);
72543
+ }
72518
72544
  function projectDirectory() {
72519
72545
  return claudeProjectDirectory({ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] }, process.cwd());
72520
72546
  }
@@ -73116,8 +73142,9 @@ async function startChannelSession(options) {
73116
73142
  if (!mayActOnRoleRecord(persisted.client_instance_id, options.clientInstanceID, heldRole !== undefined)) {
73117
73143
  return "settled";
73118
73144
  }
73145
+ const sessionID = identity.id;
73119
73146
  const claim = await options.client.setRole({
73120
- sessionID: identity.id,
73147
+ sessionID,
73121
73148
  role: persisted.role,
73122
73149
  soft: true,
73123
73150
  previousSessionID: persisted.session_id,
@@ -73130,6 +73157,7 @@ async function startChannelSession(options) {
73130
73157
  await rm5(previousFile, { force: true });
73131
73158
  return "settled";
73132
73159
  }
73160
+ logRoleClaimWarnings(warnOnStderr, persisted.role, sessionID, claim.warnings);
73133
73161
  heldRole = persisted.role;
73134
73162
  const currentFile = roleStateFile(options.stateDirectory, identity.id);
73135
73163
  if (previousFile !== currentFile)
@@ -73172,8 +73200,9 @@ async function startChannelSession(options) {
73172
73200
  fireRegained(role, "reregistered");
73173
73201
  return;
73174
73202
  }
73203
+ const sessionID = identity.id;
73175
73204
  const result = await options.client.setRole({
73176
- sessionID: identity.id,
73205
+ sessionID,
73177
73206
  role,
73178
73207
  soft: true,
73179
73208
  clientInstanceID: options.clientInstanceID
@@ -73187,6 +73216,7 @@ async function startChannelSession(options) {
73187
73216
  await refreshRoleRecord();
73188
73217
  return;
73189
73218
  }
73219
+ logRoleClaimWarnings(warnOnStderr, role, sessionID, result.warnings);
73190
73220
  fireRegained(role, "reclaimed");
73191
73221
  };
73192
73222
  let roleTransferFailureReported = false;
@@ -73654,15 +73684,17 @@ async function executeEnvoyTool(runtime, name, input) {
73654
73684
  }
73655
73685
  case EnvoyToolOperation.setRole: {
73656
73686
  const args = parseArguments(spec, input);
73687
+ const sessionID = identity.id;
73657
73688
  const result = await runtime.client.setRole({
73658
- sessionID: identity.id,
73689
+ sessionID,
73659
73690
  role: args.role,
73660
73691
  clientInstanceID: runtime.clientInstanceID
73661
73692
  });
73662
73693
  if (!result.claimed)
73663
73694
  throw new Error(`role ${args.role} is held by ${result.holder}`);
73695
+ logRoleClaimWarnings(warnOnStderr, args.role, sessionID, result.warnings);
73664
73696
  await runtime.session.rememberRole(args.role);
73665
- return result.interest;
73697
+ return result.warnings.length === 0 ? result.interest : { ...result.interest, warnings: result.warnings };
73666
73698
  }
73667
73699
  case EnvoyToolOperation.getRole: {
73668
73700
  const args = parseArguments(spec, input);
@@ -19424,6 +19424,7 @@ var EVENT_TYPE_MEMBERS = {
19424
19424
  "project.updated": true,
19425
19425
  "result.recorded": true,
19426
19426
  "result.retracted": true,
19427
+ "role.undelivered": true,
19427
19428
  "settings.architecture_source.updated": true,
19428
19429
  "settings.project_default_assignee.updated": true,
19429
19430
  "settings.repo_project.updated": true,
@@ -19612,6 +19613,15 @@ var SubscriptionRemovedEventPayloadSchema = object({
19612
19613
  pending: subscriptionRemovedEventPayloadFields.pending,
19613
19614
  request_event_id: subscriptionRemovedEventPayloadFields.request_event_id
19614
19615
  });
19616
+ var RoleUndeliveredEventPayloadSchema = strictObject({
19617
+ event_id: number2().int().positive(),
19618
+ event_type: string2(),
19619
+ role: string2(),
19620
+ keeps: number2().int().positive(),
19621
+ kept_at: string2(),
19622
+ dropped_at: string2(),
19623
+ reason: _enum2(["expired", "copy_gone"])
19624
+ }).readonly();
19615
19625
  // ../contracts/src/dispatch-api-targeted.ts
19616
19626
  var DispatchTargetedResourceIDSchema = uuid2();
19617
19627
  var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "6.12.3",
3
+ "version": "6.12.5",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -45,6 +45,6 @@
45
45
  "zod": "4.3.6"
46
46
  },
47
47
  "legion": {
48
- "daemonApiVersion": 283
48
+ "daemonApiVersion": 284
49
49
  }
50
50
  }
@@ -149,6 +149,7 @@ import {
149
149
  replayStateFile,
150
150
  replayStateWriter,
151
151
  } from "./replay-state"
152
+ import { logRoleClaimWarnings } from "./role-claim-warnings"
152
153
  import {
153
154
  pruneStaleSessionHandoffs,
154
155
  pruneStaleSessionRoles,
@@ -478,6 +479,11 @@ export function mcpResult(value: unknown): {
478
479
  return { content: [{ type: "text", text: JSON.stringify(value) }] }
479
480
  }
480
481
 
482
+ /** Writes one line to the server's warning log, its stderr. */
483
+ function warnOnStderr(line: string): void {
484
+ process.stderr.write(`envoy-channel: ${line}\n`)
485
+ }
486
+
481
487
  function projectDirectory(): string {
482
488
  return claudeProjectDirectory(
483
489
  { CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] },
@@ -1592,8 +1598,9 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
1592
1598
  ) {
1593
1599
  return "settled"
1594
1600
  }
1601
+ const sessionID = identity.id
1595
1602
  const claim = await options.client.setRole({
1596
- sessionID: identity.id,
1603
+ sessionID,
1597
1604
  role: persisted.role,
1598
1605
  soft: true,
1599
1606
  previousSessionID: persisted.session_id,
@@ -1604,6 +1611,7 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
1604
1611
  if (claim.holder !== persisted.session_id) await rm(previousFile, { force: true })
1605
1612
  return "settled"
1606
1613
  }
1614
+ logRoleClaimWarnings(warnOnStderr, persisted.role, sessionID, claim.warnings)
1607
1615
  heldRole = persisted.role
1608
1616
  const currentFile = roleStateFile(options.stateDirectory, identity.id)
1609
1617
  if (previousFile !== currentFile) await rm(previousFile, { force: true })
@@ -1682,8 +1690,9 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
1682
1690
  if (afterOutage) fireRegained(role, "reregistered")
1683
1691
  return
1684
1692
  }
1693
+ const sessionID = identity.id
1685
1694
  const result = await options.client.setRole({
1686
- sessionID: identity.id,
1695
+ sessionID,
1687
1696
  role,
1688
1697
  soft: true,
1689
1698
  clientInstanceID: options.clientInstanceID,
@@ -1697,6 +1706,7 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
1697
1706
  await refreshRoleRecord()
1698
1707
  return
1699
1708
  }
1709
+ logRoleClaimWarnings(warnOnStderr, role, sessionID, result.warnings)
1700
1710
  fireRegained(role, "reclaimed")
1701
1711
  }
1702
1712
 
@@ -2450,14 +2460,20 @@ export async function executeEnvoyTool(
2450
2460
  // The claim names this process, as every claim this server makes does: the listener
2451
2461
  // records it as the role's holder, so a second process on this session id cannot be
2452
2462
  // mistaken for the one holding the role.
2463
+ const sessionID = identity.id
2453
2464
  const result = await runtime.client.setRole({
2454
- sessionID: identity.id,
2465
+ sessionID,
2455
2466
  role: args.role,
2456
2467
  clientInstanceID: runtime.clientInstanceID,
2457
2468
  })
2458
2469
  if (!result.claimed) throw new Error(`role ${args.role} is held by ${result.holder}`)
2470
+ // The listener's warnings about the claim go to the log and, beside the interest row, to the
2471
+ // agent, which must know of a handover of the replaced session the claim did not make.
2472
+ logRoleClaimWarnings(warnOnStderr, args.role, sessionID, result.warnings)
2459
2473
  await runtime.session.rememberRole(args.role)
2460
- return result.interest
2474
+ return result.warnings.length === 0
2475
+ ? result.interest
2476
+ : { ...result.interest, warnings: result.warnings }
2461
2477
  }
2462
2478
  case EnvoyToolOperation.getRole: {
2463
2479
  const args = parseArguments(spec, input)
@@ -14,6 +14,7 @@ import pkg from "../package.json" with { type: "json" }
14
14
  import { configuredValue } from "./claude-session"
15
15
  import type { ChannelSession } from "./envoy-channel-server"
16
16
  import { paneReminderLog } from "./legion-phase-hook"
17
+ import { logRoleClaimWarnings } from "./role-claim-warnings"
17
18
 
18
19
  /**
19
20
  * A Claude Code phase worker's claim on the Legion daemon, made by the MCP server Claude Code runs
@@ -286,10 +287,13 @@ export function startLegionClaim(deps: {
286
287
  setCapability: (registered) => {
287
288
  capability = registered
288
289
  },
289
- claimRole: async (role) => {
290
+ claimRole: async (role, replaces) => {
290
291
  // Soft, so a role another live session holds is left with it, and naming this process,
291
292
  // so the listener records the claim as this process's: a second `claude` that resumed
292
293
  // this session id can then neither be taken for the holder nor release what it holds.
294
+ // `replaces`, the session the registration says this one replaces, is named as the
295
+ // claim's predecessor: the listener hands that session's unread direct and role messages
296
+ // to this one once the claim lands.
293
297
  //
294
298
  // A refusal naming this very session is that same claim seen from the other side: the
295
299
  // process this pane was relaunched from renewed it at its last heartbeat, so it stands
@@ -306,8 +310,12 @@ export function startLegionClaim(deps: {
306
310
  role,
307
311
  soft: true,
308
312
  clientInstanceID: deps.clientInstanceID,
313
+ ...(replaces ? { previousSessionID: replaces } : {}),
309
314
  })
310
- if (claimed.claimed) break
315
+ if (claimed.claimed) {
316
+ logRoleClaimWarnings(deps.log, role, sessionID, claimed.warnings)
317
+ break
318
+ }
311
319
  if (claimed.holder !== sessionID) {
312
320
  throw new Error(`Envoy role ${role} is held by live session ${claimed.holder}`)
313
321
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Logs each warning the Envoy listener answered a granted claim of `role` for `sessionID` with
3
+ * (`SetRoleResult.warnings`), one `log` line each, naming the role and the session: what the
4
+ * listener says about a claim that landed, such as a handover of the replaced session it did not
5
+ * make. Every claim the channel server makes logs them, whoever made it: a restore, a heartbeat,
6
+ * the Legion claim, or `envoy_role_set`, which also answers them to the agent.
7
+ */
8
+ export function logRoleClaimWarnings(
9
+ log: (line: string) => void,
10
+ role: string,
11
+ sessionID: string,
12
+ warnings: readonly string[],
13
+ ): void {
14
+ for (const warning of warnings) {
15
+ log(
16
+ `the Envoy listener warned about the claim of role ${role} for session ${sessionID}: ${warning}`,
17
+ )
18
+ }
19
+ }