@opengeni/db 5.0.1 → 6.0.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 (212) hide show
  1. package/dist/automations.d.ts +0 -2
  2. package/dist/canonical-human-identities.d.ts +4 -0
  3. package/dist/canonical-human-identities.js +3 -3
  4. package/dist/capability-components.d.ts +5 -13
  5. package/dist/capability-integrations.d.ts +23 -8
  6. package/dist/capability-reconciliation.d.ts +5 -0
  7. package/dist/capability-reconciliation.js +21 -0
  8. package/dist/capability-reconciliation.js.map +1 -0
  9. package/dist/{chunk-6T2GGYWE.js → chunk-4UJCXBR2.js} +4 -5800
  10. package/dist/chunk-4UJCXBR2.js.map +1 -0
  11. package/dist/{chunk-MWMXWHJD.js → chunk-7JCDSMX2.js} +2 -2
  12. package/dist/chunk-AJA2ZIUW.js +219 -0
  13. package/dist/chunk-AJA2ZIUW.js.map +1 -0
  14. package/dist/chunk-CDAT6EKW.js +247 -0
  15. package/dist/chunk-CDAT6EKW.js.map +1 -0
  16. package/dist/{chunk-DPONPYJD.js → chunk-CJI6G254.js} +70 -18
  17. package/dist/chunk-CJI6G254.js.map +1 -0
  18. package/dist/chunk-G32NVMRJ.js +276 -0
  19. package/dist/chunk-G32NVMRJ.js.map +1 -0
  20. package/dist/chunk-GABXCG3N.js +5811 -0
  21. package/dist/chunk-GABXCG3N.js.map +1 -0
  22. package/dist/{chunk-ERKVSPDX.js → chunk-LVY33EWL.js} +3 -3
  23. package/dist/{chunk-45CP2YKY.js → chunk-MAMBI2HR.js} +9 -3
  24. package/dist/{chunk-45CP2YKY.js.map → chunk-MAMBI2HR.js.map} +1 -1
  25. package/dist/{chunk-F73UKJY6.js → chunk-MN5PZMEK.js} +91 -108
  26. package/dist/chunk-MN5PZMEK.js.map +1 -0
  27. package/dist/chunk-PJI4MUZ7.js +131 -0
  28. package/dist/chunk-PJI4MUZ7.js.map +1 -0
  29. package/dist/{chunk-T6BWIGWJ.js → chunk-RIYHP2WU.js} +2 -2
  30. package/dist/{chunk-7HMK3B45.js → chunk-RL2MUXM3.js} +16 -7
  31. package/dist/chunk-RL2MUXM3.js.map +1 -0
  32. package/dist/{chunk-HQDVI2DB.js → chunk-SYKHLPTK.js} +4 -3
  33. package/dist/{chunk-HQDVI2DB.js.map → chunk-SYKHLPTK.js.map} +1 -1
  34. package/dist/{chunk-T6YLHJLS.js → chunk-XIXVVBW2.js} +198 -51
  35. package/dist/chunk-XIXVVBW2.js.map +1 -0
  36. package/dist/chunk-ZPJ6V2VG.js +156 -0
  37. package/dist/chunk-ZPJ6V2VG.js.map +1 -0
  38. package/dist/codex-capacity-recovery.d.ts +12 -0
  39. package/dist/codex-failure-eligibility.d.ts +9 -0
  40. package/dist/company-profile-schema.d.ts +4 -2
  41. package/dist/connect-attempts.d.ts +15 -0
  42. package/dist/connect-attempts.js +25 -0
  43. package/dist/connect-attempts.js.map +1 -0
  44. package/dist/connection-authority.d.ts +7 -63
  45. package/dist/connection-refresh-lock.d.ts +4 -0
  46. package/dist/connection-token-resolver.d.ts +8 -43
  47. package/dist/database-timing.d.ts +10 -0
  48. package/dist/database.d.ts +4 -0
  49. package/dist/editable-artifact-durable-export.js +2 -2
  50. package/dist/editable-artifacts.d.ts +9 -0
  51. package/dist/editable-artifacts.js +7 -5
  52. package/dist/index.d.ts +447 -78
  53. package/dist/index.js +12705 -12872
  54. package/dist/index.js.map +1 -1
  55. package/dist/insights-usage-bundle.d.ts +3 -0
  56. package/dist/integration-bindings.d.ts +1 -1
  57. package/dist/integration-facets.d.ts +18 -1
  58. package/dist/knowledge-entries-schema.d.ts +2 -0
  59. package/dist/knowledge-entries.d.ts +1 -0
  60. package/dist/knowledge-indexing.d.ts +1 -0
  61. package/dist/live-session-attempt.d.ts +35 -137
  62. package/dist/managed-auth-session-sets.js +3 -3
  63. package/dist/mcp-account-bindings.d.ts +4 -0
  64. package/dist/mcp-oauth.d.ts +11 -0
  65. package/dist/mcp-operations.js +2 -2
  66. package/dist/migrate.js +1 -1
  67. package/dist/organization-integration-policy.d.ts +51 -0
  68. package/dist/organization-integration-policy.js +18 -0
  69. package/dist/organization-integration-policy.js.map +1 -0
  70. package/dist/organization-usage.d.ts +20 -0
  71. package/dist/plugin-packages.d.ts +9 -12
  72. package/dist/pr-review.d.ts +0 -11
  73. package/dist/preference-registry-schema.d.ts +17 -0
  74. package/dist/provision-roles.js +1 -1
  75. package/dist/retained-provider-commands.d.ts +124 -6
  76. package/dist/retained-provider-commands.js +29 -97
  77. package/dist/retained-provider-commands.js.map +1 -1
  78. package/dist/retired-session-create-metadata.d.ts +4 -0
  79. package/dist/runtime-posture.d.ts +7 -5
  80. package/dist/schema.d.ts +876 -656
  81. package/dist/schema.js +5 -7
  82. package/dist/session-admission-block.d.ts +32 -0
  83. package/dist/session-attempt-writers.d.ts +4 -0
  84. package/dist/session-background-commands.js +5 -4
  85. package/dist/session-command-output.js +8 -126
  86. package/dist/session-command-output.js.map +1 -1
  87. package/dist/session-control.d.ts +5 -1
  88. package/dist/session-event-slices.d.ts +10 -0
  89. package/dist/session-event-slices.js +8 -222
  90. package/dist/session-event-slices.js.map +1 -1
  91. package/dist/session-file-attachments.d.ts +28 -0
  92. package/dist/session-goal-reports.d.ts +43 -0
  93. package/dist/session-mcp-approval.d.ts +4 -0
  94. package/dist/session-mcp-credential-rotation.js +5 -4
  95. package/dist/session-mcp-credential-rotation.js.map +1 -1
  96. package/dist/session-message-search.d.ts +22 -0
  97. package/dist/session-queue-commands.d.ts +2 -6
  98. package/dist/session-retry.d.ts +36 -0
  99. package/dist/session-tenancy.js +3 -3
  100. package/dist/skill-source-release-impact.d.ts +18 -0
  101. package/dist/skill-source-release.d.ts +9 -0
  102. package/dist/skills.d.ts +7 -1
  103. package/dist/user-resource-authority.d.ts +0 -8
  104. package/dist/video-generation.js +3 -3
  105. package/dist/workspace-tool-defaults.js +5 -4
  106. package/dist/workspace-tool-defaults.js.map +1 -1
  107. package/drizzle/0468_knowledge_relationship_projection.sql +30 -0
  108. package/drizzle/0469_knowledge_source_discovery.sql +85 -0
  109. package/drizzle/0470_organization_integration_policy.sql +151 -0
  110. package/drizzle/0471_usage_events_account_recent_index.sql +4 -0
  111. package/drizzle/0472_usage_events_workspace_recent_index.sql +4 -0
  112. package/drizzle/0473_organization_usage_analytical_capability.sql +237 -0
  113. package/drizzle/0474_goal_report_requirements.sql +156 -0
  114. package/drizzle/0475_session_event_history_statistics.sql +15 -0
  115. package/drizzle/0476_session_event_history_policy_planning.sql +29 -0
  116. package/drizzle/0477_managed_sign_in_methods.sql +303 -0
  117. package/drizzle/0478_sender_owned_connections.sql +2772 -0
  118. package/drizzle/0479_connection_create_idempotency.sql +16 -0
  119. package/drizzle/0480_private_session_organization_key_administration.sql +154 -0
  120. package/drizzle/0481_personal_connection_visibility_cleanup.sql +45 -0
  121. package/drizzle/0482_remove_packs.sql +417 -0
  122. package/drizzle/0483_preclaim_admission_block.sql +85 -0
  123. package/drizzle/0484_insights_usage_projection.sql +211 -0
  124. package/drizzle/0485_inherited_mcp_approval_policies.sql +6 -0
  125. package/drizzle/0486_reasoning_configuration_message_forks.sql +35 -0
  126. package/drizzle/0487_skill_catalog_message_forks.sql +26 -0
  127. package/drizzle/0488_permanent_skill_removal.sql +207 -0
  128. package/drizzle/0489_modal_command_byte_offsets.sql +17 -0
  129. package/drizzle/0490_periodic_capture_attempt_cadence.sql +6 -0
  130. package/drizzle/0491_warm_capture_holder_reclamation.sql +57 -0
  131. package/drizzle/0492_codex_accepted_source_authority.sql +249 -0
  132. package/drizzle/0493_stopping_command_error_containment.sql +58 -0
  133. package/drizzle/0494_mcp_account_bindings.sql +334 -0
  134. package/drizzle/0495_consented_sandbox_recovery.sql +220 -0
  135. package/drizzle/0496_supervised_command_settlement.sql +386 -0
  136. package/drizzle/0497_modal_inventory_owner_read_capability.sql +112 -0
  137. package/drizzle/0498_enrollment_membership_fence.sql +87 -0
  138. package/drizzle/0499_session_attachment_access.sql +224 -0
  139. package/drizzle/0500_session_execution_epoch.sql +37 -0
  140. package/drizzle/0501_session_sharing_execution.sql +591 -0
  141. package/drizzle/0502_active_message_boundary_forks.sql +30 -0
  142. package/package.json +17 -5
  143. package/src/automations.ts +17 -73
  144. package/src/canonical-human-identities.ts +17 -5
  145. package/src/capability-components.ts +7 -24
  146. package/src/capability-integrations.ts +301 -21
  147. package/src/capability-reconciliation.ts +19 -0
  148. package/src/codex-capacity-recovery.ts +47 -0
  149. package/src/codex-failure-eligibility.ts +93 -0
  150. package/src/connect-attempts.ts +49 -18
  151. package/src/connection-authority.ts +12 -158
  152. package/src/connection-refresh-lock.ts +22 -0
  153. package/src/connection-token-resolver.ts +58 -530
  154. package/src/database-timing.ts +43 -0
  155. package/src/database.ts +61 -26
  156. package/src/editable-artifacts.ts +1 -1
  157. package/src/index.ts +3578 -1273
  158. package/src/insights-model-bundle.ts +19 -7
  159. package/src/insights-usage-bundle.ts +16 -19
  160. package/src/integration-bindings.ts +2 -7
  161. package/src/integration-facets.ts +73 -6
  162. package/src/knowledge-entries.ts +8 -1
  163. package/src/live-session-attempt.ts +0 -22
  164. package/src/mcp-account-bindings.ts +12 -0
  165. package/src/mcp-oauth.ts +26 -0
  166. package/src/organization-integration-policy.ts +235 -0
  167. package/src/organization-usage.ts +83 -0
  168. package/src/plugin-packages.ts +226 -42
  169. package/src/pr-review.ts +7 -69
  170. package/src/preference-registry-schema.ts +1 -0
  171. package/src/provision-roles.ts +50 -37
  172. package/src/retained-provider-commands.ts +286 -9
  173. package/src/retired-session-create-metadata.ts +16 -0
  174. package/src/runtime-posture.ts +217 -13
  175. package/src/schema.ts +104 -120
  176. package/src/session-admission-block.ts +29 -0
  177. package/src/session-attempt-writers.ts +48 -0
  178. package/src/session-control.ts +21 -5
  179. package/src/session-event-slices.ts +76 -26
  180. package/src/session-file-attachments.ts +66 -0
  181. package/src/session-goal-reports.ts +255 -0
  182. package/src/session-mcp-approval.ts +30 -0
  183. package/src/session-message-search.ts +348 -0
  184. package/src/session-queue-commands.ts +60 -36
  185. package/src/session-retry.ts +319 -0
  186. package/src/skill-config-migration.ts +11 -2
  187. package/src/skill-source-release-impact.ts +33 -0
  188. package/src/skill-source-release.ts +67 -26
  189. package/src/skills.ts +44 -6
  190. package/src/user-resource-authority.ts +0 -56
  191. package/dist/chunk-6T2GGYWE.js.map +0 -1
  192. package/dist/chunk-7HMK3B45.js.map +0 -1
  193. package/dist/chunk-DPONPYJD.js.map +0 -1
  194. package/dist/chunk-F73UKJY6.js.map +0 -1
  195. package/dist/chunk-T6YLHJLS.js.map +0 -1
  196. package/dist/host-mcp-binding-match.d.ts +0 -5
  197. package/dist/host-mcp-bindings.d.ts +0 -79
  198. package/dist/host-mcp-resolvers.d.ts +0 -47
  199. package/dist/host-mcp-task-authority.d.ts +0 -43
  200. package/dist/host-selection-identity.d.ts +0 -6
  201. package/dist/pack-components.d.ts +0 -83
  202. package/dist/pack-installations.d.ts +0 -86
  203. package/src/host-mcp-binding-match.ts +0 -34
  204. package/src/host-mcp-bindings.ts +0 -777
  205. package/src/host-mcp-resolvers.ts +0 -266
  206. package/src/host-mcp-task-authority.ts +0 -384
  207. package/src/host-selection-identity.ts +0 -29
  208. package/src/pack-components.ts +0 -980
  209. package/src/pack-installations.ts +0 -950
  210. /package/dist/{chunk-MWMXWHJD.js.map → chunk-7JCDSMX2.js.map} +0 -0
  211. /package/dist/{chunk-ERKVSPDX.js.map → chunk-LVY33EWL.js.map} +0 -0
  212. /package/dist/{chunk-T6BWIGWJ.js.map → chunk-RIYHP2WU.js.map} +0 -0
package/src/schema.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import type { StoredSessionAdmissionBlock } from "./session-admission-block";
1
2
  import type {
2
3
  SandboxProviderCommand,
4
+ CommandSupervisionReceipt,
3
5
  AutomationAcceptedExecution,
4
6
  AutomationSessionTemplate,
5
7
  AttemptToolCatalog,
@@ -7,6 +9,7 @@ import type {
7
9
  DraftTimelineAnnotation,
8
10
  FirstPartyMcpToolName,
9
11
  McpPersonalConnectionDelegation,
12
+ McpConnectionAccountBinding,
10
13
  PersonalResourceAttachmentIntent,
11
14
  PersonalResourceAttachmentSummary,
12
15
  Permission,
@@ -106,6 +109,46 @@ export const managedAccounts = pgTable(
106
109
  }),
107
110
  );
108
111
 
112
+ export const organizationIntegrationPolicies = pgTable(
113
+ "organization_integration_policies",
114
+ {
115
+ accountId: uuid("account_id")
116
+ .primaryKey()
117
+ .references(() => managedAccounts.id, { onDelete: "cascade" }),
118
+ mode: text("mode").$type<"unrestricted" | "restricted">().notNull(),
119
+ allowedIntegrationKeys: jsonb("allowed_integration_keys").$type<string[]>().notNull(),
120
+ revision: bigint("revision", { mode: "number" }).notNull(),
121
+ },
122
+ (table) => ({
123
+ modeCheck: check(
124
+ "organization_integration_policies_mode_check",
125
+ sql`${table.mode} in ('unrestricted', 'restricted')`,
126
+ ),
127
+ keysCheck: check(
128
+ "organization_integration_policies_allowed_integration_keys_check",
129
+ sql`jsonb_typeof(${table.allowedIntegrationKeys}) = 'array'`,
130
+ ),
131
+ revisionCheck: check(
132
+ "organization_integration_policies_revision_check",
133
+ sql`${table.revision} between 1 and 9007199254740991`,
134
+ ),
135
+ }),
136
+ );
137
+
138
+ export const organizationIntegrationPolicyOperations = pgTable(
139
+ "organization_integration_policy_operations",
140
+ {
141
+ accountId: uuid("account_id")
142
+ .notNull()
143
+ .references(() => managedAccounts.id, { onDelete: "cascade" }),
144
+ operationId: uuid("operation_id").notNull(),
145
+ actorSubjectId: text("actor_subject_id").notNull(),
146
+ request: jsonb("request").notNull(),
147
+ result: jsonb("result").notNull(),
148
+ },
149
+ (table) => ({ identity: primaryKey({ columns: [table.accountId, table.operationId] }) }),
150
+ );
151
+
109
152
  export const workspaces = pgTable(
110
153
  "workspaces",
111
154
  {
@@ -731,7 +774,8 @@ export const organizationPrivateSessionSettingEvents = pgTable(
731
774
  accountId: uuid("account_id")
732
775
  .notNull()
733
776
  .references(() => managedAccounts.id, { onDelete: "cascade" }),
734
- actorMembershipId: uuid("actor_membership_id").notNull(),
777
+ actorMembershipId: uuid("actor_membership_id"),
778
+ actorSubjectId: text("actor_subject_id"),
735
779
  requestedEnabled: boolean("requested_enabled").notNull(),
736
780
  expectedVersion: bigint("expected_version", { mode: "number" }).notNull(),
737
781
  resultEnabled: boolean("result_enabled").notNull(),
@@ -752,6 +796,10 @@ export const organizationPrivateSessionSettingEvents = pgTable(
752
796
  "organization_private_session_setting_events_versions_check",
753
797
  sql`${table.expectedVersion} >= 0 and ${table.resultVersion} > 0`,
754
798
  ),
799
+ actorValid: check(
800
+ "organization_private_session_setting_events_actor_check",
801
+ sql`${table.actorMembershipId} is not null or (${table.actorSubjectId} is not null and ${table.actorSubjectId} like 'api_key:%')`,
802
+ ),
755
803
  }),
756
804
  );
757
805
 
@@ -1707,6 +1755,8 @@ export const connections = pgTable(
1707
1755
  kind: text("kind").notNull(),
1708
1756
  status: text("status").notNull().default("active"),
1709
1757
  credentialEncrypted: text("credential_encrypted").notNull(),
1758
+ createOperationId: text("create_operation_id"),
1759
+ createRequestDigest: text("create_request_digest"),
1710
1760
  grantedScopes: jsonb("granted_scopes").$type<string[]>().notNull().default([]),
1711
1761
  expiresAt: timestamp("expires_at", { withTimezone: true }),
1712
1762
  lastRefreshAt: timestamp("last_refresh_at", { withTimezone: true }),
@@ -1746,6 +1796,15 @@ export const connections = pgTable(
1746
1796
  table.providerDomain,
1747
1797
  table.status,
1748
1798
  ),
1799
+ createOperation: uniqueIndex("connections_create_operation_uq")
1800
+ .on(table.workspaceId, table.createdBySubjectId, table.createOperationId)
1801
+ .where(sql`${table.createOperationId} is not null`),
1802
+ createOperationPair: check(
1803
+ "connections_create_operation_pair_check",
1804
+ sql`(${table.createOperationId} is null and ${table.createRequestDigest} is null)
1805
+ or (${table.createOperationId} is not null and ${table.createRequestDigest} is not null
1806
+ and ${table.createdBySubjectId} is not null)`,
1807
+ ),
1749
1808
  workspaceSubjectProvider: index("connections_workspace_subject_provider_idx").on(
1750
1809
  table.workspaceId,
1751
1810
  table.subjectId,
@@ -4369,6 +4428,7 @@ export const sessions = pgTable(
4369
4428
  // NULL and use the bounded metadata.role compatibility fallback at the
4370
4429
  // attempt-snapshot boundary.
4371
4430
  policyRole: text("policy_role"),
4431
+ admissionBlock: jsonb("admission_block").$type<StoredSessionAdmissionBlock>(),
4372
4432
  resources: jsonb("resources").$type<unknown[]>().notNull().default([]),
4373
4433
  skills: jsonb("skills").$type<unknown[]>().notNull().default([]),
4374
4434
  tools: jsonb("tools").$type<unknown[]>().notNull().default([]),
@@ -4391,6 +4451,8 @@ export const sessions = pgTable(
4391
4451
  .notNull()
4392
4452
  .default("workspace_shared"),
4393
4453
  authorityEpoch: integer("authority_epoch").notNull().default(1),
4454
+ // Old accepted epochs remain valid across sharing, never across revocation.
4455
+ executionAuthorityEpoch: integer("execution_authority_epoch").notNull().default(1),
4394
4456
  // Agent-access scope (migration 0427). Declares how far a live attempt on
4395
4457
  // this session may reach across the workspace and how far peers may reach
4396
4458
  // into it. 'workspace' is the pre-0426 behaviour; 'user' limits reach to
@@ -4489,6 +4551,9 @@ export const sessions = pgTable(
4489
4551
  .$type<McpPersonalConnectionDelegation[]>()
4490
4552
  .notNull()
4491
4553
  .default([]),
4554
+ initialMcpAccountBindings: jsonb("initial_mcp_account_bindings").$type<
4555
+ McpConnectionAccountBinding[] | null
4556
+ >(),
4492
4557
  // Initial accepted-work staging only. The initializer consumes this inside
4493
4558
  // the same transaction that inserts the first logical turn and grant
4494
4559
  // snapshots; runtime never authorizes from the session field.
@@ -4506,6 +4571,10 @@ export const sessions = pgTable(
4506
4571
  toolPolicy: jsonb("tool_policy").$type<SessionToolPolicy>().notNull(),
4507
4572
  // Optimistic-concurrency fence for durable session tool-policy writes.
4508
4573
  toolPolicyVersion: integer("tool_policy_version").notNull().default(1),
4574
+ mcpApprovalPolicies: jsonb("mcp_approval_policies")
4575
+ .$type<Record<string, SessionMcpApprovalPolicy>>()
4576
+ .notNull()
4577
+ .default({}),
4509
4578
  // The manager session that spawned this one via session_create. Set only
4510
4579
  // when the creating grant carried a worker-signed sessionId claim (a session
4511
4580
  // spawning a worker); null for direct API creates and scheduled-task runs.
@@ -6705,6 +6774,7 @@ export const sessionTurns = pgTable(
6705
6774
  .$type<McpPersonalConnectionDelegation[]>()
6706
6775
  .notNull()
6707
6776
  .default([]),
6777
+ mcpAccountBindings: jsonb("mcp_account_bindings").$type<McpConnectionAccountBinding[] | null>(),
6708
6778
  // Credential-free public summary of a turn-bound personal Variable
6709
6779
  // Set/Rig attachment. Exact resource and grant identity lives only in the
6710
6780
  // immutable accepted-work snapshot tables.
@@ -8109,6 +8179,7 @@ export const sessionSystemUpdates = pgTable(
8109
8179
  .$type<McpPersonalConnectionDelegation[]>()
8110
8180
  .notNull()
8111
8181
  .default([]),
8182
+ mcpAccountBindings: jsonb("mcp_account_bindings").$type<McpConnectionAccountBinding[] | null>(),
8112
8183
  xaiProviderAccountAuthoritySnapshot: jsonb("xai_provider_account_authority_snapshot")
8113
8184
  .$type<XaiProviderAccountAuthoritySnapshotV1>()
8114
8185
  .notNull()
@@ -8208,6 +8279,7 @@ export const sessionSystemUpdateOutbox = pgTable(
8208
8279
  .$type<McpPersonalConnectionDelegation[]>()
8209
8280
  .notNull()
8210
8281
  .default([]),
8282
+ mcpAccountBindings: jsonb("mcp_account_bindings").$type<McpConnectionAccountBinding[] | null>(),
8211
8283
  xaiProviderAccountAuthoritySnapshot: jsonb("xai_provider_account_authority_snapshot")
8212
8284
  .$type<XaiProviderAccountAuthoritySnapshotV1>()
8213
8285
  .notNull()
@@ -9255,6 +9327,7 @@ export const sandboxLeases = pgTable(
9255
9327
  .notNull()
9256
9328
  .references(() => workspaces.id, { onDelete: "cascade" }),
9257
9329
  sandboxGroupId: uuid("sandbox_group_id").notNull(),
9330
+ publicRecovery: jsonb("public_recovery").$type<Record<string, unknown>>(),
9258
9331
 
9259
9332
  unobservableCommandDrainIds: uuid("unobservable_command_drain_ids").array(),
9260
9333
  unobservableCommandCheckedAt: timestamp("unobservable_command_checked_at", {
@@ -9332,6 +9405,11 @@ export const sandboxLeases = pgTable(
9332
9405
  // can recover immediately without pretending it resumes one provider RPC.
9333
9406
  archiveCaptureTakeoverSafe: boolean("archive_capture_takeover_safe").notNull().default(false),
9334
9407
  archiveCaptureAttempt: integer("archive_capture_attempt"),
9408
+ // Periodic capture cadence survives a failed claim's release and worker
9409
+ // restarts. This is not evidence that a recovery archive was published.
9410
+ archiveCaptureLastAttemptAt: timestamp("archive_capture_last_attempt_at", {
9411
+ withTimezone: true,
9412
+ }),
9335
9413
  archiveCaptureGeneration: integer("archive_capture_generation"),
9336
9414
  archiveCaptureStartedAt: timestamp("archive_capture_started_at", {
9337
9415
  withTimezone: true,
@@ -9844,6 +9922,13 @@ export const sandboxRetainedProcesses = pgTable(
9844
9922
  routeEpoch: integer("route_epoch").notNull(),
9845
9923
  providerSessionId: integer("provider_session_id").notNull(),
9846
9924
  providerCommand: jsonb("provider_command").$type<SandboxProviderCommand>(),
9925
+ supervisionRetentionXid: customType<{ data: string }>({ dataType: () => "xid8" })(
9926
+ "supervision_retention_xid",
9927
+ ).default(sql`pg_current_xact_id()`),
9928
+ supervisionReceipt: jsonb("supervision_receipt").$type<CommandSupervisionReceipt>(),
9929
+ supervisionOutputCaptured: boolean("supervision_output_captured").notNull().default(false),
9930
+ cancellationRequestedAt: timestamp("cancellation_requested_at", { withTimezone: true }),
9931
+ cancellationReason: text("cancellation_reason"),
9847
9932
  providerCommandInputIndex: bigint("provider_command_input_index", { mode: "number" })
9848
9933
  .notNull()
9849
9934
  .default(0),
@@ -9943,7 +10028,7 @@ export const sandboxRetainedProcesses = pgTable(
9943
10028
  sql`${table.providerCommand} IS NULL OR ((
9944
10029
  ${table.providerBackend} = 'modal'
9945
10030
  AND jsonb_typeof(${table.providerCommand}) = 'object'
9946
- AND ${table.providerCommand}->>'kind' = 'modal-control-v1'
10031
+ AND ${table.providerCommand}->>'kind' IN ('modal-control-v1', 'modal-router-v1')
9947
10032
  AND ${table.providerCommand}->>'sandboxId' = ${table.providerInstanceId}
9948
10033
  AND length(${table.providerCommand}->>'taskId') > 0
9949
10034
  AND length(${table.providerCommand}->>'execId') > 0
@@ -11078,6 +11163,7 @@ export const scheduledTasks = pgTable(
11078
11163
  .notNull()
11079
11164
  .references(() => workspaces.id, { onDelete: "cascade" }),
11080
11165
  name: text("name").notNull(),
11166
+ ownerSubjectId: text("owner_subject_id"),
11081
11167
  status: text("status").notNull().default("active"),
11082
11168
  schedule: jsonb("schedule").$type<unknown>().notNull(),
11083
11169
  temporalScheduleId: text("temporal_schedule_id").notNull(),
@@ -11729,6 +11815,17 @@ export const usageEvents = pgTable(
11729
11815
  table.eventType,
11730
11816
  table.occurredAt,
11731
11817
  ),
11818
+ accountRecent: index("usage_events_account_recent_idx").on(
11819
+ table.accountId,
11820
+ table.occurredAt.desc(),
11821
+ table.recordedAt.desc(),
11822
+ ),
11823
+ workspaceRecent: index("usage_events_workspace_recent_idx").on(
11824
+ table.accountId,
11825
+ table.workspaceId,
11826
+ table.occurredAt.desc(),
11827
+ table.recordedAt.desc(),
11828
+ ),
11732
11829
  workspaceSession: index("usage_events_workspace_session_idx").on(
11733
11830
  table.workspaceId,
11734
11831
  table.sessionId,
@@ -12159,80 +12256,6 @@ export const auditEvents = pgTable(
12159
12256
  }),
12160
12257
  );
12161
12258
 
12162
- export const packInstallations = pgTable(
12163
- "pack_installations",
12164
- {
12165
- id: uuid("id").primaryKey().defaultRandom(),
12166
- accountId: uuid("account_id")
12167
- .notNull()
12168
- .references(() => managedAccounts.id, { onDelete: "cascade" }),
12169
- workspaceId: uuid("workspace_id")
12170
- .notNull()
12171
- .references(() => workspaces.id, { onDelete: "cascade" }),
12172
- packId: text("pack_id").notNull(),
12173
- status: text("status").notNull().default("active"),
12174
- version: integer("version").notNull().default(1),
12175
- manifestSnapshot: jsonb("manifest_snapshot").$type<Record<string, unknown>>(),
12176
- manifestDigest: text("manifest_digest"),
12177
- selectedRigId: uuid("selected_rig_id").references(() => rigs.id, {
12178
- onDelete: "set null",
12179
- }),
12180
- installedBySubjectId: text("installed_by_subject_id"),
12181
- metadata: jsonb("metadata").$type<Record<string, unknown>>().notNull().default({}),
12182
- enabledAt: timestamp("enabled_at", { withTimezone: true }).notNull().defaultNow(),
12183
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
12184
- },
12185
- (table) => ({
12186
- workspaceIdentity: uniqueIndex("pack_installations_workspace_id_uq").on(
12187
- table.workspaceId,
12188
- table.id,
12189
- ),
12190
- workspacePack: uniqueIndex("pack_installations_workspace_pack_idx").on(
12191
- table.workspaceId,
12192
- table.packId,
12193
- ),
12194
- status: index("pack_installations_workspace_status_idx").on(table.workspaceId, table.status),
12195
- selectedRig: index("pack_installations_workspace_rig_idx")
12196
- .on(table.workspaceId, table.selectedRigId)
12197
- .where(sql`${table.selectedRigId} is not null`),
12198
- }),
12199
- );
12200
-
12201
- export const packInstallationComponents = pgTable(
12202
- "pack_installation_components",
12203
- {
12204
- id: uuid("id").primaryKey().defaultRandom(),
12205
- accountId: uuid("account_id")
12206
- .notNull()
12207
- .references(() => managedAccounts.id, { onDelete: "cascade" }),
12208
- workspaceId: uuid("workspace_id")
12209
- .notNull()
12210
- .references(() => workspaces.id, { onDelete: "cascade" }),
12211
- packInstallationId: uuid("pack_installation_id")
12212
- .notNull()
12213
- .references(() => packInstallations.id, { onDelete: "cascade" }),
12214
- componentKey: text("component_key").notNull(),
12215
- kind: text("kind").notNull(),
12216
- capabilityId: text("capability_id").notNull(),
12217
- resolvedId: text("resolved_id").notNull(),
12218
- digest: text("digest").notNull(),
12219
- metadata: jsonb("metadata").$type<Record<string, unknown>>().notNull().default({}),
12220
- createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12221
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
12222
- },
12223
- (table) => ({
12224
- installationKey: uniqueIndex("pack_installation_components_pack_key_uq").on(
12225
- table.packInstallationId,
12226
- table.componentKey,
12227
- ),
12228
- workspaceCapability: index("pack_installation_components_workspace_capability_idx").on(
12229
- table.workspaceId,
12230
- table.kind,
12231
- table.capabilityId,
12232
- ),
12233
- }),
12234
- );
12235
-
12236
12259
  export const automationSources = pgTable(
12237
12260
  "automation_sources",
12238
12261
  {
@@ -12250,8 +12273,7 @@ export const automationSources = pgTable(
12250
12273
  webhookSecretEncrypted: text("webhook_secret_encrypted").notNull(),
12251
12274
  status: text("status").notNull().default("active"),
12252
12275
  version: integer("version").notNull().default(1),
12253
- packInstallationId: uuid("pack_installation_id"),
12254
- packConnectorId: text("pack_connector_id"),
12276
+
12255
12277
  createdBySubjectId: text("created_by_subject_id").notNull(),
12256
12278
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12257
12279
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -12273,21 +12295,13 @@ export const automationSources = pgTable(
12273
12295
  and octet_length(${table.name}) between 1 and 512
12274
12296
  and octet_length(${table.adapterId}) between 1 and 128
12275
12297
  and octet_length(${table.createdBySubjectId}) between 1 and 4096
12276
- and jsonb_typeof(${table.configuration}) = 'object'
12277
- and ((${table.packInstallationId} is null and ${table.packConnectorId} is null)
12278
- or (${table.packInstallationId} is not null
12279
- and octet_length(${table.packConnectorId}) between 1 and 128))`,
12298
+ and jsonb_typeof(${table.configuration}) = 'object'`,
12280
12299
  ),
12281
12300
  workspaceAccount: foreignKey({
12282
12301
  columns: [table.workspaceId, table.accountId],
12283
12302
  foreignColumns: [workspaces.id, workspaces.accountId],
12284
12303
  name: "automation_sources_workspace_account_fk",
12285
12304
  }).onDelete("cascade"),
12286
- packInstallation: foreignKey({
12287
- columns: [table.workspaceId, table.packInstallationId],
12288
- foreignColumns: [packInstallations.workspaceId, packInstallations.id],
12289
- name: "automation_sources_pack_installation_fk",
12290
- }).onDelete("cascade"),
12291
12305
  }),
12292
12306
  );
12293
12307
 
@@ -12333,8 +12347,7 @@ export const automationTriggers = pgTable(
12333
12347
  name: text("name").notNull(),
12334
12348
  status: text("status").notNull().default("active"),
12335
12349
  currentRevision: integer("current_revision").notNull().default(1),
12336
- packInstallationId: uuid("pack_installation_id"),
12337
- packTemplateId: text("pack_template_id"),
12350
+
12338
12351
  createdBySubjectId: text("created_by_subject_id").notNull(),
12339
12352
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12340
12353
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -12358,11 +12371,7 @@ export const automationTriggers = pgTable(
12358
12371
  foreignColumns: [automationSources.workspaceId, automationSources.id],
12359
12372
  name: "automation_triggers_source_fk",
12360
12373
  }).onDelete("cascade"),
12361
- packInstallation: foreignKey({
12362
- columns: [table.workspaceId, table.packInstallationId],
12363
- foreignColumns: [packInstallations.workspaceId, packInstallations.id],
12364
- name: "automation_triggers_pack_installation_fk",
12365
- }).onDelete("cascade"),
12374
+
12366
12375
  workspaceAccount: foreignKey({
12367
12376
  columns: [table.workspaceId, table.accountId],
12368
12377
  foreignColumns: [workspaces.id, workspaces.accountId],
@@ -12373,9 +12382,7 @@ export const automationTriggers = pgTable(
12373
12382
  sql`${table.status} in ('active', 'paused', 'disabled')
12374
12383
  and ${table.currentRevision} > 0
12375
12384
  and octet_length(${table.name}) between 1 and 512
12376
- and octet_length(${table.createdBySubjectId}) between 1 and 4096
12377
- and ((${table.packInstallationId} is null and ${table.packTemplateId} is null)
12378
- or (${table.packInstallationId} is not null and octet_length(${table.packTemplateId}) between 1 and 128))`,
12385
+ and octet_length(${table.createdBySubjectId}) between 1 and 4096`,
12379
12386
  ),
12380
12387
  }),
12381
12388
  );
@@ -12605,29 +12612,6 @@ export const automationRunEventLinks = pgTable(
12605
12612
  }),
12606
12613
  );
12607
12614
 
12608
- export const workspacePacks = pgTable(
12609
- "workspace_packs",
12610
- {
12611
- id: uuid("id").primaryKey().defaultRandom(),
12612
- accountId: uuid("account_id")
12613
- .notNull()
12614
- .references(() => managedAccounts.id, { onDelete: "cascade" }),
12615
- workspaceId: uuid("workspace_id")
12616
- .notNull()
12617
- .references(() => workspaces.id, { onDelete: "cascade" }),
12618
- packId: text("pack_id").notNull(),
12619
- manifest: jsonb("manifest").$type<Record<string, unknown>>().notNull(),
12620
- createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12621
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
12622
- },
12623
- (table) => ({
12624
- workspacePack: uniqueIndex("workspace_packs_workspace_pack_idx").on(
12625
- table.workspaceId,
12626
- table.packId,
12627
- ),
12628
- }),
12629
- );
12630
-
12631
12615
  export const importBatches = pgTable(
12632
12616
  "import_batches",
12633
12617
  {
@@ -0,0 +1,29 @@
1
+ import { SessionAdmissionBlock, SessionStatus } from "@opengeni/contracts";
2
+ import { z } from "zod";
3
+
4
+ export type SessionAdmissionFence = { lastSequence: number; controlVersion: number };
5
+ export const StoredSessionAdmissionBlock = SessionAdmissionBlock.extend({
6
+ attemptId: z.string().uuid(),
7
+ fence: z
8
+ .object({
9
+ lastSequence: z.number().int().nonnegative(),
10
+ controlVersion: z.number().int().nonnegative(),
11
+ })
12
+ .strict(),
13
+ previousStatus: SessionStatus.exclude(["failed", "cancelled"]),
14
+ }).strict();
15
+ export type StoredSessionAdmissionBlock = z.infer<typeof StoredSessionAdmissionBlock>;
16
+
17
+ /** Never expose internal attempt/fence identities through the public projection. */
18
+ export function projectSessionAdmissionBlock(
19
+ value: StoredSessionAdmissionBlock | null | undefined,
20
+ ): SessionAdmissionBlock | null {
21
+ if (!value) return null;
22
+ StoredSessionAdmissionBlock.parse(value);
23
+ return SessionAdmissionBlock.parse({
24
+ reason: value.reason,
25
+ sqlState: value.sqlState,
26
+ retryPolicy: value.retryPolicy,
27
+ blockedAt: value.blockedAt,
28
+ });
29
+ }
@@ -0,0 +1,48 @@
1
+ import { sql, type SQL } from "drizzle-orm";
2
+
3
+ /** Physical writers retain ownership after logical settlement. A durably
4
+ * adopted background command owns its lifetime independently of the turn. */
5
+ export function sessionAttemptPendingWritersSql(attempt: SQL): SQL {
6
+ return sql`(
7
+ exists (
8
+ select 1 from sandbox_workspace_mutation_admissions admission
9
+ where admission.account_id = ${attempt}.account_id
10
+ and admission.workspace_id = ${attempt}.workspace_id
11
+ and admission.session_id = ${attempt}.session_id
12
+ and admission.settled_at is null
13
+ and (
14
+ admission.attempt_id = ${attempt}.id
15
+ or (admission.actor_kind = 'process' and exists (
16
+ select 1 from sandbox_retained_processes process
17
+ where process.account_id = ${attempt}.account_id
18
+ and process.workspace_id = ${attempt}.workspace_id
19
+ and process.session_id = ${attempt}.session_id
20
+ and process.id = admission.actor_id
21
+ and process.owner_attempt_id = ${attempt}.id
22
+ ))
23
+ )
24
+ and not exists (
25
+ select 1 from sandbox_retained_processes process
26
+ join session_background_commands command on command.retained_process_id = process.id
27
+ where process.account_id = ${attempt}.account_id
28
+ and process.workspace_id = ${attempt}.workspace_id
29
+ and process.session_id = ${attempt}.session_id
30
+ and (process.parent_admission_id = admission.id
31
+ or (admission.actor_kind = 'process' and process.id = admission.actor_id))
32
+ and command.state in ('running', 'stopping')
33
+ )
34
+ ) or exists (
35
+ select 1 from sandbox_retained_processes process
36
+ where process.account_id = ${attempt}.account_id
37
+ and process.workspace_id = ${attempt}.workspace_id
38
+ and process.session_id = ${attempt}.session_id
39
+ and process.owner_attempt_id = ${attempt}.id
40
+ and process.state = 'active'
41
+ and not exists (
42
+ select 1 from session_background_commands command
43
+ where command.retained_process_id = process.id
44
+ and command.state in ('running', 'stopping')
45
+ )
46
+ )
47
+ )`;
48
+ }
@@ -492,7 +492,7 @@ function lockBudgetFor(options: WorkspaceControlLockOptions): WorkspaceControlLo
492
492
  }
493
493
 
494
494
  /** Run one lock-acquiring statement under the remaining budget. */
495
- async function boundedLockStep<T>(
495
+ export async function boundedLockStep<T>(
496
496
  db: Database,
497
497
  workspaceId: string,
498
498
  budget: WorkspaceControlLockBudget | null,
@@ -989,11 +989,15 @@ export function sessionAuthoritySnapshotMatchesSession(
989
989
  session: Pick<
990
990
  typeof schema.sessions.$inferSelect,
991
991
  "authorityEpoch" | "visibility" | "ownerOrganizationMembershipId"
992
- >,
992
+ > & { executionAuthorityEpoch?: number },
993
993
  ): boolean {
994
994
  return (
995
- snapshot.authorityEpoch === session.authorityEpoch &&
996
- snapshot.authorityVisibility === session.visibility &&
995
+ snapshot.authorityEpoch >= (session.executionAuthorityEpoch ?? session.authorityEpoch) &&
996
+ snapshot.authorityEpoch <= session.authorityEpoch &&
997
+ (snapshot.authorityVisibility === session.visibility ||
998
+ (snapshot.authorityVisibility === "user_private" &&
999
+ session.visibility === "workspace_shared" &&
1000
+ snapshot.authorityEpoch < session.authorityEpoch)) &&
997
1001
  snapshot.authorityOwnerOrganizationMembershipId ===
998
1002
  (session.ownerOrganizationMembershipId ?? null)
999
1003
  );
@@ -2805,10 +2809,12 @@ async function insertChildOutboxRowInTransaction(
2805
2809
  }
2806
2810
  let personalConnectionDelegations: (typeof schema.sessionTurns.$inferSelect)["personalConnectionDelegations"] =
2807
2811
  [];
2812
+ let mcpAccountBindings: (typeof schema.sessionTurns.$inferSelect)["mcpAccountBindings"] = null;
2808
2813
  if (input.childSession.parentTurnId) {
2809
2814
  const [parentTurn] = await db
2810
2815
  .select({
2811
2816
  delegations: schema.sessionTurns.personalConnectionDelegations,
2817
+ mcpAccountBindings: schema.sessionTurns.mcpAccountBindings,
2812
2818
  })
2813
2819
  .from(schema.sessionTurns)
2814
2820
  .where(
@@ -2820,6 +2826,7 @@ async function insertChildOutboxRowInTransaction(
2820
2826
  )
2821
2827
  .limit(1);
2822
2828
  if (parentTurn) {
2829
+ mcpAccountBindings = parentTurn.mcpAccountBindings;
2823
2830
  const parsed = McpPersonalConnectionDelegations.safeParse(parentTurn.delegations);
2824
2831
  if (!parsed.success) {
2825
2832
  throw new SessionControlInvariantError(
@@ -2856,6 +2863,7 @@ async function insertChildOutboxRowInTransaction(
2856
2863
  ...(input.lineage ?? {}),
2857
2864
  },
2858
2865
  personalConnectionDelegations,
2866
+ mcpAccountBindings,
2859
2867
  },
2860
2868
  "summary",
2861
2869
  "summaryCodecVersion",
@@ -3518,7 +3526,8 @@ export async function mutateSessionControlInTransaction(
3518
3526
  sessionId: input.sessionId,
3519
3527
  directPauseRevision,
3520
3528
  }))
3521
- : before.state === "paused" ||
3529
+ : targetSession.admissionBlock != null ||
3530
+ before.state === "paused" ||
3522
3531
  (await continuableWakeRepairNeeded(db, {
3523
3532
  workspaceId: input.workspaceId,
3524
3533
  rootSessionId: input.sessionId,
@@ -3603,6 +3612,7 @@ export async function mutateSessionControlInTransaction(
3603
3612
  input.action === "pause" || input.action === "cancel"
3604
3613
  ? {
3605
3614
  directControlState: "paused",
3615
+ ...(input.action === "cancel" ? { admissionBlock: null } : {}),
3606
3616
  directPauseRevision: revision,
3607
3617
  controlVersion: revision,
3608
3618
  directControlReason: input.reason ?? null,
@@ -3615,6 +3625,12 @@ export async function mutateSessionControlInTransaction(
3615
3625
  }
3616
3626
  : {
3617
3627
  directControlState: "active",
3628
+ ...(targetSession.admissionBlock
3629
+ ? {
3630
+ admissionBlock: null,
3631
+ status: targetSession.admissionBlock.previousStatus,
3632
+ }
3633
+ : {}),
3618
3634
  directPauseRevision: null,
3619
3635
  subtreeRunOverrideRevision: revision,
3620
3636
  controlVersion: revision,