@opengeni/db 4.3.2 → 4.3.3-canary.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 (54) hide show
  1. package/dist/canonical-human-identities.js +3 -3
  2. package/dist/{chunk-UVBPOGA7.js → chunk-232VC2LW.js} +2 -2
  3. package/dist/{chunk-DVSLOUEI.js → chunk-2ZMTQVTR.js} +2 -2
  4. package/dist/{chunk-AI4NC6XW.js → chunk-6TKL3GQO.js} +47 -1
  5. package/dist/chunk-6TKL3GQO.js.map +1 -0
  6. package/dist/{chunk-F4BIHJ7J.js → chunk-EYF6MH6C.js} +4 -4
  7. package/dist/{chunk-I4ITNMX2.js → chunk-GVZJ7XSR.js} +16 -4
  8. package/dist/{chunk-I4ITNMX2.js.map → chunk-GVZJ7XSR.js.map} +1 -1
  9. package/dist/{chunk-XBXANJQS.js → chunk-M7PSMVFF.js} +2 -2
  10. package/dist/{chunk-PFBUHOI5.js → chunk-QLA3UQNX.js} +3 -3
  11. package/dist/{chunk-YVYBAWBU.js → chunk-THJGMEK5.js} +53 -1
  12. package/dist/chunk-THJGMEK5.js.map +1 -0
  13. package/dist/{chunk-UUPY6IGP.js → chunk-UK57QA2H.js} +2 -2
  14. package/dist/connection-token-resolver.d.ts +2 -0
  15. package/dist/database.d.ts +7 -2
  16. package/dist/editable-artifact-durable-export.js +2 -2
  17. package/dist/editable-artifacts.js +3 -3
  18. package/dist/host-mcp-bindings.d.ts +3 -1
  19. package/dist/index.d.ts +9 -0
  20. package/dist/index.js +85 -26
  21. package/dist/index.js.map +1 -1
  22. package/dist/managed-auth-session-sets.js +3 -3
  23. package/dist/mcp-operations.d.ts +95 -0
  24. package/dist/mcp-operations.js +95 -0
  25. package/dist/mcp-operations.js.map +1 -0
  26. package/dist/provision-roles.js +1 -1
  27. package/dist/retained-provider-commands.js +2 -2
  28. package/dist/runtime-posture.d.ts +3 -3
  29. package/dist/schema.d.ts +517 -0
  30. package/dist/schema.js +3 -1
  31. package/dist/session-background-commands.js +4 -4
  32. package/dist/session-command-output.js +4 -4
  33. package/dist/session-event-slices.js +2 -2
  34. package/dist/session-tenancy.js +3 -3
  35. package/dist/video-generation.js +3 -3
  36. package/dist/workspace-tool-defaults.js +4 -4
  37. package/drizzle/0459_mcp_operations.sql +396 -0
  38. package/package.json +10 -6
  39. package/src/connection-token-resolver.ts +2 -0
  40. package/src/database.ts +23 -2
  41. package/src/host-mcp-bindings.ts +14 -1
  42. package/src/index.ts +84 -4
  43. package/src/mcp-operations.ts +189 -0
  44. package/src/provision-roles.ts +6 -0
  45. package/src/runtime-posture.ts +50 -0
  46. package/src/schema.ts +46 -0
  47. package/dist/chunk-AI4NC6XW.js.map +0 -1
  48. package/dist/chunk-YVYBAWBU.js.map +0 -1
  49. /package/dist/{chunk-UVBPOGA7.js.map → chunk-232VC2LW.js.map} +0 -0
  50. /package/dist/{chunk-DVSLOUEI.js.map → chunk-2ZMTQVTR.js.map} +0 -0
  51. /package/dist/{chunk-F4BIHJ7J.js.map → chunk-EYF6MH6C.js.map} +0 -0
  52. /package/dist/{chunk-XBXANJQS.js.map → chunk-M7PSMVFF.js.map} +0 -0
  53. /package/dist/{chunk-PFBUHOI5.js.map → chunk-QLA3UQNX.js.map} +0 -0
  54. /package/dist/{chunk-UUPY6IGP.js.map → chunk-UK57QA2H.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  nestedPostgresSqlState,
3
3
  rawRows
4
- } from "./chunk-I4ITNMX2.js";
4
+ } from "./chunk-GVZJ7XSR.js";
5
5
 
6
6
  // src/managed-auth-session-sets.ts
7
7
  import {
@@ -296,4 +296,4 @@ export {
296
296
  reapManagedAuthIsolatedSessions,
297
297
  reapExpiredManagedAuthSessionSets
298
298
  };
299
- //# sourceMappingURL=chunk-UUPY6IGP.js.map
299
+ //# sourceMappingURL=chunk-UK57QA2H.js.map
@@ -60,6 +60,8 @@ export type ResolveConnectionCredentialResult = {
60
60
  connectionVersion?: number;
61
61
  /** Metadata-only owner attribution from the immediate pre-use fence. */
62
62
  connectionUseAttribution?: ConnectionUseAttribution;
63
+ /** Metadata-only equality key from current live authority; never credentials or authorization. */
64
+ operationAuthorityDigest?: string;
63
65
  /**
64
66
  * Revalidate the exact accepted attempt immediately before one target
65
67
  * provider request. Credential lookup/refresh is a separate audited
@@ -175,7 +175,7 @@ export declare function withWorkspaceRls<T>(db: Database, workspaceId: string, f
175
175
  */
176
176
  export declare function withSessionActivityRlsContext<T>(db: Database, context: RlsContext & {
177
177
  workspaceId: string;
178
- }, fn: (db: SessionActivityDatabase) => Promise<T>, transactionConfig?: PgTransactionConfig, fenceMode?: "shared" | "none"): Promise<T>;
178
+ }, fn: (db: SessionActivityDatabase) => Promise<T>, transactionConfig?: PgTransactionConfig, fenceMode?: "shared" | "none", organizationMembershipFence?: boolean): Promise<T>;
179
179
  export declare function withWorkspaceSessionActivityRls<T>(db: Database, workspaceId: string, fn: (db: SessionActivityDatabase) => Promise<T>, transactionConfig?: PgTransactionConfig): Promise<T>;
180
180
  /**
181
181
  * Run one of several ordered workspace activity scopes inside a caller-owned
@@ -191,7 +191,12 @@ export declare function withRestoredSessionActivityRlsContext<T>(db: Database, c
191
191
  * cannot express that provenance; keep the single trusted rebrand here.
192
192
  */
193
193
  export declare function withSessionActivitySavepoint<T>(db: SessionActivityDatabase, fn: (db: SessionActivityDatabase) => Promise<T>): Promise<T>;
194
- export declare function retrySessionActivityRls<T>(db: Database, workspaceId: string, options: IdempotentPersistenceTransactionOptions, fn: (db: SessionActivityDatabase) => Promise<T>): Promise<T>;
194
+ export declare function retrySessionActivityRls<T>(db: Database, workspaceId: string, options: IdempotentPersistenceTransactionOptions & {
195
+ /** Claim can inherit membership-fenced causal authority after locking the
196
+ * session. Acquire that fence before tenancy/control/session instead. An
197
+ * enclosing transaction must preserve this same lock prefix. */
198
+ organizationMembershipFence?: boolean;
199
+ }, fn: (db: SessionActivityDatabase) => Promise<T>): Promise<T>;
195
200
  export declare function retryWorkspacePersistence<T>(db: Database, workspaceId: string, options: IdempotentPersistenceTransactionOptions, fn: (db: Database) => Promise<T>): Promise<T>;
196
201
  export declare function retryRlsPersistence<T>(db: Database, context: RlsContext, options: IdempotentPersistenceTransactionOptions, fn: (db: Database) => Promise<T>): Promise<T>;
197
202
  /**
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  rawRows,
3
3
  withRlsContext
4
- } from "./chunk-I4ITNMX2.js";
5
- import "./chunk-AI4NC6XW.js";
4
+ } from "./chunk-GVZJ7XSR.js";
5
+ import "./chunk-6TKL3GQO.js";
6
6
  import "./chunk-PZ5AY32C.js";
7
7
 
8
8
  // src/editable-artifact-durable-export.ts
@@ -8,9 +8,9 @@ import {
8
8
  PostgresEditableArtifactStore,
9
9
  listEditableArtifactIdsForSession,
10
10
  touchEditableArtifactSessionLink
11
- } from "./chunk-UVBPOGA7.js";
12
- import "./chunk-I4ITNMX2.js";
13
- import "./chunk-AI4NC6XW.js";
11
+ } from "./chunk-232VC2LW.js";
12
+ import "./chunk-GVZJ7XSR.js";
13
+ import "./chunk-6TKL3GQO.js";
14
14
  import "./chunk-PZ5AY32C.js";
15
15
  export {
16
16
  EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
@@ -70,4 +70,6 @@ export declare function inheritChildHostMcpTurnAuthorities(db: Database, input:
70
70
  * Missing/revoked authority denies; infrastructure failures propagate so the
71
71
  * broker reports refresh_failed rather than misclassifying an outage.
72
72
  * The historical function name is retained for existing internal consumers. */
73
- export declare function authorizeDirectHostMcpUse(db: Database, request: McpCredentialsRequest): Promise<boolean>;
73
+ export declare function authorizeDirectHostMcpUse(db: Database, request: McpCredentialsRequest,
74
+ /** Internal metadata observer; called only after every live authorization fence succeeds. */
75
+ onAuthorized?: (snapshot: HostMcpAcceptedAuthority) => void): Promise<boolean>;
package/dist/index.d.ts CHANGED
@@ -8112,6 +8112,13 @@ export type LegacyModalCheckpointAdoptionTarget = Omit<LegacyModalCheckpointSlot
8112
8112
  * an unreferenced candidate that GC might delete while the legacy slot still
8113
8113
  * depends on that provider object. */
8114
8114
  export declare function adoptLegacyModalCheckpointArtifact(db: Database, input: LegacyModalCheckpointAdoptionTarget): Promise<boolean>;
8115
+ /** Object-candidate outcome from the publication transaction, independent of
8116
+ * lifecycle `wrote`. Absent for inline/provider receipts and pure CAS checks.
8117
+ * `unused` is NOT a retirement receipt: only the owner of a fresh candidate with
8118
+ * no other publication in flight may use it for immediate cleanup. Exceptions
8119
+ * give no disposition (commit may have happened). Legacy/shared keys and evicted
8120
+ * refs need durable no-reattachment evidence before deletion. */
8121
+ export type WorkspaceArchiveCandidateDisposition = "adopted" | "already_referenced" | "unused";
8115
8122
  export declare function persistDrainSnapshot(db: Database, input: {
8116
8123
  accountId: string;
8117
8124
  workspaceId: string;
@@ -8142,6 +8149,7 @@ export declare function persistDrainSnapshot(db: Database, input: {
8142
8149
  })): Promise<{
8143
8150
  wrote: boolean;
8144
8151
  archiveRevision: string | null;
8152
+ candidateDisposition?: WorkspaceArchiveCandidateDisposition;
8145
8153
  }>;
8146
8154
  /**
8147
8155
  * The ONE archive-fold write, shared by the drain seam (persistDrainSnapshot)
@@ -8213,6 +8221,7 @@ export declare function persistWarmSnapshot(db: Database, input: {
8213
8221
  throttled: boolean;
8214
8222
  superseded: boolean;
8215
8223
  archiveRevision: string | null;
8224
+ candidateDisposition?: WorkspaceArchiveCandidateDisposition;
8216
8225
  }>;
8217
8226
  export declare function getMaterializedSandboxFileResources(db: Database, input: {
8218
8227
  accountId: string;
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  replayAppliedSessionFork,
15
15
  sessionTenancyProductActivated,
16
16
  transitionSessionVisibility
17
- } from "./chunk-XBXANJQS.js";
17
+ } from "./chunk-M7PSMVFF.js";
18
18
  import {
19
19
  AgentCommandAuthorityError,
20
20
  CHILD_LIFECYCLE_DEDUPE_PREFIX,
@@ -108,7 +108,7 @@ import {
108
108
  updateSessionCommandReceiptResult,
109
109
  workspaceControlLockBudget,
110
110
  workspaceControlRequestLockTimeoutMs
111
- } from "./chunk-F4BIHJ7J.js";
111
+ } from "./chunk-EYF6MH6C.js";
112
112
  import {
113
113
  ACTIVE_VIDEO_GENERATION_STATUSES,
114
114
  VideoGenerationCapacityError,
@@ -140,7 +140,7 @@ import {
140
140
  settleVideoGenerationFailure,
141
141
  settleVideoGenerationReady,
142
142
  updateWorkspaceVideoGenerationPolicy
143
- } from "./chunk-PFBUHOI5.js";
143
+ } from "./chunk-QLA3UQNX.js";
144
144
  import {
145
145
  ManagedAuthActorMutationInFlightError,
146
146
  ManagedAuthLoginSlotAlreadyExistsError,
@@ -163,7 +163,7 @@ import {
163
163
  reapManagedAuthIsolatedSessions,
164
164
  releaseManagedAuthActorMutationLease,
165
165
  validateManagedAuthActorMutationLease
166
- } from "./chunk-UUPY6IGP.js";
166
+ } from "./chunk-UK57QA2H.js";
167
167
  import {
168
168
  migrate,
169
169
  runMigrations
@@ -190,7 +190,7 @@ import {
190
190
  inspectRuntimeDatabasePosture,
191
191
  provisionRoles,
192
192
  runtimeDatabaseReadyCheck
193
- } from "./chunk-YVYBAWBU.js";
193
+ } from "./chunk-THJGMEK5.js";
194
194
  import {
195
195
  CanonicalHumanIdentityAuthorityError,
196
196
  CanonicalHumanIdentityConflictError,
@@ -204,7 +204,7 @@ import {
204
204
  getCanonicalHumanIdentityProjection,
205
205
  synchronizeCanonicalHumanLoginBindings,
206
206
  validateCanonicalHumanSession
207
- } from "./chunk-DVSLOUEI.js";
207
+ } from "./chunk-2ZMTQVTR.js";
208
208
  import {
209
209
  EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
210
210
  EDITABLE_ARTIFACT_KERNEL_TAIL_MAX_BYTES,
@@ -215,7 +215,7 @@ import {
215
215
  PostgresEditableArtifactStore,
216
216
  listEditableArtifactIdsForSession,
217
217
  touchEditableArtifactSessionLink
218
- } from "./chunk-UVBPOGA7.js";
218
+ } from "./chunk-232VC2LW.js";
219
219
  import {
220
220
  SandboxProviderReadLockUnavailableError,
221
221
  SessionEventPersistenceError,
@@ -251,7 +251,7 @@ import {
251
251
  withWorkspaceSubjectRls,
252
252
  withWorkspaceSubjectSessionActivityRls,
253
253
  withWorkspaceUsageLock
254
- } from "./chunk-I4ITNMX2.js";
254
+ } from "./chunk-GVZJ7XSR.js";
255
255
  import {
256
256
  LOSSLESS_CONTENT_CODEC_VERSION,
257
257
  LOSSLESS_JSON_STRING_PREFIX,
@@ -491,7 +491,7 @@ import {
491
491
  xaiRotationSettings,
492
492
  xaiSessionAccountPins,
493
493
  xaiSubscriptionCredentials
494
- } from "./chunk-AI4NC6XW.js";
494
+ } from "./chunk-6TKL3GQO.js";
495
495
  import "./chunk-PZ5AY32C.js";
496
496
 
497
497
  // src/session-execution-policy.ts
@@ -5241,7 +5241,13 @@ async function inheritChildHostMcpTurnAuthorities(db, input) {
5241
5241
  }
5242
5242
  });
5243
5243
  }
5244
- async function authorizeDirectHostMcpUse(db, request) {
5244
+ async function authorizeDirectHostMcpUse(db, request, onAuthorized) {
5245
+ const snapshot = await resolveDirectHostMcpUseAuthority(db, request);
5246
+ if (!snapshot) return false;
5247
+ onAuthorized?.(snapshot);
5248
+ return true;
5249
+ }
5250
+ async function resolveDirectHostMcpUseAuthority(db, request) {
5245
5251
  if (!request.attemptId || !request.connectionRef.hostBinding) return false;
5246
5252
  const current = await getHostMcpLiveAttempt(
5247
5253
  db,
@@ -5321,7 +5327,7 @@ async function authorizeDirectHostMcpUse(db, request) {
5321
5327
  request.sessionId,
5322
5328
  request.attemptId
5323
5329
  );
5324
- return live !== null && live.id === request.turnId && live.executionGeneration === request.executionGeneration;
5330
+ return live !== null && live.id === request.turnId && live.executionGeneration === request.executionGeneration && a;
5325
5331
  });
5326
5332
  }
5327
5333
 
@@ -9207,6 +9213,7 @@ import {
9207
9213
  SANDBOX_PROVIDER_INSTANCE_ID_FIELDS_BY_BACKEND,
9208
9214
  parseWorkspaceArchiveDescriptor,
9209
9215
  parseWorkspaceArchiveObjectRef,
9216
+ validateWorkspaceArchiveObjectRef,
9210
9217
  workspaceArchivePayloadPresent,
9211
9218
  omitInlineWorkspaceArchiveWhenObjectRefPresent,
9212
9219
  stableJson as stableJson16,
@@ -76187,7 +76194,17 @@ async function adoptLegacyModalCheckpointArtifact(db, input) {
76187
76194
  );
76188
76195
  }
76189
76196
  function publishedWorkspaceArchiveFields(input) {
76190
- const ref = parseWorkspaceArchiveObjectRef(input.workspaceArchiveRef) ?? void 0;
76197
+ const ref = input.workspaceArchiveRef == null ? void 0 : validateWorkspaceArchiveObjectRef(input.workspaceArchiveRef, {
76198
+ accountId: input.accountId,
76199
+ workspaceId: input.workspaceId,
76200
+ sandboxGroupId: input.sandboxGroupId,
76201
+ descriptor: input.workspaceArchiveMeta
76202
+ }) ?? void 0;
76203
+ if (input.workspaceArchiveRef != null && !ref) {
76204
+ throw new Error(
76205
+ "Invalid workspace archive object ref: publication scope or descriptor mismatch"
76206
+ );
76207
+ }
76191
76208
  const inline = typeof input.workspaceArchive === "string" && input.workspaceArchive.length > 0 ? input.workspaceArchive : void 0;
76192
76209
  if (!ref && !inline) {
76193
76210
  throw new Error("workspace archive publication requires inline bytes or an object ref");
@@ -76204,11 +76221,24 @@ function publishedWorkspaceArchiveFields(input) {
76204
76221
  }
76205
76222
  return { workspaceArchive: inline };
76206
76223
  }
76224
+ function workspaceArchiveCandidateFields(candidate, lockedResumeState) {
76225
+ if (!candidate) return {};
76226
+ const sessionState = lockedResumeState?.sessionState;
76227
+ const referenced = [
76228
+ sessionState?.workspaceArchiveRef,
76229
+ sessionState?.workspaceArchivePrevRef
76230
+ ].some((value) => {
76231
+ const ref = parseWorkspaceArchiveObjectRef(value);
76232
+ return ref?.key === candidate.key && ref.backend === candidate.backend;
76233
+ });
76234
+ return { candidateDisposition: referenced ? "already_referenced" : "unused" };
76235
+ }
76207
76236
  async function persistDrainSnapshot(db, input) {
76208
76237
  const workspaceArchiveMeta = input.workspaceArchive === null ? null : parseArchiveRevision(input.workspaceArchiveMeta);
76209
76238
  if (input.workspaceArchive !== null && !workspaceArchiveMeta) {
76210
76239
  throw new Error("Invalid verified workspace archive descriptor");
76211
76240
  }
76241
+ const published = input.workspaceArchive === null ? null : publishedWorkspaceArchiveFields(input);
76212
76242
  if (workspaceArchiveMeta?.version === 2 && (workspaceArchiveMeta.provider === "modal_snapshot_filesystem" || workspaceArchiveMeta.provider === "modal_snapshot_directory") && !input.checkpointArtifactId) {
76213
76243
  throw new Error("Modal native checkpoint publication requires a registered artifact");
76214
76244
  }
@@ -76246,10 +76276,15 @@ async function persistDrainSnapshot(db, input) {
76246
76276
  for update
76247
76277
  `);
76248
76278
  const row = guard[0];
76279
+ const candidateFields = workspaceArchiveCandidateFields(
76280
+ published?.workspaceArchiveRef,
76281
+ row?.resume_state
76282
+ );
76249
76283
  if (!row) {
76250
76284
  return {
76251
76285
  wrote: false,
76252
- archiveRevision: null
76286
+ archiveRevision: null,
76287
+ ...candidateFields
76253
76288
  };
76254
76289
  }
76255
76290
  const sourceLeaseMatches = input.expectedLeaseId === void 0 || row.id === input.expectedLeaseId;
@@ -76259,7 +76294,7 @@ async function persistDrainSnapshot(db, input) {
76259
76294
  const lateReceipt = recovery.lateArchiveCapture;
76260
76295
  const coldLatePublication = input.workspaceArchive !== null && input.expectedLeaseId !== void 0 && input.providerRequestId !== void 0 && row.id === input.expectedLeaseId && row.liveness === "cold" && Number(row.refcount) === 0 && Number(row.lease_epoch) === input.expectedEpoch + 1 && row.instance_id === null && Number(row.workspace_generation) === input.expectedWorkspaceGeneration && row.archive_capture_id === null && recovery.provider.status === "missing" && recovery.provider.instanceId === input.expectedInstanceId && recovery.restore.rematerializationId === null && (recovery.restore.status === "unrecoverable" || recovery.restore.status === "degraded" || recovery.restore.status === "pending") && lateReceipt?.sourceLeaseId === input.expectedLeaseId && lateReceipt.sourceLeaseEpoch === input.expectedEpoch && lateReceipt.sourceInstanceId === input.expectedInstanceId && lateReceipt.sourceWorkspaceGeneration === input.expectedWorkspaceGeneration && lateReceipt.providerRequestId === input.providerRequestId && !row.unsettled_mutation;
76261
76296
  if (!activePublication && !coldLatePublication) {
76262
- return { wrote: false, archiveRevision: null };
76297
+ return { wrote: false, archiveRevision: null, ...candidateFields };
76263
76298
  }
76264
76299
  const priorArchive = row.prior_archive ?? null;
76265
76300
  const priorArchivePrev = row.prior_archive_prev ?? null;
@@ -76271,7 +76306,7 @@ async function persistDrainSnapshot(db, input) {
76271
76306
  archiveRevision: null
76272
76307
  };
76273
76308
  }
76274
- const published = publishedWorkspaceArchiveFields(input);
76309
+ if (!published) throw new Error("Missing workspace archive publication fields");
76275
76310
  const priorMeta = parseArchiveRevision(priorSessionState?.workspaceArchiveMeta);
76276
76311
  if (activePublication && row.archive_capture_published_at !== null) {
76277
76312
  if (priorArchive === null && priorRef === null || priorMeta === null) {
@@ -76291,7 +76326,7 @@ async function persistDrainSnapshot(db, input) {
76291
76326
  )
76292
76327
  `);
76293
76328
  }
76294
- return { wrote: true, archiveRevision: priorMeta.revision };
76329
+ return { wrote: true, archiveRevision: priorMeta.revision, ...candidateFields };
76295
76330
  }
76296
76331
  const rotation = rotateWorkspaceArchives({
76297
76332
  resumeState: row.resume_state,
@@ -76345,12 +76380,14 @@ async function persistDrainSnapshot(db, input) {
76345
76380
  if (!folded) {
76346
76381
  return {
76347
76382
  wrote: false,
76348
- archiveRevision: null
76383
+ archiveRevision: null,
76384
+ ...candidateFields
76349
76385
  };
76350
76386
  }
76351
76387
  return {
76352
76388
  wrote: true,
76353
- archiveRevision: workspaceArchiveMeta?.revision ?? null
76389
+ archiveRevision: workspaceArchiveMeta?.revision ?? null,
76390
+ ...published.workspaceArchiveRef ? { candidateDisposition: "adopted" } : {}
76354
76391
  };
76355
76392
  }
76356
76393
  );
@@ -76627,12 +76664,27 @@ async function persistWarmSnapshot(db, input) {
76627
76664
  )
76628
76665
  ).limit(1) : [];
76629
76666
  const attemptMayPersistWorkspace = attempt !== void 0 && (attempt.state === "claimed" || attempt.state === "running" ? attempt.outcome === null : attempt.state === "closed" && (attempt.outcome === "completed" || attempt.outcome === "failed" || attempt.outcome === "requires_action"));
76667
+ const candidateLease = published.workspaceArchiveRef ? await scopedDb.execute(sql81`
76668
+ select jsonb_build_object('sessionState', jsonb_build_object(
76669
+ 'workspaceArchiveRef', resume_state #> '{sessionState,workspaceArchiveRef}',
76670
+ 'workspaceArchivePrevRef', resume_state #> '{sessionState,workspaceArchivePrevRef}'
76671
+ )) as resume_state
76672
+ from sandbox_leases
76673
+ where workspace_id = ${input.workspaceId}
76674
+ and sandbox_group_id = ${input.sandboxGroupId}
76675
+ for update
76676
+ `) : [];
76677
+ const candidateFields = workspaceArchiveCandidateFields(
76678
+ published.workspaceArchiveRef,
76679
+ candidateLease[0]?.resume_state
76680
+ );
76630
76681
  if (!attempt || attempt.accountId !== input.accountId || attempt.sandboxGroupId !== input.sandboxGroupId || interruption || !attemptMayPersistWorkspace) {
76631
76682
  return {
76632
76683
  wrote: false,
76633
76684
  throttled: false,
76634
76685
  superseded: true,
76635
- archiveRevision: null
76686
+ archiveRevision: null,
76687
+ ...candidateFields
76636
76688
  };
76637
76689
  }
76638
76690
  const guard = await scopedDb.execute(sql81`
@@ -76680,7 +76732,8 @@ async function persistWarmSnapshot(db, input) {
76680
76732
  wrote: false,
76681
76733
  throttled: false,
76682
76734
  superseded: false,
76683
- archiveRevision: null
76735
+ archiveRevision: null,
76736
+ ...candidateFields
76684
76737
  };
76685
76738
  }
76686
76739
  const priorArchive = guard[0].prior_archive ?? null;
@@ -76693,7 +76746,8 @@ async function persistWarmSnapshot(db, input) {
76693
76746
  wrote: false,
76694
76747
  throttled: false,
76695
76748
  superseded: true,
76696
- archiveRevision: null
76749
+ archiveRevision: null,
76750
+ ...candidateFields
76697
76751
  };
76698
76752
  }
76699
76753
  if (input.minIntervalMs > 0 && Number.isFinite(priorAtMs) && capturedAtMs - priorAtMs < input.minIntervalMs) {
@@ -76701,7 +76755,8 @@ async function persistWarmSnapshot(db, input) {
76701
76755
  wrote: false,
76702
76756
  throttled: true,
76703
76757
  superseded: false,
76704
- archiveRevision: null
76758
+ archiveRevision: null,
76759
+ ...candidateFields
76705
76760
  };
76706
76761
  }
76707
76762
  const rotation = rotateWorkspaceArchives({
@@ -76722,7 +76777,8 @@ async function persistWarmSnapshot(db, input) {
76722
76777
  wrote: false,
76723
76778
  throttled: false,
76724
76779
  superseded: false,
76725
- archiveRevision: null
76780
+ archiveRevision: null,
76781
+ ...candidateFields
76726
76782
  };
76727
76783
  }
76728
76784
  const livenessGuard = rowLiveness;
@@ -76752,14 +76808,16 @@ async function persistWarmSnapshot(db, input) {
76752
76808
  wrote: false,
76753
76809
  throttled: false,
76754
76810
  superseded: false,
76755
- archiveRevision: null
76811
+ archiveRevision: null,
76812
+ ...candidateFields
76756
76813
  };
76757
76814
  }
76758
76815
  return {
76759
76816
  wrote: true,
76760
76817
  throttled: false,
76761
76818
  superseded: false,
76762
- archiveRevision: workspaceArchiveMeta.revision
76819
+ archiveRevision: workspaceArchiveMeta.revision,
76820
+ ...published.workspaceArchiveRef ? { candidateDisposition: "adopted" } : {}
76763
76821
  };
76764
76822
  }
76765
76823
  );
@@ -82822,7 +82880,8 @@ async function claimSessionWorkForAttempt(db, workspaceId, input) {
82822
82880
  {
82823
82881
  stage: "session_attempts.claim",
82824
82882
  eventTypes: ["session.turn.attempt_claimed"],
82825
- maxAttempts: 3
82883
+ maxAttempts: 3,
82884
+ organizationMembershipFence: true
82826
82885
  },
82827
82886
  async (scopedDb) => await withSessionActivitySavepoint(scopedDb, async (tx) => {
82828
82887
  const deliverPendingUpdates = async (accountId, turnId, turnGeneration, nextSequence, occurredAt, triggerEventId, expectedXaiAuthority, options = {}) => {