@odla-ai/harness 0.11.0 → 0.11.1

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.
@@ -422,40 +422,40 @@ async function readBoundedResponse(body, maximum) {
422
422
  return result;
423
423
  }
424
424
 
425
- // src/code-runtime.ts
426
- var CODE_RUNTIME_PROTOCOL_VERSION = 3;
427
- async function runCodeRuntimeHeartbeatLoop(options) {
428
- const heartbeatMs = options.heartbeatMs ?? 15e3;
429
- if (!Number.isSafeInteger(heartbeatMs) || heartbeatMs < 1e3 || heartbeatMs > 3e5) {
430
- throw new TypeError("heartbeatMs must be an integer from 1000 to 300000");
431
- }
432
- let retryMs = 1e3;
433
- do {
434
- if (options.signal?.aborted) return;
425
+ // src/code-runtime-overload.ts
426
+ var OVERLOAD_RETRY_DELAYS_MS = [2e3, 4e3, 8e3, 16e3];
427
+ var RETRYABLE_CODES = /* @__PURE__ */ new Set(["control_plane_overloaded", "registry_overloaded", "transport_unavailable"]);
428
+ function overloadedControlFailure(cause) {
429
+ if (!cause || typeof cause !== "object") return false;
430
+ const failure = cause;
431
+ return failure.status === 503 && typeof failure.code === "string" && RETRYABLE_CODES.has(failure.code);
432
+ }
433
+ async function withOverloadRetry(call, wait2, onRetry = () => void 0) {
434
+ for (let attempt = 0; ; attempt += 1) {
435
435
  try {
436
- const snapshot = await options.control.heartbeat(options.runtimeVersion, options.capabilities);
437
- await options.onSnapshot?.(snapshot);
438
- retryMs = 1e3;
439
- if (options.once) return;
440
- await wait(heartbeatMs, options.signal);
441
- } catch (error) {
442
- if (options.signal?.aborted) return;
443
- if (options.once || !retryableControlFailure(error)) throw error;
444
- await options.onRetry?.(error, retryMs);
445
- await wait(retryMs, options.signal);
446
- retryMs = Math.min(retryMs * 2, 3e4);
436
+ return await call();
437
+ } catch (cause) {
438
+ const delayMs = OVERLOAD_RETRY_DELAYS_MS[attempt];
439
+ if (delayMs === void 0 || !overloadedControlFailure(cause)) throw cause;
440
+ await onRetry(cause, delayMs);
441
+ await wait2(delayMs);
447
442
  }
448
- } while (!options.signal?.aborted);
443
+ }
449
444
  }
445
+
446
+ // src/code-runtime-reconciler.ts
447
+ var sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
450
448
  var CodeRuntimeReconciler = class {
451
- constructor(control, engine, onDiagnostic) {
449
+ constructor(control, engine, onDiagnostic, options = {}) {
452
450
  this.control = control;
453
451
  this.engine = engine;
454
452
  this.onDiagnostic = onDiagnostic;
453
+ this.options = options;
455
454
  }
456
455
  control;
457
456
  engine;
458
457
  onDiagnostic;
458
+ options;
459
459
  results = /* @__PURE__ */ new Map();
460
460
  async reconcile(snapshot) {
461
461
  for (const command of snapshot.commands) {
@@ -474,7 +474,15 @@ var CodeRuntimeReconciler = class {
474
474
  await this.control.acknowledge(command.commandId, completed.result);
475
475
  if (!completed.notified) {
476
476
  try {
477
- await this.engine.acknowledged?.(command, completed.result);
477
+ await withOverloadRetry(
478
+ async () => {
479
+ await this.engine.acknowledged?.(command, completed.result);
480
+ },
481
+ (ms) => (this.options.wait ?? sleep)(ms),
482
+ (cause, delayMs) => this.onDiagnostic?.(
483
+ `command ${command.commandId} acknowledged handling waits ${delayMs}ms for an overloaded control plane \xB7 ${cause instanceof Error ? cause.message : String(cause)}`
484
+ )
485
+ );
478
486
  } catch (error) {
479
487
  this.onDiagnostic?.(
480
488
  `command ${command.commandId} acknowledged handling failed \xB7 ${error instanceof Error ? error.message : String(error)}`
@@ -485,6 +493,32 @@ var CodeRuntimeReconciler = class {
485
493
  }
486
494
  }
487
495
  };
496
+
497
+ // src/code-runtime.ts
498
+ var CODE_RUNTIME_PROTOCOL_VERSION = 3;
499
+ async function runCodeRuntimeHeartbeatLoop(options) {
500
+ const heartbeatMs = options.heartbeatMs ?? 15e3;
501
+ if (!Number.isSafeInteger(heartbeatMs) || heartbeatMs < 1e3 || heartbeatMs > 3e5) {
502
+ throw new TypeError("heartbeatMs must be an integer from 1000 to 300000");
503
+ }
504
+ let retryMs = 1e3;
505
+ do {
506
+ if (options.signal?.aborted) return;
507
+ try {
508
+ const snapshot = await options.control.heartbeat(options.runtimeVersion, options.capabilities);
509
+ await options.onSnapshot?.(snapshot);
510
+ retryMs = 1e3;
511
+ if (options.once) return;
512
+ await wait(heartbeatMs, options.signal);
513
+ } catch (error) {
514
+ if (options.signal?.aborted) return;
515
+ if (options.once || !retryableControlFailure(error)) throw error;
516
+ await options.onRetry?.(error, retryMs);
517
+ await wait(retryMs, options.signal);
518
+ retryMs = Math.min(retryMs * 2, 3e4);
519
+ }
520
+ } while (!options.signal?.aborted);
521
+ }
488
522
  function retryableControlFailure(value) {
489
523
  if (!value || typeof value !== "object") return false;
490
524
  const failure = value;
@@ -2384,23 +2418,7 @@ async function sessionSkillsFor(options, command) {
2384
2418
  }
2385
2419
 
2386
2420
  // src/code-runtime-inference.ts
2387
- var OVERLOAD_RETRY_DELAYS_MS = [2e3, 4e3, 8e3, 16e3];
2388
- var RETRYABLE_CODES = /* @__PURE__ */ new Set(["control_plane_overloaded", "registry_overloaded", "transport_unavailable"]);
2389
- function overloadedControlFailure(cause) {
2390
- return cause instanceof CodeRuntimeControlError && cause.status === 503 && RETRYABLE_CODES.has(cause.code);
2391
- }
2392
- async function inferWithBackoff(infer, wait2, onRetry) {
2393
- for (let attempt = 0; ; attempt += 1) {
2394
- try {
2395
- return await infer();
2396
- } catch (cause) {
2397
- const delayMs = OVERLOAD_RETRY_DELAYS_MS[attempt];
2398
- if (delayMs === void 0 || !overloadedControlFailure(cause)) throw cause;
2399
- await onRetry(cause, delayMs);
2400
- await wait2(delayMs);
2401
- }
2402
- }
2403
- }
2421
+ var inferWithBackoff = (infer, wait2, onRetry) => withOverloadRetry(infer, wait2, (cause, delayMs) => onRetry(cause, delayMs));
2404
2422
  async function handleCodeRuntimeInference(input) {
2405
2423
  const { command, request, state } = input;
2406
2424
  const startedAt = Date.now();