@opengeni/worker-bundle 0.12.7 → 0.13.4

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 (72) hide show
  1. package/dist/activities/agent-turn.d.ts +778 -0
  2. package/dist/activities/capabilities.d.ts +18 -0
  3. package/dist/activities/codex-auth.d.ts +1 -0
  4. package/dist/activities/codex-capacity.d.ts +31 -0
  5. package/dist/activities/codex-fleet-shadow.d.ts +74 -0
  6. package/dist/activities/codex-rotation.d.ts +261 -0
  7. package/dist/activities/common.d.ts +17 -0
  8. package/dist/activities/context-compaction.d.ts +81 -0
  9. package/dist/activities/documents.d.ts +39 -0
  10. package/dist/activities/environment.d.ts +97 -0
  11. package/dist/activities/expiring-material-renewal.d.ts +38 -0
  12. package/dist/activities/file-upload-reaper.d.ts +25 -0
  13. package/dist/activities/git-credential-renewal.d.ts +41 -0
  14. package/dist/activities/goals.d.ts +16 -0
  15. package/dist/activities/mcp-credentials.d.ts +14 -0
  16. package/dist/activities/packs.d.ts +77 -0
  17. package/dist/activities/parent-wake.d.ts +54 -0
  18. package/dist/activities/recording.d.ts +90 -0
  19. package/dist/activities/redaction.d.ts +1 -0
  20. package/dist/activities/rig-verification.d.ts +131 -0
  21. package/dist/activities/run-credential-renewal.d.ts +28 -0
  22. package/dist/activities/run-credentials.d.ts +36 -0
  23. package/dist/activities/run-input.d.ts +106 -0
  24. package/dist/activities/sandbox-lease.d.ts +128 -0
  25. package/dist/activities/scheduled-tasks.d.ts +4 -0
  26. package/dist/activities/session-state.d.ts +39 -0
  27. package/dist/activities/streaming.d.ts +24 -0
  28. package/dist/activities/toolspace-token-renewal.d.ts +23 -0
  29. package/dist/activities/turn-attempt-fenced.d.ts +11 -0
  30. package/dist/activities/types.d.ts +240 -0
  31. package/dist/activities/workflow-wake.d.ts +15 -0
  32. package/dist/activities/workspace-capture.d.ts +105 -0
  33. package/dist/activities.d.ts +312 -0
  34. package/dist/concurrency.d.ts +19 -0
  35. package/dist/host-export-pump.d.ts +66 -0
  36. package/dist/host-export.d.ts +6 -67
  37. package/dist/http.d.ts +32 -0
  38. package/dist/index.d.ts +27 -388
  39. package/dist/index.js +2730 -1211
  40. package/dist/index.js.map +1 -1
  41. package/dist/observability-metrics.d.ts +200 -0
  42. package/dist/op-journal.d.ts +10 -0
  43. package/dist/sandbox-resume.d.ts +152 -0
  44. package/dist/sandbox-routing.d.ts +159 -0
  45. package/dist/worker-service-lifecycle.d.ts +20 -0
  46. package/dist/workflow-bundle.js +88 -20
  47. package/dist/workflows/activities.d.ts +27 -0
  48. package/dist/workflows/document-index.d.ts +41 -0
  49. package/dist/workflows/file-upload-reaper.d.ts +2 -0
  50. package/dist/workflows/rig-verification.d.ts +3 -0
  51. package/dist/workflows/sandbox-reaper.d.ts +1 -0
  52. package/dist/workflows/scheduled-tasks.d.ts +17 -0
  53. package/dist/workflows/session.d.ts +58 -0
  54. package/dist/workflows/workflow-wake.d.ts +3 -0
  55. package/dist/workflows.d.ts +7 -0
  56. package/package.json +13 -13
  57. package/src/activities/agent-turn.ts +874 -134
  58. package/src/activities/context-compaction.ts +265 -76
  59. package/src/activities/environment.ts +1 -0
  60. package/src/activities/goals.ts +14 -0
  61. package/src/activities/rig-verification.ts +2 -0
  62. package/src/activities/run-input.ts +18 -4
  63. package/src/activities/sandbox-lease.ts +787 -133
  64. package/src/activities/session-state.ts +56 -0
  65. package/src/activities/types.ts +21 -0
  66. package/src/activities/workspace-capture.ts +95 -4
  67. package/src/activities.ts +3 -0
  68. package/src/observability-metrics.ts +94 -0
  69. package/src/sandbox-resume.ts +383 -90
  70. package/src/sandbox-routing.ts +32 -10
  71. package/src/workflows/activities.ts +1 -0
  72. package/src/workflows/session.ts +70 -0
@@ -0,0 +1,38 @@
1
+ export type ExpiringMaterialRenewalPolicy = {
2
+ defaultRefreshMs: number;
3
+ expiryLeadMs: number;
4
+ minRefreshMs: number;
5
+ maxRetryMs: number;
6
+ };
7
+ type RenewalTimer = unknown;
8
+ export type ExpiringMaterialRenewalController = {
9
+ refreshNow(): Promise<void>;
10
+ stop(): Promise<void>;
11
+ };
12
+ export type ExpiringMaterialRenewalOptions<T> = {
13
+ initialExpiresAt: Date | null;
14
+ resolve: () => Promise<T>;
15
+ write: (material: T) => Promise<void>;
16
+ expiresAt: (material: T) => Date | null;
17
+ policy: ExpiringMaterialRenewalPolicy;
18
+ now?: () => number;
19
+ schedule?: (callback: () => void, delayMs: number) => RenewalTimer;
20
+ clearSchedule?: (timer: RenewalTimer) => void;
21
+ onSuccess?: (result: {
22
+ material: T;
23
+ nextDelayMs: number;
24
+ }) => void;
25
+ onFailure?: (failure: {
26
+ retryDelayMs: number;
27
+ errorClass: string;
28
+ }) => void;
29
+ };
30
+ export declare function nextExpiringMaterialRenewalDelay(expiresAt: Date | null, policy: ExpiringMaterialRenewalPolicy, nowMs?: number): number;
31
+ /**
32
+ * Attempt-owned single-flight renewal for expiring sandbox material.
33
+ *
34
+ * A late resolver cannot write after stop. A physical sandbox write that already
35
+ * started is drained so turn settlement cannot race a stale mutation.
36
+ */
37
+ export declare function startExpiringMaterialRenewalLoop<T>(options: ExpiringMaterialRenewalOptions<T>): ExpiringMaterialRenewalController;
38
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { ObjectStorage } from "@opengeni/storage";
2
+ import type { ActivityServices } from "./types";
3
+ export declare const FILE_UPLOAD_CLEANUP_GRACE_MS: number;
4
+ export declare const FILE_UPLOAD_CLEANUP_CLAIM_TIMEOUT_MS: number;
5
+ export declare const FILE_UPLOAD_CLEANUP_BATCH_SIZE = 100;
6
+ export type ReapExpiredFileUploadsResult = {
7
+ claimed: number;
8
+ deleted: number;
9
+ failed: number;
10
+ };
11
+ export type FileUploadReaperActivityOptions = {
12
+ graceMs?: number;
13
+ claimTimeoutMs?: number;
14
+ batchSize?: number;
15
+ /** Failure-injection seam; production uses the configured provider delete. */
16
+ deleteObject?: (storage: ObjectStorage, key: string) => Promise<void>;
17
+ };
18
+ /**
19
+ * Build the provider-neutral expired direct-upload reaper. Claims are durable
20
+ * and reclaimable; object deletion is idempotent; only a successful delete is
21
+ * settled terminally. One provider failure never aborts the rest of the batch.
22
+ */
23
+ export declare function createFileUploadReaperActivities(services: () => Promise<ActivityServices>, options?: FileUploadReaperActivityOptions): {
24
+ reapExpiredFileUploads: () => Promise<ReapExpiredFileUploadsResult>;
25
+ };
@@ -0,0 +1,41 @@
1
+ import type { GitCredentialProvider } from "@opengeni/contracts";
2
+ import type { GitTokenExpiries, GitTokenSeeds, MintedRunGitCredentials } from "./environment";
3
+ export declare const GIT_CREDENTIAL_DEFAULT_REFRESH_MS: number;
4
+ export declare const GIT_CREDENTIAL_EXPIRY_LEAD_MS: number;
5
+ export declare const GIT_CREDENTIAL_MIN_REFRESH_MS = 5000;
6
+ export declare const GIT_CREDENTIAL_MAX_RETRY_MS: number;
7
+ type RenewalTimer = unknown;
8
+ export type GitCredentialRenewalResult = {
9
+ providers: readonly GitCredentialProvider[];
10
+ nextDelayMs: number;
11
+ };
12
+ export type GitCredentialRenewalFailure = {
13
+ providers: readonly GitCredentialProvider[];
14
+ retryDelayMs: number;
15
+ errorClass: string;
16
+ };
17
+ export type GitCredentialRenewalController = {
18
+ refreshNow(): Promise<void>;
19
+ stop(): Promise<void>;
20
+ };
21
+ export type GitCredentialRenewalOptions = {
22
+ expectedProviders: readonly GitCredentialProvider[];
23
+ initialExpiresAt?: GitTokenExpiries;
24
+ mint: () => Promise<MintedRunGitCredentials | undefined>;
25
+ write: (tokens: GitTokenSeeds) => Promise<void>;
26
+ now?: () => number;
27
+ schedule?: (callback: () => void, delayMs: number) => RenewalTimer;
28
+ clearSchedule?: (timer: RenewalTimer) => void;
29
+ onSuccess?: (result: GitCredentialRenewalResult) => void;
30
+ onFailure?: (failure: GitCredentialRenewalFailure) => void;
31
+ };
32
+ /**
33
+ * Return a conservative refresh delay for a provider set.
34
+ *
35
+ * The fixed cadence caps long/unknown provider TTLs; a known earlier expiry
36
+ * pulls renewal forward. Invalid metadata is treated as unknown rather than
37
+ * allowing a token to live indefinitely.
38
+ */
39
+ export declare function nextGitCredentialRenewalDelay(expiresAt: GitTokenExpiries | undefined, providers: readonly GitCredentialProvider[], nowMs?: number): number;
40
+ export declare function startGitCredentialRenewalLoop(options: GitCredentialRenewalOptions): GitCredentialRenewalController;
41
+ export {};
@@ -0,0 +1,16 @@
1
+ import { type Settings } from "@opengeni/config";
2
+ import { type SessionGoal, type ToolRef } from "@opengeni/contracts";
3
+ import type { ActivityServices, MaybeContinueGoalInput, MaybeContinueGoalResult } from "./types";
4
+ export declare function createGoalActivities(services: () => Promise<ActivityServices>): {
5
+ enqueueGoalRetryWake: (input: MaybeContinueGoalInput) => Promise<void>;
6
+ maybeContinueGoal: (input: MaybeContinueGoalInput) => Promise<MaybeContinueGoalResult>;
7
+ };
8
+ export declare function goalContinuationPrompt(goal: SessionGoal, autoContinuation: number, cap: number | null): string;
9
+ /**
10
+ * Ensures a session/turn carries the first-party "opengeni" MCP server, which
11
+ * hosts set_session_title, the goal tools, and the permission-gated
12
+ * orchestration/environment/github tools. Attached to EVERY session/turn (not
13
+ * just goal-bearing ones); built-in tool refs are not auto-added to empty tool
14
+ * lists anywhere else in the pipeline. No-op when the server is not configured.
15
+ */
16
+ export declare function withFirstPartyTools(settings: Settings, tools: ToolRef[]): ToolRef[];
@@ -0,0 +1,14 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import type { ConnectionCredentialsPort, SessionTurn } from "@opengeni/contracts";
3
+ import { type Database, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult } from "@opengeni/db";
4
+ export declare function connectionTokenResolverForTurn(input: {
5
+ db: Database;
6
+ settings: Settings;
7
+ connectionCredentials?: ConnectionCredentialsPort | null;
8
+ accountId: string;
9
+ workspaceId: string;
10
+ sessionId: string;
11
+ rootSessionId: string;
12
+ attemptId: string;
13
+ turn: SessionTurn;
14
+ }): (request: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
@@ -0,0 +1,77 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import { CapabilityPack } from "@opengeni/contracts";
3
+ import { type Database } from "@opengeni/db";
4
+ import { type EffectiveSkillSelection, type PackSkill } from "@opengeni/runtime";
5
+ /**
6
+ * The pack-scoped runtime for a workspace: the sandbox image its sessions run
7
+ * in (when an enabled pack declares one) and the pack skills that join the
8
+ * sandbox skill index.
9
+ */
10
+ export type WorkspacePackRuntime = {
11
+ sandboxImage: string | null;
12
+ skills: PackSkill[];
13
+ };
14
+ export type WorkspaceSkillLibraryRuntime = {
15
+ skillLibrarySkills: PackSkill[];
16
+ skillLibrarySelections: EffectiveSkillSelection[];
17
+ };
18
+ /**
19
+ * Resolves the pack-scoped runtime from the workspace's active pack
20
+ * installations. Only registered (manifest-backed) packs can contribute a
21
+ * sandbox image or skills; built-in packs never declare either (enforced by a
22
+ * test on the built-in catalog), so their installations are skipped here
23
+ * without consulting the API's built-in pack list.
24
+ */
25
+ export declare function resolveWorkspacePackRuntime(db: Database, workspaceId: string): Promise<WorkspacePackRuntime>;
26
+ /**
27
+ * Resolves active immutable curated skills separately from pack skills. The
28
+ * capability installation is the workspace selection boundary; it carries
29
+ * only secret-free exact identity metadata, and the runtime loader verifies
30
+ * the pinned artifact hash before any content is materialized.
31
+ */
32
+ export declare function resolveWorkspaceSkillLibraryRuntime(db: Database, workspaceId: string): Promise<WorkspaceSkillLibraryRuntime>;
33
+ /**
34
+ * Pure composition rule for enabled pack manifests. v1 keeps this small by
35
+ * design: at most one enabled pack may declare a sandbox image (no image
36
+ * layering or composition), and skill names must be unique across enabled
37
+ * packs. Violations fail the turn with a plain error instead of guessing.
38
+ */
39
+ export declare function workspacePackRuntimeFromPacks(packs: CapabilityPack[]): WorkspacePackRuntime;
40
+ /**
41
+ * Resolves the per-workspace agent persona override (the white-label surface).
42
+ * Returns the workspace's stored template when set, else null to mean "use the
43
+ * deployment default" (settings.agentInstructionsTemplate). The runtime always
44
+ * injects the non-bypassable CORE regardless, so a null here keeps the
45
+ * byte-identical default and a non-null value only restyles the persona.
46
+ *
47
+ * This is the workspace tier of the session > workspace > deployment-default
48
+ * resolution; per-session overrides do not exist in this slice, so the worker
49
+ * resolves workspace > default and passes the result as instructionsTemplate.
50
+ */
51
+ export declare function resolveWorkspaceAgentInstructions(db: Database, workspaceId: string): Promise<string | null>;
52
+ /**
53
+ * Applies a pack-declared sandbox image to run settings. With no pack image
54
+ * the settings pass through untouched, so deployments without packs keep the
55
+ * global OPENGENI_DOCKER_IMAGE / OPENGENI_MODAL_IMAGE_REF behavior exactly.
56
+ */
57
+ export declare function settingsWithPackSandboxImage(settings: Settings, sandboxImage: string | null): Settings;
58
+ /**
59
+ * Applies the session's frozen rig-version image to run settings. Rig image is
60
+ * the TOP of the image precedence chain (rig > pack > deployment default): when
61
+ * the rig version pins an image it OVERRIDES both the deployment
62
+ * dockerImage/modalImageRef AND any pack-declared sandboxImage. When the rig
63
+ * pins no image (`null`), the settings pass through untouched so the pack /
64
+ * deployment chain below still resolves exactly as today. Applied AFTER
65
+ * settingsWithPackSandboxImage so it wins the collision; identical mechanics to
66
+ * the pack equivalent (write both image fields so docker and modal agree).
67
+ */
68
+ export declare function settingsWithRigImage(settings: Settings, rigImage: string | null): Settings;
69
+ /**
70
+ * Layers the rig version's default variable sets BELOW the session's own set:
71
+ * the session's values WIN on any key collision (explicit precedence). Both maps
72
+ * are already the decrypted-and-merged values (rig defaults merged in listed
73
+ * order upstream). Pure and deterministic — given the same inputs it returns the
74
+ * same env, which is what keeps a session's box-manifest env stable across turns
75
+ * (the rig version is frozen per session, so its default-set list is fixed).
76
+ */
77
+ export declare function mergeRigDefaultVariableSetEnvironment(rigDefaultValues: Record<string, string>, sessionValues: Record<string, string>): Record<string, string>;
@@ -0,0 +1,54 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import type { Session, SessionGoal } from "@opengeni/contracts";
3
+ import { claimPendingSessionSystemUpdateOutbox, claimPendingSessionWorkflowWakes, type Database } from "@opengeni/db";
4
+ import type { EventBus } from "@opengeni/events";
5
+ import type { ActivityServices, WakeSessionWorkflowSignal } from "./types";
6
+ export type NotifyServices = {
7
+ db: Database;
8
+ bus: EventBus;
9
+ settings: Settings;
10
+ observability: ActivityServices["observability"];
11
+ wakeSessionWorkflow: WakeSessionWorkflowSignal | null;
12
+ };
13
+ export type ReconcileParentSystemUpdateOverrides = Partial<{
14
+ claimPendingSessionSystemUpdateOutbox: typeof claimPendingSessionSystemUpdateOutbox;
15
+ }>;
16
+ export type ReconcileSessionWorkflowWakeOverrides = Partial<{
17
+ claimPendingSessionWorkflowWakes: typeof claimPendingSessionWorkflowWakes;
18
+ }>;
19
+ /**
20
+ * Enrich and deliver the durable idle-boundary row committed by
21
+ * settleSessionIdleWithParentOutbox. Idle has no single owning turn, so its
22
+ * stable episode identity is the newest non-status event sequence.
23
+ */
24
+ export declare function notifyParentOfChildIdle(svc: NotifyServices, workspaceId: string, childSessionId: string, episodeKey: string): Promise<void>;
25
+ /**
26
+ * Deliver the exact failure row already committed by turn settlement. This
27
+ * layer deliberately cannot create or rewrite the row: the settlement
28
+ * transaction is the sole owner of the failed turn id, payload, and lineage.
29
+ */
30
+ export declare function deliverFailedChildTurnToParent(svc: NotifyServices, workspaceId: string, childSessionId: string, turnId: string): Promise<void>;
31
+ export declare function reconcilePendingParentSystemUpdates(svc: NotifyServices, limit?: number, overrides?: ReconcileParentSystemUpdateOverrides): Promise<{
32
+ claimed: number;
33
+ delivered: number;
34
+ failed: number;
35
+ }>;
36
+ export declare function reconcilePendingSessionWorkflowWakes(svc: NotifyServices, limit?: number, overrides?: ReconcileSessionWorkflowWakeOverrides): Promise<{
37
+ claimed: number;
38
+ delivered: number;
39
+ failed: number;
40
+ }>;
41
+ /**
42
+ * The worker-specific lines for one child (what happened + its goal), WITHOUT
43
+ * the trailing "what to do next" instruction. Kept separate so N child
44
+ * completions can be coalesced into one internal-update inference: the DB layer
45
+ * stores each child's summary and rebuilds a single numbered digest with one
46
+ * shared trailing instruction instead of running N model calls.
47
+ */
48
+ export declare function childCompletionSummary(child: Session, goal: SessionGoal | null, terminalStatus: "idle" | "failed"): string;
49
+ /**
50
+ * The single trailing instruction appended to a child-completion (or digest)
51
+ * inference. Suppresses the "resume it now" nudge when the manager's own goal
52
+ * was paused by the user (paired with the goal_set reactivation guard).
53
+ */
54
+ export declare function childCompletionTrailing(parentGoalUserPaused: boolean): string;
@@ -0,0 +1,90 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import type { Database } from "@opengeni/db";
3
+ import type { RecordingFailedReason, RecordingStartedPayload } from "@opengeni/contracts";
4
+ import { type RecordingProcess } from "@opengeni/runtime";
5
+ import type { ObjectStorage } from "@opengeni/storage";
6
+ import { DOWNLOAD_URL_TTL_SECONDS } from "@opengeni/storage";
7
+ export type RecordingMode = "manual" | "on-turn" | "on-verify";
8
+ export type ActiveRecording = {
9
+ recordingId: string;
10
+ turnId: string | null;
11
+ mode: RecordingMode;
12
+ proc: RecordingProcess;
13
+ dimensions: [number, number];
14
+ framerate: number;
15
+ };
16
+ export declare const RECORDING_SETTLEMENT_PREP_TIMEOUT_MS = 100000;
17
+ export declare function withRecordingPreparationTimeout(preparation: Promise<PreparedRecordingSettlement>, timeoutResult: PreparedRecordingSettlement, timeoutMs?: number): Promise<PreparedRecordingSettlement>;
18
+ /**
19
+ * Insert the recording row, launch ffmpeg on the box, and return the live handle.
20
+ * Emits the `recording.started` payload (the caller publishes it on the spine).
21
+ */
22
+ export declare function beginRecording(args: {
23
+ settings: Settings;
24
+ db: Database;
25
+ accountId: string;
26
+ workspaceId: string;
27
+ sessionId: string;
28
+ turnId: string | null;
29
+ recordingId: string;
30
+ mode: RecordingMode;
31
+ session: unknown;
32
+ runAs?: string | undefined;
33
+ reason?: string | null;
34
+ }): Promise<{
35
+ active: ActiveRecording;
36
+ started: RecordingStartedPayload;
37
+ }>;
38
+ export type PreparedRecordingSettlement = {
39
+ mutation: {
40
+ action: "available";
41
+ recordingId: string;
42
+ storageKey: string;
43
+ sizeBytes: number;
44
+ durationSeconds: number;
45
+ };
46
+ deleteArtifactsAfterCommit: true;
47
+ } | {
48
+ mutation: {
49
+ action: "failed";
50
+ recordingId: string;
51
+ reason: RecordingFailedReason;
52
+ detail: string | null;
53
+ };
54
+ deleteArtifactsAfterCommit: false;
55
+ } | {
56
+ mutation: {
57
+ action: "discard";
58
+ recordingId: string;
59
+ };
60
+ deleteArtifactsAfterCommit: true;
61
+ };
62
+ /**
63
+ * Prepare an on-turn recording for the attempt-closing settlement. This performs
64
+ * only bounded box/storage work; it does not mutate canonical database state and
65
+ * never deletes the box artifact. The caller folds the returned mutation into the
66
+ * exact attempt-fenced turn settlement, then deletes artifacts only after commit.
67
+ * NEVER throws and never prevents turn truth from settling.
68
+ */
69
+ export declare function prepareRecordingForSettlement(args: {
70
+ settings: Settings;
71
+ objectStorage: ObjectStorage | null;
72
+ workspaceId: string;
73
+ sessionId: string;
74
+ active: ActiveRecording;
75
+ session: unknown;
76
+ didComputerUse: boolean;
77
+ }): Promise<PreparedRecordingSettlement>;
78
+ /**
79
+ * Compensate a start whose fenced `recording.started` event was rejected. Since
80
+ * no canonical event was admitted, this exact recording id must leave no row,
81
+ * process, or box artifact behind.
82
+ */
83
+ export declare function discardUnpublishedRecording(args: {
84
+ db: Database;
85
+ accountId: string;
86
+ workspaceId: string;
87
+ active: ActiveRecording;
88
+ session: unknown;
89
+ }): Promise<void>;
90
+ export { DOWNLOAD_URL_TTL_SECONDS };
@@ -0,0 +1 @@
1
+ export { createSecretRedactor, identityRedactor, isCredentialHeaderName, redactSensitiveData, redactSensitiveText, redactSerializedJson, type SecretForRedaction, } from "@opengeni/contracts";
@@ -0,0 +1,131 @@
1
+ import { acquireLease, commitWarmingToWarm, failWarmingToCold, markWarmLeaseInstanceLost, recordWarmingSandboxCreated, releaseLeaseHolder, touchLeaseHolder, type Database } from "@opengeni/db";
2
+ import { createTurnToolCancellationController, establishSandboxSessionFromEnvelope, serializeEstablishedSandboxEnvelope, tagModalSandbox, type EstablishedSandboxSession, type SandboxLifecycleCommandRunner } from "@opengeni/runtime";
3
+ import type { Context } from "@temporalio/activity";
4
+ import type { ActivityServices } from "./types";
5
+ export type RigVerificationWorkflowInput = {
6
+ workspaceId: string;
7
+ changeId: string;
8
+ versionId?: never;
9
+ } | {
10
+ workspaceId: string;
11
+ versionId: string;
12
+ changeId?: never;
13
+ };
14
+ export declare const RIG_VERIFICATION_OWNER_TTL_MS: number;
15
+ export declare const RIG_VERIFICATION_OWNERS_DISABLED_MESSAGE = "Rig verification lease ownership is disabled; refusing to create an unowned verifier sandbox";
16
+ export declare class RigVerificationActivityDeadlineError extends Error {
17
+ readonly startToCloseTimeoutMs: number;
18
+ readonly cleanupReserveMs: number;
19
+ readonly name = "RigVerificationActivityDeadlineError";
20
+ constructor(startToCloseTimeoutMs: number, cleanupReserveMs: number);
21
+ }
22
+ export type RigVerificationActivityLifecycle = {
23
+ signal: AbortSignal;
24
+ /** Absolute wall-clock boundary before which immediate cleanup may wait. */
25
+ cleanupDeadlineAtMs: number | null;
26
+ dispose(): void;
27
+ };
28
+ /**
29
+ * Start the verifier's real Temporal liveness/cancellation contract.
30
+ *
31
+ * The activity-local deadline is deliberately earlier than start-to-close. In
32
+ * production a 15-minute server deadline becomes a 13-minute work deadline,
33
+ * retaining two minutes for command quiescence, exact deactivation, and
34
+ * provider termination. Short integration-test deadlines use the same bounded
35
+ * one-quarter rule instead of a production-only magic value.
36
+ */
37
+ export declare function createRigVerificationActivityLifecycle(context?: Context | null): RigVerificationActivityLifecycle;
38
+ declare function terminateThrowaway(established: EstablishedSandboxSession | null): Promise<boolean>;
39
+ export type RigVerificationOwnershipDependencies = {
40
+ acquire: typeof acquireLease;
41
+ establish: typeof establishSandboxSessionFromEnvelope;
42
+ recordCreated: typeof recordWarmingSandboxCreated;
43
+ commitWarm: typeof commitWarmingToWarm;
44
+ touchHolder: typeof touchLeaseHolder;
45
+ releaseHolder: typeof releaseLeaseHolder;
46
+ failWarming: typeof failWarmingToCold;
47
+ markWarmLost: typeof markWarmLeaseInstanceLost;
48
+ serialize: typeof serializeEstablishedSandboxEnvelope;
49
+ tag: typeof tagModalSandbox;
50
+ terminate: typeof terminateThrowaway;
51
+ createCancellationController: typeof createTurnToolCancellationController;
52
+ randomUUID: () => string;
53
+ };
54
+ export type RigVerificationSandboxRunContext = {
55
+ signal: AbortSignal;
56
+ commandRunner: SandboxLifecycleCommandRunner;
57
+ };
58
+ export declare class RigVerificationLeaseUnavailableError extends Error {
59
+ readonly sandboxGroupId: string;
60
+ readonly role: "attached" | "blocked" | "rearmed" | "fenced";
61
+ readonly name = "RigVerificationLeaseUnavailableError";
62
+ constructor(sandboxGroupId: string, role: "attached" | "blocked" | "rearmed" | "fenced");
63
+ }
64
+ /**
65
+ * Run one verifier against one exactly attributed standalone sandbox.
66
+ *
67
+ * Ordering is deliberate and source-of-truth safe:
68
+ * acquire spawner -> create callback -> warming instance record -> warm commit
69
+ * -> setup/checks. The canonical sandbox lease, not provider tags, is durable
70
+ * ownership. Every exact create callback is retained before its DB write so an
71
+ * ambiguous acknowledgement can still be terminated in finally. Provider
72
+ * termination precedes clearing that exact durable pointer; when termination
73
+ * fails the pointer is retained and the holder is released with a one-millisecond
74
+ * drain grace so the normal reaper retries. Temporal cancellation first drains
75
+ * every verifier command. Cleanup waits are bounded inside the server reserve;
76
+ * lease expiry and the provider reaper remain the hard-worker-loss backstops.
77
+ */
78
+ export declare function runWithOwnedRigVerificationSandbox<T>(input: {
79
+ settings: ActivityServices["settings"];
80
+ db: Database;
81
+ observability: ActivityServices["observability"];
82
+ accountId: string;
83
+ workspaceId: string;
84
+ sandboxGroupId: string;
85
+ rigVersionId: string;
86
+ sessionIdPrefix: string;
87
+ lifecycle?: RigVerificationActivityLifecycle;
88
+ }, run: (established: EstablishedSandboxSession, context: RigVerificationSandboxRunContext) => Promise<T>, dependencies?: RigVerificationOwnershipDependencies): Promise<T>;
89
+ export declare function createRigVerificationActivities(services: () => Promise<ActivityServices>): {
90
+ verifyRigChange: (input: {
91
+ workspaceId: string;
92
+ changeId: string;
93
+ }) => Promise<{
94
+ id: string;
95
+ rigId: string;
96
+ baseVersionId: string | null;
97
+ kind: "definition_edit" | "setup_append";
98
+ payload: Record<string, unknown>;
99
+ status: "failed" | "merged" | "proposed" | "rejected" | "verifying";
100
+ proposedBy: string | null;
101
+ verification: {
102
+ [x: string]: unknown;
103
+ startedAt?: string | undefined;
104
+ finishedAt?: string | undefined;
105
+ log?: string | undefined;
106
+ checkResults?: {
107
+ name: string;
108
+ command: string;
109
+ exitCode: number | null;
110
+ output?: string | undefined;
111
+ }[] | undefined;
112
+ } | null;
113
+ resultVersionId: string | null;
114
+ createdAt: string;
115
+ updatedAt: string;
116
+ }>;
117
+ verifyRigVersion: (input: {
118
+ workspaceId: string;
119
+ versionId: string;
120
+ }) => Promise<{
121
+ versionId: string;
122
+ passed: boolean;
123
+ checkResults: {
124
+ exitCode: number | null;
125
+ output: string;
126
+ name: string;
127
+ command: string;
128
+ }[];
129
+ }>;
130
+ };
131
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { NormalizedRunCredentialMaterial } from "@opengeni/runtime";
2
+ import { type ExpiringMaterialRenewalController } from "./expiring-material-renewal";
3
+ export declare const RUN_CREDENTIAL_DEFAULT_REFRESH_MS: number;
4
+ export declare const RUN_CREDENTIAL_EXPIRY_LEAD_MS: number;
5
+ export declare const RUN_CREDENTIAL_MIN_REFRESH_MS = 5000;
6
+ export declare const RUN_CREDENTIAL_MAX_RETRY_MS: number;
7
+ export type RunCredentialRenewalController = ExpiringMaterialRenewalController;
8
+ type RenewalTimer = unknown;
9
+ export type RunCredentialRenewalOptions = {
10
+ initialExpiresAt: Date | null;
11
+ resolve: () => Promise<NormalizedRunCredentialMaterial | null>;
12
+ write: (material: NormalizedRunCredentialMaterial | null) => Promise<void>;
13
+ now?: () => number;
14
+ schedule?: (callback: () => void, delayMs: number) => RenewalTimer;
15
+ clearSchedule?: (timer: RenewalTimer) => void;
16
+ onSuccess?: (result: {
17
+ nextDelayMs: number;
18
+ authNeeded: boolean;
19
+ }) => void;
20
+ onFailure?: (failure: {
21
+ retryDelayMs: number;
22
+ errorClass: string;
23
+ }) => void;
24
+ };
25
+ export declare function nextRunCredentialRenewalDelay(expiresAt: Date | null, nowMs?: number): number;
26
+ /** Single-flight renewal; late resolves cannot mutate a stopped attempt. */
27
+ export declare function startRunCredentialRenewalLoop(options: RunCredentialRenewalOptions): RunCredentialRenewalController;
28
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { ConnectionCredentialsPort, CredentialAuthNeededPayload, SandboxBackend, RunCredentialsRequest, Session, SessionTurn } from "@opengeni/contracts";
2
+ import { type Database } from "@opengeni/db";
3
+ import { type NormalizedRunCredentialMaterial } from "@opengeni/runtime";
4
+ export type RunCredentialResolutionContext = {
5
+ db: Database;
6
+ connectionCredentials?: ConnectionCredentialsPort | null;
7
+ accountId: string;
8
+ workspaceId: string;
9
+ session: Session;
10
+ turn: SessionTurn;
11
+ attemptId: string;
12
+ effectiveSandboxBackend: SandboxBackend;
13
+ variableSet: {
14
+ id: string;
15
+ name: string;
16
+ } | null;
17
+ };
18
+ export type BoundRunCredentialResolver = {
19
+ resolve(input: {
20
+ purpose: "provision" | "renewal";
21
+ forceRefresh: boolean;
22
+ }): Promise<NormalizedRunCredentialMaterial | null>;
23
+ };
24
+ export declare function buildRunCredentialsRequest(input: Omit<RunCredentialResolutionContext, "db" | "connectionCredentials"> & {
25
+ rootSessionId: string;
26
+ purpose: "provision" | "renewal";
27
+ forceRefresh: boolean;
28
+ }): RunCredentialsRequest;
29
+ export declare function runCredentialAuthNeededPayloads(material: NormalizedRunCredentialMaterial): CredentialAuthNeededPayload[];
30
+ export declare function runCredentialModelNote(material: NormalizedRunCredentialMaterial): string | undefined;
31
+ /**
32
+ * Freeze the provider-neutral host credential request to this exact admitted
33
+ * turn. The host selects connections and material; the worker never infers a
34
+ * provider from repositories, environment names, or an OpenGeni variable set.
35
+ */
36
+ export declare function bindRunCredentialResolver(input: RunCredentialResolutionContext): Promise<BoundRunCredentialResolver | null>;