@opengeni/db 0.10.7 → 0.12.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 (35) hide show
  1. package/dist/{chunk-P6PKXY5W.js → chunk-VUKRIBO5.js} +485 -12
  2. package/dist/chunk-VUKRIBO5.js.map +1 -0
  3. package/dist/{chunk-KW526IJA.js → chunk-Y5WZZVQK.js} +80 -4
  4. package/dist/chunk-Y5WZZVQK.js.map +1 -0
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.js +5114 -2085
  7. package/dist/index.js.map +1 -1
  8. package/dist/migrate.d.ts +6 -3
  9. package/dist/migrate.js +1 -1
  10. package/dist/provision-roles.d.ts +720 -63
  11. package/dist/{schema-CqkzrBRS.d.ts → schema-CnpD6BcX.d.ts} +4684 -2913
  12. package/dist/schema.d.ts +1 -1
  13. package/dist/schema.js +17 -1
  14. package/drizzle/0109_nested_agent_depth_expand.sql +42 -0
  15. package/drizzle/0110_nested_agent_depth_boundary.sql +480 -0
  16. package/drizzle/0111_nested_agent_depth_backfill.sql +49 -0
  17. package/drizzle/0112_nested_agent_depth_contract.sql +38 -0
  18. package/drizzle/0113_nested_agent_depth_validate.sql +13 -0
  19. package/drizzle/0114_nested_agent_depth_contract.sql +49 -0
  20. package/drizzle/0115_nested_agent_depth_validate.sql +11 -0
  21. package/drizzle/0116_nested_agent_depth_index.sql +4 -0
  22. package/drizzle/0117_sandbox_recovery_generations.sql +699 -0
  23. package/drizzle/0118_new_session_drafts.sql +59 -0
  24. package/drizzle/0119_pending_tool_output_policy.sql +5 -0
  25. package/drizzle/0120_durable_goal_wake.sql +360 -0
  26. package/drizzle/0121_goal_update_idempotency.sql +11 -0
  27. package/package.json +3 -3
  28. package/src/index.ts +5961 -1240
  29. package/src/migrate.ts +131 -2
  30. package/src/new-session-drafts.ts +144 -0
  31. package/src/schema.ts +519 -15
  32. package/src/session-control.ts +42 -18
  33. package/src/session-tool-call-settlement.ts +6 -1
  34. package/dist/chunk-KW526IJA.js.map +0 -1
  35. package/dist/chunk-P6PKXY5W.js.map +0 -1
@@ -44,6 +44,8 @@ __export(schema_exports, {
44
44
  machineMetricsLatest: () => machineMetricsLatest,
45
45
  machineMetricsSeries: () => machineMetricsSeries,
46
46
  managedAccounts: () => managedAccounts,
47
+ nestedAgentDepthConfiguration: () => nestedAgentDepthConfiguration,
48
+ newSessionDrafts: () => newSessionDrafts,
47
49
  packInstallations: () => packInstallations,
48
50
  rigChanges: () => rigChanges,
49
51
  rigVersions: () => rigVersions,
@@ -53,7 +55,12 @@ __export(schema_exports, {
53
55
  sandboxLeaseLivenessValues: () => sandboxLeaseLivenessValues,
54
56
  sandboxLeases: () => sandboxLeases,
55
57
  sandboxPtySessions: () => sandboxPtySessions,
58
+ sandboxRetainedProcessStateValues: () => sandboxRetainedProcessStateValues,
59
+ sandboxRetainedProcesses: () => sandboxRetainedProcesses,
56
60
  sandboxSessionEnvelopes: () => sandboxSessionEnvelopes,
61
+ sandboxWorkspaceMutationActorKindValues: () => sandboxWorkspaceMutationActorKindValues,
62
+ sandboxWorkspaceMutationAdmissions: () => sandboxWorkspaceMutationAdmissions,
63
+ sandboxWorkspaceMutationHolderKindValues: () => sandboxWorkspaceMutationHolderKindValues,
57
64
  sandboxes: () => sandboxes,
58
65
  scheduledTaskRuns: () => scheduledTaskRuns,
59
66
  scheduledTasks: () => scheduledTasks,
@@ -71,6 +78,7 @@ __export(schema_exports, {
71
78
  sessionRecordingModeValues: () => sessionRecordingModeValues,
72
79
  sessionRecordingStateValues: () => sessionRecordingStateValues,
73
80
  sessionRecordings: () => sessionRecordings,
81
+ sessionSpawnDenials: () => sessionSpawnDenials,
74
82
  sessionSystemUpdateOutbox: () => sessionSystemUpdateOutbox,
75
83
  sessionSystemUpdates: () => sessionSystemUpdates,
76
84
  sessionTurnAttempts: () => sessionTurnAttempts,
@@ -164,6 +172,29 @@ var workspaces = pgTable(
164
172
  external: uniqueIndex("workspaces_external_idx").on(table.externalSource, table.externalId)
165
173
  })
166
174
  );
175
+ var nestedAgentDepthConfiguration = pgTable(
176
+ "nested_agent_depth_configuration",
177
+ {
178
+ singleton: boolean("singleton").primaryKey().notNull().default(true),
179
+ maxNestedAgentDepth: integer("max_nested_agent_depth").notNull(),
180
+ policySource: text("policy_source").$type().notNull(),
181
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
182
+ },
183
+ (table) => ({
184
+ singletonOnly: check(
185
+ "nested_agent_depth_configuration_singleton_check",
186
+ sql`${table.singleton}`
187
+ ),
188
+ maxValid: check(
189
+ "nested_agent_depth_configuration_max_check",
190
+ sql`${table.maxNestedAgentDepth} >= 0`
191
+ ),
192
+ sourceValid: check(
193
+ "nested_agent_depth_configuration_source_check",
194
+ sql`${table.policySource} in ('deployment', 'default')`
195
+ )
196
+ })
197
+ );
167
198
  var workspaceInferenceControls = pgTable(
168
199
  "workspace_inference_controls",
169
200
  {
@@ -711,6 +742,15 @@ var sessions = pgTable(
711
742
  // workspace to a single session row — the dedup that closes the
712
743
  // double-submit/double-dispatch stuck-queued bug.
713
744
  createIdempotencyKey: text("create_idempotency_key"),
745
+ // Immutable creation-time hierarchy and policy snapshot. These values are
746
+ // populated by the database admission boundary and never re-derived from
747
+ // a live workspace setting for an existing session.
748
+ rootSessionId: uuid("root_session_id").notNull(),
749
+ nestedAgentDepth: integer("nested_agent_depth").notNull(),
750
+ maxNestedAgentDepthOverride: integer("max_nested_agent_depth_override"),
751
+ effectiveMaxNestedAgentDepth: integer("effective_max_nested_agent_depth").notNull(),
752
+ nestedAgentDepthPolicySource: text("nested_agent_depth_policy_source").notNull(),
753
+ nestedAgentDepthPolicySessionId: uuid("nested_agent_depth_policy_session_id"),
714
754
  temporalWorkflowId: text("temporal_workflow_id"),
715
755
  activeTurnId: uuid("active_turn_id"),
716
756
  // Actual input tokens reported for the last model call of the most recent
@@ -793,10 +833,56 @@ var sessions = pgTable(
793
833
  // point and enumerate all sessions in a group for attribution/disclosure.
794
834
  sandboxGroup: index("sessions_sandbox_group_idx").on(table.workspaceId, table.sandboxGroupId),
795
835
  // Partial unique index: one session per (workspace, create_idempotency_key)
796
- // when a key is present. Concurrent creates racing on the same key see a
797
- // unique violation on all but one; the domain layer catches it and returns
798
- // the winning row instead of erroring.
799
- createIdempotency: uniqueIndex("sessions_workspace_create_idempotency_idx").on(table.workspaceId, table.createIdempotencyKey).where(sql`${table.createIdempotencyKey} is not null`)
836
+ // when a key is present. The boundary trigger reserves the cross-outcome
837
+ // winner before this source row commits; a losing source insert is
838
+ // suppressed and the domain layer replays the durable winner.
839
+ createIdempotency: uniqueIndex("sessions_workspace_create_idempotency_idx").on(table.workspaceId, table.createIdempotencyKey).where(sql`${table.createIdempotencyKey} is not null`),
840
+ rootDepth: index("sessions_workspace_root_depth_idx").on(
841
+ table.workspaceId,
842
+ table.rootSessionId,
843
+ table.nestedAgentDepth
844
+ )
845
+ })
846
+ );
847
+ var sessionSpawnDenials = pgTable(
848
+ "session_spawn_denials",
849
+ {
850
+ id: uuid("id").primaryKey().defaultRandom(),
851
+ accountId: uuid("account_id").notNull(),
852
+ workspaceId: uuid("workspace_id").notNull(),
853
+ parentSessionId: uuid("parent_session_id"),
854
+ rootSessionId: uuid("root_session_id"),
855
+ currentDepth: integer("current_depth").notNull(),
856
+ attemptedDepth: bigint("attempted_depth", { mode: "number" }).notNull(),
857
+ effectiveMaxNestedAgentDepth: integer("effective_max_nested_agent_depth").notNull(),
858
+ requestedMaxNestedAgentDepthOverride: integer("requested_max_nested_agent_depth_override"),
859
+ policySource: text("policy_source").notNull(),
860
+ policySessionId: uuid("policy_session_id"),
861
+ subjectId: text("subject_id"),
862
+ code: text("code").notNull(),
863
+ idempotencyKey: text("idempotency_key"),
864
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
865
+ },
866
+ (table) => ({
867
+ workspaceIdentity: uniqueIndex("session_spawn_denials_workspace_id_uq").on(
868
+ table.workspaceId,
869
+ table.id
870
+ ),
871
+ workspaceCreated: index("session_spawn_denials_workspace_created_idx").on(
872
+ table.workspaceId,
873
+ table.createdAt
874
+ ),
875
+ parent: index("session_spawn_denials_parent_idx").on(
876
+ table.workspaceId,
877
+ table.parentSessionId,
878
+ table.createdAt
879
+ ),
880
+ idempotency: uniqueIndex("session_spawn_denials_workspace_idempotency_idx").on(table.workspaceId, table.idempotencyKey).where(sql`${table.idempotencyKey} is not null`),
881
+ workspaceAccount: foreignKey({
882
+ name: "session_spawn_denials_workspace_account_fk",
883
+ columns: [table.workspaceId, table.accountId],
884
+ foreignColumns: [workspaces.id, workspaces.accountId]
885
+ }).onDelete("cascade")
800
886
  })
801
887
  );
802
888
  var sessionPins = pgTable(
@@ -1325,6 +1411,7 @@ var sessionCommandReceipts = pgTable(
1325
1411
  table.targetSessionId,
1326
1412
  table.createdAt
1327
1413
  ),
1414
+ goalUpdateOperation: uniqueIndex("session_command_receipts_goal_update_operation_uq").on(table.workspaceId, table.action, table.targetSessionId, table.operationKey).where(sql`${table.action} = 'goal.update'`),
1328
1415
  actorValid: check(
1329
1416
  "session_command_receipts_actor_check",
1330
1417
  sql`(
@@ -1486,6 +1573,40 @@ var composerDrafts = pgTable(
1486
1573
  revisionValid: check("composer_drafts_revision_check", sql`${table.revision} >= 1`)
1487
1574
  })
1488
1575
  );
1576
+ var newSessionDrafts = pgTable(
1577
+ "new_session_drafts",
1578
+ {
1579
+ id: uuid("id").primaryKey().defaultRandom(),
1580
+ accountId: uuid("account_id").notNull(),
1581
+ workspaceId: uuid("workspace_id").notNull(),
1582
+ subjectId: text("subject_id").notNull(),
1583
+ revision: bigint("revision", { mode: "number" }).notNull().default(1),
1584
+ text: text("text").notNull().default(""),
1585
+ resources: jsonb("resources").$type().notNull().default([]),
1586
+ tools: jsonb("tools").$type().notNull().default([]),
1587
+ model: text("model").notNull(),
1588
+ reasoningEffort: text("reasoning_effort").notNull(),
1589
+ sessionOptions: jsonb("session_options").$type().notNull().default({}),
1590
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1591
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1592
+ },
1593
+ (table) => ({
1594
+ workspaceAccount: foreignKey({
1595
+ name: "new_session_drafts_workspace_account_fk",
1596
+ columns: [table.workspaceId, table.accountId],
1597
+ foreignColumns: [workspaces.id, workspaces.accountId]
1598
+ }).onDelete("cascade"),
1599
+ subjectWorkspace: uniqueIndex("new_session_drafts_subject_workspace_uq").on(
1600
+ table.workspaceId,
1601
+ table.subjectId
1602
+ ),
1603
+ subjectValid: check(
1604
+ "new_session_drafts_subject_check",
1605
+ sql`length(btrim(${table.subjectId})) > 0`
1606
+ ),
1607
+ revisionValid: check("new_session_drafts_revision_check", sql`${table.revision} >= 1`)
1608
+ })
1609
+ );
1489
1610
  var sessionSystemUpdates = pgTable(
1490
1611
  "session_system_updates",
1491
1612
  {
@@ -1597,6 +1718,10 @@ var sessionWorkflowWakeOutbox = pgTable(
1597
1718
  "session_workflow_wake_outbox_revision_check",
1598
1719
  sql`${table.wakeRevision} > 0 and ${table.deliveredRevision} >= 0 and ${table.deliveredRevision} <= ${table.wakeRevision}`
1599
1720
  ),
1721
+ revisionSafe: check(
1722
+ "session_workflow_wake_outbox_revision_safe_check",
1723
+ sql`${table.wakeRevision} <= 9007199254740991 and ${table.deliveredRevision} <= 9007199254740991`
1724
+ ),
1600
1725
  workspaceAccount: foreignKey({
1601
1726
  name: "session_workflow_wake_outbox_workspace_account_fk",
1602
1727
  columns: [table.workspaceId, table.accountId],
@@ -1641,6 +1766,14 @@ var sessionGoals = pgTable(
1641
1766
  // per-goal override; a configured settings cap (if any) remains the hard ceiling
1642
1767
  lastContinuationTurnId: uuid("last_continuation_turn_id"),
1643
1768
  versionAtLastContinuation: integer("version_at_last_continuation"),
1769
+ // Postgres owns the continuation obligation. Terminal settlement advances
1770
+ // wakeRevision in the same transaction that makes the session idle;
1771
+ // materialization advances observedRevision only alongside the one typed
1772
+ // update, timeline events, usage row, and workflow-wake outbox row.
1773
+ // Temporal signals and workflow history are replaceable nudges over these
1774
+ // monotonic revisions.
1775
+ continuationWakeRevision: bigint("continuation_wake_revision", { mode: "number" }).notNull().default(0),
1776
+ continuationObservedRevision: bigint("continuation_observed_revision", { mode: "number" }).notNull().default(0),
1644
1777
  metadata: jsonb("metadata").$type().notNull().default({}),
1645
1778
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1646
1779
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -1654,7 +1787,11 @@ var sessionGoals = pgTable(
1654
1787
  table.workspaceId,
1655
1788
  table.sessionId
1656
1789
  ),
1657
- status: index("session_goals_workspace_status_idx").on(table.workspaceId, table.status)
1790
+ status: index("session_goals_workspace_status_idx").on(table.workspaceId, table.status),
1791
+ continuationRevisionValid: check(
1792
+ "session_goals_continuation_revision_check",
1793
+ sql`${table.continuationWakeRevision} >= 0 and ${table.continuationObservedRevision} >= 0 and ${table.continuationObservedRevision} <= ${table.continuationWakeRevision} and ${table.continuationWakeRevision} <= 9007199254740991 and ${table.continuationObservedRevision} <= 9007199254740991`
1794
+ )
1658
1795
  })
1659
1796
  );
1660
1797
  var codexCapacityWaiters = pgTable(
@@ -1943,6 +2080,7 @@ var sessionPendingToolCalls = pgTable(
1943
2080
  callId: text("call_id").notNull(),
1944
2081
  callType: text("call_type").notNull(),
1945
2082
  callItem: jsonb("call_item").$type().notNull(),
2083
+ modelToolOutputTruncationTokens: integer("model_tool_output_truncation_tokens"),
1946
2084
  resultItem: jsonb("result_item").$type(),
1947
2085
  resultRecordedAt: timestamp("result_recorded_at", { withTimezone: true }),
1948
2086
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
@@ -2025,6 +2163,13 @@ var sandboxLeases = pgTable(
2025
2163
  // was always-true → every turn fenced); int4 returns a JS number, the fix.
2026
2164
  // Epochs never approach 2^31, so the narrower type loses nothing.
2027
2165
  leaseEpoch: integer("lease_epoch").notNull().default(0),
2166
+ // Monotonic mutation intent for the live workspace. Every acknowledged
2167
+ // filesystem-writing operation advances this under the exact lease epoch +
2168
+ // provider-instance fence BEFORE it reaches the provider. A verified
2169
+ // archive fold copies the exact captured value into archive_generation in
2170
+ // the same row update; equality is the only durable completeness proof.
2171
+ workspaceGeneration: integer("workspace_generation").notNull().default(0),
2172
+ archiveGeneration: integer("archive_generation"),
2028
2173
  // The group box-envelope (the "envelope split" Critical): the small recovery
2029
2174
  // descriptor to resume()-by-id the group's box without a per-session join.
2030
2175
  resumeBackendId: text("resume_backend_id"),
@@ -2040,7 +2185,28 @@ var sandboxLeases = pgTable(
2040
2185
  },
2041
2186
  (table) => ({
2042
2187
  groupIdx: uniqueIndex("sandbox_leases_group_idx").on(table.workspaceId, table.sandboxGroupId),
2043
- reaperIdx: index("sandbox_leases_reaper_idx").on(table.expiresAt).where(sql`${table.liveness} in ('warming','warm','draining')`)
2188
+ scopedId: uniqueIndex("sandbox_leases_scoped_id_uq").on(
2189
+ table.accountId,
2190
+ table.workspaceId,
2191
+ table.sandboxGroupId,
2192
+ table.id
2193
+ ),
2194
+ accountWorkspaceId: uniqueIndex("sandbox_leases_account_workspace_id_uq").on(
2195
+ table.accountId,
2196
+ table.workspaceId,
2197
+ table.id
2198
+ ),
2199
+ reaperIdx: index("sandbox_leases_reaper_idx").on(table.expiresAt).where(sql`${table.liveness} in ('warming','warm','draining')`),
2200
+ workspaceGenerationValid: check(
2201
+ "sandbox_leases_workspace_generation_check",
2202
+ sql`${table.workspaceGeneration} >= 0`
2203
+ ),
2204
+ archiveGenerationValid: check(
2205
+ "sandbox_leases_archive_generation_check",
2206
+ sql`${table.archiveGeneration} is null
2207
+ or (${table.archiveGeneration} >= 0
2208
+ and ${table.archiveGeneration} <= ${table.workspaceGeneration})`
2209
+ )
2044
2210
  })
2045
2211
  );
2046
2212
  var sandboxLeaseHolders = pgTable(
@@ -2050,7 +2216,7 @@ var sandboxLeaseHolders = pgTable(
2050
2216
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
2051
2217
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
2052
2218
  leaseId: uuid("lease_id").notNull().references(() => sandboxLeases.id, { onDelete: "cascade" }),
2053
- kind: text("kind", { enum: ["turn", "viewer"] }).notNull(),
2219
+ kind: text("kind", { enum: ["turn", "viewer", "direct", "process"] }).notNull(),
2054
2220
  holderId: text("holder_id").notNull(),
2055
2221
  // The attributing session within the (possibly shared) group.
2056
2222
  subjectId: uuid("subject_id"),
@@ -2058,6 +2224,11 @@ var sandboxLeaseHolders = pgTable(
2058
2224
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
2059
2225
  },
2060
2226
  (table) => ({
2227
+ leaseScope: foreignKey({
2228
+ name: "sandbox_lease_holders_lease_scope_fk",
2229
+ columns: [table.accountId, table.workspaceId, table.leaseId],
2230
+ foreignColumns: [sandboxLeases.accountId, sandboxLeases.workspaceId, sandboxLeases.id]
2231
+ }).onDelete("cascade"),
2061
2232
  holderIdx: uniqueIndex("sandbox_lease_holders_holder_idx").on(
2062
2233
  table.leaseId,
2063
2234
  table.kind,
@@ -2067,6 +2238,258 @@ var sandboxLeaseHolders = pgTable(
2067
2238
  leaseIdx: index("sandbox_lease_holders_lease_idx").on(table.leaseId)
2068
2239
  })
2069
2240
  );
2241
+ var sandboxWorkspaceMutationActorKindValues = ["turn", "direct", "process"];
2242
+ var sandboxWorkspaceMutationHolderKindValues = ["turn", "direct", "process"];
2243
+ var sandboxWorkspaceMutationAdmissions = pgTable(
2244
+ "sandbox_workspace_mutation_admissions",
2245
+ {
2246
+ id: uuid("id").primaryKey().defaultRandom(),
2247
+ accountId: uuid("account_id").notNull(),
2248
+ workspaceId: uuid("workspace_id").notNull(),
2249
+ leaseId: uuid("lease_id").notNull().references(() => sandboxLeases.id, { onDelete: "cascade" }),
2250
+ sandboxGroupId: uuid("sandbox_group_id").notNull(),
2251
+ sessionId: uuid("session_id").notNull(),
2252
+ actorKind: text("actor_kind", { enum: sandboxWorkspaceMutationActorKindValues }).notNull(),
2253
+ actorId: uuid("actor_id").notNull(),
2254
+ // Exact turn authority is present only for actor_kind='turn'. Direct HTTP
2255
+ // requests and retained processes never invent a turn or quiescence owner.
2256
+ turnId: uuid("turn_id"),
2257
+ attemptId: uuid("attempt_id"),
2258
+ executionGeneration: integer("execution_generation"),
2259
+ holderKind: text("holder_kind", {
2260
+ enum: sandboxWorkspaceMutationHolderKindValues
2261
+ }).notNull(),
2262
+ holderId: text("holder_id").notNull(),
2263
+ leaseEpoch: integer("lease_epoch").notNull(),
2264
+ providerBackend: text("provider_backend").notNull(),
2265
+ providerInstanceId: text("provider_instance_id").notNull(),
2266
+ routeKind: text("route_kind", { enum: ["home", "active"] }).notNull(),
2267
+ // null route target means the persistable home/group provider. A non-null
2268
+ // target is pinned together with the active pointer epoch observed when the
2269
+ // operation was admitted.
2270
+ routeTargetId: uuid("route_target_id"),
2271
+ routeEpoch: integer("route_epoch").notNull(),
2272
+ workspaceGeneration: integer("workspace_generation").notNull(),
2273
+ operation: text("operation").notNull(),
2274
+ providerOutcome: text("provider_outcome", {
2275
+ enum: ["resolved", "rejected", "retained"]
2276
+ }),
2277
+ admittedAt: timestamp("admitted_at", { withTimezone: true }).notNull().defaultNow(),
2278
+ settledAt: timestamp("settled_at", { withTimezone: true })
2279
+ },
2280
+ (table) => ({
2281
+ workspaceAccount: foreignKey({
2282
+ name: "sandbox_workspace_mutation_admissions_workspace_account_fk",
2283
+ columns: [table.workspaceId, table.accountId],
2284
+ foreignColumns: [workspaces.id, workspaces.accountId]
2285
+ }).onDelete("cascade"),
2286
+ workspaceSession: foreignKey({
2287
+ name: "sandbox_workspace_mutation_admissions_workspace_session_fk",
2288
+ columns: [table.workspaceId, table.sessionId],
2289
+ foreignColumns: [sessions.workspaceId, sessions.id]
2290
+ }).onDelete("restrict"),
2291
+ workspaceTurn: foreignKey({
2292
+ name: "sandbox_workspace_mutation_admissions_workspace_turn_fk",
2293
+ columns: [table.workspaceId, table.turnId],
2294
+ foreignColumns: [sessionTurns.workspaceId, sessionTurns.id]
2295
+ }).onDelete("restrict"),
2296
+ workspaceAttempt: foreignKey({
2297
+ name: "sandbox_workspace_mutation_admissions_workspace_attempt_fk",
2298
+ columns: [table.workspaceId, table.attemptId],
2299
+ foreignColumns: [sessionTurnAttempts.workspaceId, sessionTurnAttempts.id]
2300
+ }).onDelete("restrict"),
2301
+ leaseGeneration: uniqueIndex("sandbox_workspace_mutation_admissions_lease_generation_uq").on(
2302
+ table.leaseId,
2303
+ table.workspaceGeneration
2304
+ ),
2305
+ scopedId: uniqueIndex("sandbox_workspace_mutation_admissions_scoped_id_uq").on(
2306
+ table.accountId,
2307
+ table.workspaceId,
2308
+ table.sessionId,
2309
+ table.leaseId,
2310
+ table.id
2311
+ ),
2312
+ blocking: index("sandbox_workspace_mutation_admissions_blocking_idx").on(table.leaseId, table.workspaceGeneration).where(sql`${table.settledAt} is null`),
2313
+ attempt: index("sandbox_workspace_mutation_admissions_attempt_idx").on(
2314
+ table.workspaceId,
2315
+ table.attemptId
2316
+ ),
2317
+ actor: index("sandbox_workspace_mutation_admissions_actor_idx").on(
2318
+ table.workspaceId,
2319
+ table.actorKind,
2320
+ table.actorId
2321
+ ),
2322
+ generationValid: check(
2323
+ "sandbox_workspace_mutation_admissions_generation_check",
2324
+ sql`${table.workspaceGeneration} > 0
2325
+ and ${table.leaseEpoch} >= 0
2326
+ and ${table.routeEpoch} >= 0
2327
+ and (${table.executionGeneration} is null or ${table.executionGeneration} > 0)`
2328
+ ),
2329
+ actorValid: check(
2330
+ "sandbox_workspace_mutation_admissions_actor_check",
2331
+ sql`(
2332
+ ${table.actorKind} = 'turn'
2333
+ and ${table.actorId} = ${table.attemptId}
2334
+ and ${table.turnId} is not null
2335
+ and ${table.attemptId} is not null
2336
+ and ${table.executionGeneration} is not null
2337
+ and ${table.holderKind} = 'turn'
2338
+ ) or (
2339
+ ${table.actorKind} = 'direct'
2340
+ and ${table.turnId} is null
2341
+ and ${table.attemptId} is null
2342
+ and ${table.executionGeneration} is null
2343
+ and ${table.holderKind} = 'direct'
2344
+ ) or (
2345
+ ${table.actorKind} = 'process'
2346
+ and ${table.turnId} is null
2347
+ and ${table.attemptId} is null
2348
+ and ${table.executionGeneration} is null
2349
+ and ${table.holderKind} = 'process'
2350
+ )`
2351
+ ),
2352
+ routeValid: check(
2353
+ "sandbox_workspace_mutation_admissions_route_check",
2354
+ sql`${table.actorKind} in ('turn', 'direct', 'process')
2355
+ and ${table.holderKind} in ('turn', 'direct', 'process')
2356
+ and octet_length(${table.holderId}) between 1 and 256
2357
+ and octet_length(${table.providerBackend}) between 1 and 64
2358
+ and octet_length(${table.providerInstanceId}) between 1 and 512
2359
+ and ${table.routeKind} in ('home', 'active')
2360
+ and (${table.routeKind} = 'active' or ${table.routeTargetId} is null)`
2361
+ ),
2362
+ operationValid: check(
2363
+ "sandbox_workspace_mutation_admissions_operation_check",
2364
+ sql`octet_length(${table.operation}) between 1 and 128`
2365
+ ),
2366
+ outcomeValid: check(
2367
+ "sandbox_workspace_mutation_admissions_outcome_check",
2368
+ sql`${table.providerOutcome} is null or ${table.providerOutcome} in ('resolved', 'rejected', 'retained')`
2369
+ ),
2370
+ settlementConsistent: check(
2371
+ "sandbox_workspace_mutation_admissions_settlement_check",
2372
+ sql`(${table.providerOutcome} is null and ${table.settledAt} is null)
2373
+ or (${table.providerOutcome} = 'retained' and ${table.settledAt} is null)
2374
+ or (${table.providerOutcome} in ('resolved', 'rejected') and ${table.settledAt} is not null)`
2375
+ )
2376
+ })
2377
+ );
2378
+ var sandboxRetainedProcessStateValues = ["active", "exited", "lost"];
2379
+ var sandboxRetainedProcesses = pgTable(
2380
+ "sandbox_retained_processes",
2381
+ {
2382
+ id: uuid("id").primaryKey().defaultRandom(),
2383
+ accountId: uuid("account_id").notNull(),
2384
+ workspaceId: uuid("workspace_id").notNull(),
2385
+ sessionId: uuid("session_id").notNull(),
2386
+ leaseId: uuid("lease_id").notNull(),
2387
+ sandboxGroupId: uuid("sandbox_group_id").notNull(),
2388
+ parentAdmissionId: uuid("parent_admission_id").notNull(),
2389
+ holderId: text("holder_id").notNull(),
2390
+ ownerActorKind: text("owner_actor_kind", { enum: ["turn", "direct"] }).notNull(),
2391
+ ownerActorId: uuid("owner_actor_id").notNull(),
2392
+ ownerTurnId: uuid("owner_turn_id"),
2393
+ ownerAttemptId: uuid("owner_attempt_id"),
2394
+ ownerExecutionGeneration: integer("owner_execution_generation"),
2395
+ leaseEpoch: integer("lease_epoch").notNull(),
2396
+ providerBackend: text("provider_backend").notNull(),
2397
+ providerInstanceId: text("provider_instance_id").notNull(),
2398
+ routeKind: text("route_kind", { enum: ["home", "active"] }).notNull(),
2399
+ routeTargetId: uuid("route_target_id"),
2400
+ routeEpoch: integer("route_epoch").notNull(),
2401
+ providerSessionId: integer("provider_session_id").notNull(),
2402
+ state: text("state", { enum: sandboxRetainedProcessStateValues }).notNull().default("active"),
2403
+ exitCode: integer("exit_code"),
2404
+ settlementReason: text("settlement_reason"),
2405
+ startedAt: timestamp("started_at", { withTimezone: true }).notNull().defaultNow(),
2406
+ settledAt: timestamp("settled_at", { withTimezone: true })
2407
+ },
2408
+ (table) => ({
2409
+ workspaceAccount: foreignKey({
2410
+ name: "sandbox_retained_processes_workspace_account_fk",
2411
+ columns: [table.workspaceId, table.accountId],
2412
+ foreignColumns: [workspaces.id, workspaces.accountId]
2413
+ }).onDelete("cascade"),
2414
+ workspaceSession: foreignKey({
2415
+ name: "sandbox_retained_processes_workspace_session_fk",
2416
+ columns: [table.workspaceId, table.sessionId],
2417
+ foreignColumns: [sessions.workspaceId, sessions.id]
2418
+ }).onDelete("restrict"),
2419
+ parentAdmissionScope: foreignKey({
2420
+ name: "sandbox_retained_processes_parent_admission_scope_fk",
2421
+ columns: [
2422
+ table.accountId,
2423
+ table.workspaceId,
2424
+ table.sessionId,
2425
+ table.leaseId,
2426
+ table.parentAdmissionId
2427
+ ],
2428
+ foreignColumns: [
2429
+ sandboxWorkspaceMutationAdmissions.accountId,
2430
+ sandboxWorkspaceMutationAdmissions.workspaceId,
2431
+ sandboxWorkspaceMutationAdmissions.sessionId,
2432
+ sandboxWorkspaceMutationAdmissions.leaseId,
2433
+ sandboxWorkspaceMutationAdmissions.id
2434
+ ]
2435
+ }).onDelete("restrict"),
2436
+ scopedId: uniqueIndex("sandbox_retained_processes_scoped_id_uq").on(
2437
+ table.accountId,
2438
+ table.workspaceId,
2439
+ table.sessionId,
2440
+ table.leaseId,
2441
+ table.id
2442
+ ),
2443
+ parentAdmission: uniqueIndex("sandbox_retained_processes_parent_admission_uq").on(
2444
+ table.parentAdmissionId
2445
+ ),
2446
+ liveProviderSession: uniqueIndex("sandbox_retained_processes_live_provider_session_uq").on(
2447
+ table.leaseId,
2448
+ table.leaseEpoch,
2449
+ table.providerInstanceId,
2450
+ table.routeEpoch,
2451
+ table.providerSessionId
2452
+ ).where(sql`${table.state} = 'active'`),
2453
+ holder: uniqueIndex("sandbox_retained_processes_holder_uq").on(table.leaseId, table.holderId),
2454
+ active: index("sandbox_retained_processes_active_idx").on(table.workspaceId, table.sessionId, table.startedAt).where(sql`${table.state} = 'active'`),
2455
+ identityValid: check(
2456
+ "sandbox_retained_processes_identity_check",
2457
+ sql`${table.leaseEpoch} >= 0
2458
+ and ${table.routeEpoch} >= 0
2459
+ and ${table.providerSessionId} > 0
2460
+ and octet_length(${table.holderId}) between 1 and 256
2461
+ and octet_length(${table.providerBackend}) between 1 and 64
2462
+ and octet_length(${table.providerInstanceId}) between 1 and 512
2463
+ and (${table.routeKind} = 'active' or ${table.routeTargetId} is null)`
2464
+ ),
2465
+ ownerValid: check(
2466
+ "sandbox_retained_processes_owner_check",
2467
+ sql`(
2468
+ ${table.ownerActorKind} = 'turn'
2469
+ and ${table.ownerActorId} = ${table.ownerAttemptId}
2470
+ and ${table.ownerTurnId} is not null
2471
+ and ${table.ownerAttemptId} is not null
2472
+ and ${table.ownerExecutionGeneration} > 0
2473
+ ) or (
2474
+ ${table.ownerActorKind} = 'direct'
2475
+ and ${table.ownerTurnId} is null
2476
+ and ${table.ownerAttemptId} is null
2477
+ and ${table.ownerExecutionGeneration} is null
2478
+ )`
2479
+ ),
2480
+ settlementValid: check(
2481
+ "sandbox_retained_processes_settlement_check",
2482
+ sql`(${table.state} = 'active' and ${table.settledAt} is null and ${table.exitCode} is null)
2483
+ or (${table.state} = 'exited' and ${table.settledAt} is not null)
2484
+ or (${table.state} = 'lost' and ${table.settledAt} is not null and ${table.exitCode} is null)`
2485
+ ),
2486
+ reasonValid: check(
2487
+ "sandbox_retained_processes_reason_check",
2488
+ sql`${table.settlementReason} is null
2489
+ or octet_length(${table.settlementReason}) between 1 and 512`
2490
+ )
2491
+ })
2492
+ );
2070
2493
  var sessionRecordingStateValues = [
2071
2494
  "recording",
2072
2495
  "finalizing",
@@ -2151,11 +2574,18 @@ var sandboxPtySessions = pgTable(
2151
2574
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
2152
2575
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
2153
2576
  sessionId: uuid("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
2154
- // The SDK numeric exec-session id used by writeStdin({ sessionId }). Null until
2155
- // the open exec yields a still-running process (a fast-exiting shell has none).
2577
+ leaseId: uuid("lease_id"),
2578
+ sandboxGroupId: uuid("sandbox_group_id"),
2579
+ retainedProcessId: uuid("retained_process_id"),
2580
+ openAdmissionId: uuid("open_admission_id"),
2581
+ // Copied provider locator for the adopted retained process.
2156
2582
  execSessionId: integer("exec_session_id"),
2157
2583
  leaseEpoch: integer("lease_epoch").notNull(),
2158
- // fenced to the box that opened it
2584
+ providerBackend: text("provider_backend"),
2585
+ providerInstanceId: text("provider_instance_id"),
2586
+ routeKind: text("route_kind", { enum: ["home", "active"] }),
2587
+ routeTargetId: uuid("route_target_id"),
2588
+ routeEpoch: integer("route_epoch"),
2159
2589
  cols: integer("cols").notNull(),
2160
2590
  rows: integer("rows").notNull(),
2161
2591
  shell: text("shell").notNull(),
@@ -2170,7 +2600,42 @@ var sandboxPtySessions = pgTable(
2170
2600
  closedAt: timestamp("closed_at", { withTimezone: true })
2171
2601
  },
2172
2602
  (table) => ({
2173
- openIdx: index("sandbox_pty_sessions_session_idx").on(table.workspaceId, table.sessionId).where(sql`${table.status} = 'open'`)
2603
+ retainedProcessScope: foreignKey({
2604
+ name: "sandbox_pty_sessions_retained_process_scope_fk",
2605
+ columns: [
2606
+ table.accountId,
2607
+ table.workspaceId,
2608
+ table.sessionId,
2609
+ table.leaseId,
2610
+ table.retainedProcessId
2611
+ ],
2612
+ foreignColumns: [
2613
+ sandboxRetainedProcesses.accountId,
2614
+ sandboxRetainedProcesses.workspaceId,
2615
+ sandboxRetainedProcesses.sessionId,
2616
+ sandboxRetainedProcesses.leaseId,
2617
+ sandboxRetainedProcesses.id
2618
+ ]
2619
+ }).onDelete("restrict"),
2620
+ openIdx: index("sandbox_pty_sessions_session_idx").on(table.workspaceId, table.sessionId).where(sql`${table.status} = 'open'`),
2621
+ processIdx: uniqueIndex("sandbox_pty_sessions_open_process_uq").on(table.retainedProcessId).where(sql`${table.status} = 'open'`),
2622
+ openIdentityValid: check(
2623
+ "sandbox_pty_sessions_open_identity_check",
2624
+ sql`${table.status} <> 'open' or (
2625
+ ${table.leaseId} is not null
2626
+ and ${table.sandboxGroupId} is not null
2627
+ and ${table.retainedProcessId} is not null
2628
+ and ${table.openAdmissionId} is not null
2629
+ and ${table.execSessionId} > 0
2630
+ and octet_length(${table.providerBackend}) between 1 and 64
2631
+ and octet_length(${table.providerInstanceId}) between 1 and 512
2632
+ and ${table.routeKind} in ('home', 'active')
2633
+ and (${table.routeKind} = 'active' or ${table.routeTargetId} is null)
2634
+ and ${table.routeEpoch} is not null
2635
+ and ${table.leaseEpoch} >= 0
2636
+ and ${table.routeEpoch} >= 0
2637
+ )`
2638
+ )
2174
2639
  })
2175
2640
  );
2176
2641
  var enrollmentExposureValues = ["whole-machine"];
@@ -3117,6 +3582,7 @@ var rigChanges = pgTable(
3117
3582
  export {
3118
3583
  managedAccounts,
3119
3584
  workspaces,
3585
+ nestedAgentDepthConfiguration,
3120
3586
  workspaceInferenceControls,
3121
3587
  workspaceSessionActivityRevisions,
3122
3588
  workspaceMemberships,
@@ -3132,6 +3598,7 @@ export {
3132
3598
  workspaceModelPolicies,
3133
3599
  codexCredentialLeases,
3134
3600
  sessions,
3601
+ sessionSpawnDenials,
3135
3602
  sessionPins,
3136
3603
  sessionListSnapshots,
3137
3604
  sessionMcpServers,
@@ -3147,6 +3614,7 @@ export {
3147
3614
  workspaceControlEvents,
3148
3615
  sessionAttemptInterruptions,
3149
3616
  composerDrafts,
3617
+ newSessionDrafts,
3150
3618
  sessionSystemUpdates,
3151
3619
  sessionSystemUpdateOutbox,
3152
3620
  sessionWorkflowWakeOutbox,
@@ -3161,6 +3629,11 @@ export {
3161
3629
  sandboxLeaseLivenessValues,
3162
3630
  sandboxLeases,
3163
3631
  sandboxLeaseHolders,
3632
+ sandboxWorkspaceMutationActorKindValues,
3633
+ sandboxWorkspaceMutationHolderKindValues,
3634
+ sandboxWorkspaceMutationAdmissions,
3635
+ sandboxRetainedProcessStateValues,
3636
+ sandboxRetainedProcesses,
3164
3637
  sessionRecordingStateValues,
3165
3638
  sessionRecordingModeValues,
3166
3639
  sessionRecordingCodecValues,
@@ -3203,4 +3676,4 @@ export {
3203
3676
  rigChanges,
3204
3677
  schema_exports
3205
3678
  };
3206
- //# sourceMappingURL=chunk-P6PKXY5W.js.map
3679
+ //# sourceMappingURL=chunk-VUKRIBO5.js.map