@opengeni/worker-bundle 0.28.3-canary.0 → 0.28.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.
- package/dist/activities/sandbox-lease.d.ts +4 -4
- package/dist/{activities-control-JUBMDBDZ.js → activities-control-UXGPMDL3.js} +70 -55
- package/dist/activities-control-UXGPMDL3.js.map +1 -0
- package/dist/{activities-turn-I2ZKGZE6.js → activities-turn-NOYDE7PX.js} +12 -12
- package/dist/activities-turn-NOYDE7PX.js.map +1 -0
- package/dist/{chunk-A4XQWVZK.js → chunk-BARTLVBK.js} +25 -25
- package/dist/chunk-BARTLVBK.js.map +1 -0
- package/dist/{chunk-ZNIKZQMN.js → chunk-NNXLW6V7.js} +111 -144
- package/dist/chunk-NNXLW6V7.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/observability-metrics.d.ts +4 -12
- package/dist/sandbox-archive-storage.d.ts +3 -15
- package/dist/sandbox-resume.d.ts +1 -1
- package/package.json +17 -17
- package/src/activities/agent-turn/claim.ts +3 -3
- package/src/activities/agent-turn/finalization.ts +5 -10
- package/src/activities/agent-turn/stream-attempt.ts +1 -1
- package/src/activities/sandbox-lease.ts +71 -64
- package/src/observability-metrics.ts +24 -28
- package/src/sandbox-archive-storage.ts +18 -82
- package/src/sandbox-resume.ts +63 -79
- package/dist/activities-control-JUBMDBDZ.js.map +0 -1
- package/dist/activities-turn-I2ZKGZE6.js.map +0 -1
- package/dist/chunk-A4XQWVZK.js.map +0 -1
- package/dist/chunk-ZNIKZQMN.js.map +0 -1
|
@@ -2,7 +2,7 @@ import type { ProviderCommandPersistence } from "@opengeni/runtime";
|
|
|
2
2
|
import { type OpStatus } from "@opengeni/agent-proto";
|
|
3
3
|
import { listLiveModalSandboxLeaseAttributions, readLease, type ReapDrainable, type RetainedProcessProviderProof, type SandboxRetainedProcess, type LeaseSnapshot } from "@opengeni/db";
|
|
4
4
|
import { type ConnectedMachineBackgroundCommandClaim, type ConnectedMachineBackgroundCommandProof } from "@opengeni/db/session-background-commands";
|
|
5
|
-
import {
|
|
5
|
+
import { createSandboxClientForBackend, inspectModalSandboxLifecycle, resolveModalCheckpointProviderBindingForSession, terminateModalSandboxById, type ModalOrphanSweepTermination, type ModalCheckpointProviderBinding, type ProviderWorkspaceCapturePolicy, type WorkspaceArchiveDescriptor, type ControlRpc } from "@opengeni/runtime/sandbox";
|
|
6
6
|
import { type SandboxDrainActivityInput, type SandboxLeaseSweepMaintenanceInput } from "../sandbox-reaper-contract.js";
|
|
7
7
|
import type { ControlActivityServices as ActivityServices } from "./types.js";
|
|
8
8
|
import { type RetainedProcessReconciliationOutcome } from "../observability-metrics.js";
|
|
@@ -40,7 +40,7 @@ type CreateSandboxClientForBackendFn = typeof createSandboxClientForBackend;
|
|
|
40
40
|
* backends with no persistWorkspace — ensures a re-arm during the snapshot window
|
|
41
41
|
* aborts the terminate before client.delete()).
|
|
42
42
|
*/
|
|
43
|
-
export type PersistArchiveFn = (archiveBase64: string |
|
|
43
|
+
export type PersistArchiveFn = (archiveBase64: string | null, archiveMetadata?: WorkspaceArchiveDescriptor, providerSession?: unknown, providerBinding?: Awaited<ReturnType<typeof resolveModalCheckpointProviderBindingForSession>> | null) => Promise<{
|
|
44
44
|
wrote: boolean;
|
|
45
45
|
archiveRevision?: string | null;
|
|
46
46
|
}>;
|
|
@@ -60,7 +60,7 @@ export type DrainCaptureDisposition = "capture_required" | "archive_published";
|
|
|
60
60
|
* Test seams may return the legacy boolean shorthand. Production returns the
|
|
61
61
|
* typed outcome so the cold commit can distinguish a clean stop from definitive
|
|
62
62
|
* provider disappearance before capture. */
|
|
63
|
-
export type TerminateBoxFn = (settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, capturePolicy?: ProviderWorkspaceCapturePolicy | null
|
|
63
|
+
export type TerminateBoxFn = (settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, capturePolicy?: ProviderWorkspaceCapturePolicy | null) => Promise<boolean | ProviderTerminationOutcome>;
|
|
64
64
|
export type SweepModalOrphansFn = (settings: ActivityServices["settings"], db: ActivityServices["db"], observability: ActivityServices["observability"]) => Promise<number>;
|
|
65
65
|
export type InspectOpenSandboxKubernetesInventoryFn = (input: {
|
|
66
66
|
namespace: string;
|
|
@@ -199,4 +199,4 @@ export declare function sandboxDrainReason(lease: Pick<LeaseSnapshot, "rotationR
|
|
|
199
199
|
* draining until its adapter can prove termination. A truly instance-less or
|
|
200
200
|
* `none`-backed row is a no-op.
|
|
201
201
|
*/
|
|
202
|
-
export declare function terminateProviderBox(settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, createClientForBackend?: CreateSandboxClientForBackendFn, terminateModalById?: typeof terminateModalSandboxById, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, claimedCapturePolicy?: ProviderWorkspaceCapturePolicy | null
|
|
202
|
+
export declare function terminateProviderBox(settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, createClientForBackend?: CreateSandboxClientForBackendFn, terminateModalById?: typeof terminateModalSandboxById, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, claimedCapturePolicy?: ProviderWorkspaceCapturePolicy | null): Promise<ProviderTerminationOutcome>;
|
|
@@ -10,16 +10,18 @@ import {
|
|
|
10
10
|
MAX_AUTOMATIC_PROVIDER_RECOVERIES,
|
|
11
11
|
assertReusableSessionRevivable,
|
|
12
12
|
captureConnectedCommandOutput,
|
|
13
|
+
collectWorkspaceArchiveObjectKeys,
|
|
13
14
|
createCodexCapacityActivities,
|
|
14
15
|
createGoalActivities,
|
|
15
16
|
createSharedActivityServices,
|
|
16
17
|
currentActivityContext,
|
|
18
|
+
deleteUnpublishedWorkspaceArchiveObject,
|
|
19
|
+
deleteWorkspaceArchiveObjectKeys,
|
|
17
20
|
deliverFailedChildTurnToParent,
|
|
18
21
|
evaluateIncidentTelemetryPreflight,
|
|
19
22
|
incidentTelemetryAuthorityFence,
|
|
20
23
|
incidentTelemetryPreflightDeclaration,
|
|
21
24
|
notifyParentOfChildIdle,
|
|
22
|
-
persistWorkspaceArchiveCandidate,
|
|
23
25
|
providerRecoveryCountFromMetadata,
|
|
24
26
|
putVersion1TarArchiveOrInline,
|
|
25
27
|
reconcileAutomaticSessionTitleFanout,
|
|
@@ -31,7 +33,7 @@ import {
|
|
|
31
33
|
scheduledUserMessagePayload,
|
|
32
34
|
withFirstPartyTools,
|
|
33
35
|
workflowIdForSession
|
|
34
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-NNXLW6V7.js";
|
|
35
37
|
import {
|
|
36
38
|
inspectOpenSandboxKubernetesInventory,
|
|
37
39
|
recordCreditBalanceGauges,
|
|
@@ -51,7 +53,7 @@ import {
|
|
|
51
53
|
recordTurnsQueuedGauge,
|
|
52
54
|
recordWorkerDeathRecoveryMetrics,
|
|
53
55
|
runtimeMetricsHooksForObservability
|
|
54
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-BARTLVBK.js";
|
|
55
57
|
|
|
56
58
|
// src/activities/browser-state-artifact-reaper.ts
|
|
57
59
|
import {
|
|
@@ -5241,8 +5243,7 @@ import { sandboxWarmRateMicrosPerSecond } from "@opengeni/config";
|
|
|
5241
5243
|
import { appendSessionCommandOutput } from "@opengeni/db/session-command-output";
|
|
5242
5244
|
import { sandboxLeaseTelemetryKey } from "@opengeni/observability";
|
|
5243
5245
|
import {
|
|
5244
|
-
|
|
5245
|
-
disposeWorkspaceArchive,
|
|
5246
|
+
captureVerifiedWorkspaceArchive,
|
|
5246
5247
|
cancelSelfhostedOp,
|
|
5247
5248
|
assertConsistentSandboxProviderIdentity,
|
|
5248
5249
|
createSandboxClientForBackend,
|
|
@@ -5361,7 +5362,7 @@ function sandboxDrainActivityAttempt() {
|
|
|
5361
5362
|
}
|
|
5362
5363
|
}
|
|
5363
5364
|
function createSandboxLeaseActivities(services, options = {}) {
|
|
5364
|
-
const terminateBox = options.terminateBox ?? (async (settings, lease, observability, persistArchive, providerCaptureRequestId, captureDisposition, capturePolicy
|
|
5365
|
+
const terminateBox = options.terminateBox ?? (async (settings, lease, observability, persistArchive, providerCaptureRequestId, captureDisposition, capturePolicy) => await terminateProviderBox(
|
|
5365
5366
|
settings,
|
|
5366
5367
|
lease,
|
|
5367
5368
|
observability,
|
|
@@ -5370,8 +5371,7 @@ function createSandboxLeaseActivities(services, options = {}) {
|
|
|
5370
5371
|
terminateModalSandboxById,
|
|
5371
5372
|
providerCaptureRequestId,
|
|
5372
5373
|
captureDisposition,
|
|
5373
|
-
capturePolicy
|
|
5374
|
-
diskBackedArchives
|
|
5374
|
+
capturePolicy
|
|
5375
5375
|
));
|
|
5376
5376
|
const sweepModalOrphans = options.sweepModalOrphans ?? sweepModalOrphansForConfiguredBackend;
|
|
5377
5377
|
const inspectOpenSandboxInventory = options.inspectOpenSandboxKubernetesInventory ?? inspectOpenSandboxKubernetesInventory;
|
|
@@ -7044,7 +7044,7 @@ async function terminateDrainableBox(db, settings, row, observability, terminate
|
|
|
7044
7044
|
}
|
|
7045
7045
|
const archiveMetrics = runtimeMetricsHooksForObservability(observability);
|
|
7046
7046
|
let checkpointArtifactId = null;
|
|
7047
|
-
if (
|
|
7047
|
+
if (archiveBase64 && archiveMetadata?.version === 2 && (archiveMetadata.provider === "modal_snapshot_filesystem" || archiveMetadata.provider === "modal_snapshot_directory")) {
|
|
7048
7048
|
if (!providerBinding) {
|
|
7049
7049
|
throw new Error("Modal native snapshot has no exact session provider identity");
|
|
7050
7050
|
}
|
|
@@ -7084,29 +7084,57 @@ async function terminateDrainableBox(db, settings, row, observability, terminate
|
|
|
7084
7084
|
if (!archiveMetadata) {
|
|
7085
7085
|
throw new Error("Sandbox snapshot publication requires a verified archive descriptor");
|
|
7086
7086
|
}
|
|
7087
|
-
const
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7087
|
+
const priorKeys = collectWorkspaceArchiveObjectKeys(
|
|
7088
|
+
lease.resumeState ?? null
|
|
7089
|
+
);
|
|
7090
|
+
let workspaceArchiveRef;
|
|
7091
|
+
try {
|
|
7092
|
+
const published = await putVersion1TarArchiveOrInline({
|
|
7093
|
+
backend: lease.backend,
|
|
7094
|
+
objectStorage,
|
|
7095
|
+
accountId,
|
|
7096
|
+
workspaceId: row.workspaceId,
|
|
7097
|
+
sandboxGroupId: row.sandboxGroupId,
|
|
7098
|
+
archive: {
|
|
7099
|
+
bytes: Buffer.from(archiveBase64, "base64"),
|
|
7100
|
+
descriptor: archiveMetadata,
|
|
7101
|
+
base64: archiveBase64
|
|
7102
|
+
},
|
|
7103
|
+
metrics: archiveMetrics
|
|
7104
|
+
});
|
|
7105
|
+
workspaceArchiveRef = published.workspaceArchiveRef;
|
|
7106
|
+
result = await persistDrainSnapshot(db, {
|
|
7104
7107
|
...baseInput,
|
|
7105
7108
|
workspaceArchiveMeta: archiveMetadata,
|
|
7106
7109
|
...published,
|
|
7107
7110
|
...checkpointArtifactId ? { checkpointArtifactId } : {}
|
|
7108
|
-
})
|
|
7109
|
-
|
|
7111
|
+
});
|
|
7112
|
+
if (published.workspaceArchiveRef && objectStorage) {
|
|
7113
|
+
if (!result.wrote) {
|
|
7114
|
+
await deleteUnpublishedWorkspaceArchiveObject(
|
|
7115
|
+
objectStorage,
|
|
7116
|
+
published.workspaceArchiveRef,
|
|
7117
|
+
archiveMetrics
|
|
7118
|
+
);
|
|
7119
|
+
} else {
|
|
7120
|
+
const afterLease = await readLease(db, row.workspaceId, row.sandboxGroupId);
|
|
7121
|
+
const afterKeys = collectWorkspaceArchiveObjectKeys(
|
|
7122
|
+
afterLease?.resumeState ?? null
|
|
7123
|
+
);
|
|
7124
|
+
await deleteWorkspaceArchiveObjectKeys(
|
|
7125
|
+
objectStorage,
|
|
7126
|
+
[...priorKeys].filter((key) => !afterKeys.has(key))
|
|
7127
|
+
).catch(() => void 0);
|
|
7128
|
+
}
|
|
7129
|
+
}
|
|
7130
|
+
} catch (error) {
|
|
7131
|
+
await deleteUnpublishedWorkspaceArchiveObject(
|
|
7132
|
+
objectStorage,
|
|
7133
|
+
workspaceArchiveRef,
|
|
7134
|
+
archiveMetrics
|
|
7135
|
+
);
|
|
7136
|
+
throw error;
|
|
7137
|
+
}
|
|
7110
7138
|
}
|
|
7111
7139
|
if (!result.wrote && checkpointArtifactId) {
|
|
7112
7140
|
await markSandboxCheckpointArtifactDeletePending2(db, {
|
|
@@ -7129,8 +7157,7 @@ async function terminateDrainableBox(db, settings, row, observability, terminate
|
|
|
7129
7157
|
persistArchive,
|
|
7130
7158
|
captureClaim?.providerRequestId ?? attempt.operationId,
|
|
7131
7159
|
captureDisposition,
|
|
7132
|
-
capturePolicy
|
|
7133
|
-
Boolean(objectStorage)
|
|
7160
|
+
capturePolicy
|
|
7134
7161
|
);
|
|
7135
7162
|
const terminated = typeof termination === "boolean" ? termination : termination.terminated;
|
|
7136
7163
|
if (!terminated) {
|
|
@@ -7186,7 +7213,7 @@ function providerDrainLogIdentity(lease, backend) {
|
|
|
7186
7213
|
instanceId: lease.instanceId
|
|
7187
7214
|
};
|
|
7188
7215
|
}
|
|
7189
|
-
async function terminateProviderBox(settings, lease, observability, persistArchive, createClientForBackend = createSandboxClientForBackend, terminateModalById = terminateModalSandboxById, providerCaptureRequestId, captureDisposition = "capture_required", claimedCapturePolicy
|
|
7216
|
+
async function terminateProviderBox(settings, lease, observability, persistArchive, createClientForBackend = createSandboxClientForBackend, terminateModalById = terminateModalSandboxById, providerCaptureRequestId, captureDisposition = "capture_required", claimedCapturePolicy) {
|
|
7190
7217
|
const durableBackendId = lease.resumeBackendId ?? lease.backend;
|
|
7191
7218
|
const backend = sandboxBackendForSdkBackendId(durableBackendId) ?? durableBackendId;
|
|
7192
7219
|
const logIdentity = providerDrainLogIdentity(lease, backend);
|
|
@@ -7308,15 +7335,10 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
7308
7335
|
) : null;
|
|
7309
7336
|
try {
|
|
7310
7337
|
if (captureDisposition !== "archive_published" && session?.persistWorkspace) {
|
|
7311
|
-
const capture =
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
requestId: providerCaptureRequestId ?? randomUUID2(),
|
|
7316
|
-
strategy: liveCapturePolicy.strategy
|
|
7317
|
-
},
|
|
7318
|
-
diskBackedArchives
|
|
7319
|
-
);
|
|
7338
|
+
const capture = captureVerifiedWorkspaceArchive(session, Date.now(), {
|
|
7339
|
+
requestId: providerCaptureRequestId ?? randomUUID2(),
|
|
7340
|
+
strategy: liveCapturePolicy.strategy
|
|
7341
|
+
});
|
|
7320
7342
|
verifiedArchive = await awaitProviderCaptureWithLatePublication({
|
|
7321
7343
|
capture,
|
|
7322
7344
|
timeoutMs: settings.sandboxSnapshotTimeoutMs,
|
|
@@ -7330,7 +7352,7 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
7330
7352
|
publishLate: async (archive) => {
|
|
7331
7353
|
try {
|
|
7332
7354
|
const result = await persistArchive(
|
|
7333
|
-
archive.
|
|
7355
|
+
archive.base64,
|
|
7334
7356
|
archive.descriptor,
|
|
7335
7357
|
session,
|
|
7336
7358
|
checkpointBinding
|
|
@@ -7346,8 +7368,6 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
7346
7368
|
...logIdentity,
|
|
7347
7369
|
error: error instanceof Error ? error.message : String(error)
|
|
7348
7370
|
});
|
|
7349
|
-
} finally {
|
|
7350
|
-
await disposeWorkspaceArchive(archive);
|
|
7351
7371
|
}
|
|
7352
7372
|
},
|
|
7353
7373
|
observeLateFailure: (error) => {
|
|
@@ -7379,17 +7399,12 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
7379
7399
|
...logIdentity
|
|
7380
7400
|
});
|
|
7381
7401
|
} else if (verifiedArchive) {
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7386
|
-
|
|
7387
|
-
|
|
7388
|
-
checkpointBinding
|
|
7389
|
-
));
|
|
7390
|
-
} finally {
|
|
7391
|
-
await disposeWorkspaceArchive(verifiedArchive);
|
|
7392
|
-
}
|
|
7402
|
+
const { wrote } = await persistArchive(
|
|
7403
|
+
verifiedArchive.base64,
|
|
7404
|
+
verifiedArchive.descriptor,
|
|
7405
|
+
session,
|
|
7406
|
+
checkpointBinding
|
|
7407
|
+
);
|
|
7393
7408
|
if (!wrote) {
|
|
7394
7409
|
observability.info(
|
|
7395
7410
|
"sandbox reaper: lease re-armed during persist \u2014 leaving box RUNNING (no terminate)",
|
|
@@ -10335,4 +10350,4 @@ export {
|
|
|
10335
10350
|
createControlActivities,
|
|
10336
10351
|
createControlActivitiesFromServices
|
|
10337
10352
|
};
|
|
10338
|
-
//# sourceMappingURL=activities-control-
|
|
10353
|
+
//# sourceMappingURL=activities-control-UXGPMDL3.js.map
|