@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "6.8.0",
3
+ "version": "6.8.1-canary.41842879332001",
4
4
  "description": "Opengeni worker entry and reusable embedded lifecycle, shipped with a release-coherent pre-bundled Temporal workflow artifact.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -56,33 +56,33 @@
56
56
  "@1password/sdk": "0.5.0",
57
57
  "@keeper-security/secrets-manager-core": "17.6.0",
58
58
  "@llamaindex/liteparse": "2.14.2",
59
- "@opengeni/agent-proto": "6.8.0",
60
- "@opengeni/capabilities": "6.8.0",
61
- "@opengeni/codemode": "6.8.0",
62
- "@opengeni/codex": "6.8.0",
63
- "@opengeni/config": "6.8.0",
64
- "@opengeni/contracts": "6.8.0",
65
- "@opengeni/core": "6.8.0",
66
- "@opengeni/db": "6.8.0",
67
- "@opengeni/decisions": "6.8.0",
68
- "@opengeni/documents": "6.8.0",
69
- "@opengeni/events": "6.8.0",
70
- "@opengeni/github": "6.8.0",
71
- "@opengeni/interaction": "6.8.0",
72
- "@opengeni/jev": "6.8.0",
73
- "@opengeni/network": "6.8.0",
74
- "@opengeni/observability": "6.8.0",
75
- "@opengeni/runtime": "6.8.0",
76
- "@opengeni/sdk": "6.8.0",
77
- "@opengeni/storage": "6.8.0",
78
- "@opengeni/subscriptions": "6.8.0",
79
- "@opengeni/tool-gateway": "6.8.0",
80
- "@opengeni/vaults": "6.8.0",
81
- "@opengeni/vaults-bitwarden": "6.8.0",
82
- "@opengeni/vaults-keeper": "6.8.0",
83
- "@opengeni/vaults-onepassword": "6.8.0",
84
- "@opengeni/vaults-protonpass": "6.8.0",
85
- "@opengeni/xai-subscription": "6.8.0",
59
+ "@opengeni/agent-proto": "6.8.1-canary.41842879332001",
60
+ "@opengeni/capabilities": "6.8.1-canary.41842879332001",
61
+ "@opengeni/codemode": "6.8.1-canary.41842879332001",
62
+ "@opengeni/codex": "6.8.1-canary.41842879332001",
63
+ "@opengeni/config": "6.8.1-canary.41842879332001",
64
+ "@opengeni/contracts": "6.8.1-canary.41842879332001",
65
+ "@opengeni/core": "6.8.1-canary.41842879332001",
66
+ "@opengeni/db": "6.8.1-canary.41842879332001",
67
+ "@opengeni/decisions": "6.8.1-canary.41842879332001",
68
+ "@opengeni/documents": "6.8.1-canary.41842879332001",
69
+ "@opengeni/events": "6.8.1-canary.41842879332001",
70
+ "@opengeni/github": "6.8.1-canary.41842879332001",
71
+ "@opengeni/interaction": "6.8.1-canary.41842879332001",
72
+ "@opengeni/jev": "6.8.1-canary.41842879332001",
73
+ "@opengeni/network": "6.8.1-canary.41842879332001",
74
+ "@opengeni/observability": "6.8.1-canary.41842879332001",
75
+ "@opengeni/runtime": "6.8.1-canary.41842879332001",
76
+ "@opengeni/sdk": "6.8.1-canary.41842879332001",
77
+ "@opengeni/storage": "6.8.1-canary.41842879332001",
78
+ "@opengeni/subscriptions": "6.8.1-canary.41842879332001",
79
+ "@opengeni/tool-gateway": "6.8.1-canary.41842879332001",
80
+ "@opengeni/vaults": "6.8.1-canary.41842879332001",
81
+ "@opengeni/vaults-bitwarden": "6.8.1-canary.41842879332001",
82
+ "@opengeni/vaults-keeper": "6.8.1-canary.41842879332001",
83
+ "@opengeni/vaults-onepassword": "6.8.1-canary.41842879332001",
84
+ "@opengeni/vaults-protonpass": "6.8.1-canary.41842879332001",
85
+ "@opengeni/xai-subscription": "6.8.1-canary.41842879332001",
86
86
  "@temporalio/activity": "^1.17.0",
87
87
  "@temporalio/client": "^1.17.0",
88
88
  "@temporalio/worker": "^1.17.0",
@@ -92,5 +92,6 @@
92
92
  },
93
93
  "engines": {
94
94
  "node": ">=18"
95
- }
95
+ },
96
+ "gitHead": "ff8b16463fb0dff3e03bb65f123c9fe3f500eedf"
96
97
  }
@@ -29,7 +29,13 @@ import {
29
29
  } from "@opengeni/config";
30
30
  import { projectReasoningConfigurations, supportsReasoningConfiguration } from "@opengeni/codex";
31
31
  import { settingsWithSessionMcpServersForRun } from "../capabilities";
32
- import { resolveRigProviderImageForRun, settingsWithWorkspaceSandboxImage } from "@opengeni/core";
32
+ import {
33
+ resolveRigProviderImageForRun,
34
+ rigProviderImageSourceImage,
35
+ settingsWithWorkspaceSandboxImage,
36
+ } from "@opengeni/core";
37
+ import { requestStaleRigProviderImageRefresh } from "../rig-provider-image-refresh";
38
+ import type { StartRigProviderImageRefresh } from "../types";
33
39
  import { createModelHistoryAttachmentProjector } from "../run-input";
34
40
  import {
35
41
  loadTurnSearchRecords,
@@ -101,6 +107,8 @@ export type GovernanceModelDeps = {
101
107
  sha256: string;
102
108
  filename: string;
103
109
  }>;
110
+ /** Optional background rebuild of a stale sandbox environment image. */
111
+ startRigProviderImageRefresh?: StartRigProviderImageRefresh | null;
104
112
  };
105
113
 
106
114
  export type GovernanceModelOk = {
@@ -344,6 +352,16 @@ export async function prepareGovernanceAndModel(
344
352
  turn.sandboxBackend,
345
353
  );
346
354
  const providerImageSettings = providerImageSelection.settings;
355
+ requestStaleRigProviderImageRefresh({
356
+ selection: providerImageSelection,
357
+ turnUsesDeploymentBase:
358
+ rigProviderImageSourceImage(logicalSandboxSettings, turn.sandboxBackend) ===
359
+ rigProviderImageSourceImage(capabilitySettings, turn.sandboxBackend),
360
+ workspaceId: input.workspaceId,
361
+ versionId: rigVersion?.id ?? null,
362
+ start: deps.startRigProviderImageRefresh,
363
+ warn: (message, context) => observability.warn(message, context),
364
+ });
347
365
  const verifiedRigProviderImageId =
348
366
  providerImageSelection.reason === "selected"
349
367
  ? (providerImageSelection.imageId ?? undefined)
@@ -291,6 +291,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
291
291
  personalGitHubCredentials,
292
292
  startVideoGenerationWorkflow,
293
293
  startSessionTitleWorkflow,
294
+ startRigProviderImageRefresh,
294
295
  } = resolvedServices;
295
296
  const activityContext = currentActivityContext();
296
297
  const cancellationSignal = activityContext?.cancellationSignal;
@@ -769,6 +770,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
769
770
  turnExecutionPolicy,
770
771
  chargesOpenGeniCredits: billingState.chargesOpenGeniCredits,
771
772
  requiredGeneratedVideoFiles,
773
+ startRigProviderImageRefresh: startRigProviderImageRefresh ?? null,
772
774
  });
773
775
  if ("exit" in governance) return governance.exit;
774
776
  await assertTurnModelConnection(db, providerTurn, {
@@ -0,0 +1,56 @@
1
+ import type { RigProviderImageSelectionReason } from "@opengeni/core";
2
+ import { errorMessage } from "@opengeni/contracts/values";
3
+ import type { StartRigProviderImageRefresh } from "./types";
4
+
5
+ /**
6
+ * Deterministic Temporal workflow id for an automatic provider-image rebuild:
7
+ * at most one start per version, expected content and UTC day.
8
+ */
9
+ export function rigProviderImageRefreshWorkflowId(input: {
10
+ versionId: string;
11
+ contentHash: string;
12
+ now?: Date;
13
+ }): string {
14
+ const day = (input.now ?? new Date()).toISOString().slice(0, 10);
15
+ const content = input.contentHash.replace(/^sha256:/, "").slice(0, 32);
16
+ return `rig-provider-image-refresh:${input.versionId}:${content}:${day}`;
17
+ }
18
+
19
+ /**
20
+ * A ready, cold-boot-proven provider image whose content no longer matches is
21
+ * stale: the deployment base image (or the content identity protocol) moved
22
+ * after it was built. The turn still uses the ordinary setup path, and asks
23
+ * once in the background for a rebuild on the current base so later fresh
24
+ * sandboxes start from a prebuilt image again. Never awaited by the turn.
25
+ */
26
+ export function requestStaleRigProviderImageRefresh(input: {
27
+ selection: { reason: RigProviderImageSelectionReason; contentHash: string | null };
28
+ /**
29
+ * Verification always builds on the deployment base. A turn on a
30
+ * workspace-selected base could never be served by that rebuild.
31
+ */
32
+ turnUsesDeploymentBase: boolean;
33
+ workspaceId: string;
34
+ versionId: string | null;
35
+ start: StartRigProviderImageRefresh | null | undefined;
36
+ warn: (message: string, context: { versionId: string; error: string }) => void;
37
+ }): boolean {
38
+ if (input.selection.reason !== "content_mismatch" || !input.turnUsesDeploymentBase) return false;
39
+ if (!input.versionId || !input.selection.contentHash || !input.start) return false;
40
+ const versionId = input.versionId;
41
+ void Promise.resolve()
42
+ .then(() =>
43
+ input.start!({
44
+ workspaceId: input.workspaceId,
45
+ versionId,
46
+ contentHash: input.selection.contentHash!,
47
+ }),
48
+ )
49
+ .catch((error: unknown) => {
50
+ input.warn("sandbox environment provider image refresh could not start", {
51
+ versionId,
52
+ error: errorMessage(error),
53
+ });
54
+ });
55
+ return true;
56
+ }
@@ -444,6 +444,12 @@ export class RigVerificationLeaseUnavailableError extends Error {
444
444
  /**
445
445
  * Run one verifier against one exactly attributed standalone sandbox.
446
446
  *
447
+ * Every run owns a brand-new lease group. A verification must prove a clean
448
+ * box, so it can never reuse an earlier run's lease: keying the lease by the
449
+ * change, version or build request left a cold lease behind after the first
450
+ * run, and every later verification of the same target then failed at once
451
+ * as `rearmed`/`attached` instead of creating a fresh sandbox.
452
+ *
447
453
  * Ordering is deliberate and source-of-truth safe:
448
454
  * acquire spawner -> create callback -> warming instance record -> warm commit
449
455
  * -> setup/checks. The canonical sandbox lease, not provider tags, is durable
@@ -462,7 +468,6 @@ export async function runWithOwnedRigVerificationSandbox<T>(
462
468
  observability: ControlActivityServices["observability"];
463
469
  accountId: string;
464
470
  workspaceId: string;
465
- sandboxGroupId: string;
466
471
  rigVersionId: string;
467
472
  sessionIdPrefix: string;
468
473
  lifecycle?: RigVerificationActivityLifecycle;
@@ -481,6 +486,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
481
486
  }
482
487
 
483
488
  const holderId = `rig-verification:${dependencies.randomUUID()}`;
489
+ const sandboxGroupId = dependencies.randomUUID();
484
490
  const fallbackController = new AbortController();
485
491
  const signal = input.lifecycle?.signal ?? fallbackController.signal;
486
492
  const commandController = dependencies.createCancellationController(signal);
@@ -527,7 +533,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
527
533
  dependencies.markWarmLost(input.db, {
528
534
  accountId: input.accountId,
529
535
  workspaceId: input.workspaceId,
530
- sandboxGroupId: input.sandboxGroupId,
536
+ sandboxGroupId,
531
537
  expectedEpoch: cleanupEpoch + 1,
532
538
  expectedInstanceId: instanceId,
533
539
  }),
@@ -536,7 +542,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
536
542
  dependencies.failWarming(input.db, {
537
543
  accountId: input.accountId,
538
544
  workspaceId: input.workspaceId,
539
- sandboxGroupId: input.sandboxGroupId,
545
+ sandboxGroupId,
540
546
  expectedEpoch: cleanupEpoch,
541
547
  }),
542
548
  ),
@@ -576,7 +582,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
576
582
  const lease = await dependencies.acquire(input.db, {
577
583
  accountId: input.accountId,
578
584
  workspaceId: input.workspaceId,
579
- sandboxGroupId: input.sandboxGroupId,
585
+ sandboxGroupId,
580
586
  kind: "turn",
581
587
  holderId,
582
588
  subjectId: null,
@@ -595,7 +601,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
595
601
  .touchHolder(input.db, {
596
602
  accountId: input.accountId,
597
603
  workspaceId: input.workspaceId,
598
- sandboxGroupId: input.sandboxGroupId,
604
+ sandboxGroupId,
599
605
  kind: "turn",
600
606
  holderId,
601
607
  })
@@ -605,7 +611,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
605
611
  holderLivenessTimer.unref();
606
612
  }
607
613
  if (lease.role !== "spawner") {
608
- throw new RigVerificationLeaseUnavailableError(input.sandboxGroupId, lease.role);
614
+ throw new RigVerificationLeaseUnavailableError(sandboxGroupId, lease.role);
609
615
  }
610
616
  ownsWarmingEpoch = true;
611
617
 
@@ -616,7 +622,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
616
622
  createIdentity: {
617
623
  accountId: input.accountId,
618
624
  workspaceId: input.workspaceId,
619
- sandboxGroupId: input.sandboxGroupId,
625
+ sandboxGroupId,
620
626
  },
621
627
  environment: {},
622
628
  onSandboxCreated: async (created) => {
@@ -628,7 +634,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
628
634
  const recorded = await dependencies.recordCreated(input.db, {
629
635
  accountId: input.accountId,
630
636
  workspaceId: input.workspaceId,
631
- sandboxGroupId: input.sandboxGroupId,
637
+ sandboxGroupId,
632
638
  expectedEpoch: lease.lease.leaseEpoch,
633
639
  instanceId: created.instanceId,
634
640
  resumeBackendId: created.backendId,
@@ -637,7 +643,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
637
643
  warmingLeaseTtlMs: RIG_VERIFICATION_OWNER_TTL_MS,
638
644
  });
639
645
  if (!recorded.recorded) {
640
- throw new RigVerificationLeaseUnavailableError(input.sandboxGroupId, "fenced");
646
+ throw new RigVerificationLeaseUnavailableError(sandboxGroupId, "fenced");
641
647
  }
642
648
 
643
649
  if (created.backendId === "modal" && !signal.aborted) {
@@ -646,7 +652,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
646
652
  dependencies.tag(input.settings, created.instanceId, {
647
653
  leaseId: lease.lease.id,
648
654
  workspaceId: input.workspaceId,
649
- sandboxGroupId: input.sandboxGroupId,
655
+ sandboxGroupId,
650
656
  }),
651
657
  signal,
652
658
  );
@@ -694,7 +700,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
694
700
  const committed = await dependencies.commitWarm(input.db, {
695
701
  accountId: input.accountId,
696
702
  workspaceId: input.workspaceId,
697
- sandboxGroupId: input.sandboxGroupId,
703
+ sandboxGroupId,
698
704
  expectedEpoch: lease.lease.leaseEpoch,
699
705
  instanceId: established.instanceId,
700
706
  dataPlaneUrl: null,
@@ -703,7 +709,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
703
709
  leaseTtlMs: RIG_VERIFICATION_OWNER_TTL_MS,
704
710
  });
705
711
  if (!committed.committed || !committed.lease) {
706
- throw new RigVerificationLeaseUnavailableError(input.sandboxGroupId, "fenced");
712
+ throw new RigVerificationLeaseUnavailableError(sandboxGroupId, "fenced");
707
713
  }
708
714
  const result = await run(established, {
709
715
  signal,
@@ -759,7 +765,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
759
765
  await dependencies.failWarming(input.db, {
760
766
  accountId: input.accountId,
761
767
  workspaceId: input.workspaceId,
762
- sandboxGroupId: input.sandboxGroupId,
768
+ sandboxGroupId,
763
769
  expectedEpoch,
764
770
  });
765
771
  }
@@ -790,7 +796,7 @@ export async function runWithOwnedRigVerificationSandbox<T>(
790
796
  dependencies.releaseHolder(input.db, {
791
797
  accountId: input.accountId,
792
798
  workspaceId: input.workspaceId,
793
- sandboxGroupId: input.sandboxGroupId,
799
+ sandboxGroupId,
794
800
  kind: "turn",
795
801
  holderId,
796
802
  idleGraceMs: RIG_VERIFICATION_RELEASE_GRACE_MS,
@@ -950,7 +956,6 @@ export async function verifyRigProviderImageColdBoot(
950
956
  observability: ControlActivityServices["observability"];
951
957
  accountId: string;
952
958
  workspaceId: string;
953
- buildRequestId: string;
954
959
  rigVersionId: string;
955
960
  sessionIdPrefix: string;
956
961
  imageId: string;
@@ -974,7 +979,6 @@ export async function verifyRigProviderImageColdBoot(
974
979
  observability: input.observability,
975
980
  accountId: input.accountId,
976
981
  workspaceId: input.workspaceId,
977
- sandboxGroupId: input.buildRequestId,
978
982
  rigVersionId: input.rigVersionId,
979
983
  sessionIdPrefix: input.sessionIdPrefix,
980
984
  lifecycle: input.lifecycle,
@@ -1210,7 +1214,6 @@ export async function buildVerifiedRigProviderImage(input: {
1210
1214
  observability: input.observability,
1211
1215
  accountId: input.accountId,
1212
1216
  workspaceId: input.workspaceId,
1213
- buildRequestId: building.buildRequestId,
1214
1217
  rigVersionId: input.target.id,
1215
1218
  sessionIdPrefix: `rig-provider-image-${input.target.id}`,
1216
1219
  imageId: built.imageId,
@@ -1394,7 +1397,6 @@ export function createRigVerificationActivities(services: () => Promise<ControlA
1394
1397
  observability,
1395
1398
  accountId: rig.accountId,
1396
1399
  workspaceId: input.workspaceId,
1397
- sandboxGroupId: change.id,
1398
1400
  rigVersionId: candidateVersion.id,
1399
1401
  sessionIdPrefix: `rig-verification-${change.id}`,
1400
1402
  lifecycle,
@@ -1588,7 +1590,6 @@ export function createRigVerificationActivities(services: () => Promise<ControlA
1588
1590
  observability,
1589
1591
  accountId: rig.accountId,
1590
1592
  workspaceId: input.workspaceId,
1591
- sandboxGroupId: version.id,
1592
1593
  rigVersionId: version.id,
1593
1594
  sessionIdPrefix: `rig-version-verification-${version.id}`,
1594
1595
  lifecycle,
@@ -42,6 +42,7 @@ import {
42
42
  validProviderOverloadRecoveryDelay,
43
43
  } from "./agent-turn/provider-recovery-policy";
44
44
  import { writeSessionUsageReceipts } from "./agent-turn/session-usage-custody";
45
+ import { resolveWorkerShutdownTiming } from "../worker-shutdown";
45
46
  import type {
46
47
  ControlActivityServices,
47
48
  ExpireSessionHumanInputInput,
@@ -506,7 +507,7 @@ export function createSessionStateActivities(
506
507
  async function reconcileSessionAttemptQuiescenceActivity(
507
508
  input: ReconcileSessionAttemptQuiescenceInput,
508
509
  ): Promise<ReconcileSessionAttemptQuiescenceResult> {
509
- const { db, bus, inspectSessionAttemptActivity } = await services();
510
+ const { db, bus, inspectSessionAttemptActivity, settings } = await services();
510
511
  const activityRef = await getSessionAttemptActivityRefFn(db, {
511
512
  ...input,
512
513
  temporalWorkflowId: input.workflowId,
@@ -526,6 +527,9 @@ export function createSessionStateActivities(
526
527
  temporalWorkflowRunId: activityRef.workflowRunId,
527
528
  temporalActivityId: activityRef.activityId,
528
529
  activitySettled: true,
530
+ // A worker-shutdown closure's process has exited once this has passed.
531
+ workerProcessExitDeadlineMs: resolveWorkerShutdownTiming("turn", settings)
532
+ .processExitDeadlineMs,
529
533
  });
530
534
  if (result.events.length > 0) {
531
535
  await publishDurableSessionEventsFn(
@@ -75,6 +75,19 @@ export type StartRecordingWorkflow = (input: {
75
75
  ownerSubjectId: string;
76
76
  }) => Promise<"started" | "already_running">;
77
77
 
78
+ /**
79
+ * Start the clean-replay verification that rebuilds a sandbox environment
80
+ * version's provider image for the deployment's current base image. The
81
+ * start is deduplicated per version, expected content and UTC day, so every
82
+ * turn that meets the stale image may ask without starting more than one
83
+ * rebuild a day.
84
+ */
85
+ export type StartRigProviderImageRefresh = (input: {
86
+ workspaceId: string;
87
+ versionId: string;
88
+ contentHash: string;
89
+ }) => Promise<"started" | "already_running">;
90
+
78
91
  /** Exact activity-owned proof that the hard sandbox/tool fence physically
79
92
  * drained. This is delivery evidence only: the workflow still validates the
80
93
  * persisted attempt dispatch and commits the authoritative Postgres receipt. */
@@ -124,6 +137,7 @@ export type SharedActivityServices = {
124
137
  startVideoGenerationWorkflow?: StartVideoGenerationWorkflow | null;
125
138
  startSessionTitleWorkflow?: StartSessionTitleWorkflow | null;
126
139
  startRecordingWorkflow?: StartRecordingWorkflow | null;
140
+ startRigProviderImageRefresh?: StartRigProviderImageRefresh | null;
127
141
  // §7.5 P3 — host-entitlements port, the WORKER half of the same seam the API
128
142
  // edge exposes on `AppDependencies`. When set, `ensureRunAllowed` (turn-entry
129
143
  // AND the mid-stream budget valve) delegates the funding decision to
@@ -99,6 +99,7 @@ export function createSharedActivityServices(
99
99
  startSandboxReaperWorkflow: dependencies.startSandboxReaperWorkflow ?? null,
100
100
  startVideoGenerationWorkflow: dependencies.startVideoGenerationWorkflow ?? null,
101
101
  startRecordingWorkflow: dependencies.startRecordingWorkflow ?? null,
102
+ startRigProviderImageRefresh: dependencies.startRigProviderImageRefresh ?? null,
102
103
  startSessionTitleWorkflow: environmentsEncryptionKeyBytes(settings)
103
104
  ? (dependencies.startSessionTitleWorkflow ?? null)
104
105
  : null,
package/src/index.ts CHANGED
@@ -54,10 +54,12 @@ import type {
54
54
  StartSandboxReaperWorkflow,
55
55
  StartVideoGenerationWorkflow,
56
56
  StartRecordingWorkflow,
57
+ StartRigProviderImageRefresh,
57
58
  StartSessionTitleWorkflow,
58
59
  WakeSessionWorkflowSignal,
59
60
  } from "./activities/types";
60
61
  import { turnTaskQueue } from "./workflows/activities";
62
+ import { rigProviderImageRefreshWorkflowId } from "./activities/rig-provider-image-refresh";
61
63
  import { createTurnTaskQueueStatsClient } from "./turn-task-queue-reader";
62
64
  import { installTemporalRuntimeLogging } from "./temporal-runtime-logger";
63
65
  import {
@@ -468,6 +470,7 @@ export async function createWorkerWorkflowSignaler(
468
470
  startVideoGenerationWorkflow: StartVideoGenerationWorkflow;
469
471
  startSessionTitleWorkflow: StartSessionTitleWorkflow;
470
472
  startRecordingWorkflow: StartRecordingWorkflow;
473
+ startRigProviderImageRefresh: StartRigProviderImageRefresh;
471
474
  check: () => Promise<void>;
472
475
  close: () => Promise<void>;
473
476
  }> {
@@ -680,6 +683,23 @@ export async function createWorkerWorkflowSignaler(
680
683
  throw error;
681
684
  }
682
685
  },
686
+ startRigProviderImageRefresh: async ({ workspaceId, versionId, contentHash }) => {
687
+ try {
688
+ await temporal.workflow.start("rigVerificationWorkflow", {
689
+ taskQueue: settings.temporalTaskQueue,
690
+ workflowId: rigProviderImageRefreshWorkflowId({ versionId, contentHash }),
691
+ // One automatic attempt per version, content and day. A failed
692
+ // rebuild is not retried by every following turn; the next day or
693
+ // an explicit verify tries again.
694
+ workflowIdReusePolicy: "REJECT_DUPLICATE",
695
+ args: [{ workspaceId, versionId }],
696
+ });
697
+ return "started";
698
+ } catch (error) {
699
+ if (error instanceof WorkflowExecutionAlreadyStartedError) return "already_running";
700
+ throw error;
701
+ }
702
+ },
683
703
  check: async () => {
684
704
  await connection.workflowService.getSystemInfo({});
685
705
  },
@@ -904,6 +924,11 @@ export async function createOpenGeniWorkerService(
904
924
  options.activityDependencies.startSessionTitleWorkflow ?? signaler?.startSessionTitleWorkflow;
905
925
  const startRecordingWorkflow =
906
926
  options.activityDependencies.startRecordingWorkflow ?? signaler?.startRecordingWorkflow;
927
+ // Optional: hosts without a Temporal client simply skip automatic rebuilds.
928
+ const startRigProviderImageRefresh =
929
+ options.activityDependencies.startRigProviderImageRefresh ??
930
+ signaler?.startRigProviderImageRefresh ??
931
+ null;
907
932
  if (
908
933
  !wakeSessionWorkflow ||
909
934
  !signalSessionAttemptQuiesced ||
@@ -933,6 +958,7 @@ export async function createOpenGeniWorkerService(
933
958
  startVideoGenerationWorkflow,
934
959
  startSessionTitleWorkflow,
935
960
  startRecordingWorkflow,
961
+ startRigProviderImageRefresh,
936
962
  requestWorkerDrain: () => {
937
963
  if (!cleanupContainment) throw new Error("worker cleanup containment is not initialized");
938
964
  cleanupContainment.request();