@moxt-ai/mobius 0.0.57 → 0.0.59

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/dist/index.js CHANGED
@@ -38909,6 +38909,25 @@ var RelayConnectionDiagnostics = class {
38909
38909
  addFailureDetails(details, failure2);
38910
38910
  this.#record("relay_connection_failed", connectionEpoch.toString(), details, true);
38911
38911
  };
38912
+ /**
38913
+ * Records that the Runtime gave up on Agent turns the Relay already settled. This is not a connection
38914
+ * failure, so it is recorded independently of the per-epoch failure deduplication.
38915
+ */
38916
+ reconciliationAbandoned = (connectionEpoch, relayErrorCode2, turnCount) => {
38917
+ this.#record(
38918
+ "relay_reconciliation_abandoned",
38919
+ connectionEpoch.toString(),
38920
+ {
38921
+ connectionEpoch: connectionEpoch.toString(),
38922
+ relayErrorCode: relayErrorCode2 ?? "unknown",
38923
+ relayOrigin: this.#relayOrigin,
38924
+ source: "reconciliation_abandoned",
38925
+ turnCount: turnCount.toString(),
38926
+ ...this.#route
38927
+ },
38928
+ true
38929
+ );
38930
+ };
38912
38931
  connectionOpened = (connectionEpoch) => {
38913
38932
  this.#record(
38914
38933
  "relay_connection_opened",
@@ -39855,11 +39874,34 @@ var ActiveDaemonTurn = class {
39855
39874
  };
39856
39875
  var ActiveTurnReconciliationError = class extends Error {
39857
39876
  code = "active_turn_reconciliation_failed";
39877
+ diagnosticDetails;
39878
+ relayErrorCode;
39879
+ terminal;
39858
39880
  constructor(message, options = {}) {
39859
39881
  super(message, options);
39860
39882
  this.name = "ActiveTurnReconciliationError";
39883
+ this.relayErrorCode = options.relayErrorCode ?? null;
39884
+ this.terminal = options.terminal ?? false;
39885
+ this.diagnosticDetails = this.relayErrorCode === null ? {} : { relayErrorCode: this.relayErrorCode };
39861
39886
  }
39862
39887
  };
39888
+ var TERMINAL_RECONCILIATION_RELAY_CODES = /* @__PURE__ */ new Set(["session_conflict"]);
39889
+ async function relayErrorCode(response) {
39890
+ try {
39891
+ const body = JSON.parse(await response.text());
39892
+ if (typeof body !== "object" || body === null) {
39893
+ return null;
39894
+ }
39895
+ const error62 = Reflect.get(body, "error");
39896
+ if (typeof error62 !== "object" || error62 === null) {
39897
+ return null;
39898
+ }
39899
+ const code = Reflect.get(error62, "code");
39900
+ return typeof code === "string" && code.length > 0 ? code : null;
39901
+ } catch {
39902
+ return null;
39903
+ }
39904
+ }
39863
39905
  function activeTurnReconciliationEndpoint(config2, turn) {
39864
39906
  const endpoint = relayHttpEndpoint(config2.relayUrl);
39865
39907
  let channelPath = "";
@@ -39897,12 +39939,15 @@ async function reconcileActiveTurn(config2, turn, signal) {
39897
39939
  { cause: error62 }
39898
39940
  );
39899
39941
  }
39900
- await response.body?.cancel();
39901
39942
  if (!response.ok) {
39943
+ const errorCode = await relayErrorCode(response);
39944
+ const terminal = errorCode !== null && TERMINAL_RECONCILIATION_RELAY_CODES.has(errorCode);
39902
39945
  throw new ActiveTurnReconciliationError(
39903
- `The Relay rejected the active Agent turn reconciliation with status ${response.status.toString()}`
39946
+ terminal ? `The Relay reported that the active Agent turn can no longer be reconciled (${errorCode})` : `The Relay rejected the active Agent turn reconciliation with status ${response.status.toString()}`,
39947
+ { relayErrorCode: errorCode, terminal }
39904
39948
  );
39905
39949
  }
39950
+ await response.body?.cancel();
39906
39951
  }
39907
39952
  async function reconcileActiveTurns(config2, turns, signal) {
39908
39953
  await Promise.all(turns.map(async (turn) => await reconcileActiveTurn(config2, turn, signal)));
@@ -40985,9 +41030,24 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
40985
41030
  );
40986
41031
  }
40987
41032
  }
41033
+ async function retainStillInstalledAgents(previous2, refreshed, signal) {
41034
+ const refreshedIdentifiers = new Set(refreshed.map((agent) => agent.id));
41035
+ const retained = [];
41036
+ for (const agent of previous2) {
41037
+ if (refreshedIdentifiers.has(agent.id)) {
41038
+ continue;
41039
+ }
41040
+ signal.throwIfAborted();
41041
+ if (await revalidateExecutable(agent.agentIdentity)) {
41042
+ retained.push(agent);
41043
+ }
41044
+ }
41045
+ return Object.freeze([...refreshed, ...retained]);
41046
+ }
40988
41047
  async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
40989
41048
  signal.throwIfAborted();
40990
- const environment = await resolveEnvironment(signal);
41049
+ const shellEnvironment = await resolveEnvironment(signal);
41050
+ const environment = new DaemonLocalContext(config2.localContext.stateDirectory, shellEnvironment).environment;
40991
41051
  signal.throwIfAborted();
40992
41052
  const inventory = await discoverLocalAgentInventory({
40993
41053
  defaultWorkspace: config2.defaultWorkspace,
@@ -40995,9 +41055,12 @@ async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
40995
41055
  signal
40996
41056
  });
40997
41057
  const previousCatalog = config2.catalog.read();
41058
+ const refreshedAgents = inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment));
41059
+ const agents = await retainStillInstalledAgents(previousCatalog.agents, refreshedAgents, signal);
41060
+ const verifiedIdentifiers = new Set(agents.map((agent) => agent.id));
40998
41061
  config2.catalog.transition(
40999
- inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment)),
41000
- inventory.installable
41062
+ agents,
41063
+ inventory.installable.filter((agent) => !verifiedIdentifiers.has(agent.id))
41001
41064
  );
41002
41065
  try {
41003
41066
  await publishAgentCatalog(config2, signal);
@@ -41899,6 +41962,24 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41899
41962
  return;
41900
41963
  }
41901
41964
  console.error("Mobius daemon could not reconcile active Agent turns", error62);
41965
+ if (error62 instanceof ActiveTurnReconciliationError && error62.terminal) {
41966
+ diagnostics.reconciliationAbandoned(
41967
+ connectionEpoch,
41968
+ error62.relayErrorCode,
41969
+ reconnectingTurns.length
41970
+ );
41971
+ console.error(
41972
+ "Mobius daemon abandoned Agent turns the Relay already settled",
41973
+ error62.relayErrorCode
41974
+ );
41975
+ for (const turn of reconnectingTurns) {
41976
+ activeTurns.delete(turn.command.commandId);
41977
+ turn.abortDaemon();
41978
+ }
41979
+ publisher.connect(socket);
41980
+ resumeRuntimeDeliveries();
41981
+ return;
41982
+ }
41902
41983
  failAndClose(
41903
41984
  new Error("Active Agent turn reconciliation failed", { cause: error62 }),
41904
41985
  ACTIVE_TURN_RECONCILIATION_CLOSE_CODE,