@opengeni/db 4.3.2-canary.0 → 4.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/db",
3
- "version": "4.3.2-canary.0",
3
+ "version": "4.3.2",
4
4
  "description": "OpenGeni persistence: Drizzle schema, RLS-scoped query layer, the SQL migration runner, and role provisioning.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -94,11 +94,11 @@
94
94
  "prepublishOnly": "bash ../../scripts/prepublish-guard"
95
95
  },
96
96
  "dependencies": {
97
- "@opengeni/codemode": "^0.5.5-canary.0",
98
- "@opengeni/codex": "^0.2.22-canary.7",
99
- "@opengeni/config": "^1.1.1-canary.0",
100
- "@opengeni/contracts": "^3.0.1-canary.0",
101
- "@opengeni/network": "^0.3.1-canary.7",
97
+ "@opengeni/codemode": "^0.5.5",
98
+ "@opengeni/codex": "^0.2.22",
99
+ "@opengeni/config": "^1.1.1",
100
+ "@opengeni/contracts": "^3.0.1",
101
+ "@opengeni/network": "^0.3.1",
102
102
  "drizzle-orm": "^0.45.2",
103
103
  "postgres": "^3.4.7"
104
104
  },
package/src/index.ts CHANGED
@@ -272,7 +272,6 @@ import {
272
272
  SANDBOX_PROVIDER_INSTANCE_ID_FIELDS_BY_BACKEND,
273
273
  parseWorkspaceArchiveDescriptor,
274
274
  parseWorkspaceArchiveObjectRef,
275
- validateWorkspaceArchiveObjectRef,
276
275
  workspaceArchivePayloadPresent,
277
276
  omitInlineWorkspaceArchiveWhenObjectRefPresent,
278
277
  type WorkspaceArchiveObjectRef,
@@ -53449,30 +53448,13 @@ export async function adoptLegacyModalCheckpointArtifact(
53449
53448
  }
53450
53449
 
53451
53450
  function publishedWorkspaceArchiveFields(input: {
53452
- accountId: string;
53453
- workspaceId: string;
53454
- sandboxGroupId: string;
53455
- workspaceArchiveMeta: SandboxArchiveRevision;
53456
53451
  workspaceArchive?: string | null;
53457
53452
  workspaceArchiveRef?: WorkspaceArchiveObjectRef | null;
53458
53453
  }): {
53459
53454
  workspaceArchive?: string;
53460
53455
  workspaceArchiveRef?: WorkspaceArchiveObjectRef;
53461
53456
  } {
53462
- const ref =
53463
- input.workspaceArchiveRef == null
53464
- ? undefined
53465
- : (validateWorkspaceArchiveObjectRef(input.workspaceArchiveRef, {
53466
- accountId: input.accountId,
53467
- workspaceId: input.workspaceId,
53468
- sandboxGroupId: input.sandboxGroupId,
53469
- descriptor: input.workspaceArchiveMeta,
53470
- }) ?? undefined);
53471
- if (input.workspaceArchiveRef != null && !ref) {
53472
- throw new Error(
53473
- "Invalid workspace archive object ref: publication scope or descriptor mismatch",
53474
- );
53475
- }
53457
+ const ref = parseWorkspaceArchiveObjectRef(input.workspaceArchiveRef) ?? undefined;
53476
53458
  const inline =
53477
53459
  typeof input.workspaceArchive === "string" && input.workspaceArchive.length > 0
53478
53460
  ? input.workspaceArchive
@@ -53493,30 +53475,6 @@ function publishedWorkspaceArchiveFields(input: {
53493
53475
  return { workspaceArchive: inline };
53494
53476
  }
53495
53477
 
53496
- /** Object-candidate outcome from the publication transaction, independent of
53497
- * lifecycle `wrote`. Absent for inline/provider receipts and pure CAS checks.
53498
- * `unused` is NOT a retirement receipt: only the owner of a fresh candidate with
53499
- * no other publication in flight may use it for immediate cleanup. Exceptions
53500
- * give no disposition (commit may have happened). Legacy/shared keys and evicted
53501
- * refs need durable no-reattachment evidence before deletion. */
53502
- export type WorkspaceArchiveCandidateDisposition = "adopted" | "already_referenced" | "unused";
53503
-
53504
- function workspaceArchiveCandidateFields(
53505
- candidate: WorkspaceArchiveObjectRef | undefined,
53506
- lockedResumeState: Record<string, unknown> | null | undefined,
53507
- ): { candidateDisposition?: WorkspaceArchiveCandidateDisposition } {
53508
- if (!candidate) return {};
53509
- const sessionState = lockedResumeState?.sessionState as Record<string, unknown> | undefined;
53510
- const referenced = [
53511
- sessionState?.workspaceArchiveRef,
53512
- sessionState?.workspaceArchivePrevRef,
53513
- ].some((value) => {
53514
- const ref = parseWorkspaceArchiveObjectRef(value);
53515
- return ref?.key === candidate.key && ref.backend === candidate.backend;
53516
- });
53517
- return { candidateDisposition: referenced ? "already_referenced" : "unused" };
53518
- }
53519
-
53520
53478
  export async function persistDrainSnapshot(
53521
53479
  db: Database,
53522
53480
  input: {
@@ -53553,14 +53511,12 @@ export async function persistDrainSnapshot(
53553
53511
  ): Promise<{
53554
53512
  wrote: boolean;
53555
53513
  archiveRevision: string | null;
53556
- candidateDisposition?: WorkspaceArchiveCandidateDisposition;
53557
53514
  }> {
53558
53515
  const workspaceArchiveMeta =
53559
53516
  input.workspaceArchive === null ? null : parseArchiveRevision(input.workspaceArchiveMeta);
53560
53517
  if (input.workspaceArchive !== null && !workspaceArchiveMeta) {
53561
53518
  throw new Error("Invalid verified workspace archive descriptor");
53562
53519
  }
53563
- const published = input.workspaceArchive === null ? null : publishedWorkspaceArchiveFields(input);
53564
53520
  if (
53565
53521
  workspaceArchiveMeta?.version === 2 &&
53566
53522
  (workspaceArchiveMeta.provider === "modal_snapshot_filesystem" ||
@@ -53619,15 +53575,10 @@ export async function persistDrainSnapshot(
53619
53575
  for update
53620
53576
  `);
53621
53577
  const row = guard[0];
53622
- const candidateFields = workspaceArchiveCandidateFields(
53623
- published?.workspaceArchiveRef,
53624
- row?.resume_state,
53625
- );
53626
53578
  if (!row) {
53627
53579
  return {
53628
53580
  wrote: false,
53629
53581
  archiveRevision: null,
53630
- ...candidateFields,
53631
53582
  };
53632
53583
  }
53633
53584
  const sourceLeaseMatches =
@@ -53673,7 +53624,7 @@ export async function persistDrainSnapshot(
53673
53624
  lateReceipt.providerRequestId === input.providerRequestId &&
53674
53625
  !row.unsettled_mutation;
53675
53626
  if (!activePublication && !coldLatePublication) {
53676
- return { wrote: false, archiveRevision: null, ...candidateFields };
53627
+ return { wrote: false, archiveRevision: null };
53677
53628
  }
53678
53629
  const priorArchive = row.prior_archive ?? null;
53679
53630
  const priorArchivePrev = row.prior_archive_prev ?? null;
@@ -53691,7 +53642,7 @@ export async function persistDrainSnapshot(
53691
53642
  archiveRevision: null,
53692
53643
  };
53693
53644
  }
53694
- if (!published) throw new Error("Missing workspace archive publication fields");
53645
+ const published = publishedWorkspaceArchiveFields(input);
53695
53646
  const priorMeta = parseArchiveRevision(priorSessionState?.workspaceArchiveMeta);
53696
53647
  if (activePublication && row.archive_capture_published_at !== null) {
53697
53648
  // A predecessor and its successor may receive the same provider result.
@@ -53717,7 +53668,7 @@ export async function persistDrainSnapshot(
53717
53668
  )
53718
53669
  `);
53719
53670
  }
53720
- return { wrote: true, archiveRevision: priorMeta.revision, ...candidateFields };
53671
+ return { wrote: true, archiveRevision: priorMeta.revision };
53721
53672
  }
53722
53673
  const rotation = rotateWorkspaceArchives({
53723
53674
  resumeState: row.resume_state,
@@ -53778,13 +53729,11 @@ export async function persistDrainSnapshot(
53778
53729
  return {
53779
53730
  wrote: false,
53780
53731
  archiveRevision: null,
53781
- ...candidateFields,
53782
53732
  };
53783
53733
  }
53784
53734
  return {
53785
53735
  wrote: true,
53786
53736
  archiveRevision: workspaceArchiveMeta?.revision ?? null,
53787
- ...(published.workspaceArchiveRef ? { candidateDisposition: "adopted" as const } : {}),
53788
53737
  };
53789
53738
  },
53790
53739
  );
@@ -54183,7 +54132,6 @@ export async function persistWarmSnapshot(
54183
54132
  throttled: boolean;
54184
54133
  superseded: boolean;
54185
54134
  archiveRevision: string | null;
54186
- candidateDisposition?: WorkspaceArchiveCandidateDisposition;
54187
54135
  }> {
54188
54136
  const capturedAtMs = input.capturedAtMs ?? Date.now();
54189
54137
  const workspaceArchiveMeta = parseArchiveRevision(input.workspaceArchiveMeta);
@@ -54253,26 +54201,6 @@ export async function persistWarmSnapshot(
54253
54201
  (attempt.outcome === "completed" ||
54254
54202
  attempt.outcome === "failed" ||
54255
54203
  attempt.outcome === "requires_action"));
54256
- // Even a replay rejected by the attempt/epoch/capture guards may name
54257
- // a committed current or previous object. Inspect those slots under the
54258
- // same lease lock as publication, after the canonical workspace lock.
54259
- // This conveys no retirement or no-future-reattachment authority.
54260
- const candidateLease = published.workspaceArchiveRef
54261
- ? await scopedDb.execute<{ resume_state: Record<string, unknown> | null }>(sql`
54262
- select jsonb_build_object('sessionState', jsonb_build_object(
54263
- 'workspaceArchiveRef', resume_state #> '{sessionState,workspaceArchiveRef}',
54264
- 'workspaceArchivePrevRef', resume_state #> '{sessionState,workspaceArchivePrevRef}'
54265
- )) as resume_state
54266
- from sandbox_leases
54267
- where workspace_id = ${input.workspaceId}
54268
- and sandbox_group_id = ${input.sandboxGroupId}
54269
- for update
54270
- `)
54271
- : [];
54272
- const candidateFields = workspaceArchiveCandidateFields(
54273
- published.workspaceArchiveRef,
54274
- candidateLease[0]?.resume_state,
54275
- );
54276
54204
  if (
54277
54205
  !attempt ||
54278
54206
  attempt.accountId !== input.accountId ||
@@ -54285,7 +54213,6 @@ export async function persistWarmSnapshot(
54285
54213
  throttled: false,
54286
54214
  superseded: true,
54287
54215
  archiveRevision: null,
54288
- ...candidateFields,
54289
54216
  };
54290
54217
  }
54291
54218
  const guard = await scopedDb.execute<{
@@ -54343,7 +54270,6 @@ export async function persistWarmSnapshot(
54343
54270
  throttled: false,
54344
54271
  superseded: false,
54345
54272
  archiveRevision: null,
54346
- ...candidateFields,
54347
54273
  };
54348
54274
  }
54349
54275
  const priorArchive = guard[0]!.prior_archive ?? null;
@@ -54364,7 +54290,6 @@ export async function persistWarmSnapshot(
54364
54290
  throttled: false,
54365
54291
  superseded: true,
54366
54292
  archiveRevision: null,
54367
- ...candidateFields,
54368
54293
  };
54369
54294
  }
54370
54295
  if (
@@ -54377,7 +54302,6 @@ export async function persistWarmSnapshot(
54377
54302
  throttled: true,
54378
54303
  superseded: false,
54379
54304
  archiveRevision: null,
54380
- ...candidateFields,
54381
54305
  };
54382
54306
  }
54383
54307
  const rotation = rotateWorkspaceArchives({
@@ -54399,7 +54323,6 @@ export async function persistWarmSnapshot(
54399
54323
  throttled: false,
54400
54324
  superseded: false,
54401
54325
  archiveRevision: null,
54402
- ...candidateFields,
54403
54326
  };
54404
54327
  }
54405
54328
  const livenessGuard: "warm" | "draining" = rowLiveness;
@@ -54432,7 +54355,6 @@ export async function persistWarmSnapshot(
54432
54355
  throttled: false,
54433
54356
  superseded: false,
54434
54357
  archiveRevision: null,
54435
- ...candidateFields,
54436
54358
  };
54437
54359
  }
54438
54360
  return {
@@ -54440,7 +54362,6 @@ export async function persistWarmSnapshot(
54440
54362
  throttled: false,
54441
54363
  superseded: false,
54442
54364
  archiveRevision: workspaceArchiveMeta.revision,
54443
- ...(published.workspaceArchiveRef ? { candidateDisposition: "adopted" as const } : {}),
54444
54365
  };
54445
54366
  },
54446
54367
  );