@opengeni/db 3.1.3-canary.38890816741001 → 3.2.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.
@@ -3598,6 +3598,20 @@ async function linkProviderVault(db, context, input) {
3598
3598
  )
3599
3599
  );
3600
3600
  }
3601
+ async function preflightProviderVaultLink(db, context, input) {
3602
+ const passed = new Error("vault link preflight passed");
3603
+ try {
3604
+ await db.transaction(async (tx) => {
3605
+ await linkProviderVault(tx, context, {
3606
+ ...input,
3607
+ providerVaultRef: `preflight:${crypto.randomUUID()}`
3608
+ });
3609
+ throw passed;
3610
+ });
3611
+ } catch (error) {
3612
+ if (error !== passed) throw error;
3613
+ }
3614
+ }
3601
3615
  async function getProviderVaultSyncTarget(db, context, vaultId) {
3602
3616
  return await inVaultContext(
3603
3617
  db,
@@ -86996,13 +87010,49 @@ async function claimWorkspaceArchiveCapture(db, input) {
86996
87010
  const lead = input.deadlineMandatoryCaptureLeadMs;
86997
87011
  const [deadline] = input.liveness === "draining" && lead !== void 0 && Number.isSafeInteger(lead) ? await scopedDb.execute(sql139`
86998
87012
  select (
86999
- ${row.rotation_requested_at !== null}
87000
- and ${row.provider_deadline_at ?? null}::timestamptz is not null
87013
+ ${row.provider_deadline_at ?? null}::timestamptz is not null
87001
87014
  and ${row.provider_deadline_at ?? null}::timestamptz
87002
87015
  <= now() + (${lead}::bigint * interval '1 millisecond')
87003
87016
  ) as mandatory
87004
87017
  `) : [];
87005
- if (deadline?.mandatory !== true) {
87018
+ const abandonAfterMs = input.abandonedSetupCaptureAfterMs;
87019
+ const [abandoned] = deadline?.mandatory !== true && input.liveness === "draining" && input.pointInTimeCapture === true && abandonAfterMs !== void 0 && Number.isSafeInteger(abandonAfterMs) && abandonAfterMs > 0 ? await scopedDb.execute(sql139`
87020
+ select coalesce(bool_and(coalesce(
87021
+ admission.actor_kind = 'turn'
87022
+ and admission.actor_id = attempt.id
87023
+ and admission.operation in ('lazyOwnedSandboxSetup', 'eagerOwnedSandboxSetup')
87024
+ and admission.route_kind = 'home'
87025
+ and admission.route_target_id is null
87026
+ and attempt.state = 'closed'
87027
+ and attempt.closed_at
87028
+ <= now() - (${abandonAfterMs}::bigint * interval '1 millisecond')
87029
+ and turn.status = 'recovering'
87030
+ and turn.active_attempt_id is null
87031
+ and turn.execution_generation = attempt.execution_generation
87032
+ and turn.metadata -> 'sandboxSetupOutcomeUnknown' @> jsonb_build_object(
87033
+ 'version', 1, 'turnId', turn.id::text, 'attemptId', attempt.id::text,
87034
+ 'reason', 'sandbox_command_start_outcome_unknown')
87035
+ and not exists (select 1 from sandbox_retained_processes process
87036
+ where process.workspace_id = attempt.workspace_id
87037
+ and process.session_id = attempt.session_id
87038
+ and process.owner_attempt_id = attempt.id
87039
+ and process.state = 'active'),
87040
+ false)), false) as abandoned
87041
+ from sandbox_workspace_mutation_admissions admission
87042
+ left join session_turn_attempts attempt
87043
+ on attempt.account_id = admission.account_id
87044
+ and attempt.workspace_id = admission.workspace_id
87045
+ and attempt.session_id = admission.session_id
87046
+ and attempt.turn_id = admission.turn_id
87047
+ and attempt.id = admission.attempt_id
87048
+ and attempt.execution_generation = admission.execution_generation
87049
+ left join session_turns turn
87050
+ on turn.workspace_id = attempt.workspace_id
87051
+ and turn.session_id = attempt.session_id
87052
+ and turn.id = attempt.turn_id
87053
+ where admission.id = any(${`{${unsettled.map((admission) => admission.id).join(",")}}`}::uuid[])
87054
+ `) : [];
87055
+ if (deadline?.mandatory !== true && abandoned?.abandoned !== true) {
87006
87056
  return { status: "mutation_in_progress" };
87007
87057
  }
87008
87058
  await scopedDb.execute(sql139`
@@ -107277,6 +107327,7 @@ export {
107277
107327
  upsertProviderVaultItems,
107278
107328
  setVaultSyncStatus,
107279
107329
  linkProviderVault,
107330
+ preflightProviderVaultLink,
107280
107331
  getProviderVaultSyncTarget,
107281
107332
  getProviderVaultItemRef,
107282
107333
  applySecretAnswersInTransaction,
@@ -109451,4 +109502,4 @@ export {
109451
109502
  isCodexBilledModel2 as isCodexBilledModel,
109452
109503
  sql140 as sql
109453
109504
  };
109454
- //# sourceMappingURL=chunk-JMX6XSIF.js.map
109505
+ //# sourceMappingURL=chunk-V2X2NK7T.js.map