@ai-sdk/harness-codex 1.0.176 → 1.0.177

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @ai-sdk/harness-codex
2
2
 
3
+ ## 1.0.177
4
+
5
+ ### Patch Changes
6
+
7
+ - a54f0fd: fix(harness): abort a running turn when its host disconnects for good
8
+ - Updated dependencies [8e8033a]
9
+ - Updated dependencies [a54f0fd]
10
+ - @ai-sdk/harness@1.0.175
11
+
3
12
  ## 1.0.176
4
13
 
5
14
  ### Patch Changes
@@ -200,6 +200,12 @@ const WS_OPEN = 1;
200
200
  async function runBridge(options) {
201
201
  const { bridgeType, bridgeStateDir, onStart, onStop, onDestroy } = options;
202
202
  const teardownGraceMs = options.turnTeardownGraceMs ?? 1e4;
203
+ const hostDisconnectTimeoutMs = options.hostDisconnectTimeoutMs != null && Number.isFinite(options.hostDisconnectTimeoutMs) && options.hostDisconnectTimeoutMs > 0 ? Math.min(options.hostDisconnectTimeoutMs, 2147483647) : void 0;
204
+ let hostDisconnectTimer;
205
+ const clearHostDisconnectTimer = () => {
206
+ clearTimeout(hostDisconnectTimer);
207
+ hostDisconnectTimer = void 0;
208
+ };
203
209
  const expectedToken = options.token ?? env.BRIDGE_CHANNEL_TOKEN ?? "";
204
210
  const bridgeWsPort = options.port ?? parseInt(env.BRIDGE_WS_PORT ?? "0", 10);
205
211
  const bridgeMetaPath = `${bridgeStateDir}/bridge-meta.json`;
@@ -387,6 +393,7 @@ async function runBridge(options) {
387
393
  const thisTurn = new Promise((resolve) => turnFinished = resolve);
388
394
  activeTurn = thisTurn;
389
395
  activeSocket = ws;
396
+ clearHostDisconnectTimer();
390
397
  const firstTurn = isFirstTurn;
391
398
  isFirstTurn = false;
392
399
  eventLog = [];
@@ -453,6 +460,7 @@ async function runBridge(options) {
453
460
  activeTurn = void 0;
454
461
  currentTurnState = "waiting";
455
462
  writeBridgeMeta("waiting");
463
+ clearHostDisconnectTimer();
456
464
  }
457
465
  turnFinished();
458
466
  }
@@ -519,6 +527,7 @@ async function runBridge(options) {
519
527
  return;
520
528
  case "resume":
521
529
  activeSocket = ws;
530
+ clearHostDisconnectTimer();
522
531
  replay(ws, msg.lastSeenEventId);
523
532
  return;
524
533
  case "destroy":
@@ -606,8 +615,18 @@ async function runBridge(options) {
606
615
  }
607
616
  handleInbound(parsed, ws);
608
617
  });
609
- ws.on("close", () => {
610
- if (activeSocket === ws) activeSocket = void 0;
618
+ ws.on("close", (_code, reason) => {
619
+ if (activeSocket === ws) {
620
+ activeSocket = void 0;
621
+ if (hostDisconnectTimeoutMs != null && activeTurn != null && reason.toString() !== "suspended") {
622
+ clearHostDisconnectTimer();
623
+ hostDisconnectTimer = setTimeout(() => {
624
+ hostDisconnectTimer = void 0;
625
+ if (activeSocket == null) turnAbort?.abort();
626
+ }, hostDisconnectTimeoutMs);
627
+ hostDisconnectTimer.unref?.();
628
+ }
629
+ }
611
630
  });
612
631
  ws.on("error", () => {});
613
632
  });
@@ -2129,6 +2148,7 @@ const appServer = createCodexAppServerRuntime();
2129
2148
  await runBridge({
2130
2149
  bridgeType: "codex",
2131
2150
  bridgeStateDir,
2151
+ ...args.hostDisconnectTimeoutMs !== void 0 ? { hostDisconnectTimeoutMs: args.hostDisconnectTimeoutMs } : {},
2132
2152
  onStart: runTurn,
2133
2153
  onStop: async () => {
2134
2154
  const data = threadState.id ? { threadId: threadState.id } : {};
@@ -2220,6 +2240,7 @@ function parseArgs(args) {
2220
2240
  const out = {};
2221
2241
  for (let i = 0; i < args.length; i++) if (args[i] === "--workdir" && i + 1 < args.length) out.workdir = args[++i];
2222
2242
  else if (args[i] === "--bridge-state-dir" && i + 1 < args.length) out.bridgeStateDir = args[++i];
2243
+ else if (args[i] === "--host-disconnect-timeout-ms" && i + 1 < args.length) out.hostDisconnectTimeoutMs = Number(args[++i]);
2223
2244
  return out;
2224
2245
  }
2225
2246
  function emitFatal(message) {