@opengeni/db 4.3.0-canary.0 → 4.3.2-canary.0

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/canonical-human-identities.js +3 -3
  2. package/dist/{chunk-Y5XFVJJM.js → chunk-AI4NC6XW.js} +6 -5
  3. package/dist/chunk-AI4NC6XW.js.map +1 -0
  4. package/dist/{chunk-IHADTE7C.js → chunk-DVSLOUEI.js} +2 -2
  5. package/dist/{chunk-7JPLGBSA.js → chunk-F4BIHJ7J.js} +4 -4
  6. package/dist/{chunk-SGJDIF2D.js → chunk-I4ITNMX2.js} +2 -2
  7. package/dist/{chunk-NCSPNCQK.js → chunk-PFBUHOI5.js} +3 -3
  8. package/dist/{chunk-YGRT6VZO.js → chunk-UUPY6IGP.js} +2 -2
  9. package/dist/{chunk-YGBOVXC7.js → chunk-UVBPOGA7.js} +2 -2
  10. package/dist/{chunk-ILKJKDII.js → chunk-XBXANJQS.js} +2 -2
  11. package/dist/editable-artifact-durable-export.js +2 -2
  12. package/dist/editable-artifacts.js +3 -3
  13. package/dist/index.d.ts +9 -0
  14. package/dist/index.js +84 -26
  15. package/dist/index.js.map +1 -1
  16. package/dist/managed-auth-session-sets.js +3 -3
  17. package/dist/retained-provider-commands.js +2 -2
  18. package/dist/schema.js +1 -1
  19. package/dist/session-background-commands.js +4 -4
  20. package/dist/session-command-output.js +4 -4
  21. package/dist/session-event-slices.js +2 -2
  22. package/dist/session-tenancy.js +3 -3
  23. package/dist/video-generation.js +3 -3
  24. package/dist/workspace-tool-defaults.js +4 -4
  25. package/package.json +6 -6
  26. package/src/index.ts +83 -4
  27. package/src/schema.ts +5 -4
  28. package/src/workspace-artifacts.ts +10 -4
  29. package/dist/chunk-Y5XFVJJM.js.map +0 -1
  30. /package/dist/{chunk-IHADTE7C.js.map → chunk-DVSLOUEI.js.map} +0 -0
  31. /package/dist/{chunk-7JPLGBSA.js.map → chunk-F4BIHJ7J.js.map} +0 -0
  32. /package/dist/{chunk-SGJDIF2D.js.map → chunk-I4ITNMX2.js.map} +0 -0
  33. /package/dist/{chunk-NCSPNCQK.js.map → chunk-PFBUHOI5.js.map} +0 -0
  34. /package/dist/{chunk-YGRT6VZO.js.map → chunk-UUPY6IGP.js.map} +0 -0
  35. /package/dist/{chunk-YGBOVXC7.js.map → chunk-UVBPOGA7.js.map} +0 -0
  36. /package/dist/{chunk-ILKJKDII.js.map → chunk-XBXANJQS.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  nestedPostgresSqlState,
3
3
  rawRows
4
- } from "./chunk-SGJDIF2D.js";
4
+ } from "./chunk-I4ITNMX2.js";
5
5
 
6
6
  // src/canonical-human-identities.ts
7
7
  import { createHash } from "crypto";
@@ -309,4 +309,4 @@ export {
309
309
  getCanonicalHumanIdentityProjection,
310
310
  applyCanonicalHumanIdentityOperation
311
311
  };
312
- //# sourceMappingURL=chunk-IHADTE7C.js.map
312
+ //# sourceMappingURL=chunk-DVSLOUEI.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cancelUnacceptedVideoGenerationsForToolCallsInTransaction
3
- } from "./chunk-NCSPNCQK.js";
3
+ } from "./chunk-PFBUHOI5.js";
4
4
  import {
5
5
  nestedPostgresSqlState,
6
6
  rawRows,
@@ -10,7 +10,7 @@ import {
10
10
  withSessionActivityRlsContext,
11
11
  withWorkspaceRls,
12
12
  withWorkspaceSubjectRls
13
- } from "./chunk-SGJDIF2D.js";
13
+ } from "./chunk-I4ITNMX2.js";
14
14
  import {
15
15
  LOSSLESS_CONTENT_CODEC_VERSION,
16
16
  auditEvents,
@@ -37,7 +37,7 @@ import {
37
37
  workspaceControlEvents,
38
38
  workspaceInferenceControls,
39
39
  workspaces
40
- } from "./chunk-Y5XFVJJM.js";
40
+ } from "./chunk-AI4NC6XW.js";
41
41
 
42
42
  // src/session-background-commands.ts
43
43
  import { SessionCommandFailure } from "@opengeni/contracts";
@@ -4769,4 +4769,4 @@ export {
4769
4769
  setWorkspacePauseTimerInTransaction,
4770
4770
  fireWorkspacePauseTimerInTransaction
4771
4771
  };
4772
- //# sourceMappingURL=chunk-7JPLGBSA.js.map
4772
+ //# sourceMappingURL=chunk-F4BIHJ7J.js.map
@@ -4,7 +4,7 @@ import {
4
4
  sessions,
5
5
  workspaceSessionActivityRevisions,
6
6
  workspaces
7
- } from "./chunk-Y5XFVJJM.js";
7
+ } from "./chunk-AI4NC6XW.js";
8
8
 
9
9
  // src/persistence-errors.ts
10
10
  var SQLSTATE_KEYS = ["sqlState", "sqlstate", "code"];
@@ -755,4 +755,4 @@ export {
755
755
  withAccountRls,
756
756
  dbBindingFor
757
757
  };
758
- //# sourceMappingURL=chunk-SGJDIF2D.js.map
758
+ //# sourceMappingURL=chunk-I4ITNMX2.js.map
@@ -2,7 +2,7 @@ import {
2
2
  rawRows,
3
3
  withRlsContext,
4
4
  withWorkspaceRls
5
- } from "./chunk-SGJDIF2D.js";
5
+ } from "./chunk-I4ITNMX2.js";
6
6
  import {
7
7
  connections,
8
8
  creditLedgerEntries,
@@ -14,7 +14,7 @@ import {
14
14
  workspaceVideoGenerationPolicies,
15
15
  workspaceVideoGenerationQuotas,
16
16
  workspaces
17
- } from "./chunk-Y5XFVJJM.js";
17
+ } from "./chunk-AI4NC6XW.js";
18
18
 
19
19
  // src/video-generation.ts
20
20
  import {
@@ -992,4 +992,4 @@ export {
992
992
  mediaGenerationResultForStoredOperation,
993
993
  getVideoGenerationOperationSummary
994
994
  };
995
- //# sourceMappingURL=chunk-NCSPNCQK.js.map
995
+ //# sourceMappingURL=chunk-PFBUHOI5.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  nestedPostgresSqlState,
3
3
  rawRows
4
- } from "./chunk-SGJDIF2D.js";
4
+ } from "./chunk-I4ITNMX2.js";
5
5
 
6
6
  // src/managed-auth-session-sets.ts
7
7
  import {
@@ -296,4 +296,4 @@ export {
296
296
  reapManagedAuthIsolatedSessions,
297
297
  reapExpiredManagedAuthSessionSets
298
298
  };
299
- //# sourceMappingURL=chunk-YGRT6VZO.js.map
299
+ //# sourceMappingURL=chunk-UUPY6IGP.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  rawRows,
3
3
  withRlsContext
4
- } from "./chunk-SGJDIF2D.js";
4
+ } from "./chunk-I4ITNMX2.js";
5
5
 
6
6
  // src/editable-artifacts.ts
7
7
  import { createHash } from "crypto";
@@ -3540,4 +3540,4 @@ export {
3540
3540
  PostgresEditableArtifactStore,
3541
3541
  PostgresEditableArtifactLiveReadStore
3542
3542
  };
3543
- //# sourceMappingURL=chunk-YGBOVXC7.js.map
3543
+ //# sourceMappingURL=chunk-UVBPOGA7.js.map
@@ -5,7 +5,7 @@ import {
5
5
  withWorkspaceRls,
6
6
  withWorkspaceSubjectRls,
7
7
  withWorkspaceSubjectSessionActivityRls
8
- } from "./chunk-SGJDIF2D.js";
8
+ } from "./chunk-I4ITNMX2.js";
9
9
 
10
10
  // src/session-tenancy.ts
11
11
  import { createHash } from "crypto";
@@ -502,4 +502,4 @@ export {
502
502
  forkSessionContent,
503
503
  replayAppliedSessionFork
504
504
  };
505
- //# sourceMappingURL=chunk-ILKJKDII.js.map
505
+ //# sourceMappingURL=chunk-XBXANJQS.js.map
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  rawRows,
3
3
  withRlsContext
4
- } from "./chunk-SGJDIF2D.js";
5
- import "./chunk-Y5XFVJJM.js";
4
+ } from "./chunk-I4ITNMX2.js";
5
+ import "./chunk-AI4NC6XW.js";
6
6
  import "./chunk-PZ5AY32C.js";
7
7
 
8
8
  // src/editable-artifact-durable-export.ts
@@ -8,9 +8,9 @@ import {
8
8
  PostgresEditableArtifactStore,
9
9
  listEditableArtifactIdsForSession,
10
10
  touchEditableArtifactSessionLink
11
- } from "./chunk-YGBOVXC7.js";
12
- import "./chunk-SGJDIF2D.js";
13
- import "./chunk-Y5XFVJJM.js";
11
+ } from "./chunk-UVBPOGA7.js";
12
+ import "./chunk-I4ITNMX2.js";
13
+ import "./chunk-AI4NC6XW.js";
14
14
  import "./chunk-PZ5AY32C.js";
15
15
  export {
16
16
  EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
package/dist/index.d.ts CHANGED
@@ -8112,6 +8112,13 @@ export type LegacyModalCheckpointAdoptionTarget = Omit<LegacyModalCheckpointSlot
8112
8112
  * an unreferenced candidate that GC might delete while the legacy slot still
8113
8113
  * depends on that provider object. */
8114
8114
  export declare function adoptLegacyModalCheckpointArtifact(db: Database, input: LegacyModalCheckpointAdoptionTarget): Promise<boolean>;
8115
+ /** Object-candidate outcome from the publication transaction, independent of
8116
+ * lifecycle `wrote`. Absent for inline/provider receipts and pure CAS checks.
8117
+ * `unused` is NOT a retirement receipt: only the owner of a fresh candidate with
8118
+ * no other publication in flight may use it for immediate cleanup. Exceptions
8119
+ * give no disposition (commit may have happened). Legacy/shared keys and evicted
8120
+ * refs need durable no-reattachment evidence before deletion. */
8121
+ export type WorkspaceArchiveCandidateDisposition = "adopted" | "already_referenced" | "unused";
8115
8122
  export declare function persistDrainSnapshot(db: Database, input: {
8116
8123
  accountId: string;
8117
8124
  workspaceId: string;
@@ -8142,6 +8149,7 @@ export declare function persistDrainSnapshot(db: Database, input: {
8142
8149
  })): Promise<{
8143
8150
  wrote: boolean;
8144
8151
  archiveRevision: string | null;
8152
+ candidateDisposition?: WorkspaceArchiveCandidateDisposition;
8145
8153
  }>;
8146
8154
  /**
8147
8155
  * The ONE archive-fold write, shared by the drain seam (persistDrainSnapshot)
@@ -8213,6 +8221,7 @@ export declare function persistWarmSnapshot(db: Database, input: {
8213
8221
  throttled: boolean;
8214
8222
  superseded: boolean;
8215
8223
  archiveRevision: string | null;
8224
+ candidateDisposition?: WorkspaceArchiveCandidateDisposition;
8216
8225
  }>;
8217
8226
  export declare function getMaterializedSandboxFileResources(db: Database, input: {
8218
8227
  accountId: string;
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  replayAppliedSessionFork,
15
15
  sessionTenancyProductActivated,
16
16
  transitionSessionVisibility
17
- } from "./chunk-ILKJKDII.js";
17
+ } from "./chunk-XBXANJQS.js";
18
18
  import {
19
19
  AgentCommandAuthorityError,
20
20
  CHILD_LIFECYCLE_DEDUPE_PREFIX,
@@ -108,7 +108,7 @@ import {
108
108
  updateSessionCommandReceiptResult,
109
109
  workspaceControlLockBudget,
110
110
  workspaceControlRequestLockTimeoutMs
111
- } from "./chunk-7JPLGBSA.js";
111
+ } from "./chunk-F4BIHJ7J.js";
112
112
  import {
113
113
  ACTIVE_VIDEO_GENERATION_STATUSES,
114
114
  VideoGenerationCapacityError,
@@ -140,7 +140,7 @@ import {
140
140
  settleVideoGenerationFailure,
141
141
  settleVideoGenerationReady,
142
142
  updateWorkspaceVideoGenerationPolicy
143
- } from "./chunk-NCSPNCQK.js";
143
+ } from "./chunk-PFBUHOI5.js";
144
144
  import {
145
145
  ManagedAuthActorMutationInFlightError,
146
146
  ManagedAuthLoginSlotAlreadyExistsError,
@@ -163,7 +163,7 @@ import {
163
163
  reapManagedAuthIsolatedSessions,
164
164
  releaseManagedAuthActorMutationLease,
165
165
  validateManagedAuthActorMutationLease
166
- } from "./chunk-YGRT6VZO.js";
166
+ } from "./chunk-UUPY6IGP.js";
167
167
  import {
168
168
  migrate,
169
169
  runMigrations
@@ -204,7 +204,7 @@ import {
204
204
  getCanonicalHumanIdentityProjection,
205
205
  synchronizeCanonicalHumanLoginBindings,
206
206
  validateCanonicalHumanSession
207
- } from "./chunk-IHADTE7C.js";
207
+ } from "./chunk-DVSLOUEI.js";
208
208
  import {
209
209
  EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
210
210
  EDITABLE_ARTIFACT_KERNEL_TAIL_MAX_BYTES,
@@ -215,7 +215,7 @@ import {
215
215
  PostgresEditableArtifactStore,
216
216
  listEditableArtifactIdsForSession,
217
217
  touchEditableArtifactSessionLink
218
- } from "./chunk-YGBOVXC7.js";
218
+ } from "./chunk-UVBPOGA7.js";
219
219
  import {
220
220
  SandboxProviderReadLockUnavailableError,
221
221
  SessionEventPersistenceError,
@@ -251,7 +251,7 @@ import {
251
251
  withWorkspaceSubjectRls,
252
252
  withWorkspaceSubjectSessionActivityRls,
253
253
  withWorkspaceUsageLock
254
- } from "./chunk-SGJDIF2D.js";
254
+ } from "./chunk-I4ITNMX2.js";
255
255
  import {
256
256
  LOSSLESS_CONTENT_CODEC_VERSION,
257
257
  LOSSLESS_JSON_STRING_PREFIX,
@@ -491,7 +491,7 @@ import {
491
491
  xaiRotationSettings,
492
492
  xaiSessionAccountPins,
493
493
  xaiSubscriptionCredentials
494
- } from "./chunk-Y5XFVJJM.js";
494
+ } from "./chunk-AI4NC6XW.js";
495
495
  import "./chunk-PZ5AY32C.js";
496
496
 
497
497
  // src/session-execution-policy.ts
@@ -9207,6 +9207,7 @@ import {
9207
9207
  SANDBOX_PROVIDER_INSTANCE_ID_FIELDS_BY_BACKEND,
9208
9208
  parseWorkspaceArchiveDescriptor,
9209
9209
  parseWorkspaceArchiveObjectRef,
9210
+ validateWorkspaceArchiveObjectRef,
9210
9211
  workspaceArchivePayloadPresent,
9211
9212
  omitInlineWorkspaceArchiveWhenObjectRefPresent,
9212
9213
  stableJson as stableJson16,
@@ -35290,7 +35291,11 @@ async function assertAttemptAuthority(scopedDb, input) {
35290
35291
  FOR NO KEY UPDATE OF session
35291
35292
  ), locked_turn AS MATERIALIZED (
35292
35293
  SELECT turn.id, turn.account_id, turn.workspace_id, turn.session_id,
35293
- turn.active_attempt_id, turn.execution_generation, turn.initiator_subject_id
35294
+ turn.active_attempt_id, turn.execution_generation,
35295
+ coalesce(
35296
+ turn.initiating_human_subject_id,
35297
+ case when turn.initiator_kind = 'subject' then turn.initiator_subject_id end
35298
+ ) as initiating_human_subject_id
35294
35299
  FROM session_turns turn
35295
35300
  JOIN locked_session session
35296
35301
  ON session.id = turn.session_id
@@ -35300,8 +35305,10 @@ async function assertAttemptAuthority(scopedDb, input) {
35300
35305
  AND turn.active_attempt_id = ${input.sourceAttemptId}::uuid
35301
35306
  AND turn.execution_generation = ${input.sourceExecutionGeneration}
35302
35307
  AND turn.status IN ('running', 'requires_action', 'recovering', 'waiting_capacity')
35303
- AND turn.initiator_kind = 'subject'
35304
- AND length(btrim(turn.initiator_subject_id)) BETWEEN 1 AND 1024
35308
+ AND length(btrim(coalesce(
35309
+ turn.initiating_human_subject_id,
35310
+ case when turn.initiator_kind = 'subject' then turn.initiator_subject_id end
35311
+ ))) BETWEEN 1 AND 1024
35305
35312
  FOR UPDATE OF turn
35306
35313
  ), locked_attempt AS MATERIALIZED (
35307
35314
  SELECT attempt.id, attempt.account_id, attempt.workspace_id,
@@ -35330,7 +35337,7 @@ async function assertAttemptAuthority(scopedDb, input) {
35330
35337
  `);
35331
35338
  if (!rows[0]) {
35332
35339
  throw new WorkspaceArtifactOperationError(
35333
- "Artifact mutation requires the exact active attempt and execution generation"
35340
+ "Artifact mutation requires the exact active attempt, execution generation, and immutable human authority"
35334
35341
  );
35335
35342
  }
35336
35343
  }
@@ -76181,7 +76188,17 @@ async function adoptLegacyModalCheckpointArtifact(db, input) {
76181
76188
  );
76182
76189
  }
76183
76190
  function publishedWorkspaceArchiveFields(input) {
76184
- const ref = parseWorkspaceArchiveObjectRef(input.workspaceArchiveRef) ?? void 0;
76191
+ const ref = input.workspaceArchiveRef == null ? void 0 : validateWorkspaceArchiveObjectRef(input.workspaceArchiveRef, {
76192
+ accountId: input.accountId,
76193
+ workspaceId: input.workspaceId,
76194
+ sandboxGroupId: input.sandboxGroupId,
76195
+ descriptor: input.workspaceArchiveMeta
76196
+ }) ?? void 0;
76197
+ if (input.workspaceArchiveRef != null && !ref) {
76198
+ throw new Error(
76199
+ "Invalid workspace archive object ref: publication scope or descriptor mismatch"
76200
+ );
76201
+ }
76185
76202
  const inline = typeof input.workspaceArchive === "string" && input.workspaceArchive.length > 0 ? input.workspaceArchive : void 0;
76186
76203
  if (!ref && !inline) {
76187
76204
  throw new Error("workspace archive publication requires inline bytes or an object ref");
@@ -76198,11 +76215,24 @@ function publishedWorkspaceArchiveFields(input) {
76198
76215
  }
76199
76216
  return { workspaceArchive: inline };
76200
76217
  }
76218
+ function workspaceArchiveCandidateFields(candidate, lockedResumeState) {
76219
+ if (!candidate) return {};
76220
+ const sessionState = lockedResumeState?.sessionState;
76221
+ const referenced = [
76222
+ sessionState?.workspaceArchiveRef,
76223
+ sessionState?.workspaceArchivePrevRef
76224
+ ].some((value) => {
76225
+ const ref = parseWorkspaceArchiveObjectRef(value);
76226
+ return ref?.key === candidate.key && ref.backend === candidate.backend;
76227
+ });
76228
+ return { candidateDisposition: referenced ? "already_referenced" : "unused" };
76229
+ }
76201
76230
  async function persistDrainSnapshot(db, input) {
76202
76231
  const workspaceArchiveMeta = input.workspaceArchive === null ? null : parseArchiveRevision(input.workspaceArchiveMeta);
76203
76232
  if (input.workspaceArchive !== null && !workspaceArchiveMeta) {
76204
76233
  throw new Error("Invalid verified workspace archive descriptor");
76205
76234
  }
76235
+ const published = input.workspaceArchive === null ? null : publishedWorkspaceArchiveFields(input);
76206
76236
  if (workspaceArchiveMeta?.version === 2 && (workspaceArchiveMeta.provider === "modal_snapshot_filesystem" || workspaceArchiveMeta.provider === "modal_snapshot_directory") && !input.checkpointArtifactId) {
76207
76237
  throw new Error("Modal native checkpoint publication requires a registered artifact");
76208
76238
  }
@@ -76240,10 +76270,15 @@ async function persistDrainSnapshot(db, input) {
76240
76270
  for update
76241
76271
  `);
76242
76272
  const row = guard[0];
76273
+ const candidateFields = workspaceArchiveCandidateFields(
76274
+ published?.workspaceArchiveRef,
76275
+ row?.resume_state
76276
+ );
76243
76277
  if (!row) {
76244
76278
  return {
76245
76279
  wrote: false,
76246
- archiveRevision: null
76280
+ archiveRevision: null,
76281
+ ...candidateFields
76247
76282
  };
76248
76283
  }
76249
76284
  const sourceLeaseMatches = input.expectedLeaseId === void 0 || row.id === input.expectedLeaseId;
@@ -76253,7 +76288,7 @@ async function persistDrainSnapshot(db, input) {
76253
76288
  const lateReceipt = recovery.lateArchiveCapture;
76254
76289
  const coldLatePublication = input.workspaceArchive !== null && input.expectedLeaseId !== void 0 && input.providerRequestId !== void 0 && row.id === input.expectedLeaseId && row.liveness === "cold" && Number(row.refcount) === 0 && Number(row.lease_epoch) === input.expectedEpoch + 1 && row.instance_id === null && Number(row.workspace_generation) === input.expectedWorkspaceGeneration && row.archive_capture_id === null && recovery.provider.status === "missing" && recovery.provider.instanceId === input.expectedInstanceId && recovery.restore.rematerializationId === null && (recovery.restore.status === "unrecoverable" || recovery.restore.status === "degraded" || recovery.restore.status === "pending") && lateReceipt?.sourceLeaseId === input.expectedLeaseId && lateReceipt.sourceLeaseEpoch === input.expectedEpoch && lateReceipt.sourceInstanceId === input.expectedInstanceId && lateReceipt.sourceWorkspaceGeneration === input.expectedWorkspaceGeneration && lateReceipt.providerRequestId === input.providerRequestId && !row.unsettled_mutation;
76255
76290
  if (!activePublication && !coldLatePublication) {
76256
- return { wrote: false, archiveRevision: null };
76291
+ return { wrote: false, archiveRevision: null, ...candidateFields };
76257
76292
  }
76258
76293
  const priorArchive = row.prior_archive ?? null;
76259
76294
  const priorArchivePrev = row.prior_archive_prev ?? null;
@@ -76265,7 +76300,7 @@ async function persistDrainSnapshot(db, input) {
76265
76300
  archiveRevision: null
76266
76301
  };
76267
76302
  }
76268
- const published = publishedWorkspaceArchiveFields(input);
76303
+ if (!published) throw new Error("Missing workspace archive publication fields");
76269
76304
  const priorMeta = parseArchiveRevision(priorSessionState?.workspaceArchiveMeta);
76270
76305
  if (activePublication && row.archive_capture_published_at !== null) {
76271
76306
  if (priorArchive === null && priorRef === null || priorMeta === null) {
@@ -76285,7 +76320,7 @@ async function persistDrainSnapshot(db, input) {
76285
76320
  )
76286
76321
  `);
76287
76322
  }
76288
- return { wrote: true, archiveRevision: priorMeta.revision };
76323
+ return { wrote: true, archiveRevision: priorMeta.revision, ...candidateFields };
76289
76324
  }
76290
76325
  const rotation = rotateWorkspaceArchives({
76291
76326
  resumeState: row.resume_state,
@@ -76339,12 +76374,14 @@ async function persistDrainSnapshot(db, input) {
76339
76374
  if (!folded) {
76340
76375
  return {
76341
76376
  wrote: false,
76342
- archiveRevision: null
76377
+ archiveRevision: null,
76378
+ ...candidateFields
76343
76379
  };
76344
76380
  }
76345
76381
  return {
76346
76382
  wrote: true,
76347
- archiveRevision: workspaceArchiveMeta?.revision ?? null
76383
+ archiveRevision: workspaceArchiveMeta?.revision ?? null,
76384
+ ...published.workspaceArchiveRef ? { candidateDisposition: "adopted" } : {}
76348
76385
  };
76349
76386
  }
76350
76387
  );
@@ -76621,12 +76658,27 @@ async function persistWarmSnapshot(db, input) {
76621
76658
  )
76622
76659
  ).limit(1) : [];
76623
76660
  const attemptMayPersistWorkspace = attempt !== void 0 && (attempt.state === "claimed" || attempt.state === "running" ? attempt.outcome === null : attempt.state === "closed" && (attempt.outcome === "completed" || attempt.outcome === "failed" || attempt.outcome === "requires_action"));
76661
+ const candidateLease = published.workspaceArchiveRef ? await scopedDb.execute(sql81`
76662
+ select jsonb_build_object('sessionState', jsonb_build_object(
76663
+ 'workspaceArchiveRef', resume_state #> '{sessionState,workspaceArchiveRef}',
76664
+ 'workspaceArchivePrevRef', resume_state #> '{sessionState,workspaceArchivePrevRef}'
76665
+ )) as resume_state
76666
+ from sandbox_leases
76667
+ where workspace_id = ${input.workspaceId}
76668
+ and sandbox_group_id = ${input.sandboxGroupId}
76669
+ for update
76670
+ `) : [];
76671
+ const candidateFields = workspaceArchiveCandidateFields(
76672
+ published.workspaceArchiveRef,
76673
+ candidateLease[0]?.resume_state
76674
+ );
76624
76675
  if (!attempt || attempt.accountId !== input.accountId || attempt.sandboxGroupId !== input.sandboxGroupId || interruption || !attemptMayPersistWorkspace) {
76625
76676
  return {
76626
76677
  wrote: false,
76627
76678
  throttled: false,
76628
76679
  superseded: true,
76629
- archiveRevision: null
76680
+ archiveRevision: null,
76681
+ ...candidateFields
76630
76682
  };
76631
76683
  }
76632
76684
  const guard = await scopedDb.execute(sql81`
@@ -76674,7 +76726,8 @@ async function persistWarmSnapshot(db, input) {
76674
76726
  wrote: false,
76675
76727
  throttled: false,
76676
76728
  superseded: false,
76677
- archiveRevision: null
76729
+ archiveRevision: null,
76730
+ ...candidateFields
76678
76731
  };
76679
76732
  }
76680
76733
  const priorArchive = guard[0].prior_archive ?? null;
@@ -76687,7 +76740,8 @@ async function persistWarmSnapshot(db, input) {
76687
76740
  wrote: false,
76688
76741
  throttled: false,
76689
76742
  superseded: true,
76690
- archiveRevision: null
76743
+ archiveRevision: null,
76744
+ ...candidateFields
76691
76745
  };
76692
76746
  }
76693
76747
  if (input.minIntervalMs > 0 && Number.isFinite(priorAtMs) && capturedAtMs - priorAtMs < input.minIntervalMs) {
@@ -76695,7 +76749,8 @@ async function persistWarmSnapshot(db, input) {
76695
76749
  wrote: false,
76696
76750
  throttled: true,
76697
76751
  superseded: false,
76698
- archiveRevision: null
76752
+ archiveRevision: null,
76753
+ ...candidateFields
76699
76754
  };
76700
76755
  }
76701
76756
  const rotation = rotateWorkspaceArchives({
@@ -76716,7 +76771,8 @@ async function persistWarmSnapshot(db, input) {
76716
76771
  wrote: false,
76717
76772
  throttled: false,
76718
76773
  superseded: false,
76719
- archiveRevision: null
76774
+ archiveRevision: null,
76775
+ ...candidateFields
76720
76776
  };
76721
76777
  }
76722
76778
  const livenessGuard = rowLiveness;
@@ -76746,14 +76802,16 @@ async function persistWarmSnapshot(db, input) {
76746
76802
  wrote: false,
76747
76803
  throttled: false,
76748
76804
  superseded: false,
76749
- archiveRevision: null
76805
+ archiveRevision: null,
76806
+ ...candidateFields
76750
76807
  };
76751
76808
  }
76752
76809
  return {
76753
76810
  wrote: true,
76754
76811
  throttled: false,
76755
76812
  superseded: false,
76756
- archiveRevision: workspaceArchiveMeta.revision
76813
+ archiveRevision: workspaceArchiveMeta.revision,
76814
+ ...published.workspaceArchiveRef ? { candidateDisposition: "adopted" } : {}
76757
76815
  };
76758
76816
  }
76759
76817
  );