@opengeni/worker-bundle 1.4.0 → 1.4.4
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/activities/agent-turn/errors.d.ts +6 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +22 -0
- package/dist/activities/agent-turn/turn-context.d.ts +6 -0
- package/dist/activities/agent-turn/web-search.d.ts +5 -1
- package/dist/activities/codemode-dispatcher.d.ts +8 -0
- package/dist/activities/programmatic-approvals.d.ts +0 -17
- package/dist/activities/sandbox-lease.d.ts +9 -0
- package/dist/{activities-control-D5KVEPHI.js → activities-control-VRFS65FT.js} +59 -13
- package/dist/activities-control-VRFS65FT.js.map +1 -0
- package/dist/{activities-turn-4Z3M7Z3F.js → activities-turn-P2YAW2QW.js} +6038 -5890
- package/dist/activities-turn-P2YAW2QW.js.map +1 -0
- package/dist/{chunk-BMTWULF7.js → chunk-BICGFGO7.js} +92 -17
- package/dist/chunk-BICGFGO7.js.map +1 -0
- package/dist/{chunk-FF4HPY7L.js → chunk-HVNNCWEU.js} +108 -3
- package/dist/chunk-HVNNCWEU.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/observability-metrics.d.ts +52 -14
- package/dist/sandbox-resume.d.ts +3 -0
- package/package.json +21 -21
- package/src/activities/agent-turn/errors.ts +61 -7
- package/src/activities/agent-turn/finalization.ts +16 -0
- package/src/activities/agent-turn/run.ts +12 -0
- package/src/activities/agent-turn/sandbox-establish.ts +87 -80
- package/src/activities/agent-turn/sandbox-provision.ts +51 -0
- package/src/activities/agent-turn/stream-attempt.ts +37 -50
- package/src/activities/agent-turn/turn-context.ts +8 -0
- package/src/activities/agent-turn/web-search.ts +135 -6
- package/src/activities/codemode-dispatcher.ts +57 -8
- package/src/activities/programmatic-approvals.ts +0 -26
- package/src/activities/sandbox-lease.ts +77 -10
- package/src/observability-metrics.ts +130 -18
- package/src/sandbox-resume.ts +24 -5
- package/src/sandbox-routing.ts +12 -0
- package/dist/activities-control-D5KVEPHI.js.map +0 -1
- package/dist/activities-turn-4Z3M7Z3F.js.map +0 -1
- package/dist/chunk-BMTWULF7.js.map +0 -1
- package/dist/chunk-FF4HPY7L.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
observabilityEventBusOptions
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HVNNCWEU.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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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 ??
|
|
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 ??
|
|
8992
|
+
const wait = options.wait ?? sleep;
|
|
8957
8993
|
let lastError;
|
|
8958
8994
|
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
8959
8995
|
try {
|
|
@@ -9143,6 +9179,7 @@ import {
|
|
|
9143
9179
|
RoutingWorkspaceRootChangedError,
|
|
9144
9180
|
RoutingBackendRecoveryRequiredError as RoutingBackendRecoveryRequiredError2,
|
|
9145
9181
|
ResponsesStreamingTerminalError,
|
|
9182
|
+
classifyModelStreamIdleTimeoutError,
|
|
9146
9183
|
SandboxMaterializationVerificationError,
|
|
9147
9184
|
materializationVerificationDiagnostic,
|
|
9148
9185
|
PROVIDER_QUOTA_EXHAUSTED_CODE,
|
|
@@ -10018,8 +10055,9 @@ function retryableDatabaseFailureCode(error, requireDatabaseProvenance = false)
|
|
|
10018
10055
|
boundaries.add(node);
|
|
10019
10056
|
const sqlState = typed ? node.details.sqlState : typeof record.code === "string" ? record.code : null;
|
|
10020
10057
|
const connectionOutage = requireDatabaseProvenance ? isRunningTurnDatabaseConnectionSqlState(sqlState) : isDatabaseConnectionSqlState(sqlState);
|
|
10021
|
-
const
|
|
10022
|
-
|
|
10058
|
+
const rolledBack = isRetryablePersistenceSqlState(sqlState);
|
|
10059
|
+
const code = typed ? retryablePersistenceFailureCode(sqlState) : connectionOutage || rolledBack ? databaseFailureCode(sqlState) : null;
|
|
10060
|
+
if (!code || requireDatabaseProvenance && !connectionOutage && !rolledBack && !(sqlState === null && hasOwnTransport(node)))
|
|
10023
10061
|
return null;
|
|
10024
10062
|
if (!requireDatabaseProvenance || ownDatabaseNodes.has(node)) codes.add(code);
|
|
10025
10063
|
}
|
|
@@ -10062,8 +10100,7 @@ function retryablePersistenceFailureCode(sqlState) {
|
|
|
10062
10100
|
}
|
|
10063
10101
|
function postClaimDatabaseRecoveryFailure(input) {
|
|
10064
10102
|
const code = retryableDatabaseFailureCode(input.error, input.requireDatabaseProvenance);
|
|
10065
|
-
if (!code || input.executionGeneration < 1
|
|
10066
|
-
return null;
|
|
10103
|
+
if (!code || input.executionGeneration < 1) return null;
|
|
10067
10104
|
if (input.sandboxSetupOutcomeUnknown && input.sandboxSetupRecoveryExhausted || (input.sandboxSetupOutcomeUnknown || input.sandboxSetupRecoveryExhausted) && input.providerRecovery) {
|
|
10068
10105
|
return null;
|
|
10069
10106
|
}
|
|
@@ -10358,6 +10395,20 @@ function providerHttpStatus(error) {
|
|
|
10358
10395
|
}
|
|
10359
10396
|
return void 0;
|
|
10360
10397
|
}
|
|
10398
|
+
function isTransportTimeoutError(error) {
|
|
10399
|
+
let current = error;
|
|
10400
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10401
|
+
for (let depth = 0; depth < 8 && current && typeof current === "object"; depth += 1) {
|
|
10402
|
+
if (seen.has(current)) break;
|
|
10403
|
+
seen.add(current);
|
|
10404
|
+
const value = current;
|
|
10405
|
+
if (value.name === "TimeoutError" || value.message === "The operation timed out.") {
|
|
10406
|
+
return true;
|
|
10407
|
+
}
|
|
10408
|
+
current = value.cause;
|
|
10409
|
+
}
|
|
10410
|
+
return false;
|
|
10411
|
+
}
|
|
10361
10412
|
function isTransientProviderError(error) {
|
|
10362
10413
|
if (error instanceof ResponsesStreamingTerminalError) {
|
|
10363
10414
|
return error.category === "unavailable";
|
|
@@ -10721,6 +10772,28 @@ function baseAgentRunFailurePayload(error, options = {}) {
|
|
|
10721
10772
|
...mcpTransportDiagnostic ? { mcpTransportDiagnostic } : {}
|
|
10722
10773
|
};
|
|
10723
10774
|
}
|
|
10775
|
+
const streamIdle = classifyModelStreamIdleTimeoutError(error);
|
|
10776
|
+
if (streamIdle) {
|
|
10777
|
+
const seconds = streamIdle.idleTimeoutMs !== null ? Math.round(streamIdle.idleTimeoutMs / 1e3) : null;
|
|
10778
|
+
const window = seconds !== null ? ` for ${seconds}s` : "";
|
|
10779
|
+
return {
|
|
10780
|
+
error: streamIdle.kind === "progress" ? `The model provider stream stalled: only keepalive traffic and no response progress${window}. The same turn will retry after a short delay.` : `The model provider stopped sending response data${window}. The same turn will retry after a short delay.`,
|
|
10781
|
+
code: "provider_unavailable",
|
|
10782
|
+
retryable: true,
|
|
10783
|
+
timeoutClass: streamIdle.kind === "progress" ? "progress_stream" : "idle_stream",
|
|
10784
|
+
responseObserved: true,
|
|
10785
|
+
detail: streamIdle.message
|
|
10786
|
+
};
|
|
10787
|
+
}
|
|
10788
|
+
if (status === void 0 && isTransportTimeoutError(error)) {
|
|
10789
|
+
return {
|
|
10790
|
+
error: "The model provider connection timed out. The same turn will retry after a short delay.",
|
|
10791
|
+
code: "provider_unavailable",
|
|
10792
|
+
retryable: true,
|
|
10793
|
+
timeoutClass: "transport",
|
|
10794
|
+
detail: message
|
|
10795
|
+
};
|
|
10796
|
+
}
|
|
10724
10797
|
if (code === UNKNOWN_MODEL_FINISH_REASON_CODE) {
|
|
10725
10798
|
return {
|
|
10726
10799
|
error: "The model provider ended its response ambiguously. Partial output was not accepted as complete; the same turn will retry from durable history.",
|
|
@@ -10957,6 +11030,8 @@ export {
|
|
|
10957
11030
|
turnOperationCancellationFailure,
|
|
10958
11031
|
throwIfTurnOperationCancelled,
|
|
10959
11032
|
waitForTurnOperation,
|
|
11033
|
+
trackPhysicalSandboxResume,
|
|
11034
|
+
drainPhysicalSandboxResumes,
|
|
10960
11035
|
classifySandboxLogicalProvisionFailure,
|
|
10961
11036
|
isLazySandboxProvisionRetryable,
|
|
10962
11037
|
sandboxDeadlineRotationRecoveryDelayMs,
|
|
@@ -11009,4 +11084,4 @@ export {
|
|
|
11009
11084
|
CODEX_USAGE_LIMIT_MAX_RESUME_MS,
|
|
11010
11085
|
classifyClaudeCredentialFailure
|
|
11011
11086
|
};
|
|
11012
|
-
//# sourceMappingURL=chunk-
|
|
11087
|
+
//# sourceMappingURL=chunk-BICGFGO7.js.map
|