@opengeni/db 4.0.0-canary.1 → 4.0.0-canary.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.
Files changed (38) hide show
  1. package/dist/canonical-human-identities.js +3 -3
  2. package/dist/{chunk-2HGYCAXN.js → chunk-B5Y3TCSP.js} +2 -2
  3. package/dist/{chunk-A5RFBEZR.js → chunk-CQF6G4IF.js} +3 -3
  4. package/dist/{chunk-FVZINOBB.js → chunk-DUB3LUVM.js} +21 -9
  5. package/dist/chunk-DUB3LUVM.js.map +1 -0
  6. package/dist/{chunk-YVDQDD33.js → chunk-L2QFSPFP.js} +2 -2
  7. package/dist/{chunk-47LKLIIK.js → chunk-NPKBYGAK.js} +2 -2
  8. package/dist/{chunk-XAKQCOF3.js → chunk-PWJJKCTF.js} +11 -1
  9. package/dist/chunk-PWJJKCTF.js.map +1 -0
  10. package/dist/{chunk-I6YPQMAL.js → chunk-VU2IK37Y.js} +2 -2
  11. package/dist/{chunk-ZQ32COTC.js → chunk-XIYAXH47.js} +2 -2
  12. package/dist/editable-artifact-durable-export.js +2 -2
  13. package/dist/editable-artifacts.js +3 -3
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.js +191 -16
  16. package/dist/index.js.map +1 -1
  17. package/dist/managed-auth-session-sets.js +3 -3
  18. package/dist/schema.d.ts +51 -0
  19. package/dist/schema.js +1 -1
  20. package/dist/session-background-commands.d.ts +6 -0
  21. package/dist/session-background-commands.js +4 -4
  22. package/dist/session-command-output.js +4 -4
  23. package/dist/session-event-slices.js +2 -2
  24. package/dist/session-tenancy.js +3 -3
  25. package/dist/video-generation.js +3 -3
  26. package/drizzle/0419_background_command_launch_authority.sql +56 -0
  27. package/package.json +6 -6
  28. package/src/index.ts +264 -10
  29. package/src/schema.ts +10 -0
  30. package/src/session-background-commands.ts +33 -0
  31. package/dist/chunk-FVZINOBB.js.map +0 -1
  32. package/dist/chunk-XAKQCOF3.js.map +0 -1
  33. /package/dist/{chunk-2HGYCAXN.js.map → chunk-B5Y3TCSP.js.map} +0 -0
  34. /package/dist/{chunk-A5RFBEZR.js.map → chunk-CQF6G4IF.js.map} +0 -0
  35. /package/dist/{chunk-YVDQDD33.js.map → chunk-L2QFSPFP.js.map} +0 -0
  36. /package/dist/{chunk-47LKLIIK.js.map → chunk-NPKBYGAK.js.map} +0 -0
  37. /package/dist/{chunk-I6YPQMAL.js.map → chunk-VU2IK37Y.js.map} +0 -0
  38. /package/dist/{chunk-ZQ32COTC.js.map → chunk-XIYAXH47.js.map} +0 -0
package/src/schema.ts CHANGED
@@ -9737,6 +9737,10 @@ export const sessionBackgroundCommands = pgTable(
9737
9737
  .notNull()
9738
9738
  .default("running"),
9739
9739
  retainedProcessId: uuid("retained_process_id"),
9740
+ // Exact launch receipt, never inferred from a later turn or session owner.
9741
+ launchTurnId: uuid("launch_turn_id"),
9742
+ launchAttemptId: uuid("launch_attempt_id"),
9743
+ launchExecutionGeneration: integer("launch_execution_generation"),
9740
9744
  controlWorkspaceId: uuid("control_workspace_id"),
9741
9745
  enrollmentId: uuid("enrollment_id"),
9742
9746
  connectionInstanceId: text("connection_instance_id"),
@@ -9815,6 +9819,12 @@ export const sessionBackgroundCommands = pgTable(
9815
9819
  stopping: index("session_background_commands_stopping_idx")
9816
9820
  .on(table.reconcileAfter, table.cancelRequestedAt, table.id)
9817
9821
  .where(sql`${table.state} in ('running', 'stopping')`),
9822
+ launchIdentityValid: check(
9823
+ "session_background_commands_launch_identity_check",
9824
+ sql`(${table.launchTurnId} is null and ${table.launchAttemptId} is null and ${table.launchExecutionGeneration} is null)
9825
+ or (${table.launchTurnId} is not null and ${table.launchAttemptId} is not null
9826
+ and ${table.launchExecutionGeneration} is not null and ${table.launchExecutionGeneration} > 0)`,
9827
+ ),
9818
9828
  providerValid: check(
9819
9829
  "session_background_commands_provider_check",
9820
9830
  sql`${table.provider} in ('managed', 'connected_machine')`,
@@ -205,6 +205,9 @@ export async function insertManagedSessionBackgroundCommandInTransaction(
205
205
  commandId: string;
206
206
  retainedProcessId: string;
207
207
  command: string;
208
+ turnId?: string;
209
+ attemptId?: string;
210
+ executionGeneration?: number;
208
211
  },
209
212
  ): Promise<SessionBackgroundCommand> {
210
213
  const [process] = await db
@@ -213,6 +216,11 @@ export async function insertManagedSessionBackgroundCommandInTransaction(
213
216
  workspaceId: schema.sandboxRetainedProcesses.workspaceId,
214
217
  sessionId: schema.sandboxRetainedProcesses.sessionId,
215
218
  state: schema.sandboxRetainedProcesses.state,
219
+ ownerActorKind: schema.sandboxRetainedProcesses.ownerActorKind,
220
+ ownerActorId: schema.sandboxRetainedProcesses.ownerActorId,
221
+ ownerTurnId: schema.sandboxRetainedProcesses.ownerTurnId,
222
+ ownerAttemptId: schema.sandboxRetainedProcesses.ownerAttemptId,
223
+ ownerExecutionGeneration: schema.sandboxRetainedProcesses.ownerExecutionGeneration,
216
224
  })
217
225
  .from(schema.sandboxRetainedProcesses)
218
226
  .where(eq(schema.sandboxRetainedProcesses.id, input.retainedProcessId))
@@ -238,6 +246,9 @@ export async function insertManagedSessionBackgroundCommandInTransaction(
238
246
  state: "running",
239
247
  retainedProcessId: input.retainedProcessId,
240
248
  commandPreview: commandPreview(input.command),
249
+ launchTurnId: input.turnId ?? null,
250
+ launchAttemptId: input.attemptId ?? null,
251
+ launchExecutionGeneration: input.executionGeneration ?? null,
241
252
  })
242
253
  .onConflictDoUpdate({
243
254
  target: schema.sessionBackgroundCommands.retainedProcessId,
@@ -246,10 +257,23 @@ export async function insertManagedSessionBackgroundCommandInTransaction(
246
257
  })
247
258
  .returning();
248
259
  if (!row) throw new Error("Managed background command adoption returned no row");
260
+ const legacyReplayMatches =
261
+ row.launchTurnId === null &&
262
+ row.launchAttemptId === null &&
263
+ row.launchExecutionGeneration === null &&
264
+ process.ownerActorKind === "turn" &&
265
+ process.ownerActorId === input.attemptId &&
266
+ process.ownerTurnId === input.turnId &&
267
+ process.ownerAttemptId === input.attemptId &&
268
+ process.ownerExecutionGeneration === input.executionGeneration;
249
269
  if (
250
270
  row.accountId !== input.accountId ||
251
271
  row.workspaceId !== input.workspaceId ||
252
272
  row.sessionId !== input.sessionId ||
273
+ (!legacyReplayMatches &&
274
+ (row.launchTurnId !== (input.turnId ?? null) ||
275
+ row.launchAttemptId !== (input.attemptId ?? null) ||
276
+ row.launchExecutionGeneration !== (input.executionGeneration ?? null))) ||
253
277
  row.provider !== "managed" ||
254
278
  row.retainedProcessId !== input.retainedProcessId
255
279
  ) {
@@ -271,6 +295,9 @@ export async function insertConnectedMachineSessionBackgroundCommandInTransactio
271
295
  connectionInstanceId: string;
272
296
  opId: string;
273
297
  command: string;
298
+ turnId?: string;
299
+ attemptId?: string;
300
+ executionGeneration?: number;
274
301
  },
275
302
  ): Promise<SessionBackgroundCommand> {
276
303
  const [row] = await db
@@ -287,6 +314,9 @@ export async function insertConnectedMachineSessionBackgroundCommandInTransactio
287
314
  connectionInstanceId: input.connectionInstanceId,
288
315
  opId: input.opId,
289
316
  commandPreview: commandPreview(input.command),
317
+ launchTurnId: input.turnId ?? null,
318
+ launchAttemptId: input.attemptId ?? null,
319
+ launchExecutionGeneration: input.executionGeneration ?? null,
290
320
  })
291
321
  .onConflictDoUpdate({
292
322
  target: [
@@ -304,6 +334,9 @@ export async function insertConnectedMachineSessionBackgroundCommandInTransactio
304
334
  row.accountId !== input.accountId ||
305
335
  row.workspaceId !== input.workspaceId ||
306
336
  row.sessionId !== input.sessionId ||
337
+ row.launchTurnId !== (input.turnId ?? null) ||
338
+ row.launchAttemptId !== (input.attemptId ?? null) ||
339
+ row.launchExecutionGeneration !== (input.executionGeneration ?? null) ||
307
340
  row.provider !== "connected_machine" ||
308
341
  row.controlWorkspaceId !== input.controlWorkspaceId ||
309
342
  row.enrollmentId !== input.enrollmentId ||