@opengeni/worker-bundle 1.4.0 → 1.4.2

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.
Files changed (36) hide show
  1. package/dist/activities/agent-turn/sandbox-provision.d.ts +22 -0
  2. package/dist/activities/agent-turn/turn-context.d.ts +6 -0
  3. package/dist/activities/agent-turn/web-search.d.ts +5 -1
  4. package/dist/activities/codemode-dispatcher.d.ts +8 -0
  5. package/dist/activities/programmatic-approvals.d.ts +0 -17
  6. package/dist/activities/sandbox-lease.d.ts +4 -0
  7. package/dist/{activities-control-D5KVEPHI.js → activities-control-AKJZHDTY.js} +53 -13
  8. package/dist/activities-control-AKJZHDTY.js.map +1 -0
  9. package/dist/{activities-turn-4Z3M7Z3F.js → activities-turn-AOXNE6BM.js} +6038 -5890
  10. package/dist/activities-turn-AOXNE6BM.js.map +1 -0
  11. package/dist/{chunk-FF4HPY7L.js → chunk-DCQ7XTXW.js} +108 -3
  12. package/dist/chunk-DCQ7XTXW.js.map +1 -0
  13. package/dist/{chunk-BMTWULF7.js → chunk-WVZQJBGD.js} +55 -17
  14. package/dist/chunk-WVZQJBGD.js.map +1 -0
  15. package/dist/index.js +2 -2
  16. package/dist/observability-metrics.d.ts +52 -14
  17. package/dist/sandbox-resume.d.ts +3 -0
  18. package/package.json +21 -21
  19. package/src/activities/agent-turn/errors.ts +7 -7
  20. package/src/activities/agent-turn/finalization.ts +16 -0
  21. package/src/activities/agent-turn/run.ts +12 -0
  22. package/src/activities/agent-turn/sandbox-establish.ts +87 -80
  23. package/src/activities/agent-turn/sandbox-provision.ts +51 -0
  24. package/src/activities/agent-turn/stream-attempt.ts +37 -50
  25. package/src/activities/agent-turn/turn-context.ts +8 -0
  26. package/src/activities/agent-turn/web-search.ts +135 -6
  27. package/src/activities/codemode-dispatcher.ts +57 -8
  28. package/src/activities/programmatic-approvals.ts +0 -26
  29. package/src/activities/sandbox-lease.ts +63 -10
  30. package/src/observability-metrics.ts +130 -18
  31. package/src/sandbox-resume.ts +24 -5
  32. package/src/sandbox-routing.ts +12 -0
  33. package/dist/activities-control-D5KVEPHI.js.map +0 -1
  34. package/dist/activities-turn-4Z3M7Z3F.js.map +0 -1
  35. package/dist/chunk-BMTWULF7.js.map +0 -1
  36. package/dist/chunk-FF4HPY7L.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  observabilityEventBusOptions
3
- } from "./chunk-FF4HPY7L.js";
3
+ } from "./chunk-DCQ7XTXW.js";
4
4
 
5
5
  // src/activity-services.ts
6
6
  import {
@@ -1565,7 +1565,7 @@ var GoogleDriveProviderTransportError = class extends Error {
1565
1565
  };
1566
1566
  async function fetchGoogleDriveProvider(input) {
1567
1567
  const now = input.now ?? Date.now;
1568
- const sleep3 = input.sleep ?? Bun.sleep;
1568
+ const sleep2 = input.sleep ?? Bun.sleep;
1569
1569
  let retryDelaySpentMs = 0;
1570
1570
  for (let attempt = 1; attempt <= input.policy.attempts; attempt += 1) {
1571
1571
  let response;
@@ -1586,7 +1586,7 @@ async function fetchGoogleDriveProvider(input) {
1586
1586
  recordRetry(input.observability, input.operation, "transport", attempt, delayMs2);
1587
1587
  retryDelaySpentMs += delayMs2;
1588
1588
  input.heartbeat?.({ operation: input.operation, attempt, phase: "retry_delay_start" });
1589
- await sleep3(delayMs2);
1589
+ await sleep2(delayMs2);
1590
1590
  input.heartbeat?.({ operation: input.operation, attempt, phase: "retry_delay_end" });
1591
1591
  continue;
1592
1592
  }
@@ -1616,7 +1616,7 @@ async function fetchGoogleDriveProvider(input) {
1616
1616
  );
1617
1617
  retryDelaySpentMs += delayMs;
1618
1618
  input.heartbeat?.({ operation: input.operation, attempt, phase: "retry_delay_start" });
1619
- await sleep3(delayMs);
1619
+ await sleep2(delayMs);
1620
1620
  input.heartbeat?.({ operation: input.operation, attempt, phase: "retry_delay_end" });
1621
1621
  }
1622
1622
  throw new GoogleDriveProviderTransportError();
@@ -4998,6 +4998,7 @@ import {
4998
4998
  readActiveSandbox,
4999
4999
  resolvePersonalMachineConnectionForAttempt,
5000
5000
  SandboxRetainedProcessPromotionFencedError,
5001
+ SandboxRetainedProcessTerminalError,
5001
5002
  SandboxWorkspaceMutationOutputRejectedError
5002
5003
  } from "@opengeni/db";
5003
5004
  import {
@@ -5217,9 +5218,6 @@ var SandboxLeaseInstanceLostError = class extends SandboxLeaseSupersededError {
5217
5218
  }
5218
5219
  };
5219
5220
  var WARMING_POLL_INTERVAL_MS = 250;
5220
- async function sleep(ms) {
5221
- await new Promise((resolve) => setTimeout(resolve, ms));
5222
- }
5223
5221
  async function waitForSandboxExecReadiness(established, timeoutMs = MODAL_EXEC_READINESS_TIMEOUT_MS, identity = {}, signal) {
5224
5222
  try {
5225
5223
  await verifySandboxExecReadiness(established, timeoutMs, signal);
@@ -5949,6 +5947,7 @@ async function resumeBoxForTurnOnce(services, ids, kind, holderId) {
5949
5947
  if (acquired.role === "spawner") {
5950
5948
  const expectedEpoch = acquired.lease.leaseEpoch;
5951
5949
  let createdEstablished = null;
5950
+ let published = false;
5952
5951
  let providerCreateOperationId;
5953
5952
  let providerCreateBindingKey;
5954
5953
  let rematerialization = null;
@@ -6271,13 +6270,19 @@ async function resumeBoxForTurnOnce(services, ids, kind, holderId) {
6271
6270
  await release();
6272
6271
  throw new SandboxLeaseSupersededError(ids.sandboxGroupId, expectedEpoch);
6273
6272
  }
6273
+ published = true;
6274
6274
  holderLeaseHeartbeat = {
6275
6275
  expectedEpoch: committed.lease.leaseEpoch,
6276
6276
  leaseTtlMs
6277
6277
  };
6278
+ await services.onSpawnedSandboxPublished?.();
6278
6279
  throwIfReleasedOrCancelled();
6279
6280
  return { established, leaseEpoch: committed.lease.leaseEpoch, release };
6280
6281
  } catch (error) {
6282
+ if (published) {
6283
+ await release();
6284
+ throw error;
6285
+ }
6281
6286
  if (error instanceof SandboxLeaseSupersededError) {
6282
6287
  await terminateEstablishedSandbox(createdEstablished);
6283
6288
  await release();
@@ -6402,7 +6407,9 @@ async function waitForWarm(services, ids) {
6402
6407
  const deadline = Date.now() + settings.sandboxWarmingTimeoutMs;
6403
6408
  let instanceId = null;
6404
6409
  while (Date.now() < deadline) {
6405
- await sleep(WARMING_POLL_INTERVAL_MS);
6410
+ if (!await sleepUnlessCancelled(WARMING_POLL_INTERVAL_MS, services.cancellationSignal)) {
6411
+ throw services.cancellationSignal?.reason instanceof Error ? services.cancellationSignal.reason : new Error("Sandbox warming wait was cancelled with its owning turn attempt");
6412
+ }
6406
6413
  const lease = await readLease(db, ids.workspaceId, ids.sandboxGroupId);
6407
6414
  if (!lease) {
6408
6415
  throw new SandboxLeaseSupersededError(ids.sandboxGroupId, 0);
@@ -6732,6 +6739,12 @@ function afterRetainedProcessMutation(services, ids) {
6732
6739
  operation: op,
6733
6740
  outcome
6734
6741
  })) {
6742
+ if (error.retainedProcessTerminal) {
6743
+ throw new SandboxRetainedProcessTerminalError(
6744
+ error.retainedProcessTerminal.state,
6745
+ error.retainedProcessTerminal.exitCode
6746
+ );
6747
+ }
6735
6748
  throw new RoutingMutationOutputRejectedError(op, error.code, { cause: error });
6736
6749
  }
6737
6750
  throw error;
@@ -8544,7 +8557,30 @@ async function waitForTurnOperation(operation, signal, disposeLateResult) {
8544
8557
  signal.removeEventListener("abort", cancel);
8545
8558
  }
8546
8559
  }
8547
- function sleep2(ms) {
8560
+ var PHYSICAL_SANDBOX_RESUME_DRAIN_TIMEOUT_MS = 6e4;
8561
+ function trackPhysicalSandboxResume(inFlight, operation) {
8562
+ inFlight.add(operation);
8563
+ const settle = () => {
8564
+ inFlight.delete(operation);
8565
+ };
8566
+ operation.then(settle, settle);
8567
+ return operation;
8568
+ }
8569
+ async function drainPhysicalSandboxResumes(inFlight, timeoutMs = PHYSICAL_SANDBOX_RESUME_DRAIN_TIMEOUT_MS) {
8570
+ if (inFlight.size === 0) return "none";
8571
+ let timer;
8572
+ try {
8573
+ return await Promise.race([
8574
+ Promise.allSettled([...inFlight]).then(() => "settled"),
8575
+ new Promise((resolve) => {
8576
+ timer = setTimeout(() => resolve("timed_out"), Math.max(1, timeoutMs));
8577
+ })
8578
+ ]);
8579
+ } finally {
8580
+ if (timer) clearTimeout(timer);
8581
+ }
8582
+ }
8583
+ function sleep(ms) {
8548
8584
  return new Promise((resolve) => setTimeout(resolve, ms));
8549
8585
  }
8550
8586
  function sandboxProvisionErrorChain(error) {
@@ -8769,7 +8805,7 @@ function createTurnSandboxProvisioner(establish, options = {}) {
8769
8805
  if (!retrying) {
8770
8806
  throw error;
8771
8807
  }
8772
- await sleep2(backoffMs * internalAttempts);
8808
+ await sleep(backoffMs * internalAttempts);
8773
8809
  }
8774
8810
  }
8775
8811
  };
@@ -8904,7 +8940,7 @@ async function persistOrSignalSessionAttemptQuiescence(input) {
8904
8940
  cause: receiptError
8905
8941
  });
8906
8942
  }
8907
- const delay = input.sleep ?? sleep2;
8943
+ const delay = input.sleep ?? sleep;
8908
8944
  let retryMs = QUIESCENCE_PROOF_SIGNAL_INITIAL_RETRY_MS;
8909
8945
  let attempt = 1;
8910
8946
  for (; ; ) {
@@ -8953,7 +8989,7 @@ async function drainAttemptOwnedSandboxWriters(input) {
8953
8989
  async function releaseTurnSandboxAfterWriterDrain(sandbox, options = {}) {
8954
8990
  const maxAttempts = Math.max(1, options.maxAttempts ?? 3);
8955
8991
  const retryDelayMs2 = Math.max(0, options.retryDelayMs ?? 50);
8956
- const wait = options.wait ?? sleep2;
8992
+ const wait = options.wait ?? sleep;
8957
8993
  let lastError;
8958
8994
  for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
8959
8995
  try {
@@ -10018,8 +10054,9 @@ function retryableDatabaseFailureCode(error, requireDatabaseProvenance = false)
10018
10054
  boundaries.add(node);
10019
10055
  const sqlState = typed ? node.details.sqlState : typeof record.code === "string" ? record.code : null;
10020
10056
  const connectionOutage = requireDatabaseProvenance ? isRunningTurnDatabaseConnectionSqlState(sqlState) : isDatabaseConnectionSqlState(sqlState);
10021
- const code = typed ? retryablePersistenceFailureCode(sqlState) : connectionOutage || isRetryablePersistenceSqlState(sqlState) ? databaseFailureCode(sqlState) : null;
10022
- if (!code || requireDatabaseProvenance && !connectionOutage && !(sqlState === null && hasOwnTransport(node)))
10057
+ const rolledBack = isRetryablePersistenceSqlState(sqlState);
10058
+ const code = typed ? retryablePersistenceFailureCode(sqlState) : connectionOutage || rolledBack ? databaseFailureCode(sqlState) : null;
10059
+ if (!code || requireDatabaseProvenance && !connectionOutage && !rolledBack && !(sqlState === null && hasOwnTransport(node)))
10023
10060
  return null;
10024
10061
  if (!requireDatabaseProvenance || ownDatabaseNodes.has(node)) codes.add(code);
10025
10062
  }
@@ -10062,8 +10099,7 @@ function retryablePersistenceFailureCode(sqlState) {
10062
10099
  }
10063
10100
  function postClaimDatabaseRecoveryFailure(input) {
10064
10101
  const code = retryableDatabaseFailureCode(input.error, input.requireDatabaseProvenance);
10065
- if (!code || input.executionGeneration < 1 || input.requireDatabaseProvenance && code !== "db_failure")
10066
- return null;
10102
+ if (!code || input.executionGeneration < 1) return null;
10067
10103
  if (input.sandboxSetupOutcomeUnknown && input.sandboxSetupRecoveryExhausted || (input.sandboxSetupOutcomeUnknown || input.sandboxSetupRecoveryExhausted) && input.providerRecovery) {
10068
10104
  return null;
10069
10105
  }
@@ -10957,6 +10993,8 @@ export {
10957
10993
  turnOperationCancellationFailure,
10958
10994
  throwIfTurnOperationCancelled,
10959
10995
  waitForTurnOperation,
10996
+ trackPhysicalSandboxResume,
10997
+ drainPhysicalSandboxResumes,
10960
10998
  classifySandboxLogicalProvisionFailure,
10961
10999
  isLazySandboxProvisionRetryable,
10962
11000
  sandboxDeadlineRotationRecoveryDelayMs,
@@ -11009,4 +11047,4 @@ export {
11009
11047
  CODEX_USAGE_LIMIT_MAX_RESUME_MS,
11010
11048
  classifyClaudeCredentialFailure
11011
11049
  };
11012
- //# sourceMappingURL=chunk-BMTWULF7.js.map
11050
+ //# sourceMappingURL=chunk-WVZQJBGD.js.map