@evident-ai/cli 3.5.2-dev.659ea21 → 3.5.2-dev.6f1ed0e

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
@@ -1157,7 +1157,7 @@ import ora4 from "ora";
1157
1157
  import { select as select4 } from "@inquirer/prompts";
1158
1158
 
1159
1159
  // src/lib/telemetry.ts
1160
- var CLI_VERSION = (true ? "3.5.2-dev.659ea21" : void 0) ?? process.env.npm_package_version ?? "unknown";
1160
+ var CLI_VERSION = (true ? "3.5.2-dev.6f1ed0e" : void 0) ?? process.env.npm_package_version ?? "unknown";
1161
1161
  function getCliVersion() {
1162
1162
  return CLI_VERSION;
1163
1163
  }
@@ -5554,6 +5554,7 @@ function classifyUpgradeRejection(headers) {
5554
5554
  }
5555
5555
  var MAX_RECONNECT_DELAY = 3e4;
5556
5556
  var BASE_RECONNECT_DELAY = 500;
5557
+ var RELAY_SILENCE_TIMEOUT_MS = 9e4;
5557
5558
  function getReconnectDelay(attempt) {
5558
5559
  const exponentialDelay = BASE_RECONNECT_DELAY * Math.pow(2, attempt);
5559
5560
  const jitter = Math.random() * 1e3;
@@ -5625,10 +5626,27 @@ function connectTunnel(options) {
5625
5626
  ws.close();
5626
5627
  reject(new Error("Connection timeout"));
5627
5628
  }, 3e4);
5629
+ let relaySilenceTimeout;
5630
+ let relaySilenceTimedOut = false;
5631
+ const clearRelaySilenceTimeout = () => {
5632
+ if (relaySilenceTimeout === void 0) return;
5633
+ clearTimeout(relaySilenceTimeout);
5634
+ relaySilenceTimeout = void 0;
5635
+ };
5636
+ const armRelaySilenceTimeout = () => {
5637
+ clearRelaySilenceTimeout();
5638
+ relaySilenceTimeout = setTimeout(() => {
5639
+ relaySilenceTimeout = void 0;
5640
+ relaySilenceTimedOut = true;
5641
+ ws.terminate();
5642
+ }, RELAY_SILENCE_TIMEOUT_MS);
5643
+ relaySilenceTimeout.unref?.();
5644
+ };
5628
5645
  let upgradeRejection = null;
5629
5646
  let upgradeRejectionReason = null;
5630
5647
  ws.on("unexpected-response", (_req, res) => {
5631
5648
  clearTimeout(connectionTimeout);
5649
+ clearRelaySilenceTimeout();
5632
5650
  const reason = classifyUpgradeRejection(res.headers);
5633
5651
  upgradeRejectionReason = reason;
5634
5652
  const chunks = [];
@@ -5658,6 +5676,7 @@ function connectTunnel(options) {
5658
5676
  onInfo?.("WebSocket connection established");
5659
5677
  });
5660
5678
  ws.on("message", (data, isBinary) => {
5679
+ if (relaySilenceTimeout !== void 0) armRelaySilenceTimeout();
5661
5680
  if (isBinary) {
5662
5681
  try {
5663
5682
  const frame = decodeBinaryBodyFrame(toUint8Array(data));
@@ -5691,6 +5710,7 @@ function connectTunnel(options) {
5691
5710
  switch (message.type) {
5692
5711
  case "connected": {
5693
5712
  clearTimeout(connectionTimeout);
5713
+ armRelaySilenceTimeout();
5694
5714
  forwarder.setBinaryFramesSupported(message.binary_frames === true);
5695
5715
  const connectedAgentId = message.agent_id ?? agentId;
5696
5716
  onConnected?.(connectedAgentId);
@@ -5715,6 +5735,7 @@ function connectTunnel(options) {
5715
5735
  });
5716
5736
  ws.on("error", (error2) => {
5717
5737
  clearTimeout(connectionTimeout);
5738
+ clearRelaySilenceTimeout();
5718
5739
  const detail = upgradeRejection ?? describeSocketError(error2, url);
5719
5740
  if (upgradeRejectionReason === "do_code_updated") {
5720
5741
  onWarning?.("Relay redeployed \u2014 reconnecting");
@@ -5726,7 +5747,8 @@ function connectTunnel(options) {
5726
5747
  );
5727
5748
  });
5728
5749
  ws.on("close", (code, reason) => {
5729
- const reasonStr = reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
5750
+ clearRelaySilenceTimeout();
5751
+ const reasonStr = (relaySilenceTimedOut ? "no relay heartbeat for 90s \u2014 reconnecting" : void 0) || reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
5730
5752
  forwarder.abortAll();
5731
5753
  onDisconnected?.(code, reasonStr);
5732
5754
  });
@@ -5734,7 +5756,7 @@ function connectTunnel(options) {
5734
5756
  }
5735
5757
 
5736
5758
  // src/lib/tunnel/runner-connection.ts
5737
- var RunnerConnection = class {
5759
+ var RunnerConnection = class _RunnerConnection {
5738
5760
  opts;
5739
5761
  sleep;
5740
5762
  now;
@@ -5748,6 +5770,10 @@ var RunnerConnection = class {
5748
5770
  reconnectAttempt = 0;
5749
5771
  generation = 0;
5750
5772
  disconnectedAtMs = null;
5773
+ static RELAY_RECONNECT_CLOSE_REASONS = /* @__PURE__ */ new Set([
5774
+ "No pong received",
5775
+ "Orphaned socket"
5776
+ ]);
5751
5777
  constructor(opts) {
5752
5778
  this.opts = opts;
5753
5779
  this.resolvedAgentId = opts.agentId;
@@ -5804,7 +5830,8 @@ var RunnerConnection = class {
5804
5830
  onDisconnected: (code, reason) => {
5805
5831
  this.disconnectedAtMs = this.now();
5806
5832
  events.onDisconnected(code, reason, { generation: this.generation });
5807
- if (this.opts.isRunning() && code !== 1e3 && !this.reconnecting) {
5833
+ const relayRequestedReconnect = code === 1e3 && _RunnerConnection.RELAY_RECONNECT_CLOSE_REASONS.has(reason);
5834
+ if (this.opts.isRunning() && (code !== 1e3 || relayRequestedReconnect) && !this.reconnecting) {
5808
5835
  this.reconnectPromise = this.connectWithRetry(true).catch((err) => {
5809
5836
  events.onError?.(`Reconnection failed: ${err.message}`);
5810
5837
  });