@opengeni/worker-bundle 1.0.1-canary.4 → 2.0.0-canary.35585322809001

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 (111) hide show
  1. package/dist/activities/agent-turn/codex.d.ts +1 -1
  2. package/dist/activities/agent-turn/compaction-prep.d.ts +1 -5
  3. package/dist/activities/agent-turn/errors.d.ts +26 -6
  4. package/dist/activities/agent-turn/governance-model.d.ts +0 -2
  5. package/dist/activities/agent-turn/recovery-warning.d.ts +8 -0
  6. package/dist/activities/agent-turn/run-credentials.d.ts +0 -1
  7. package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -1
  8. package/dist/activities/agent-turn/sandbox-route.d.ts +0 -20
  9. package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
  10. package/dist/activities/agent-turn/skill-remove.d.ts +14 -0
  11. package/dist/activities/agent-turn/skill-search.d.ts +1 -1
  12. package/dist/activities/agent-turn/stream-attempt.d.ts +1 -0
  13. package/dist/activities/agent-turn/tool-environment.d.ts +0 -4
  14. package/dist/activities/agent-turn/turn-sandbox-access.d.ts +3 -0
  15. package/dist/activities/codex-capacity.d.ts +6 -1
  16. package/dist/activities/codex-rotation.d.ts +1 -1
  17. package/dist/activities/context-compaction.d.ts +7 -1
  18. package/dist/activities/mcp-account-routes.d.ts +22 -0
  19. package/dist/activities/mcp-credentials.d.ts +12 -13
  20. package/dist/activities/mcp-operation-authority.d.ts +0 -5
  21. package/dist/activities/rig-verification.d.ts +2 -3
  22. package/dist/activities/sandbox-images.d.ts +1 -1
  23. package/dist/activities/sandbox-lease.d.ts +2 -2
  24. package/dist/activities/session-state.d.ts +57 -2
  25. package/dist/activities/types.d.ts +12 -3
  26. package/dist/{activities-control-FNC52DPR.js → activities-control-BOLIY3H4.js} +344 -163
  27. package/dist/activities-control-BOLIY3H4.js.map +1 -0
  28. package/dist/activities-control.d.ts +110 -2
  29. package/dist/{activities-turn-TQ3D6UE2.js → activities-turn-2B3WMHBB.js} +602 -357
  30. package/dist/activities-turn-2B3WMHBB.js.map +1 -0
  31. package/dist/activities.d.ts +110 -2
  32. package/dist/artifact-materializer-entry.js +5 -2
  33. package/dist/artifact-materializer-entry.js.map +1 -1
  34. package/dist/artifact-outbox-entry.js +2 -2
  35. package/dist/artifact-outbox-entry.js.map +1 -1
  36. package/dist/{chunk-A4XQWVZK.js → chunk-I7HKKMUJ.js} +77 -1
  37. package/dist/chunk-I7HKKMUJ.js.map +1 -0
  38. package/dist/{chunk-ECDL2TV4.js → chunk-TVEE2UUC.js} +257 -146
  39. package/dist/chunk-TVEE2UUC.js.map +1 -0
  40. package/dist/editable-artifact-materializer-service.d.ts +2 -2
  41. package/dist/editable-artifact-outbox-service.d.ts +2 -2
  42. package/dist/index.d.ts +55 -1
  43. package/dist/index.js +4 -3
  44. package/dist/index.js.map +1 -1
  45. package/dist/observability-metrics.d.ts +11 -3
  46. package/dist/retained-process-diagnostics.d.ts +4 -0
  47. package/dist/sandbox-resume.d.ts +2 -12
  48. package/dist/sandbox-routing.d.ts +5 -3
  49. package/dist/sandbox-snapshot-diagnostics.d.ts +20 -0
  50. package/dist/warm-capture-holder.d.ts +3 -0
  51. package/dist/workflow-bundle.js +51 -11
  52. package/package.json +19 -19
  53. package/src/activities/agent-turn/agent-build.ts +42 -5
  54. package/src/activities/agent-turn/claim.ts +11 -0
  55. package/src/activities/agent-turn/codex-capacity.ts +26 -4
  56. package/src/activities/agent-turn/codex.ts +6 -2
  57. package/src/activities/agent-turn/compaction-prep.ts +53 -72
  58. package/src/activities/agent-turn/errors.ts +77 -10
  59. package/src/activities/agent-turn/failure-settlement.ts +49 -28
  60. package/src/activities/agent-turn/finalization.ts +27 -4
  61. package/src/activities/agent-turn/governance-model.ts +15 -19
  62. package/src/activities/agent-turn/history.ts +24 -10
  63. package/src/activities/agent-turn/recovery-warning.ts +18 -0
  64. package/src/activities/agent-turn/run-credentials.ts +3 -7
  65. package/src/activities/agent-turn/run.ts +67 -13
  66. package/src/activities/agent-turn/sandbox-establish.ts +10 -2
  67. package/src/activities/agent-turn/sandbox-route.ts +0 -20
  68. package/src/activities/agent-turn/sandbox-runtime.ts +40 -7
  69. package/src/activities/agent-turn/skill-remove.ts +46 -0
  70. package/src/activities/agent-turn/skill-save.ts +1 -1
  71. package/src/activities/agent-turn/skill-search.ts +1 -1
  72. package/src/activities/agent-turn/skill-selection.ts +1 -0
  73. package/src/activities/agent-turn/skill-tools.ts +10 -5
  74. package/src/activities/agent-turn/stream-attempt.ts +38 -15
  75. package/src/activities/agent-turn/tool-environment.ts +34 -27
  76. package/src/activities/agent-turn/turn-sandbox-access.ts +7 -1
  77. package/src/activities/capabilities.ts +17 -2
  78. package/src/activities/codex-capacity.ts +38 -9
  79. package/src/activities/codex-rotation.ts +18 -5
  80. package/src/activities/context-compaction.ts +26 -4
  81. package/src/activities/google-drive-publication.ts +1 -3
  82. package/src/activities/mcp-account-routes.ts +139 -0
  83. package/src/activities/mcp-credentials.ts +83 -194
  84. package/src/activities/mcp-operation-authority.ts +16 -41
  85. package/src/activities/parent-wake.ts +8 -0
  86. package/src/activities/rig-verification.ts +38 -37
  87. package/src/activities/run-input.ts +25 -16
  88. package/src/activities/sandbox-images.ts +0 -1
  89. package/src/activities/sandbox-lease.ts +145 -37
  90. package/src/activities/scheduled-tasks.ts +118 -93
  91. package/src/activities/session-state.ts +83 -3
  92. package/src/activities/types.ts +18 -2
  93. package/src/editable-artifact-materializer-service.ts +7 -3
  94. package/src/editable-artifact-outbox-service.ts +4 -4
  95. package/src/github-rest-mcp.ts +0 -1
  96. package/src/index.ts +2 -1
  97. package/src/observability-metrics.ts +105 -2
  98. package/src/personal-github-git-credentials.ts +0 -1
  99. package/src/pr-review-credentials.ts +0 -2
  100. package/src/retained-process-diagnostics.ts +50 -0
  101. package/src/sandbox-resume.ts +58 -73
  102. package/src/sandbox-routing.ts +44 -19
  103. package/src/sandbox-snapshot-diagnostics.ts +112 -0
  104. package/src/warm-capture-holder.ts +15 -0
  105. package/src/workflows/session.ts +64 -2
  106. package/dist/activities/packs.d.ts +0 -55
  107. package/dist/activities-control-FNC52DPR.js.map +0 -1
  108. package/dist/activities-turn-TQ3D6UE2.js.map +0 -1
  109. package/dist/chunk-A4XQWVZK.js.map +0 -1
  110. package/dist/chunk-ECDL2TV4.js.map +0 -1
  111. package/src/activities/packs.ts +0 -166
@@ -24,7 +24,7 @@ export declare function acceptsPromptCacheKeyForTurn(resolvedModel: {
24
24
  export declare function refreshCappedCodexUsageRows(db: ActivityServices["db"], settings: Settings, workspaceId: string, accounts: Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>, capacitySignals: {
25
25
  signalCodexCapacityWorkflow?: ActivityServices["signalCodexCapacityWorkflow"] | undefined;
26
26
  wakeSessionWorkflow: ActivityServices["wakeSessionWorkflow"];
27
- }): Promise<Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>>;
27
+ }, acceptedTurnId?: string): Promise<Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>>;
28
28
  /**
29
29
  * True once the lifetime last confirmed by Postgres is no longer trustworthy.
30
30
  * A missing or malformed deadline fails closed for a holder that claims to be
@@ -1,4 +1,3 @@
1
- import { serializedToolsForRemoteCompaction } from "@opengeni/runtime";
2
1
  import { type Settings } from "@opengeni/config";
3
2
  import { maybeCompactContext } from "../context-compaction.js";
4
3
  import type { CompactionSummarizer, RemoteCompactionV2Requester } from "../context-compaction.js";
@@ -10,10 +9,7 @@ import type { ClaimTurnOk } from "./claim.js";
10
9
  import type { GovernanceModelOk } from "./governance-model.js";
11
10
  import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState, ProviderTurnState, TurnControlState } from "./turn-context.js";
12
11
  export type RemoteCompactionPrefix = {
13
- tools: Awaited<ReturnType<typeof serializedToolsForRemoteCompaction>>;
14
- instructions: string;
15
- toolsReady: boolean;
16
- agent: Parameters<typeof serializedToolsForRemoteCompaction>[0] | null;
12
+ agent: ReturnType<ActivityServices["runtime"]["buildAgent"]> | null;
17
13
  };
18
14
  export type CompactionPrepDeps = {
19
15
  input: RunAgentTurnInput;
@@ -1,4 +1,4 @@
1
- import { type MaterializationVerificationDiagnostic } from "@opengeni/runtime";
1
+ import { type CompactionProviderRejection, type MaterializationVerificationDiagnostic } from "@opengeni/runtime";
2
2
  import { type McpTransportRequestFailureDiagnostic } from "@opengeni/runtime/mcp-network";
3
3
  import { ApplicationFailure } from "@temporalio/activity";
4
4
  import type { CodexAccountStatus } from "@opengeni/db";
@@ -68,11 +68,9 @@ export declare function escapedMcpTimeoutRecoveryFailure(input: {
68
68
  * Convert the atomic claim transaction's failure into a small, stable
69
69
  * Temporal wire contract. The original error remains in activity diagnostics,
70
70
  * but SQL text, parameters, and arbitrary invariant messages never enter
71
- * workflow history. Every database failure is safe to re-read after backoff
72
- * because the claim transaction contains no model/tool effects. Database
73
- * constraints and authorization guards can also be repaired by a deployment or
74
- * authority refresh, so they must preserve pending work. Only a non-database
75
- * claim invariant is terminal.
71
+ * workflow history. Operational failures retry; other persistence rejections
72
+ * retain accepted work behind a durable explicit-recheck fence. Repeating the
73
+ * same rejected transaction without changed conditions is not recovery.
76
74
  */
77
75
  export declare function preClaimAdmissionFailure(error: unknown): ApplicationFailure;
78
76
  /**
@@ -148,7 +146,29 @@ export type SafeErrorDiagnostic = {
148
146
  */
149
147
  export declare function safeErrorDiagnostic(error: unknown): SafeErrorDiagnostic;
150
148
  export declare function safeErrorForTelemetry(error: unknown): Error;
149
+ /**
150
+ * Guidance appended to a definitive provider rejection. Repeating the exact
151
+ * request cannot succeed, so the generic "send another message to retry"
152
+ * advice is wrong here: a new prompt re-sends the same rejected history.
153
+ */
154
+ export declare const COMPACTION_PROVIDER_REJECTION_GUIDANCE = "The provider refused this exact request, so repeating it fails the same way until the conversation changes. If a new message fails again, start a new session.";
151
155
  export declare function compactionFailureReasonFromError(error: unknown): string;
156
+ /**
157
+ * Exact `turn.failed` payload for a terminal compaction failure. A definitive
158
+ * provider rejection additionally carries its closed identifier record so the
159
+ * timeline, API consumers, and operators can name the rejected field without
160
+ * parsing the message.
161
+ */
162
+ export declare function compactionFailureTurnEventPayload(error: unknown, overrides?: {
163
+ error?: string;
164
+ }): {
165
+ error: string;
166
+ code: "context_compaction_failed";
167
+ retryable: false;
168
+ recovery: "user_message";
169
+ compacted: false;
170
+ providerRejection?: CompactionProviderRejection;
171
+ };
152
172
  export declare function isCompactionSummaryFailure(error: unknown): boolean;
153
173
  export declare function shouldRecoverCompactionProviderFailure(error: unknown): boolean;
154
174
  export declare function classifyContextWindowOverflowError(error: unknown): {
@@ -1,7 +1,6 @@
1
1
  import { materializeRigVersionForAttempt } from "@opengeni/db";
2
2
  import { renderWorkspaceGovernanceContext, type OpenGeniRuntime } from "@opengeni/runtime";
3
3
  import { type Settings } from "@opengeni/config";
4
- import { resolveWorkspacePackRuntime } from "../packs.js";
5
4
  import { createModelHistoryAttachmentProjector } from "../run-input.js";
6
5
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput, RunAgentTurnResult } from "../types.js";
7
6
  import { buildCompanyBrainContributionReceipt } from "../../model-context-contributions.js";
@@ -35,7 +34,6 @@ export type GovernanceModelDeps = {
35
34
  };
36
35
  export type GovernanceModelOk = {
37
36
  runtimePreparationStartedAt: number;
38
- packRuntime: Awaited<ReturnType<typeof resolveWorkspacePackRuntime>>;
39
37
  rigVersion: NonNullable<Awaited<ReturnType<typeof materializeRigVersionForAttempt>>>["version"] | null;
40
38
  rigName: string | null;
41
39
  agentHumanInputEnabled: boolean;
@@ -0,0 +1,8 @@
1
+ import { type Database } from "@opengeni/db";
2
+ /** Opt-in belongs to this warning-aware worker implementation, not the DB
3
+ * client, role defaults or deployment configuration. Claim stamps it locally. */
4
+ export declare const FILESYSTEM_DISCONTINUITY_PROTOCOL: 1;
5
+ export declare function recoveryAwareSessionInstructions(db: Database, workspaceId: string, session: {
6
+ id: string;
7
+ instructions?: string | null;
8
+ }): Promise<string>;
@@ -54,7 +54,6 @@ export declare function prepareRunCredentials(deps: PrepareRunCredentialsDeps):
54
54
  initialRunCredentialMaterial: NormalizedRunCredentialMaterial | null;
55
55
  runCredentialsNote: string | undefined;
56
56
  authorizeGitHubTokenMint: GitHubTokenMintAuthorization;
57
- hostCredentialRootSessionId: string | null;
58
57
  gitCredentialAuthority: import("../environment.js").GitCredentialAuthority | undefined;
59
58
  codemodeAuthority: {
60
59
  sessionId: string;
@@ -4,7 +4,7 @@ import { type GitCredentialTokenWriterSession, type NormalizedRunCredentialMater
4
4
  import { type Settings } from "@opengeni/config";
5
5
  import { mergeResourceRefs } from "../common.js";
6
6
  import { type MintedRunGitCredentials, type SandboxCodemodeAuthority } from "../environment.js";
7
- import { rigProviderImageSourceImage } from "../packs.js";
7
+ import { rigProviderImageSourceImage } from "../sandbox-images.js";
8
8
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput } from "../types.js";
9
9
  import type { currentActivityContext } from "../streaming.js";
10
10
  import { type ResumedTurnSandbox } from "../../sandbox-resume.js";
@@ -109,15 +109,6 @@ export declare function reconcileActiveSandboxPointer(db: ActivityServices["db"]
109
109
  type: SessionEventType;
110
110
  payload: unknown;
111
111
  }>) => Promise<void> | void): Promise<LoadedActivePointer>;
112
- /**
113
- * Warm the Modal private-registry image for the image ref this turn actually
114
- * resolved, not only the deployment-global OPENGENI_MODAL_IMAGE_REF warmed at
115
- * worker boot. A provider-native modalImageId bypasses registry import and is
116
- * resolved by ModalImageSelector.fromId during create. Otherwise packs can
117
- * override `modalImageRef` per workspace/turn, so a private pack image must be
118
- * resolved before sandbox creation or Modal falls back to the unauthenticated
119
- * `fromTag` path.
120
- */
121
112
  export declare function ensureTurnModalRegistryImage(runSettings: Settings, sandboxCreationBackend: Settings["sandboxBackend"] | undefined, ensureRegistryImage?: (settings: Settings) => Promise<void>): Promise<void>;
122
113
  export declare const SANDBOX_ARTIFACT_RUNTIME_MANIFEST = "/opt/opengeni/artifact-runtime/installation.json";
123
114
  export declare const SANDBOX_ARTIFACT_TOOL_ENTRY = "/opt/opengeni/artifact-runtime/skill-facade-entry.mjs";
@@ -125,17 +116,6 @@ export type SandboxArtifactRuntimeAdmission = Readonly<{
125
116
  available: boolean;
126
117
  environment: Readonly<Record<string, string>>;
127
118
  }>;
128
- /**
129
- * Admit the optional native standalone-file runtime only for the deployment's
130
- * exact base sandbox image contract. A pack/rig image override is an
131
- * independent filesystem and therefore fails closed even when the deployment
132
- * base image is capable. Collaborative artifact skills are admitted separately
133
- * from the frozen canonical tool catalog.
134
- *
135
- * This keeps lazy provisioning intact: CI/release proves the image closure,
136
- * while a before-agent-start doctor verifies the actual box before any model
137
- * call. No speculative sandbox is created merely to populate the skill index.
138
- */
139
119
  export declare function sandboxArtifactRuntimeAdmission(deploymentSettings: Settings, runSettings: Settings, backend: Settings["sandboxBackend"] | undefined, options?: Readonly<{
140
120
  production?: boolean;
141
121
  }>): SandboxArtifactRuntimeAdmission;
@@ -40,7 +40,7 @@ export declare function createSandboxTurnRuntime(deps: SandboxTurnRuntimeDeps):
40
40
  onHomeSandboxRebound: (rebound: {
41
41
  established: EstablishedSandboxSession;
42
42
  leaseEpoch: number;
43
- }) => void;
43
+ }) => Promise<void>;
44
44
  runWorkspaceMutationForSandbox: <T>(sandbox: ResumedTurnSandbox, operation: string, mutation: () => Promise<T>, observePhase?: (measurement: {
45
45
  phase: "admission" | "provider" | "settlement" | "snapshot_wait";
46
46
  outcome: "completed" | "failed";
@@ -0,0 +1,14 @@
1
+ import type { AttemptToolDefinition } from "@opengeni/codemode";
2
+ import { z } from "zod";
3
+ import type { SkillWriteReceipt } from "@opengeni/contracts";
4
+ export declare const SkillRemoveRequest: z.ZodObject<{
5
+ operationId: z.ZodUUID;
6
+ skillId: z.ZodUUID;
7
+ expectedRevisionId: z.ZodNullable<z.ZodUUID>;
8
+ expectedScopeVersion: z.ZodNumber;
9
+ reason: z.ZodString;
10
+ }, z.core.$strict>;
11
+ export declare function createSkillRemoveAttemptToolDefinition(input: {
12
+ authorize: () => Promise<void>;
13
+ remove: (request: z.infer<typeof SkillRemoveRequest>) => Promise<SkillWriteReceipt>;
14
+ }): AttemptToolDefinition;
@@ -7,7 +7,7 @@ export type WorkspaceSkillSearchEntry = Readonly<{
7
7
  revisionId?: string;
8
8
  scopeVersion?: number;
9
9
  installationVersion?: number;
10
- source?: "workspace" | "builtin" | "session" | "pack";
10
+ source?: "workspace" | "builtin" | "session";
11
11
  }>;
12
12
  export declare function createSkillSearchAttemptToolDefinition(input: {
13
13
  authorize: () => Promise<void>;
@@ -82,6 +82,7 @@ export type TurnStreamAttemptDeps = {
82
82
  turn: {
83
83
  executionGeneration: number;
84
84
  model: string;
85
+ source?: string;
85
86
  };
86
87
  trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>;
87
88
  humanInputResume: Awaited<ReturnType<typeof getHumanInputResumeForEvent>>;
@@ -9,7 +9,6 @@ import type { GovernanceModelOk } from "./governance-model.js";
9
9
  import type { SandboxTurnRuntime } from "./sandbox-runtime.js";
10
10
  import type { sandboxArtifactRuntimeAdmission } from "./sandbox-route.js";
11
11
  import type { AttemptIdentityState, EventingState, SandboxRuntimeState, WorkspaceRefState } from "./turn-context.js";
12
- import type { RuntimeSkillActivation } from "@opengeni/runtime";
13
12
  export type PrepareTurnToolPolicyDeps = {
14
13
  input: RunAgentTurnInput;
15
14
  db: ActivityServices["db"];
@@ -25,7 +24,6 @@ export type PrepareTurnToolPolicyDeps = {
25
24
  };
26
25
  export type PrepareTurnToolRuntimeDeps = {
27
26
  fetchKnowledgeSource?: ((input: import("../types.js").RunKnowledgeSourceSyncBatchInput) => Promise<import("../types.js").RunKnowledgeSourceSyncBatchResult>) | undefined;
28
- selectedSkillActivations: readonly RuntimeSkillActivation[];
29
27
  input: RunAgentTurnInput;
30
28
  catalogSourceSettings: Settings;
31
29
  db: ActivityServices["db"];
@@ -34,7 +32,6 @@ export type PrepareTurnToolRuntimeDeps = {
34
32
  objectStorage: ActivityServices["objectStorage"];
35
33
  observability: ActivityServices["observability"];
36
34
  cancellationSignal: AbortSignal | undefined;
37
- connectionCredentials: ActivityServices["connectionCredentials"];
38
35
  eventing: EventingState;
39
36
  attempt: AttemptIdentityState;
40
37
  sandboxState: SandboxRuntimeState;
@@ -55,7 +52,6 @@ export type PrepareTurnToolRuntimeDeps = {
55
52
  accountId: string;
56
53
  workspaceId: string;
57
54
  };
58
- hostCredentialRootSessionId: string | null;
59
55
  sandboxArtifactRuntime: ReturnType<typeof sandboxArtifactRuntimeAdmission>;
60
56
  activeSandboxBackend: Settings["sandboxBackend"] | undefined;
61
57
  groupBoxBackend: Settings["sandboxBackend"];
@@ -7,6 +7,9 @@ export type ResolvedTurnSandboxAccess = Readonly<{
7
7
  session: ChannelASession;
8
8
  leaseEpoch: number;
9
9
  }>;
10
+ /** The lazy wrapper remains the agent's owner even after provisioning fills
11
+ * resolvedSandbox with the raw provider handle for capture and release. */
12
+ export declare function ownedTurnSandboxForAgent(sandboxState: TurnSandboxAccessState): import("@opengeni/runtime").EstablishedSandboxSession | undefined;
10
13
  /** Join the turn's canonical sandbox boundary and return its active routed session. */
11
14
  export declare function resolveTurnSandboxAccess(sandboxState: TurnSandboxAccessState, sdkOwnedSandboxSession: unknown, unavailableMessage: string): Promise<ResolvedTurnSandboxAccess>;
12
15
  export {};
@@ -17,7 +17,7 @@ export declare function signalCodexCapacityWakeTargets(services: CodexCapacitySi
17
17
  export declare function signalPendingCodexCapacityWakeTargets(services: CodexCapacitySignalServices & {
18
18
  db: ControlActivityServices["db"];
19
19
  }, workspaceId: string): Promise<void>;
20
- export declare function codexCapacityDecision<TPolicyScope = never, TUnavailableDiagnostic = never>(context: CodexCapacitySelectionContext<TPolicyScope, TUnavailableDiagnostic>): ReturnType<Parameters<typeof reconcileCodexCapacityWaitDb>[2]>;
20
+ export declare function codexCapacityDecision<TPolicyScope = never, TUnavailableDiagnostic = never>(context: CodexCapacitySelectionContext<TPolicyScope, TUnavailableDiagnostic>, now?: Date): ReturnType<Parameters<typeof reconcileCodexCapacityWaitDb>[2]>;
21
21
  /**
22
22
  * Arm a durable Codex waiter and immediately re-evaluate it under the
23
23
  * allocator lock. A capacity mutation that commits just before the waiter is
@@ -28,6 +28,11 @@ export declare function codexCapacityDecision<TPolicyScope = never, TUnavailable
28
28
  export declare function armAndReconcileCodexCapacityWait(services: Pick<ControlActivityServices, "db" | "bus">, input: Parameters<typeof armCodexCapacityWait>[1], options?: {
29
29
  onArmed?: () => void;
30
30
  }): Promise<{
31
+ action: "stopped";
32
+ sessionStatus: "failed" | "queued";
33
+ waiter: import("@opengeni/db").CodexCapacityWait;
34
+ events: import("@opengeni/contracts").SessionEvent[];
35
+ } | {
31
36
  action: "stale";
32
37
  waiter: import("@opengeni/db").CodexCapacityWait | null;
33
38
  events: import("@opengeni/contracts").SessionEvent[];
@@ -1,7 +1,7 @@
1
1
  import type { CodexAccountStatus, CodexCredentialLeaseSelectionContext, CodexLeaseAccountStatus, CodexPinSource } from "@opengeni/db";
2
2
  export type CodexRotationAccount = CodexAccountStatus | CodexLeaseAccountStatus;
3
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;
4
+ export declare function codexAccountNeedsLiveCapacityRefresh(account: Pick<CodexAccountStatus, "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">, _now: Date): boolean;
5
5
  export type CodexRotationStrategy = "most_remaining" | "round_robin" | "drain_then_next" | "sharded";
6
6
  /**
7
7
  * The ONE strategy rotation-enabled workspaces run: sticky-sharded. The legacy
@@ -1,5 +1,5 @@
1
1
  import { type Database } from "@opengeni/db";
2
- import { type CompactionItem } from "@opengeni/runtime";
2
+ import { type CompactionItem, type CompactionProviderRejection } from "@opengeni/runtime";
3
3
  import { type Settings } from "@opengeni/config";
4
4
  import type { SessionEvent } from "@opengeni/contracts";
5
5
  export type MaybeCompactResult = {
@@ -77,6 +77,12 @@ export declare function settleFailedContextCompactionLandmark(db: Database, scop
77
77
  }, options?: {
78
78
  clearRequestedCompaction?: boolean;
79
79
  publishLiveEvents?: (events: SessionEvent[]) => Promise<void>;
80
+ /**
81
+ * Closed identifier record of a definitive provider rejection. Carried on
82
+ * the visible `compaction.skipped` landmark so the timeline can name the
83
+ * rejected field instead of offering a retry that cannot succeed.
84
+ */
85
+ providerRejection?: CompactionProviderRejection | null;
80
86
  }): Promise<Extract<MaybeCompactResult, {
81
87
  compacted: false;
82
88
  }>>;
@@ -0,0 +1,22 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import type { McpConnectionAccountBinding, ToolRef, ToolAuthNeededPayload } from "@opengeni/contracts";
3
+ import type { ApiIntegrationRuntime } from "@opengeni/db";
4
+ export declare function accountRouteAuthNeededPayload(payload: ToolAuthNeededPayload, bindings: readonly McpConnectionAccountBinding[] | null | undefined): ToolAuthNeededPayload;
5
+ /** Expand only after canonical tool-policy admission. Aliases are execution
6
+ * identities, never an alternate way to gain admission to a connector. */
7
+ export declare function expandMcpAccountRoutes(input: {
8
+ settings: Settings;
9
+ tools: ToolRef[];
10
+ bindings: readonly McpConnectionAccountBinding[] | null | undefined;
11
+ }): {
12
+ settings: Settings;
13
+ tools: ToolRef[];
14
+ accountLabels: ReadonlyMap<string, string>;
15
+ };
16
+ /** Each adapter closes over its own immutable credential ref and authority
17
+ * generation. Sharing a provider transport never shares a credential resolver. */
18
+ export declare function expandApiIntegrationAccountRoutes(input: {
19
+ integrations: readonly ApiIntegrationRuntime[];
20
+ bindings: readonly McpConnectionAccountBinding[] | null | undefined;
21
+ tools: readonly ToolRef[];
22
+ }): ApiIntegrationRuntime[];
@@ -1,22 +1,21 @@
1
1
  import type { Settings } from "@opengeni/config";
2
- import type { ConnectionCredentialsPort } from "@opengeni/contracts";
3
- import { getSessionTurnForAttempt, resolveAcceptedConnectionUse, sessionTenancyProductActivated, type Database, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult, type SessionTurnForExecution } from "@opengeni/db";
4
- import { type Observability } from "@opengeni/observability";
5
- export declare function connectionTokenResolverForTurn(input: {
2
+ import { resolveAcceptedConnectionUse, type Database, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult, type SessionTurnForExecution } from "@opengeni/db";
3
+ type TurnConnectionInput = {
6
4
  db: Database;
7
5
  settings: Settings;
8
- connectionCredentials?: ConnectionCredentialsPort | null;
9
6
  accountId: string;
10
7
  workspaceId: string;
11
8
  sessionId: string;
12
- rootSessionId: string;
13
9
  attemptId: string;
14
10
  turn: SessionTurnForExecution;
11
+ /** Policy identities before account expansion; never used to select credentials. */
12
+ canonicalMcpServerIds?: readonly string[];
15
13
  authorizeAcceptedUse?: typeof resolveAcceptedConnectionUse;
16
- /** Test seam; production always reads the canonical active-attempt projection. */
17
- getHostTurnForAttempt?: typeof getSessionTurnForAttempt;
18
- /** Test seam for the activation fence on pre-snapshot workspace refs. */
19
- isSessionTenancyProductActivated?: typeof sessionTenancyProductActivated;
20
- /** Optional; used only for content-free compatibility-lane counters. */
21
- observability?: Observability | null | undefined;
22
- }): (request: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
14
+ };
15
+ type CredentialResolver = (request: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
16
+ export declare function connectionTokenResolverForTurn(input: TurnConnectionInput): CredentialResolver;
17
+ /** Bind the ordinary credential resolver to one immutable accepted turn.
18
+ * Credential acquisition and refresh stay inside the native connection engine;
19
+ * this layer adds the exact execution context and physical-request checks. */
20
+ export declare function bindNativeConnectionCredentialsToTurn(input: TurnConnectionInput, nativeResolver: CredentialResolver): CredentialResolver;
21
+ export {};
@@ -1,16 +1,11 @@
1
1
  import type { ConnectionUseAttribution } from "@opengeni/contracts/connection-authority";
2
- import type { HostMcpAcceptedAuthority } from "@opengeni/contracts/host-mcp-bindings";
3
2
  import type { ResolveConnectionCredentialInput } from "@opengeni/db";
4
3
  /** Metadata only. Callers must obtain authority from a current live fence.
5
4
  * This equality key is never authorization and never replaces physical-use checks. */
6
5
  export declare function mcpOperationAuthorityDigest(request: ResolveConnectionCredentialInput, authority: {
7
6
  native: ConnectionUseAttribution;
8
- host?: never;
9
7
  principal?: {
10
8
  kind: string;
11
9
  subjectId?: string;
12
10
  };
13
- } | {
14
- host: HostMcpAcceptedAuthority;
15
- native?: never;
16
11
  }): string;
@@ -4,7 +4,6 @@ import { acquireLease, commitWarmingToWarm, failWarmingToCold, markWarmLeaseInst
4
4
  import { createTurnToolCancellationController, establishSandboxSessionFromEnvelope, serializeEstablishedSandboxEnvelope, tagModalSandbox, type EstablishedSandboxSession, type TurnSandboxCommandArgs, type TurnSandboxCommandSession } from "@opengeni/runtime/sandbox";
5
5
  import type { Context } from "@temporalio/activity";
6
6
  import type { ControlActivityServices } from "./types.js";
7
- import { type WorkspacePackRuntime } from "./packs.js";
8
7
  type SandboxLifecycleCommandRunner = (session: TurnSandboxCommandSession, args: TurnSandboxCommandArgs) => Promise<unknown>;
9
8
  export type RigVerificationWorkflowInput = {
10
9
  workspaceId: string;
@@ -29,7 +28,7 @@ export type RigPlatformCheckResult = CommandResult & RigCheck;
29
28
  */
30
29
  export declare function rigPlatformChecksForSettings(settings: ControlActivityServices["settings"]): RigCheck[];
31
30
  export declare const RIG_VERIFICATION_OWNER_TTL_MS: number;
32
- export declare const RIG_VERIFICATION_OWNERS_DISABLED_MESSAGE = "Rig verification lease ownership is disabled; refusing to create an unowned verifier sandbox";
31
+ export declare const RIG_VERIFICATION_OWNERS_DISABLED_MESSAGE = "Sandbox Environment verification lease ownership is disabled; refusing to create an unowned verifier sandbox";
33
32
  export declare class RigVerificationActivityDeadlineError extends Error {
34
33
  readonly startToCloseTimeoutMs: number;
35
34
  readonly cleanupReserveMs: number;
@@ -146,7 +145,7 @@ export declare function buildVerifiedRigProviderImage(input: {
146
145
  lifecycle: RigVerificationActivityLifecycle;
147
146
  signal: AbortSignal;
148
147
  }): Promise<RigProviderImage>;
149
- export declare function settingsForRigVerification(settings: ControlActivityServices["settings"], packRuntime: WorkspacePackRuntime, rigImage: string | null): ControlActivityServices["settings"];
148
+ export declare function settingsForRigVerification(settings: ControlActivityServices["settings"], rigImage: string | null): ControlActivityServices["settings"];
150
149
  export declare function createRigVerificationActivities(services: () => Promise<ControlActivityServices>): {
151
150
  verifyRigChange: (input: {
152
151
  workspaceId: string;
@@ -1 +1 @@
1
- export { resolveRigProviderImageSelection, rigProviderImageSourceImage, settingsWithPackSandboxImage, settingsWithRigImage, settingsWithRigProviderImage, type RigProviderImageSelectionReason, } from "@opengeni/core";
1
+ export { resolveRigProviderImageSelection, rigProviderImageSourceImage, settingsWithRigImage, settingsWithRigProviderImage, type RigProviderImageSelectionReason, } from "@opengeni/core";
@@ -60,7 +60,7 @@ export type DrainCaptureDisposition = "capture_required" | "archive_published";
60
60
  * Test seams may return the legacy boolean shorthand. Production returns the
61
61
  * typed outcome so the cold commit can distinguish a clean stop from definitive
62
62
  * provider disappearance before capture. */
63
- export type TerminateBoxFn = (settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, capturePolicy?: ProviderWorkspaceCapturePolicy | null, diskBackedArchives?: boolean, releaseFailedCapture?: () => Promise<void>) => Promise<boolean | ProviderTerminationOutcome>;
63
+ export type TerminateBoxFn = (settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, capturePolicy?: ProviderWorkspaceCapturePolicy | null, diskBackedArchives?: boolean, releaseFailedCapture?: () => Promise<void>, workspaceId?: string) => Promise<boolean | ProviderTerminationOutcome>;
64
64
  export type SweepModalOrphansFn = (settings: ActivityServices["settings"], db: ActivityServices["db"], observability: ActivityServices["observability"]) => Promise<number>;
65
65
  export type InspectOpenSandboxKubernetesInventoryFn = (input: {
66
66
  namespace: string;
@@ -208,4 +208,4 @@ export declare function sandboxDrainReason(lease: Pick<LeaseSnapshot, "rotationR
208
208
  * draining until its adapter can prove termination. A truly instance-less or
209
209
  * `none`-backed row is a no-op.
210
210
  */
211
- export declare function terminateProviderBox(settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, createClientForBackend?: CreateSandboxClientForBackendFn, terminateModalById?: typeof terminateModalSandboxById, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, claimedCapturePolicy?: ProviderWorkspaceCapturePolicy | null, diskBackedArchives?: boolean, releaseFailedCapture?: () => Promise<void>): Promise<ProviderTerminationOutcome>;
211
+ export declare function terminateProviderBox(settings: ActivityServices["settings"], lease: NonNullable<Awaited<ReturnType<typeof readLease>>>, observability: ActivityServices["observability"], persistArchive: PersistArchiveFn, createClientForBackend?: CreateSandboxClientForBackendFn, terminateModalById?: typeof terminateModalSandboxById, providerCaptureRequestId?: string, captureDisposition?: DrainCaptureDisposition, claimedCapturePolicy?: ProviderWorkspaceCapturePolicy | null, diskBackedArchives?: boolean, releaseFailedCapture?: () => Promise<void>, workspaceId?: string): Promise<ProviderTerminationOutcome>;
@@ -1,4 +1,4 @@
1
- import { settleSessionAttemptInterruptions, applySessionTurnSettlement, enqueueSessionWorkflowWake, failSessionWorkBeforeAttemptClaim, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, settleSessionInputWait as settleSessionInputWaitDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionInteractionIntervention as expireSessionInteractionInterventionDb, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
1
+ import { settleSessionAttemptInterruptions, applySessionTurnSettlement, enqueueSessionWorkflowWake, failSessionWorkBeforeAttemptClaim, blockSessionWorkBeforeAttemptClaim, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, settleSessionInputWait as settleSessionInputWaitDb, 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
4
  import { recordTurnsQueuedGauge, recordWorkerDeathRecoveryMetrics } from "../observability-metrics.js";
@@ -8,6 +8,7 @@ export type SessionStateActivityOverrides = Partial<{
8
8
  applySessionTurnSettlement: typeof applySessionTurnSettlement;
9
9
  enqueueSessionWorkflowWake: typeof enqueueSessionWorkflowWake;
10
10
  failSessionWorkBeforeAttemptClaim: typeof failSessionWorkBeforeAttemptClaim;
11
+ blockSessionWorkBeforeAttemptClaim: typeof blockSessionWorkBeforeAttemptClaim;
11
12
  requestSessionTurnRecovery: typeof requestSessionTurnRecovery;
12
13
  recoverSessionDispatch: typeof recoverSessionDispatch;
13
14
  reconcileSessionAttemptQuiescence: typeof reconcileSessionAttemptQuiescence;
@@ -38,7 +39,61 @@ export declare function createSessionStateActivities(services: () => Promise<Con
38
39
  reconcileSessionAttemptQuiescence: (input: ReconcileSessionAttemptQuiescenceInput) => Promise<ReconcileSessionAttemptQuiescenceResult>;
39
40
  recoverDispatch: (input: RecoverDispatchInput) => Promise<RecoverDispatchResult>;
40
41
  recoverEscapedMcpTimeout: (input: RecoverEscapedMcpTimeoutInput) => Promise<RecoverEscapedMcpTimeoutResult>;
41
- peekSessionWork: (input: PeekSessionWorkInput) => Promise<import("@opengeni/db").SessionWorkPeek>;
42
+ peekSessionWork: (input: PeekSessionWorkInput) => Promise<{
43
+ kind: "unavailable";
44
+ } | {
45
+ kind: "attempt-owned";
46
+ turnId: string;
47
+ attemptId: string;
48
+ executionGeneration: number;
49
+ activityRef: import("@opengeni/db").SessionAttemptActivityRef;
50
+ } | {
51
+ kind: "runnable";
52
+ admissionFence?: import("@opengeni/db").SessionAdmissionFence;
53
+ } | {
54
+ kind: "admission-blocked";
55
+ } | {
56
+ kind: "sandbox-lifecycle-wait";
57
+ ref: import("@opengeni/db").SandboxLifecycleWait;
58
+ } | {
59
+ kind: "approval-pending";
60
+ triggerEventId: string;
61
+ admissionFence?: import("@opengeni/db").SessionAdmissionFence;
62
+ } | {
63
+ kind: "approval-wait";
64
+ humanInputRequestId?: string;
65
+ interactionInterventionId?: string;
66
+ expiresAt?: string;
67
+ } | {
68
+ kind: "capacity-wait";
69
+ ref: {
70
+ provider?: "codex" | "xai";
71
+ waiterId: string;
72
+ generation: number;
73
+ nextCheckAt: string;
74
+ wakeRevision: number;
75
+ };
76
+ } | {
77
+ kind: "interruption-pending";
78
+ attemptId: string;
79
+ } | {
80
+ kind: "cancellation-wait";
81
+ attemptId: string;
82
+ } | {
83
+ kind: "input-wait";
84
+ disposition: "held" | "timeout" | "superseded";
85
+ waitTurnId: string;
86
+ deadlineAt: string;
87
+ } | {
88
+ kind: "idle";
89
+ } | {
90
+ kind: "attempt-owned";
91
+ turnId: string;
92
+ attemptId: string;
93
+ executionGeneration: number;
94
+ activityRef: import("@opengeni/db").SessionAttemptActivityRef;
95
+ ownerActivityState: "pending" | "settled" | "unknown";
96
+ }>;
42
97
  settleSessionInputWait: (input: SettleSessionInputWaitInput) => Promise<SettleSessionInputWaitResult>;
43
98
  expireSessionHumanInput: (input: ExpireSessionHumanInputInput) => Promise<ExpireSessionHumanInputResult>;
44
99
  expireSessionInteractionIntervention: (input: ExpireSessionInteractionInterventionInput) => Promise<ExpireSessionInteractionInterventionResult>;
@@ -1,6 +1,6 @@
1
1
  import type { Settings } from "@opengeni/config";
2
2
  import type { ConnectionCredentialsPort, DocumentAuthorityKind, EntitlementsPort, KnowledgeSourceSyncRunSummary, ScheduledTaskTriggerType, TurnInitiator } from "@opengeni/contracts";
3
- import type { Database, SessionWorkflowWakeDeliveryResult } from "@opengeni/db";
3
+ import type { Database, SessionWorkflowWakeDeliveryResult, SessionAdmissionFence } from "@opengeni/db";
4
4
  import type { DocumentServices } from "@opengeni/documents";
5
5
  import type { EventBus } from "@opengeni/events";
6
6
  import type { Observability } from "@opengeni/observability";
@@ -191,6 +191,7 @@ export type FailSessionAttemptInput = {
191
191
  * committed claim discovered by the control lane can recover the exact
192
192
  * attempt instead of terminally failing it. */
193
193
  preClaimFailure?: PreClaimFailureDetail;
194
+ admissionFence?: SessionAdmissionFence;
194
195
  /** Added in v4. A claimed attempt that lost operational database access
195
196
  * before turn-start completion carries its exact immutable turn identity so
196
197
  * the DB-only control lane can recover it instead of terminally failing it. */
@@ -201,6 +202,8 @@ export type FailSessionAttemptInput = {
201
202
  error?: string;
202
203
  };
203
204
  export type FailSessionAttemptResult = {
205
+ action: "blocked";
206
+ } | {
204
207
  action: "failed";
205
208
  } | {
206
209
  action: "recovering";
@@ -211,10 +214,13 @@ export type FailSessionAttemptResult = {
211
214
  } | {
212
215
  action: "stale";
213
216
  };
214
- export type PreClaimFailureDisposition = "retryable" | "permanent";
217
+ export type PreClaimFailureDisposition = "retryable" | "permanent" | "blocked";
215
218
  export type PreClaimFailureDetail = {
216
219
  disposition: PreClaimFailureDisposition;
217
220
  code: "db_deadlock" | "db_serialization_failure" | "db_failure" | "claim_invariant";
221
+ sqlState?: string | null;
222
+ reason?: "database_claim_rejected" | "initiator_membership_required" | "personal_resource_grant_required";
223
+ retryPolicy?: "explicit_recheck";
218
224
  };
219
225
  export declare const PRE_CLAIM_FAILURE_TYPE = "OpenGeniPreClaimFailure";
220
226
  export declare const PRE_CLAIM_FAILURE_MESSAGE = "Agent turn admission failed before attempt claim.";
@@ -273,6 +279,9 @@ export type RecoverEscapedMcpTimeoutResult = {
273
279
  export type PeekSessionWorkInput = {
274
280
  workspaceId: string;
275
281
  sessionId: string;
282
+ includeAdmissionFence?: boolean;
283
+ /** Versioned workflow observer opt-in, never a caller authorization grant. */
284
+ observerAccountId?: string;
276
285
  };
277
286
  export type SettleSessionInputWaitInput = {
278
287
  accountId: string;
@@ -334,7 +343,7 @@ export type DispatchScheduledTaskRunResult = {
334
343
  action: "deleted";
335
344
  } | {
336
345
  action: "blocked";
337
- reason: "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit" | "malformed_manual_trigger" | "scheduled_task_paused" | "scheduled_authority_exhausted" | "scheduled_run_terminal" | "scheduled_execution_unrepresentable" | "knowledge_source_paused" | "legacy_source_schedule_requires_migration" | "incident_preflight_metadata_missing" | "incident_responder_under_capable" | "incident_data_source_unsuitable";
346
+ reason: "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit" | "malformed_manual_trigger" | "scheduled_task_paused" | "scheduled_authority_exhausted" | "scheduled_run_terminal" | "scheduled_execution_unrepresentable" | "connection_account_unavailable" | "knowledge_source_paused" | "legacy_source_schedule_requires_migration" | "incident_preflight_metadata_missing" | "incident_responder_under_capable" | "incident_data_source_unsuitable";
338
347
  } | {
339
348
  action: "start" | "signal";
340
349
  accountId: string;