@opengeni/worker-bundle 6.8.0 → 6.8.1-canary.41842879332001

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 (32) hide show
  1. package/dist/activities/agent-turn/governance-model.d.ts +3 -0
  2. package/dist/activities/rig-provider-image-refresh.d.ts +36 -0
  3. package/dist/activities/rig-verification.d.ts +6 -2
  4. package/dist/activities/types.d.ts +13 -0
  5. package/dist/{activities-control-6HEEWPLL.js → activities-control-HO563R2O.js} +23 -21
  6. package/dist/activities-control-HO563R2O.js.map +1 -0
  7. package/dist/{activities-turn-E6VP3XVJ.js → activities-turn-TGP5NHS7.js} +26 -9
  8. package/dist/activities-turn-TGP5NHS7.js.map +1 -0
  9. package/dist/artifact-materializer-entry.js +0 -0
  10. package/dist/artifact-outbox-entry.js +0 -0
  11. package/dist/{chunk-ZEGN4DC4.js → chunk-NKTJ5VQ4.js} +2 -1
  12. package/dist/chunk-NKTJ5VQ4.js.map +1 -0
  13. package/dist/chunk-VFL7V45S.js +320 -0
  14. package/dist/chunk-VFL7V45S.js.map +1 -0
  15. package/dist/chunk-YTPJJBDP.js +31 -0
  16. package/dist/chunk-YTPJJBDP.js.map +1 -0
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.js +38 -305
  19. package/dist/index.js.map +1 -1
  20. package/dist/workflow-bundle.js +1 -1
  21. package/package.json +30 -29
  22. package/src/activities/agent-turn/governance-model.ts +19 -1
  23. package/src/activities/agent-turn/run.ts +2 -0
  24. package/src/activities/rig-provider-image-refresh.ts +56 -0
  25. package/src/activities/rig-verification.ts +20 -19
  26. package/src/activities/session-state.ts +5 -1
  27. package/src/activities/types.ts +14 -0
  28. package/src/activity-services.ts +1 -0
  29. package/src/index.ts +26 -0
  30. package/dist/activities-control-6HEEWPLL.js.map +0 -1
  31. package/dist/activities-turn-E6VP3XVJ.js.map +0 -1
  32. package/dist/chunk-ZEGN4DC4.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { materializeRigVersionForAttempt, freezeAgentLearningPolicy } from "@opengeni/db";
2
2
  import { renderWorkspaceGovernanceContext, type OpenGeniRuntime } from "@opengeni/runtime";
3
3
  import { type Settings } from "@opengeni/config";
4
+ import type { StartRigProviderImageRefresh } from "../types.js";
4
5
  import { createModelHistoryAttachmentProjector } from "../run-input.js";
5
6
  import { type TurnSearchRecords } from "../search-record-form.js";
6
7
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput, RunAgentTurnResult } from "../types.js";
@@ -36,6 +37,8 @@ export type GovernanceModelDeps = {
36
37
  sha256: string;
37
38
  filename: string;
38
39
  }>;
40
+ /** Optional background rebuild of a stale sandbox environment image. */
41
+ startRigProviderImageRefresh?: StartRigProviderImageRefresh | null;
39
42
  };
40
43
  export type GovernanceModelOk = {
41
44
  runtimePreparationStartedAt: number;
@@ -0,0 +1,36 @@
1
+ import type { RigProviderImageSelectionReason } from "@opengeni/core";
2
+ import type { StartRigProviderImageRefresh } from "./types.js";
3
+ /**
4
+ * Deterministic Temporal workflow id for an automatic provider-image rebuild:
5
+ * at most one start per version, expected content and UTC day.
6
+ */
7
+ export declare function rigProviderImageRefreshWorkflowId(input: {
8
+ versionId: string;
9
+ contentHash: string;
10
+ now?: Date;
11
+ }): string;
12
+ /**
13
+ * A ready, cold-boot-proven provider image whose content no longer matches is
14
+ * stale: the deployment base image (or the content identity protocol) moved
15
+ * after it was built. The turn still uses the ordinary setup path, and asks
16
+ * once in the background for a rebuild on the current base so later fresh
17
+ * sandboxes start from a prebuilt image again. Never awaited by the turn.
18
+ */
19
+ export declare function requestStaleRigProviderImageRefresh(input: {
20
+ selection: {
21
+ reason: RigProviderImageSelectionReason;
22
+ contentHash: string | null;
23
+ };
24
+ /**
25
+ * Verification always builds on the deployment base. A turn on a
26
+ * workspace-selected base could never be served by that rebuild.
27
+ */
28
+ turnUsesDeploymentBase: boolean;
29
+ workspaceId: string;
30
+ versionId: string | null;
31
+ start: StartRigProviderImageRefresh | null | undefined;
32
+ warn: (message: string, context: {
33
+ versionId: string;
34
+ error: string;
35
+ }) => void;
36
+ }): boolean;
@@ -86,6 +86,12 @@ export declare class RigVerificationLeaseUnavailableError extends Error {
86
86
  /**
87
87
  * Run one verifier against one exactly attributed standalone sandbox.
88
88
  *
89
+ * Every run owns a brand-new lease group. A verification must prove a clean
90
+ * box, so it can never reuse an earlier run's lease: keying the lease by the
91
+ * change, version or build request left a cold lease behind after the first
92
+ * run, and every later verification of the same target then failed at once
93
+ * as `rearmed`/`attached` instead of creating a fresh sandbox.
94
+ *
89
95
  * Ordering is deliberate and source-of-truth safe:
90
96
  * acquire spawner -> create callback -> warming instance record -> warm commit
91
97
  * -> setup/checks. The canonical sandbox lease, not provider tags, is durable
@@ -103,7 +109,6 @@ export declare function runWithOwnedRigVerificationSandbox<T>(input: {
103
109
  observability: ControlActivityServices["observability"];
104
110
  accountId: string;
105
111
  workspaceId: string;
106
- sandboxGroupId: string;
107
112
  rigVersionId: string;
108
113
  sessionIdPrefix: string;
109
114
  lifecycle?: RigVerificationActivityLifecycle;
@@ -120,7 +125,6 @@ export declare function verifyRigProviderImageColdBoot(input: {
120
125
  observability: ControlActivityServices["observability"];
121
126
  accountId: string;
122
127
  workspaceId: string;
123
- buildRequestId: string;
124
128
  rigVersionId: string;
125
129
  sessionIdPrefix: string;
126
130
  imageId: string;
@@ -47,6 +47,18 @@ export type StartRecordingWorkflow = (input: {
47
47
  versionId: string | null;
48
48
  ownerSubjectId: string;
49
49
  }) => Promise<"started" | "already_running">;
50
+ /**
51
+ * Start the clean-replay verification that rebuilds a sandbox environment
52
+ * version's provider image for the deployment's current base image. The
53
+ * start is deduplicated per version, expected content and UTC day, so every
54
+ * turn that meets the stale image may ask without starting more than one
55
+ * rebuild a day.
56
+ */
57
+ export type StartRigProviderImageRefresh = (input: {
58
+ workspaceId: string;
59
+ versionId: string;
60
+ contentHash: string;
61
+ }) => Promise<"started" | "already_running">;
50
62
  /** Exact activity-owned proof that the hard sandbox/tool fence physically
51
63
  * drained. This is delivery evidence only: the workflow still validates the
52
64
  * persisted attempt dispatch and commits the authoritative Postgres receipt. */
@@ -93,6 +105,7 @@ export type SharedActivityServices = {
93
105
  startVideoGenerationWorkflow?: StartVideoGenerationWorkflow | null;
94
106
  startSessionTitleWorkflow?: StartSessionTitleWorkflow | null;
95
107
  startRecordingWorkflow?: StartRecordingWorkflow | null;
108
+ startRigProviderImageRefresh?: StartRigProviderImageRefresh | null;
96
109
  entitlements?: EntitlementsPort | null;
97
110
  connectionCredentials?: VaultConnectionCredentialsPort | null;
98
111
  /**
@@ -20,7 +20,10 @@ import {
20
20
  withFirstPartyTools,
21
21
  workflowIdForSession,
22
22
  writeSessionUsageReceipts
23
- } from "./chunk-ZEGN4DC4.js";
23
+ } from "./chunk-NKTJ5VQ4.js";
24
+ import {
25
+ resolveWorkerShutdownTiming
26
+ } from "./chunk-VFL7V45S.js";
24
27
  import "./chunk-5E7CLEQM.js";
25
28
  import {
26
29
  createSiteAuthMaintenanceActivities
@@ -4025,6 +4028,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4025
4028
  throw new Error(RIG_VERIFICATION_OWNERS_DISABLED_MESSAGE);
4026
4029
  }
4027
4030
  const holderId = `rig-verification:${dependencies.randomUUID()}`;
4031
+ const sandboxGroupId = dependencies.randomUUID();
4028
4032
  const fallbackController = new AbortController();
4029
4033
  const signal = input.lifecycle?.signal ?? fallbackController.signal;
4030
4034
  const commandController = dependencies.createCancellationController(signal);
@@ -4060,7 +4064,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4060
4064
  () => dependencies.markWarmLost(input.db, {
4061
4065
  accountId: input.accountId,
4062
4066
  workspaceId: input.workspaceId,
4063
- sandboxGroupId: input.sandboxGroupId,
4067
+ sandboxGroupId,
4064
4068
  expectedEpoch: cleanupEpoch + 1,
4065
4069
  expectedInstanceId: instanceId
4066
4070
  })
@@ -4069,7 +4073,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4069
4073
  () => dependencies.failWarming(input.db, {
4070
4074
  accountId: input.accountId,
4071
4075
  workspaceId: input.workspaceId,
4072
- sandboxGroupId: input.sandboxGroupId,
4076
+ sandboxGroupId,
4073
4077
  expectedEpoch: cleanupEpoch
4074
4078
  })
4075
4079
  )
@@ -4107,7 +4111,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4107
4111
  const lease = await dependencies.acquire(input.db, {
4108
4112
  accountId: input.accountId,
4109
4113
  workspaceId: input.workspaceId,
4110
- sandboxGroupId: input.sandboxGroupId,
4114
+ sandboxGroupId,
4111
4115
  kind: "turn",
4112
4116
  holderId,
4113
4117
  subjectId: null,
@@ -4125,7 +4129,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4125
4129
  void dependencies.touchHolder(input.db, {
4126
4130
  accountId: input.accountId,
4127
4131
  workspaceId: input.workspaceId,
4128
- sandboxGroupId: input.sandboxGroupId,
4132
+ sandboxGroupId,
4129
4133
  kind: "turn",
4130
4134
  holderId
4131
4135
  }).catch(() => void 0);
@@ -4134,7 +4138,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4134
4138
  holderLivenessTimer.unref();
4135
4139
  }
4136
4140
  if (lease.role !== "spawner") {
4137
- throw new RigVerificationLeaseUnavailableError(input.sandboxGroupId, lease.role);
4141
+ throw new RigVerificationLeaseUnavailableError(sandboxGroupId, lease.role);
4138
4142
  }
4139
4143
  ownsWarmingEpoch = true;
4140
4144
  establishmentPromise = Promise.resolve().then(
@@ -4144,7 +4148,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4144
4148
  createIdentity: {
4145
4149
  accountId: input.accountId,
4146
4150
  workspaceId: input.workspaceId,
4147
- sandboxGroupId: input.sandboxGroupId
4151
+ sandboxGroupId
4148
4152
  },
4149
4153
  environment: {},
4150
4154
  onSandboxCreated: async (created) => {
@@ -4153,7 +4157,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4153
4157
  const recorded = await dependencies.recordCreated(input.db, {
4154
4158
  accountId: input.accountId,
4155
4159
  workspaceId: input.workspaceId,
4156
- sandboxGroupId: input.sandboxGroupId,
4160
+ sandboxGroupId,
4157
4161
  expectedEpoch: lease.lease.leaseEpoch,
4158
4162
  instanceId: created.instanceId,
4159
4163
  resumeBackendId: created.backendId,
@@ -4162,7 +4166,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4162
4166
  warmingLeaseTtlMs: RIG_VERIFICATION_OWNER_TTL_MS
4163
4167
  });
4164
4168
  if (!recorded.recorded) {
4165
- throw new RigVerificationLeaseUnavailableError(input.sandboxGroupId, "fenced");
4169
+ throw new RigVerificationLeaseUnavailableError(sandboxGroupId, "fenced");
4166
4170
  }
4167
4171
  if (created.backendId === "modal" && !signal.aborted) {
4168
4172
  try {
@@ -4170,7 +4174,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4170
4174
  dependencies.tag(input.settings, created.instanceId, {
4171
4175
  leaseId: lease.lease.id,
4172
4176
  workspaceId: input.workspaceId,
4173
- sandboxGroupId: input.sandboxGroupId
4177
+ sandboxGroupId
4174
4178
  }),
4175
4179
  signal
4176
4180
  );
@@ -4210,7 +4214,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4210
4214
  const committed = await dependencies.commitWarm(input.db, {
4211
4215
  accountId: input.accountId,
4212
4216
  workspaceId: input.workspaceId,
4213
- sandboxGroupId: input.sandboxGroupId,
4217
+ sandboxGroupId,
4214
4218
  expectedEpoch: lease.lease.leaseEpoch,
4215
4219
  instanceId: established.instanceId,
4216
4220
  dataPlaneUrl: null,
@@ -4219,7 +4223,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4219
4223
  leaseTtlMs: RIG_VERIFICATION_OWNER_TTL_MS
4220
4224
  });
4221
4225
  if (!committed.committed || !committed.lease) {
4222
- throw new RigVerificationLeaseUnavailableError(input.sandboxGroupId, "fenced");
4226
+ throw new RigVerificationLeaseUnavailableError(sandboxGroupId, "fenced");
4223
4227
  }
4224
4228
  const result = await run(established, {
4225
4229
  signal,
@@ -4263,7 +4267,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4263
4267
  await dependencies.failWarming(input.db, {
4264
4268
  accountId: input.accountId,
4265
4269
  workspaceId: input.workspaceId,
4266
- sandboxGroupId: input.sandboxGroupId,
4270
+ sandboxGroupId,
4267
4271
  expectedEpoch
4268
4272
  });
4269
4273
  }
@@ -4290,7 +4294,7 @@ async function runWithOwnedRigVerificationSandbox(input, run, dependencies = def
4290
4294
  () => dependencies.releaseHolder(input.db, {
4291
4295
  accountId: input.accountId,
4292
4296
  workspaceId: input.workspaceId,
4293
- sandboxGroupId: input.sandboxGroupId,
4297
+ sandboxGroupId,
4294
4298
  kind: "turn",
4295
4299
  holderId,
4296
4300
  idleGraceMs: RIG_VERIFICATION_RELEASE_GRACE_MS
@@ -4406,7 +4410,6 @@ async function verifyRigProviderImageColdBoot(input, dependencies = defaultRigPr
4406
4410
  observability: input.observability,
4407
4411
  accountId: input.accountId,
4408
4412
  workspaceId: input.workspaceId,
4409
- sandboxGroupId: input.buildRequestId,
4410
4413
  rigVersionId: input.rigVersionId,
4411
4414
  sessionIdPrefix: input.sessionIdPrefix,
4412
4415
  lifecycle: input.lifecycle
@@ -4612,7 +4615,6 @@ async function buildVerifiedRigProviderImage(input) {
4612
4615
  observability: input.observability,
4613
4616
  accountId: input.accountId,
4614
4617
  workspaceId: input.workspaceId,
4615
- buildRequestId: building.buildRequestId,
4616
4618
  rigVersionId: input.target.id,
4617
4619
  sessionIdPrefix: `rig-provider-image-${input.target.id}`,
4618
4620
  imageId: built.imageId,
@@ -4765,7 +4767,6 @@ function createRigVerificationActivities(services) {
4765
4767
  observability,
4766
4768
  accountId: rig.accountId,
4767
4769
  workspaceId: input.workspaceId,
4768
- sandboxGroupId: change.id,
4769
4770
  rigVersionId: candidateVersion.id,
4770
4771
  sessionIdPrefix: `rig-verification-${change.id}`,
4771
4772
  lifecycle
@@ -4950,7 +4951,6 @@ function createRigVerificationActivities(services) {
4950
4951
  observability,
4951
4952
  accountId: rig.accountId,
4952
4953
  workspaceId: input.workspaceId,
4953
- sandboxGroupId: version.id,
4954
4954
  rigVersionId: version.id,
4955
4955
  sessionIdPrefix: `rig-version-verification-${version.id}`,
4956
4956
  lifecycle
@@ -8129,7 +8129,7 @@ function createSessionStateActivities(services, overrides = {}) {
8129
8129
  }
8130
8130
  }
8131
8131
  async function reconcileSessionAttemptQuiescenceActivity(input) {
8132
- const { db, bus, inspectSessionAttemptActivity } = await services();
8132
+ const { db, bus, inspectSessionAttemptActivity, settings } = await services();
8133
8133
  const activityRef = await getSessionAttemptActivityRefFn(db, {
8134
8134
  ...input,
8135
8135
  temporalWorkflowId: input.workflowId
@@ -8148,7 +8148,9 @@ function createSessionStateActivities(services, overrides = {}) {
8148
8148
  temporalWorkflowId: input.workflowId,
8149
8149
  temporalWorkflowRunId: activityRef.workflowRunId,
8150
8150
  temporalActivityId: activityRef.activityId,
8151
- activitySettled: true
8151
+ activitySettled: true,
8152
+ // A worker-shutdown closure's process has exited once this has passed.
8153
+ workerProcessExitDeadlineMs: resolveWorkerShutdownTiming("turn", settings).processExitDeadlineMs
8152
8154
  });
8153
8155
  if (result.events.length > 0) {
8154
8156
  await publishDurableSessionEventsFn(
@@ -8961,4 +8963,4 @@ export {
8961
8963
  createControlActivities,
8962
8964
  createControlActivitiesFromServices
8963
8965
  };
8964
- //# sourceMappingURL=activities-control-6HEEWPLL.js.map
8966
+ //# sourceMappingURL=activities-control-HO563R2O.js.map