@opengeni/worker-bundle 0.28.4-canary.0 → 0.28.4-canary.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.
@@ -0,0 +1 @@
1
+ export { codexSelectionDiagnostics } from "@opengeni/db";
@@ -4,7 +4,7 @@ export declare const CODEX_FLEET_SHADOW_MAX_PAYLOAD_BYTES: number;
4
4
  export type CodexFleetActualDecisionV1 = {
5
5
  outcome: "selected" | "waiting" | "none";
6
6
  candidateKey: string | null;
7
- reason: "lease_reused" | "pin" | "rotation" | "active" | "all_capped" | "allocator_disabled" | "none";
7
+ reason: "lease_reused" | "affinity_reused" | "assigned" | "switched" | "pin" | "rotation" | "active" | "all_capped" | "allocator_disabled" | "none";
8
8
  };
9
9
  export type CodexFleetShadowComparisonV1 = "match" | "different_candidate" | "different_outcome" | "not_comparable_truncated";
10
10
  export type CodexFleetShadowPayloadV1 = {
@@ -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, diskBackedArchives?: boolean) => Promise<boolean | ProviderTerminationOutcome>;
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, diskBackedArchives?: boolean, releaseFailedCapture?: () => Promise<void>) => 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;
@@ -114,6 +114,14 @@ export declare class SandboxProviderCaptureTimeoutError extends Error {
114
114
  readonly name = "SandboxProviderCaptureTimeoutError";
115
115
  constructor(sandboxGroupId: string, backend: string, timeoutMs: number, leaseEpoch: number, instanceId: string);
116
116
  }
117
+ export declare function awaitProviderCaptureWithLatePublication<T>(input: {
118
+ capture: Promise<T>;
119
+ timeoutMs: number;
120
+ timeoutError: SandboxProviderCaptureTimeoutError;
121
+ publishLate: (value: T) => Promise<void>;
122
+ observeLateFailure: (error: unknown) => void;
123
+ observeLatePublicationFailure: (error: unknown) => void;
124
+ }): Promise<T>;
117
125
  export type SandboxLeaseSweepPlan = {
118
126
  drainable: ReapDrainable[];
119
127
  timeoutClass: SandboxDrainActivityInput["timeoutClass"];
@@ -199,4 +207,4 @@ export declare function sandboxDrainReason(lease: Pick<LeaseSnapshot, "rotationR
199
207
  * draining until its adapter can prove termination. A truly instance-less or
200
208
  * `none`-backed row is a no-op.
201
209
  */
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, diskBackedArchives?: boolean): Promise<ProviderTerminationOutcome>;
210
+ 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, diskBackedArchives?: boolean, releaseFailedCapture?: () => Promise<void>): Promise<ProviderTerminationOutcome>;
@@ -31,7 +31,7 @@ import {
31
31
  scheduledUserMessagePayload,
32
32
  withFirstPartyTools,
33
33
  workflowIdForSession
34
- } from "./chunk-ZNIKZQMN.js";
34
+ } from "./chunk-OA5CSY5N.js";
35
35
  import {
36
36
  inspectOpenSandboxKubernetesInventory,
37
37
  recordCreditBalanceGauges,
@@ -5199,6 +5199,7 @@ import {
5199
5199
  appendSessionEventToSandboxGroup,
5200
5200
  bindRetainedProcessProviderIdentity,
5201
5201
  claimWorkspaceArchiveCapture,
5202
+ releaseWorkspaceArchiveCapture,
5202
5203
  claimSandboxCheckpointArtifactsForGc,
5203
5204
  claimTerminalRetainedProcesses,
5204
5205
  countActiveRetainedProcessesByOwnerState,
@@ -5312,7 +5313,7 @@ async function awaitProviderCaptureWithLatePublication(input) {
5312
5313
  ]);
5313
5314
  } catch (error) {
5314
5315
  if (error !== timeoutError) throw error;
5315
- void input.capture.then(input.publishLate).catch(input.observeLateFailure);
5316
+ void input.capture.then(input.publishLate, input.observeLateFailure).catch(input.observeLatePublicationFailure);
5316
5317
  throw error;
5317
5318
  } finally {
5318
5319
  if (timeout) clearTimeout(timeout);
@@ -5362,7 +5363,7 @@ function sandboxDrainActivityAttempt() {
5362
5363
  }
5363
5364
  }
5364
5365
  function createSandboxLeaseActivities(services, options = {}) {
5365
- const terminateBox = options.terminateBox ?? (async (settings, lease, observability, persistArchive, providerCaptureRequestId, captureDisposition, capturePolicy, diskBackedArchives) => await terminateProviderBox(
5366
+ const terminateBox = options.terminateBox ?? (async (settings, lease, observability, persistArchive, providerCaptureRequestId, captureDisposition, capturePolicy, diskBackedArchives, releaseFailedCapture) => await terminateProviderBox(
5366
5367
  settings,
5367
5368
  lease,
5368
5369
  observability,
@@ -5372,7 +5373,8 @@ function createSandboxLeaseActivities(services, options = {}) {
5372
5373
  providerCaptureRequestId,
5373
5374
  captureDisposition,
5374
5375
  capturePolicy,
5375
- diskBackedArchives
5376
+ diskBackedArchives,
5377
+ releaseFailedCapture
5376
5378
  ));
5377
5379
  const sweepModalOrphans = options.sweepModalOrphans ?? sweepModalOrphansForConfiguredBackend;
5378
5380
  const inspectOpenSandboxInventory = options.inspectOpenSandboxKubernetesInventory ?? inspectOpenSandboxKubernetesInventory;
@@ -7131,7 +7133,18 @@ async function terminateDrainableBox(db, settings, row, observability, terminate
7131
7133
  captureClaim?.providerRequestId ?? attempt.operationId,
7132
7134
  captureDisposition,
7133
7135
  capturePolicy,
7134
- Boolean(objectStorage)
7136
+ Boolean(objectStorage),
7137
+ async () => {
7138
+ if (!captureClaim || !lease.instanceId) return;
7139
+ await releaseWorkspaceArchiveCapture(db, {
7140
+ accountId,
7141
+ workspaceId: row.workspaceId,
7142
+ sandboxGroupId: row.sandboxGroupId,
7143
+ captureId: captureClaim.id,
7144
+ expectedEpoch: row.leaseEpoch,
7145
+ expectedInstanceId: lease.instanceId
7146
+ });
7147
+ }
7135
7148
  );
7136
7149
  const terminated = typeof termination === "boolean" ? termination : termination.terminated;
7137
7150
  if (!terminated) {
@@ -7187,10 +7200,20 @@ function providerDrainLogIdentity(lease, backend) {
7187
7200
  instanceId: lease.instanceId
7188
7201
  };
7189
7202
  }
7190
- async function terminateProviderBox(settings, lease, observability, persistArchive, createClientForBackend = createSandboxClientForBackend, terminateModalById = terminateModalSandboxById, providerCaptureRequestId, captureDisposition = "capture_required", claimedCapturePolicy, diskBackedArchives = false) {
7203
+ async function terminateProviderBox(settings, lease, observability, persistArchive, createClientForBackend = createSandboxClientForBackend, terminateModalById = terminateModalSandboxById, providerCaptureRequestId, captureDisposition = "capture_required", claimedCapturePolicy, diskBackedArchives = false, releaseFailedCapture) {
7191
7204
  const durableBackendId = lease.resumeBackendId ?? lease.backend;
7192
7205
  const backend = sandboxBackendForSdkBackendId(durableBackendId) ?? durableBackendId;
7193
7206
  const logIdentity = providerDrainLogIdentity(lease, backend);
7207
+ const releaseAfterCaptureFailure = async () => {
7208
+ try {
7209
+ await releaseFailedCapture?.();
7210
+ } catch (error) {
7211
+ observability.warn("sandbox reaper: failed capture claim release failed", {
7212
+ ...logIdentity,
7213
+ error: error instanceof Error ? error.message : String(error)
7214
+ });
7215
+ }
7216
+ };
7194
7217
  if (!backend || backend === "none") {
7195
7218
  return { terminated: true, providerMissingBeforeCapture: false };
7196
7219
  }
@@ -7351,7 +7374,14 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
7351
7374
  await disposeWorkspaceArchive(archive);
7352
7375
  }
7353
7376
  },
7377
+ observeLatePublicationFailure: (error) => {
7378
+ observability.warn("sandbox reaper: late capture publication cleanup failed", {
7379
+ ...logIdentity,
7380
+ error: error instanceof Error ? error.message : String(error)
7381
+ });
7382
+ },
7354
7383
  observeLateFailure: (error) => {
7384
+ void releaseAfterCaptureFailure();
7355
7385
  observability.warn("sandbox reaper: timed-out provider capture later failed", {
7356
7386
  ...logIdentity,
7357
7387
  error: error instanceof Error ? error.message : String(error)
@@ -7373,6 +7403,9 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
7373
7403
  error: error instanceof Error ? error.message : String(error)
7374
7404
  }
7375
7405
  );
7406
+ if (!(error instanceof SandboxProviderCaptureTimeoutError)) {
7407
+ await releaseAfterCaptureFailure();
7408
+ }
7376
7409
  throw error;
7377
7410
  }
7378
7411
  if (captureDisposition === "archive_published") {
@@ -10336,4 +10369,4 @@ export {
10336
10369
  createControlActivities,
10337
10370
  createControlActivitiesFromServices
10338
10371
  };
10339
- //# sourceMappingURL=activities-control-J5QNRWVH.js.map
10372
+ //# sourceMappingURL=activities-control-MKGEOBXT.js.map