@opengeni/worker-bundle 0.22.8 → 0.23.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 (74) hide show
  1. package/dist/activities/agent-turn/agent-build.d.ts +1 -4
  2. package/dist/activities/agent-turn/claim.d.ts +2 -4
  3. package/dist/activities/agent-turn/codex.d.ts +6 -5
  4. package/dist/activities/agent-turn/compaction-prep.d.ts +2 -0
  5. package/dist/activities/agent-turn/errors.d.ts +13 -0
  6. package/dist/activities/agent-turn/finalization.d.ts +1 -3
  7. package/dist/activities/agent-turn/quiescence.d.ts +39 -0
  8. package/dist/activities/agent-turn/sandbox-route.d.ts +14 -24
  9. package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -4
  10. package/dist/activities/agent-turn/sandbox-shared-preparation.d.ts +30 -0
  11. package/dist/activities/agent-turn/stream-attempt.d.ts +7 -0
  12. package/dist/activities/agent-turn/tool-policy.d.ts +3 -32
  13. package/dist/activities/agent-turn/turn-context.d.ts +1 -8
  14. package/dist/activities/agent-turn/turn-sandbox-access.d.ts +12 -0
  15. package/dist/activities/agent-turn/video-reference-sandbox.d.ts +7 -0
  16. package/dist/activities/codex-rotation.d.ts +2 -0
  17. package/dist/activities/session-state.d.ts +2 -1
  18. package/dist/{activities-control-VZIIV7RX.js → activities-control-52W5IDWM.js} +125 -13
  19. package/dist/activities-control-52W5IDWM.js.map +1 -0
  20. package/dist/{activities-turn-5RGQDBFV.js → activities-turn-A2G2KLSY.js} +534 -482
  21. package/dist/activities-turn-A2G2KLSY.js.map +1 -0
  22. package/dist/{chunk-NAVSAZ56.js → chunk-GFNXVZVQ.js} +160 -1
  23. package/dist/chunk-GFNXVZVQ.js.map +1 -0
  24. package/dist/{chunk-O4HDX5SC.js → chunk-IPVMCAW5.js} +144 -15
  25. package/dist/chunk-IPVMCAW5.js.map +1 -0
  26. package/dist/index.js +42 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/observability-metrics.d.ts +28 -0
  29. package/dist/personal-github-git-credentials.d.ts +1 -0
  30. package/dist/unhandled-rejection-boundary.d.ts +29 -0
  31. package/package.json +18 -18
  32. package/src/activities/agent-turn/agent-build.ts +15 -31
  33. package/src/activities/agent-turn/claim.ts +29 -68
  34. package/src/activities/agent-turn/codex.ts +19 -10
  35. package/src/activities/agent-turn/compaction-prep.ts +50 -1
  36. package/src/activities/agent-turn/errors.ts +78 -0
  37. package/src/activities/agent-turn/failure-settlement.ts +30 -19
  38. package/src/activities/agent-turn/finalization.ts +24 -21
  39. package/src/activities/agent-turn/history.ts +5 -1
  40. package/src/activities/agent-turn/quiescence.ts +86 -0
  41. package/src/activities/agent-turn/run-credentials.ts +12 -1
  42. package/src/activities/agent-turn/run.ts +14 -11
  43. package/src/activities/agent-turn/sandbox-establish.ts +46 -11
  44. package/src/activities/agent-turn/sandbox-route.ts +21 -25
  45. package/src/activities/agent-turn/sandbox-runtime.ts +1 -116
  46. package/src/activities/agent-turn/sandbox-shared-preparation.ts +206 -0
  47. package/src/activities/agent-turn/stream-attempt.ts +98 -14
  48. package/src/activities/agent-turn/tool-environment.ts +10 -13
  49. package/src/activities/agent-turn/tool-policy.ts +3 -55
  50. package/src/activities/agent-turn/turn-context.ts +8 -14
  51. package/src/activities/agent-turn/{image-reference-sandbox.ts → turn-sandbox-access.ts} +15 -13
  52. package/src/activities/agent-turn/video-reference-sandbox.ts +23 -0
  53. package/src/activities/codex-capacity.ts +13 -5
  54. package/src/activities/codex-rotation.ts +17 -0
  55. package/src/activities/goals.ts +10 -4
  56. package/src/activities/retained-screenshots.ts +104 -21
  57. package/src/activities/sandbox-lease.ts +7 -4
  58. package/src/activities/scheduled-tasks.ts +128 -4
  59. package/src/activities/session-state.ts +8 -1
  60. package/src/github-rest-mcp.ts +6 -3
  61. package/src/http.ts +3 -0
  62. package/src/index.ts +19 -0
  63. package/src/observability-metrics.ts +200 -0
  64. package/src/personal-github-git-credentials.ts +45 -4
  65. package/src/sandbox-resume.ts +1 -1
  66. package/src/sandbox-routing.ts +7 -4
  67. package/src/unhandled-rejection-boundary.ts +73 -0
  68. package/dist/activities/agent-turn/image-reference-sandbox.d.ts +0 -14
  69. package/dist/activities/recording.d.ts +0 -90
  70. package/dist/activities-control-VZIIV7RX.js.map +0 -1
  71. package/dist/activities-turn-5RGQDBFV.js.map +0 -1
  72. package/dist/chunk-NAVSAZ56.js.map +0 -1
  73. package/dist/chunk-O4HDX5SC.js.map +0 -1
  74. package/src/activities/recording.ts +0 -279
@@ -7,11 +7,10 @@ import { createTurnMediaArtifacts } from "./media-artifacts.js";
7
7
  import type { ClaimTurnOk } from "./claim.js";
8
8
  import type { GovernanceModelOk } from "./governance-model.js";
9
9
  import type { CompactionPrepOk } from "./compaction-prep.js";
10
- import type { SandboxTurnRuntime } from "./sandbox-runtime.js";
11
10
  import type { runtimeResourcesForTurn } from "./file-resources.js";
12
11
  import type { sandboxArtifactRuntimeAdmission } from "./sandbox-route.js";
13
12
  import type { loadWorkspaceEnvironmentForRunWithCredentials, sandboxEnvironmentForRun } from "../environment.js";
14
- import type { AttemptIdentityState, EventingState, ProviderTurnState, RecordingState, SandboxRuntimeState } from "./turn-context.js";
13
+ import type { AttemptIdentityState, EventingState, ProviderTurnState, SandboxRuntimeState } from "./turn-context.js";
15
14
  export type BuildTurnAgentDeps = {
16
15
  input: RunAgentTurnInput;
17
16
  db: ActivityServices["db"];
@@ -23,8 +22,6 @@ export type BuildTurnAgentDeps = {
23
22
  eventing: EventingState;
24
23
  attempt: AttemptIdentityState;
25
24
  sandboxState: SandboxRuntimeState;
26
- recordingState: RecordingState;
27
- maybeStartOnTurnRecording: SandboxTurnRuntime["maybeStartOnTurnRecording"];
28
25
  providerTurn: ProviderTurnState;
29
26
  media: ReturnType<typeof createTurnMediaArtifacts>;
30
27
  leases: ReturnType<typeof createTurnCredentialLeases>;
@@ -6,14 +6,13 @@ import { makeTurnOpJournal } from "../../op-journal.js";
6
6
  import { createTurnCredentialLeases } from "./credential-leases.js";
7
7
  import { createTurnMediaArtifacts } from "./media-artifacts.js";
8
8
  import type { TurnExecutionPolicyV1 } from "@opengeni/contracts";
9
- import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState, RecordingState, SandboxRuntimeState, TurnControlState } from "./turn-context.js";
9
+ import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState, SandboxRuntimeState, TurnControlState } from "./turn-context.js";
10
10
  export type ClaimTurnDeps = {
11
11
  input: RunAgentTurnInput;
12
12
  settings: Settings;
13
13
  db: ActivityServices["db"];
14
14
  bus: ActivityServices["bus"];
15
15
  runtime: ActivityServices["runtime"];
16
- objectStorage: ActivityServices["objectStorage"];
17
16
  observability: ActivityServices["observability"];
18
17
  entitlements: ActivityServices["entitlements"];
19
18
  wakeSessionWorkflow: ActivityServices["wakeSessionWorkflow"];
@@ -25,13 +24,11 @@ export type ClaimTurnDeps = {
25
24
  attempt: AttemptIdentityState;
26
25
  billingState: BillingState;
27
26
  sandboxState: SandboxRuntimeState;
28
- recordingState: RecordingState;
29
27
  eventing: EventingState;
30
28
  leases: ReturnType<typeof createTurnCredentialLeases>;
31
29
  media: ReturnType<typeof createTurnMediaArtifacts>;
32
30
  claimedResult: ClaimedResult;
33
31
  acknowledgeLostAttemptOwnership: () => void;
34
- abandonActiveRecording: (reason: string, disposition?: "failed" | "discard") => Promise<void>;
35
32
  };
36
33
  export type ClaimTurnOk = {
37
34
  turn: SessionTurnForExecution;
@@ -45,6 +42,7 @@ export type ClaimTurnOk = {
45
42
  trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>;
46
43
  humanInputResume: Awaited<ReturnType<typeof getHumanInputResumeForEvent>>;
47
44
  interactionInterventionResume: Awaited<ReturnType<typeof getInteractionInterventionResumeForEvent>>;
45
+ attachPendingUpdatesAfterOpenSuffix: () => Promise<boolean>;
48
46
  throwIfWorkerShuttingDown: () => void;
49
47
  throwIfTurnCancelled: () => void;
50
48
  opJournal: ReturnType<typeof makeTurnOpJournal>;
@@ -16,14 +16,15 @@ export declare function acceptsPromptCacheKeyForTurn(resolvedModel: {
16
16
  * would idle-loop forever. Before idling, refresh LIVE usage for every connected account
17
17
  * the cache marks exhausted (bounded to the account count), which re-writes the
18
18
  * cache columns, then return the re-read rows so the ranker can pick up a genuinely-reset
19
- * window THIS turn. A refresh/read failure is swallowed (fall back to the pre-refresh rows
20
- * + the bounded idle). Cooling (429'd) accounts are NOT refreshed: their exhaustedUntil
21
- * cooldown is authoritative, and refreshing them would burn a provider call for nothing.
19
+ * window THIS turn. Typed quota cooldowns are also refreshed because the provider may
20
+ * replace an allowance cycle before its original reset; revision fencing makes that
21
+ * repair safe. Generic backpressure and legacy-unknown cooldowns are never reconciled.
22
+ * A refresh/read failure is swallowed (fall back to the pre-refresh rows + bounded idle).
22
23
  */
23
- export declare function refreshCappedCodexUsageRows(db: ActivityServices["db"], settings: Settings, workspaceId: string, accounts: Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil">>, capacitySignals: {
24
+ export declare function refreshCappedCodexUsageRows(db: ActivityServices["db"], settings: Settings, workspaceId: string, accounts: Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>, capacitySignals: {
24
25
  signalCodexCapacityWorkflow?: ActivityServices["signalCodexCapacityWorkflow"] | undefined;
25
26
  wakeSessionWorkflow: ActivityServices["wakeSessionWorkflow"];
26
- }): Promise<Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil">>>;
27
+ }): Promise<Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>>;
27
28
  /**
28
29
  * True once the lifetime last confirmed by Postgres is no longer trustworthy.
29
30
  * A missing or malformed deadline fails closed for a holder that claims to be
@@ -60,6 +60,7 @@ export type CompactionPrepOk = {
60
60
  compactionModeOptions: NonNullable<Parameters<typeof maybeCompactContext>[5]>;
61
61
  compactionOnlyTurn: boolean;
62
62
  compactionSummarizerFor: (systemInstructions?: string) => CompactionSummarizer;
63
+ settleDeferredSteerAfterCompaction: () => Promise<RunAgentTurnResult | null>;
63
64
  };
64
65
  export type CompactionPrepOutcome = {
65
66
  exit: RunAgentTurnResult;
@@ -74,6 +75,7 @@ export type PostAgentCompactionDeps = CompactionPrepDeps & {
74
75
  compactionModeOptions: CompactionPrepOk["compactionModeOptions"];
75
76
  compactionOnlyTurn: boolean;
76
77
  compactionSummarizerFor: CompactionPrepOk["compactionSummarizerFor"];
78
+ settleDeferredSteerAfterCompaction: CompactionPrepOk["settleDeferredSteerAfterCompaction"];
77
79
  agent: ReturnType<ActivityServices["runtime"]["buildAgent"]>;
78
80
  };
79
81
  export type PostAgentCompactionOk = {
@@ -36,6 +36,7 @@ export declare function providerRecoveryExhaustedFailure<T extends Record<string
36
36
  lastRetryableError: string;
37
37
  };
38
38
  export declare function providerRecoveryCountFromMetadata(metadata: Record<string, unknown>): number;
39
+ export declare function providerRecoveryCountAfterModelRequestPhase(currentCount: number, phase: string): number;
39
40
  export declare function headerValue(headers: unknown, name: string): string | null;
40
41
  /** Read a provider Retry-After hint without retaining response headers/body. */
41
42
  export declare function providerRetryAfterMs(error: unknown, nowMs?: number): number | null;
@@ -95,6 +96,18 @@ export declare function postClaimDatabaseRecoveryFailure(input: {
95
96
  * then fails with the existing relogin error path).
96
97
  */
97
98
  export declare function isWorkerShutdownCancellation(error: unknown): boolean;
99
+ export type SandboxLifecycleTransitionDiagnostic = {
100
+ sandboxGroupId: string;
101
+ leaseEpoch: number;
102
+ reason: "capture_in_progress" | "rotation_in_progress" | "provider_recovery_in_progress";
103
+ };
104
+ /**
105
+ * Recover a typed sandbox lifecycle transition through the structural wrappers
106
+ * used by parallel Agents SDK function-tool execution. Never infer transition
107
+ * truth from message text: only the original class or an exact, fully-shaped
108
+ * cross-package error object is accepted.
109
+ */
110
+ export declare function sandboxLifecycleTransitionDiagnostic(error: unknown): SandboxLifecycleTransitionDiagnostic | null;
98
111
  /**
99
112
  * Recognize the one active-route transition that cannot finish inside its
100
113
  * originating attempt. A Modal-home session may start on a Connected Machine
@@ -5,7 +5,7 @@ import { createModelCheckpointMemoryCollector } from "../../model-checkpoint-mem
5
5
  import { makeMachineOpObserver } from "../../observability-metrics.js";
6
6
  import { type ResumedTurnSandbox } from "../../sandbox-resume.js";
7
7
  import { createTurnCredentialLeases } from "./credential-leases.js";
8
- import type { AttemptIdentityState, EventingState, ProviderTurnState, RecordingState, RenewalState, SandboxRuntimeState, TurnControlState, WorkspaceRefState } from "./turn-context.js";
8
+ import type { AttemptIdentityState, EventingState, ProviderTurnState, RenewalState, SandboxRuntimeState, TurnControlState, WorkspaceRefState } from "./turn-context.js";
9
9
  export type TurnFinalizationDeps = {
10
10
  input: RunAgentTurnInput;
11
11
  settings: Settings;
@@ -29,14 +29,12 @@ export type TurnFinalizationDeps = {
29
29
  attempt: AttemptIdentityState;
30
30
  sandboxState: SandboxRuntimeState;
31
31
  renewals: RenewalState;
32
- recordingState: RecordingState;
33
32
  eventing: EventingState;
34
33
  providerTurn: ProviderTurnState;
35
34
  workspaceRefs: WorkspaceRefState;
36
35
  runWorkspaceMutationForSandbox: <T>(sandbox: ResumedTurnSandbox, operation: string, mutation: () => Promise<T>) => Promise<T>;
37
36
  requireResolvedSandboxForMutation: (message: string) => ResumedTurnSandbox;
38
37
  stopLeaseHeartbeat: () => void;
39
- abandonActiveRecording: (reason: string, disposition?: "failed" | "discard") => Promise<void>;
40
38
  turnCompletionMemoryCollector: ReturnType<typeof createModelCheckpointMemoryCollector>;
41
39
  };
42
40
  export declare function finalizeTurnAttempt(deps: TurnFinalizationDeps): Promise<void>;
@@ -45,6 +45,17 @@ export declare function assertSessionAttemptQuiescenceRecoveryDurable(input: {
45
45
  }): void;
46
46
  export declare const QUIESCENCE_PROOF_SIGNAL_INITIAL_RETRY_MS = 250;
47
47
  export declare const QUIESCENCE_PROOF_SIGNAL_MAX_RETRY_MS = 5000;
48
+ export declare const TURN_QUIESCENCE_WATCHDOG_MS: number;
49
+ /** A fenced activity must never heartbeat forever while its physical writer
50
+ * drain is stuck. The last-resort worker exit stops every in-process writer;
51
+ * Kubernetes replaces the pod and the workflow's heartbeat-lease reconciler
52
+ * then commits the exact quiescence receipt. */
53
+ export declare function armTurnQuiescenceWatchdog(input: {
54
+ enabled: boolean;
55
+ timeoutMs?: number;
56
+ onTimeout?: () => void;
57
+ terminateWorker: () => void;
58
+ }): () => void;
48
59
  /** Persist the authoritative receipt or durably hand the exact physical proof
49
60
  * to Temporal. This retries signal delivery, not DB eligibility or workflow
50
61
  * state. The proof object never changes between attempts. */
@@ -100,6 +111,34 @@ export declare function waitForTurnFinalizerStep<T>(operation: Promise<T>, signa
100
111
  * may pin the activity behind cancellation after durable writes are fenced.
101
112
  */
102
113
  export declare function waitForTurnStreamCleanup(batcherFlush: Promise<unknown>, providerCompleted: Promise<unknown>, signal: AbortSignal | undefined): Promise<void>;
114
+ export declare class IncompleteAgentStreamError extends Error {
115
+ readonly name = "IncompleteAgentStreamError";
116
+ constructor(message?: string);
117
+ }
118
+ /**
119
+ * Prove that SDK completion authority did not report a failure or runtime
120
+ * cancellation. The Agents SDK closes its ReadableStream immediately when its
121
+ * run signal aborts, so iterator EOF is not completion authority: the separate
122
+ * `completed` promise carries the eventual run failure.
123
+ *
124
+ * Only Temporal cancellation detaches cleanup. Internal runtime cancellation
125
+ * such as a provider-deadline sandbox rotation must escape to the turn failure
126
+ * settlement path, which checkpoints and redispatches the same logical turn.
127
+ */
128
+ export declare function assertSuccessfulAgentStreamCompletion(input: {
129
+ batcherFlush: Promise<unknown>;
130
+ stream: {
131
+ completed: Promise<void>;
132
+ error: unknown;
133
+ };
134
+ temporalCancellationSignal: AbortSignal | undefined;
135
+ runtimeCancellationSignal: AbortSignal;
136
+ }): Promise<void>;
137
+ /** Call after any more-specific empty-stream recovery has had priority. */
138
+ export declare function assertAgentStreamNotCancelled(cancelled: boolean): void;
139
+ /** Interruption streams do not produce a normal final output. Call this only
140
+ * after the interruption branch has settled any required action. */
141
+ export declare function requireAgentStreamFinalOutput(finalOutput: unknown | undefined): unknown;
103
142
  /**
104
143
  * Terminal settlement closes the active attempt before turn finalization. The
105
144
  * ordinary workspace admission therefore correctly returns `attempt_fenced`
@@ -17,6 +17,20 @@ export declare function managedSandboxOwnershipForTurn(machinePrimary: boolean,
17
17
  holderId: TurnSandboxLeaseHolderId;
18
18
  sandboxGroupId: string;
19
19
  } | null;
20
+ /**
21
+ * Bind backend-aware runtime settings to the route that will actually execute.
22
+ *
23
+ * A machine-home turn keeps `selfhosted` as its durable policy. After an
24
+ * explicit clear-to-default, however, both the ownership-inverted path and the
25
+ * legacy SDK-owned path must construct manifests and clients for the resolved
26
+ * managed group backend. Machine-primary and ordinary session routes preserve
27
+ * their existing settings object.
28
+ */
29
+ export declare function sandboxSettingsForRoute(input: {
30
+ runSettings: Settings;
31
+ machinePrimary: boolean;
32
+ groupBoxBackend: Settings["sandboxBackend"];
33
+ }): Settings;
20
34
  /** A sandboxless home still establishes an explicitly attached Connected Machine. */
21
35
  export declare function shouldEstablishSandboxForTurn(sandboxOwnershipEnabled: boolean, homeBackend: Settings["sandboxBackend"], machinePrimary: boolean): boolean;
22
36
  export declare function sandboxEstablishPolicyDecision(input: {
@@ -125,27 +139,3 @@ export type SandboxArtifactRuntimeAdmission = Readonly<{
125
139
  export declare function sandboxArtifactRuntimeAdmission(deploymentSettings: Settings, runSettings: Settings, backend: Settings["sandboxBackend"] | undefined, options?: Readonly<{
126
140
  production?: boolean;
127
141
  }>): SandboxArtifactRuntimeAdmission;
128
- /**
129
- * Decide whether the first actual computer action may start a proof recording.
130
- *
131
- * On-turn recording runs ffmpeg/x11grab INSIDE the box and reads the .mp4 back
132
- * out of the box's /tmp — plumbing that exists only for OpenGeni-operated cloud
133
- * boxes (the Modal desktop backend). A turn whose EFFECTIVE backend is a connected
134
- * machine ("selfhosted") runs on the user's REAL computer, which has none of that
135
- * capture plumbing (and the platform must never shell ffmpeg onto a user's machine
136
- * — the same reason the runtime skips its setup hooks for selfhosted). Left ungated
137
- * it films nothing, finds no /tmp file, and emits recording.started followed by
138
- * recording.failed{box-death} on EVERY machine-primary turn — misleading timeline
139
- * noise + wasted work. So gate it off, exactly like a recording-disabled deployment:
140
- * skip silently, emit nothing (no new event shape).
141
- *
142
- * `effectiveBackend` is the resolved ACTIVE backend for the turn
143
- * (resolveActiveSandboxBackend) — NOT the session's home backend. A modal-home
144
- * session actively swapped onto a machine resolves to "selfhosted" here and
145
- * correctly skips; a machine-home turn that degraded back to its cloud group box
146
- * (swap-away / flag-off) resolves to undefined and records as before.
147
- *
148
- * EDGE — mid-turn swap: this is evaluated once when computer-use first runs. A swap
149
- * after recording starts is deliberately ignored; the partial recording already has
150
- * defined failure semantics, so there is no stop/restart machinery.
151
- */
@@ -3,7 +3,7 @@ import { type Settings } from "@opengeni/config";
3
3
  import { currentActivityContext } from "../streaming.js";
4
4
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput } from "../types.js";
5
5
  import { type ResumedTurnSandbox } from "../../sandbox-resume.js";
6
- import type { AttemptIdentityState, EventingState, RecordingState, SandboxRuntimeState } from "./turn-context.js";
6
+ import type { AttemptIdentityState, EventingState, SandboxRuntimeState } from "./turn-context.js";
7
7
  export type SandboxTurnRuntimeDeps = {
8
8
  input: RunAgentTurnInput;
9
9
  settings: Settings;
@@ -14,7 +14,6 @@ export type SandboxTurnRuntimeDeps = {
14
14
  activityContext: ReturnType<typeof currentActivityContext>;
15
15
  sandboxRotationController: AbortController;
16
16
  sandboxState: SandboxRuntimeState;
17
- recordingState: RecordingState;
18
17
  eventing: EventingState;
19
18
  attempt: AttemptIdentityState;
20
19
  };
@@ -33,12 +32,10 @@ export declare function createSandboxTurnRuntime(deps: SandboxTurnRuntimeDeps):
33
32
  durationSeconds: number;
34
33
  }) => void) => Promise<T>;
35
34
  stopLeaseHeartbeat: () => void;
36
- abandonActiveRecording: (reason: string, disposition?: "failed" | "discard") => Promise<void>;
37
35
  flushRuntimeBatcher: () => Promise<void>;
38
36
  publishSandboxLifecycleEvents: (sandbox: ResumedTurnSandbox) => Promise<void>;
39
37
  publishSandboxLost: (lostSandbox: {
40
38
  instanceId: string;
41
39
  }) => Promise<void>;
42
40
  startLeaseHeartbeat: (sandbox: ResumedTurnSandbox, warmBackend: Settings["sandboxBackend"] | undefined) => void;
43
- maybeStartOnTurnRecording: (sandbox: ResumedTurnSandbox, effectiveBackend: Settings["sandboxBackend"] | undefined) => Promise<void>;
44
41
  };
@@ -0,0 +1,30 @@
1
+ import { type Database } from "@opengeni/db";
2
+ import type { ResumedTurnSandbox } from "../../sandbox-resume.js";
3
+ type SharedRigSetupCoordinatorInput = {
4
+ specHash: string;
5
+ timeoutMs: number;
6
+ execute: () => Promise<void>;
7
+ };
8
+ type SharedRigSetupCoordinatorOptions = {
9
+ db: Database;
10
+ accountId: string;
11
+ workspaceId: string;
12
+ sandboxGroupId: string;
13
+ attemptId: string;
14
+ holderId: string;
15
+ sandbox: ResumedTurnSandbox;
16
+ signal?: AbortSignal;
17
+ observe?: (measurement: {
18
+ path: "owner" | "joined" | "reused";
19
+ outcome: "completed" | "failed";
20
+ durationSeconds: number;
21
+ }) => void;
22
+ };
23
+ /**
24
+ * Coordinate immutable rig setup across workers. Joiners use a revision-aware,
25
+ * exponentially backed-off durable read instead of the old fixed 250 ms lease
26
+ * polling pattern. PostgreSQL remains source of truth; a lost completion write
27
+ * is recovered by the next deadline owner through the hook's box-local marker.
28
+ */
29
+ export declare function createSharedRigSetupCoordinator(options: SharedRigSetupCoordinatorOptions): (input: SharedRigSetupCoordinatorInput) => Promise<"executed" | "reused">;
30
+ export {};
@@ -82,12 +82,14 @@ export type TurnStreamAttemptDeps = {
82
82
  };
83
83
  trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>;
84
84
  humanInputResume: Awaited<ReturnType<typeof getHumanInputResumeForEvent>>;
85
+ attachPendingUpdatesAfterOpenSuffix: () => Promise<boolean>;
85
86
  agent: ReturnType<ActivityServices["runtime"]["buildAgent"]>;
86
87
  resolvedModel: ReturnType<ActivityServices["runtime"]["resolveTurnModel"]>;
87
88
  providerApi: HistoryProviderApi;
88
89
  runSettings: Settings;
89
90
  turnTools: ReturnType<typeof withFirstPartyTools>;
90
91
  compactSummarizer: CompactionSummarizer;
92
+ settleDeferredSteerAfterCompaction: () => Promise<RunAgentTurnResult | null>;
91
93
  compactionModelHistoryProjector: (items: Array<Record<string, unknown>>) => Promise<Array<Record<string, unknown>>>;
92
94
  generatedImageHistoryProjector: (items: Array<Record<string, unknown>>) => Promise<Array<Record<string, unknown>>>;
93
95
  modelHistoryProjector: ModelHistoryAttachmentProjector;
@@ -104,4 +106,9 @@ export type TurnStreamAttemptDeps = {
104
106
  requestDigest: string;
105
107
  }>;
106
108
  };
109
+ export declare function attachPendingUpdatesBeforePreparingModelInput(input: {
110
+ shouldAttach: boolean;
111
+ attachPendingUpdates: () => Promise<boolean>;
112
+ prepareModelInput: () => Promise<void>;
113
+ }): Promise<boolean>;
107
114
  export declare function runTurnStreamAttempt(deps: TurnStreamAttemptDeps): Promise<RunAgentTurnResult>;
@@ -1,37 +1,6 @@
1
- import { type ComputerToolMode, type LazyToolTransport } from "@opengeni/runtime";
1
+ import { type LazyToolTransport } from "@opengeni/runtime";
2
2
  import { type ModelProviderApi, type RegistryProviderKind, type Settings } from "@opengeni/config";
3
3
  import { type ModelAttachmentInputPolicy } from "../run-input.js";
4
- export declare function shouldStartOnTurnRecording(params: {
5
- recordingEnabled: boolean;
6
- desktopEnabled: boolean;
7
- establishedBackendId: string;
8
- effectiveBackend: Settings["sandboxBackend"] | undefined;
9
- }): boolean;
10
- /**
11
- * Decide the EXPLICIT computer-use tool transport for THIS turn.
12
- *
13
- * Computer-use is ordinary `computer_*` function tools bound to the live
14
- * desktop. The worker picks the mode from the resolved provider so the runtime
15
- * never string-sniffs the model instance:
16
- * • catalogue `inputModalities` must include `image`, or computer-use is off
17
- * • Responses wires (Azure/OpenAI, Gateway, Codex, legacy client) →
18
- * "function-image": screenshot results are structured `{type:'image'}`
19
- * • Chat Completions → "disabled": tool results on that wire are text, so a
20
- * screenshot would become a base64 string rather than an image the model sees
21
- *
22
- * Pure + exported so the mapping is unit-testable without a live turn.
23
- */
24
- export declare function computerToolModeForTurn(resolvedModel: {
25
- provider: {
26
- kind: RegistryProviderKind;
27
- api: ModelProviderApi;
28
- };
29
- configured: {
30
- capabilities: {
31
- inputModalities: string[];
32
- };
33
- };
34
- } | null): ComputerToolMode;
35
4
  /** Chat wires and Gateway models do not advertise OpenAI's hosted sandbox tool types. */
36
5
  export declare function structuredToolTransportForTurn(resolvedModel: {
37
6
  provider: {
@@ -59,6 +28,8 @@ export declare function lazyToolTransportForTurn(resolvedModel: {
59
28
  export declare function shouldDeferNonEagerToolPreparation(args: {
60
29
  lazyToolTransport: LazyToolTransport | null;
61
30
  progressiveDisclosureEnabled: boolean;
31
+ /** Retained for call-site compatibility; the lazy runtime now gates artifact
32
+ * and ordinary function calls on the same exact preparation promise. */
62
33
  artifactRuntimeAvailable: boolean;
63
34
  triggerKind: "next" | "approval";
64
35
  triggerType: string;
@@ -8,7 +8,6 @@ import type { CodemodeAttemptDispatcher } from "../codemode-dispatcher.js";
8
8
  import type { CodemodeTokenRenewalController } from "../codemode-token-renewal.js";
9
9
  import type { GitCredentialRenewalController } from "../git-credential-renewal.js";
10
10
  import type { RunCredentialRenewalController } from "../run-credential-renewal.js";
11
- import type { ActiveRecording } from "../recording.js";
12
11
  import type { createRuntimeBatcher, startActivityHeartbeat } from "../streaming.js";
13
12
  import type { RunAgentTurnResult } from "../types.js";
14
13
  import type { TurnOutcome } from "../../observability-metrics.js";
@@ -21,7 +20,7 @@ export type ClaimedResult = (result: Omit<Extract<RunAgentTurnResult, {
21
20
  }>, "turnId" | "attemptId">) => RunAgentTurnResult;
22
21
  export type TurnSettleFn = (input: {
23
22
  events: Array<Omit<AppendEventInput, "producerId" | "producerSeq" | "turnId">>;
24
- turnStatus: "queued" | "running" | "completed" | "failed" | "cancelled" | "requires_action";
23
+ turnStatus: "queued" | "running" | "completed" | "failed" | "cancelled" | "superseded" | "requires_action";
25
24
  sessionStatus: SessionStatus;
26
25
  activeTurnId: string | null;
27
26
  consumeRequestedCompactionFailure?: boolean;
@@ -84,11 +83,6 @@ export type RenewalState = {
84
83
  codemodeTokenRenewalClosed: boolean;
85
84
  publishedRunCredentialNotices: Set<string>;
86
85
  };
87
- export type RecordingState = {
88
- activeRecording: ActiveRecording | null;
89
- computerUseRecordingStart: Promise<void> | null;
90
- didComputerUse: boolean;
91
- };
92
86
  export type EventingState = {
93
87
  heartbeatTimer: ReturnType<typeof startActivityHeartbeat> | undefined;
94
88
  batcher: ReturnType<typeof createRuntimeBatcher> | null;
@@ -133,7 +127,6 @@ export type TurnContext = {
133
127
  billingState: BillingState;
134
128
  sandboxState: SandboxRuntimeState;
135
129
  renewals: RenewalState;
136
- recordingState: RecordingState;
137
130
  eventing: EventingState;
138
131
  workspaceRefs: WorkspaceRefState;
139
132
  providerTurn: ProviderTurnState;
@@ -0,0 +1,12 @@
1
+ import type { ChannelASession } from "@opengeni/runtime/sandbox";
2
+ import type { ResumedTurnSandbox } from "../../sandbox-resume.js";
3
+ import type { SandboxRuntimeState } from "./turn-context.js";
4
+ type TurnSandboxAccessState = Pick<SandboxRuntimeState, "resolvedSandbox" | "lazyOwnedSandbox" | "turnSandboxProvisioner">;
5
+ export type ResolvedTurnSandboxAccess = Readonly<{
6
+ sandbox: ResumedTurnSandbox | null;
7
+ session: ChannelASession;
8
+ leaseEpoch: number;
9
+ }>;
10
+ /** Join the turn's canonical sandbox boundary and return its active routed session. */
11
+ export declare function resolveTurnSandboxAccess(sandboxState: TurnSandboxAccessState, sdkOwnedSandboxSession: unknown, unavailableMessage: string): Promise<ResolvedTurnSandboxAccess>;
12
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { GenerateVideoToolInput } from "@opengeni/contracts";
2
+ import type { SandboxRuntimeState } from "./turn-context.js";
3
+ import { type ResolvedTurnSandboxAccess } from "./turn-sandbox-access.js";
4
+ type VideoReferenceSandboxState = Pick<SandboxRuntimeState, "resolvedSandbox" | "lazyOwnedSandbox" | "turnSandboxProvisioner">;
5
+ /** Text-to-video stays sandbox-free; source-bearing requests join the turn sandbox before I/O. */
6
+ export declare function resolveVideoReferenceSandboxAccess(request: GenerateVideoToolInput, sandboxState: VideoReferenceSandboxState, sdkOwnedSandboxSession: unknown): Promise<ResolvedTurnSandboxAccess | null>;
7
+ export {};
@@ -1,5 +1,7 @@
1
1
  import type { CodexAccountStatus, CodexCredentialLeaseSelectionContext, CodexLeaseAccountStatus, CodexPinSource } from "@opengeni/db";
2
2
  export type CodexRotationAccount = CodexAccountStatus | CodexLeaseAccountStatus;
3
+ /** Capacity metadata worth an authoritative live read before/all through an idle. */
4
+ export declare function codexAccountNeedsLiveCapacityRefresh(account: Pick<CodexAccountStatus, "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">, now: Date): boolean;
3
5
  export type CodexRotationStrategy = "most_remaining" | "round_robin" | "drain_then_next" | "sharded";
4
6
  /**
5
7
  * The ONE strategy rotation-enabled workspaces run: sticky-sharded. The legacy
@@ -1,7 +1,7 @@
1
1
  import { settleSessionAttemptInterruptions, applySessionTurnSettlement, enqueueSessionWorkflowWake, failSessionWorkBeforeAttemptClaim, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionInteractionIntervention as expireSessionInteractionInterventionDb, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
2
2
  import { publishDurableSessionEvents } from "@opengeni/events";
3
3
  import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake.js";
4
- import { recordTurnsQueuedGauge } from "../observability-metrics.js";
4
+ import { recordTurnsQueuedGauge, recordWorkerDeathRecoveryMetrics } from "../observability-metrics.js";
5
5
  import type { ControlActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, ExpireSessionInteractionInterventionInput, ExpireSessionInteractionInterventionResult, PeekSessionWorkInput, FailSessionAttemptInput, FailSessionAttemptResult, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types.js";
6
6
  export type SessionStateActivityOverrides = Partial<{
7
7
  settleSessionAttemptInterruptions: typeof settleSessionAttemptInterruptions;
@@ -25,6 +25,7 @@ export type SessionStateActivityOverrides = Partial<{
25
25
  deliverFailedChildTurnToParent: typeof deliverFailedChildTurnToParent;
26
26
  notifyParentOfChildIdle: typeof notifyParentOfChildIdle;
27
27
  recordTurnsQueuedGauge: typeof recordTurnsQueuedGauge;
28
+ recordWorkerDeathRecoveryMetrics: typeof recordWorkerDeathRecoveryMetrics;
28
29
  }>;
29
30
  export declare const WORKER_DEATH_MAX_REDISPATCHES = 3;
30
31
  export declare function createSessionStateActivities(services: () => Promise<ControlActivityServices>, overrides?: SessionStateActivityOverrides): {