@tangle-network/agent-app 0.62.1 → 0.62.3

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.
@@ -41,9 +41,9 @@ import {
41
41
  createSandboxRunTool,
42
42
  escalationHints,
43
43
  flattenHistory
44
- } from "../chunk-MVKMDROU.js";
44
+ } from "../chunk-ISRPOPMM.js";
45
45
  import "../chunk-F4TUZYMX.js";
46
- import "../chunk-4MD5PS4F.js";
46
+ import "../chunk-PK65B6HP.js";
47
47
  import {
48
48
  ModelFailoverExhaustedError,
49
49
  buildModelChain,
@@ -7,9 +7,10 @@ import {
7
7
  isSandboxBoxConfigFailure,
8
8
  isSandboxHostCapacityFailure,
9
9
  plannedHostRestart,
10
+ readDuringPlannedHostRestart,
10
11
  sandboxTransientBackoffMs,
11
12
  serializeSandboxProvisioningError
12
- } from "./chunk-4MD5PS4F.js";
13
+ } from "./chunk-PK65B6HP.js";
13
14
  import {
14
15
  assertProfilePromptWithinBudget,
15
16
  fingerprintAgentProfile
@@ -2279,9 +2280,14 @@ function hasRecentEgress(box, desired) {
2279
2280
  const verified = checksFor(box)?.egress;
2280
2281
  return isRecent(verified?.at, TRUSTED_REUSE_TTL_MS) && verified?.key === normalizedEgressPolicy(desired);
2281
2282
  }
2282
- async function pushRuntimeEnv(box, env, measure) {
2283
+ async function pushRuntimeEnv(box, env, measure, deadline) {
2283
2284
  try {
2284
- await (measure ? measure("runtime_env_push", () => box.setRuntimeEnv(env)) : box.setRuntimeEnv(env));
2285
+ const push = () => box.setRuntimeEnv(env);
2286
+ const deliver = async () => {
2287
+ if (deadline === void 0) await push();
2288
+ else await readDuringPlannedHostRestart(push, deadline);
2289
+ };
2290
+ await (measure ? measure("runtime_env_push", deliver) : deliver());
2285
2291
  recordCheck(box, { env: { digest: runtimeEnvDigest(env), at: Date.now() } });
2286
2292
  return ok(void 0);
2287
2293
  } catch (cause) {
@@ -2323,8 +2329,9 @@ function recordVerifiedEgress(box, desired) {
2323
2329
  recordCheck(box, { egress: { key: normalizedEgressPolicy(desired), at: Date.now() } });
2324
2330
  }
2325
2331
  async function finalizeExistingBox(shell, client, box, stage, name, workspaceId, userId, harness, scope, runtimeEnv, prefetch = {}) {
2332
+ const deadline = Date.now() + (shell.provisionTimeoutMs ?? DEFAULT_PROVISION_TIMEOUT_MS);
2326
2333
  if (!prefetch.egressVerified) {
2327
- await assertExistingBoxEgress(box, shell.egressPolicy, shell.migrateEgressPolicy, stage, name, prefetch.egress);
2334
+ await assertExistingBoxEgress(box, shell.egressPolicy, shell.migrateEgressPolicy, stage, name, deadline, prefetch.egress);
2328
2335
  }
2329
2336
  const written = await materializeDeferredFilesForExistingBox(
2330
2337
  shell,
@@ -2344,11 +2351,11 @@ async function finalizeExistingBox(shell, client, box, stage, name, workspaceId,
2344
2351
  if (prefetch.runtimeEnv) {
2345
2352
  let renewed = await prefetch.runtimeEnv;
2346
2353
  if (!renewed.succeeded && plannedHostRestart(renewed.error)) {
2347
- renewed = await pushRuntimeEnv(finalBox, runtimeEnv);
2354
+ renewed = await pushRuntimeEnv(finalBox, runtimeEnv, void 0, deadline);
2348
2355
  }
2349
2356
  if (!renewed.succeeded) throw renewed.error;
2350
2357
  } else if (!prefetch.envDelivered && Object.keys(runtimeEnv).length > 0) {
2351
- const renewed = await pushRuntimeEnv(finalBox, runtimeEnv);
2358
+ const renewed = await pushRuntimeEnv(finalBox, runtimeEnv, void 0, deadline);
2352
2359
  if (!renewed.succeeded) throw renewed.error;
2353
2360
  }
2354
2361
  if (shell.bootstrap) {
@@ -2394,7 +2401,7 @@ function existingBoxEgressError(operation, box, stage, name, cause) {
2394
2401
  }
2395
2402
  );
2396
2403
  }
2397
- async function assertExistingBoxEgress(box, desired, migrate, stage, name, prefetched) {
2404
+ async function assertExistingBoxEgress(box, desired, migrate, stage, name, deadline, prefetched) {
2398
2405
  if (!desired) return;
2399
2406
  let current;
2400
2407
  const read = prefetched ? await prefetched : void 0;
@@ -2405,7 +2412,7 @@ async function assertExistingBoxEgress(box, desired, migrate, stage, name, prefe
2405
2412
  throw existingBoxEgressError("read", box, stage, name, read.error);
2406
2413
  }
2407
2414
  try {
2408
- current = await box.egress.get();
2415
+ current = (await readDuringPlannedHostRestart(() => box.egress.get(), deadline)).value;
2409
2416
  } catch (cause) {
2410
2417
  throw existingBoxEgressError("read", box, stage, name, cause);
2411
2418
  }
@@ -2440,21 +2447,6 @@ async function assertExistingBoxEgress(box, desired, migrate, stage, name, prefe
2440
2447
  }
2441
2448
 
2442
2449
  // src/sandbox/box-health.ts
2443
- async function readDuringPlannedHostRestart(read, deadline) {
2444
- let waited = false;
2445
- for (; ; ) {
2446
- try {
2447
- return { value: await read(), waited };
2448
- } catch (error) {
2449
- if (!plannedHostRestart(error)) throw error;
2450
- const hint = error.retryAfterMs;
2451
- const delay = typeof hint === "number" && Number.isFinite(hint) && hint > 0 ? hint : sandboxTransientBackoffMs(1);
2452
- if (Date.now() + delay >= deadline) throw error;
2453
- waited = true;
2454
- await new Promise((resolve) => setTimeout(resolve, delay));
2455
- }
2456
- }
2457
- }
2458
2450
  async function isBoxAlive(box, probe, deadline) {
2459
2451
  if (!probe) return ok(void 0);
2460
2452
  try {
@@ -3694,4 +3686,4 @@ export {
3694
3686
  deleteSecret,
3695
3687
  mintSandboxScopedToken
3696
3688
  };
3697
- //# sourceMappingURL=chunk-MVKMDROU.js.map
3689
+ //# sourceMappingURL=chunk-ISRPOPMM.js.map