@opengeni/worker-bundle 0.14.1 → 0.15.1
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.
- package/dist/activities/agent-turn.d.ts +13 -3
- package/dist/activities/capabilities.d.ts +1 -0
- package/dist/activities/packs.d.ts +2 -1
- package/dist/index.js +234 -16
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/activities/agent-turn.ts +263 -12
- package/src/activities/capabilities.ts +13 -0
- package/src/activities/packs.ts +13 -1
- package/src/index.ts +4 -3
|
@@ -526,9 +526,11 @@ export declare function reconcileActiveSandboxPointer(db: ActivityServices["db"]
|
|
|
526
526
|
/**
|
|
527
527
|
* Warm the Modal private-registry image for the image ref this turn actually
|
|
528
528
|
* resolved, not only the deployment-global OPENGENI_MODAL_IMAGE_REF warmed at
|
|
529
|
-
* worker boot.
|
|
530
|
-
*
|
|
531
|
-
*
|
|
529
|
+
* worker boot. A provider-native modalImageId bypasses registry import and is
|
|
530
|
+
* resolved by ModalImageSelector.fromId during create. Otherwise packs can
|
|
531
|
+
* override `modalImageRef` per workspace/turn, so a private pack image must be
|
|
532
|
+
* resolved before sandbox creation or Modal falls back to the unauthenticated
|
|
533
|
+
* `fromTag` path.
|
|
532
534
|
*/
|
|
533
535
|
export declare function ensureTurnModalRegistryImage(runSettings: Settings, sandboxCreationBackend: Settings["sandboxBackend"] | undefined, ensureRegistryImage?: (settings: Settings) => Promise<void>): Promise<void>;
|
|
534
536
|
/**
|
|
@@ -577,6 +579,8 @@ export declare function shouldStartOnTurnRecording(params: {
|
|
|
577
579
|
* • a "chat" (OpenAIChatCompletionsModel wire) provider → "disabled": it cannot
|
|
578
580
|
* receive a screenshot through a proven visual transport, so computer use fails
|
|
579
581
|
* closed instead of serializing the image as text.
|
|
582
|
+
* • Vercel Gateway providers → "disabled": their curated models support ordinary
|
|
583
|
+
* function tools and vision input, not OpenAI's hosted computer tool.
|
|
580
584
|
* • everything else — built-in Azure/OpenAI responses, registry "responses"
|
|
581
585
|
* providers, AND the LEGACY global-client fallback (resolveTurnModel returned
|
|
582
586
|
* null) — → "hosted": real Responses hosted-tool support.
|
|
@@ -589,6 +593,12 @@ export declare function computerToolModeForTurn(resolvedModel: {
|
|
|
589
593
|
api: ModelProviderApi;
|
|
590
594
|
};
|
|
591
595
|
} | null): ComputerToolMode;
|
|
596
|
+
/** Gateway models do not advertise OpenAI's hosted apply_patch/view_image tool types. */
|
|
597
|
+
export declare function structuredToolTransportForTurn(resolvedModel: {
|
|
598
|
+
provider: {
|
|
599
|
+
kind: RegistryProviderKind;
|
|
600
|
+
};
|
|
601
|
+
} | null): boolean;
|
|
592
602
|
/**
|
|
593
603
|
* Native web search is a runtime capability, not part of the session's MCP
|
|
594
604
|
* allow-list. Attach it whenever the resolved provider advertises runnable
|
|
@@ -16,3 +16,4 @@ export declare function settingsWithSessionMcpServers(settings: Settings, server
|
|
|
16
16
|
export declare function settingsWithCodexCredential(db: Database, workspaceId: string, settings: Settings, activeOverride?: boolean): Promise<Settings>;
|
|
17
17
|
/** Pure: append the synthetic codex-subscription provider, idempotently. */
|
|
18
18
|
export declare function withCodexProvider(settings: Settings): Settings;
|
|
19
|
+
export declare function settingsWithWorkspaceGatewayCredential(db: Database, workspaceId: string, settings: Settings): Promise<Settings>;
|
|
@@ -9,6 +9,7 @@ import { type EffectiveSkillSelection, type PackSkill } from "@opengeni/runtime"
|
|
|
9
9
|
*/
|
|
10
10
|
export type WorkspacePackRuntime = {
|
|
11
11
|
sandboxImage: string | null;
|
|
12
|
+
sandboxProviderImages: CapabilityPack["sandboxProviderImages"] | null;
|
|
12
13
|
skills: PackSkill[];
|
|
13
14
|
};
|
|
14
15
|
export type WorkspaceSkillLibraryRuntime = {
|
|
@@ -54,7 +55,7 @@ export declare function resolveWorkspaceAgentInstructions(db: Database, workspac
|
|
|
54
55
|
* the settings pass through untouched, so deployments without packs keep the
|
|
55
56
|
* global OPENGENI_DOCKER_IMAGE / OPENGENI_MODAL_IMAGE_REF behavior exactly.
|
|
56
57
|
*/
|
|
57
|
-
export declare function settingsWithPackSandboxImage(settings: Settings, sandboxImage: string | null): Settings;
|
|
58
|
+
export declare function settingsWithPackSandboxImage(settings: Settings, sandboxImage: string | null, sandboxProviderImages?: CapabilityPack["sandboxProviderImages"] | null): Settings;
|
|
58
59
|
/**
|
|
59
60
|
* Applies the session's frozen rig-version image to run settings. Rig image is
|
|
60
61
|
* the TOP of the image precedence chain (rig > pack > deployment default): when
|
package/dist/index.js
CHANGED
|
@@ -113,7 +113,10 @@ import {
|
|
|
113
113
|
isSessionEventPersistenceError,
|
|
114
114
|
getEnrollment,
|
|
115
115
|
abandonRecordingForTurnAttempt,
|
|
116
|
-
markSessionAttemptQuiesced
|
|
116
|
+
markSessionAttemptQuiesced,
|
|
117
|
+
beginConnectorActionExecution,
|
|
118
|
+
completeConnectorActionExecution,
|
|
119
|
+
prepareConnectorActionApproval
|
|
117
120
|
} from "@opengeni/db";
|
|
118
121
|
import { appendAndPublishTurnEventsFenced, publishDurableSessionEvents } from "@opengeni/events";
|
|
119
122
|
import { sandboxOperationMetricObserver } from "@opengeni/observability";
|
|
@@ -131,6 +134,7 @@ import {
|
|
|
131
134
|
composeAgentInstructions,
|
|
132
135
|
summarizeForCompaction as summarizeForCompaction2,
|
|
133
136
|
requestRemoteCompactionV2,
|
|
137
|
+
serializedToolsForRemoteCompaction,
|
|
134
138
|
REMOTE_COMPACTION_V2_BETA_FEATURE,
|
|
135
139
|
REMOTE_COMPACTION_V2_IMPLEMENTATION as REMOTE_COMPACTION_V2_IMPLEMENTATION2,
|
|
136
140
|
CompactionProviderResponseError,
|
|
@@ -198,13 +202,16 @@ import { ApplicationFailure, CancelledFailure as CancelledFailure2 } from "@temp
|
|
|
198
202
|
// src/activities/capabilities.ts
|
|
199
203
|
import {
|
|
200
204
|
environmentsEncryptionKeyBytes,
|
|
201
|
-
withCodexCatalogProvider
|
|
205
|
+
withCodexCatalogProvider,
|
|
206
|
+
withWorkspaceGatewayCatalogProvider,
|
|
207
|
+
withWorkspaceGatewayCredential
|
|
202
208
|
} from "@opengeni/config";
|
|
203
209
|
import { settingsWithEnabledCapabilityMcpServers } from "@opengeni/core";
|
|
204
210
|
import {
|
|
205
211
|
listSessionMcpServerMetadata,
|
|
206
212
|
listSessionMcpServersForRun,
|
|
207
|
-
workspaceCodexSubscriptionActive
|
|
213
|
+
workspaceCodexSubscriptionActive,
|
|
214
|
+
loadWorkspaceVercelAiGatewayApiKey
|
|
208
215
|
} from "@opengeni/db";
|
|
209
216
|
async function settingsWithSessionMcpServersForRun(db, workspaceId, sessionId, attemptId, settings, options) {
|
|
210
217
|
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
@@ -263,6 +270,11 @@ async function settingsWithCodexCredential(db, workspaceId, settings, activeOver
|
|
|
263
270
|
function withCodexProvider(settings) {
|
|
264
271
|
return withCodexCatalogProvider(settings);
|
|
265
272
|
}
|
|
273
|
+
async function settingsWithWorkspaceGatewayCredential(db, workspaceId, settings) {
|
|
274
|
+
const catalogSettings = withWorkspaceGatewayCatalogProvider(settings);
|
|
275
|
+
const apiKey = await loadWorkspaceVercelAiGatewayApiKey(db, settings, workspaceId);
|
|
276
|
+
return apiKey ? withWorkspaceGatewayCredential(catalogSettings, apiKey) : catalogSettings;
|
|
277
|
+
}
|
|
266
278
|
|
|
267
279
|
// src/activities/codex-rotation.ts
|
|
268
280
|
function effectiveRotationStrategy(_stored) {
|
|
@@ -2655,7 +2667,11 @@ import {
|
|
|
2655
2667
|
isSkillLibraryEntryId,
|
|
2656
2668
|
loadSkillLibrarySkill
|
|
2657
2669
|
} from "@opengeni/runtime";
|
|
2658
|
-
var emptyPackRuntime = {
|
|
2670
|
+
var emptyPackRuntime = {
|
|
2671
|
+
sandboxImage: null,
|
|
2672
|
+
sandboxProviderImages: null,
|
|
2673
|
+
skills: []
|
|
2674
|
+
};
|
|
2659
2675
|
async function resolveWorkspacePackRuntime(db, workspaceId) {
|
|
2660
2676
|
const installations = await listPackInstallations(db, workspaceId);
|
|
2661
2677
|
const active = installations.filter((installation) => installation.status === "active");
|
|
@@ -2771,6 +2787,7 @@ function workspacePackRuntimeFromPacks(packs) {
|
|
|
2771
2787
|
}
|
|
2772
2788
|
return {
|
|
2773
2789
|
sandboxImage: imagePacks[0]?.sandboxImage?.trim() ?? null,
|
|
2790
|
+
sandboxProviderImages: imagePacks[0]?.sandboxProviderImages ?? null,
|
|
2774
2791
|
skills
|
|
2775
2792
|
};
|
|
2776
2793
|
}
|
|
@@ -2778,14 +2795,15 @@ async function resolveWorkspaceAgentInstructions(db, workspaceId) {
|
|
|
2778
2795
|
const workspace = await getWorkspace(db, workspaceId);
|
|
2779
2796
|
return workspace?.agentInstructions ?? null;
|
|
2780
2797
|
}
|
|
2781
|
-
function settingsWithPackSandboxImage(settings, sandboxImage) {
|
|
2798
|
+
function settingsWithPackSandboxImage(settings, sandboxImage, sandboxProviderImages = null) {
|
|
2782
2799
|
if (!sandboxImage) {
|
|
2783
2800
|
return settings;
|
|
2784
2801
|
}
|
|
2785
2802
|
return {
|
|
2786
2803
|
...settings,
|
|
2787
2804
|
dockerImage: sandboxImage,
|
|
2788
|
-
modalImageRef: sandboxImage
|
|
2805
|
+
modalImageRef: sandboxImage,
|
|
2806
|
+
modalImageId: sandboxProviderImages?.modal?.imageId
|
|
2789
2807
|
};
|
|
2790
2808
|
}
|
|
2791
2809
|
function settingsWithRigImage(settings, rigImage) {
|
|
@@ -2795,7 +2813,11 @@ function settingsWithRigImage(settings, rigImage) {
|
|
|
2795
2813
|
return {
|
|
2796
2814
|
...settings,
|
|
2797
2815
|
dockerImage: rigImage,
|
|
2798
|
-
modalImageRef: rigImage
|
|
2816
|
+
modalImageRef: rigImage,
|
|
2817
|
+
// A rig image has no provider-native identity in the current rig contract.
|
|
2818
|
+
// Clear a lower-precedence pack/deployment ID so the rig cannot silently
|
|
2819
|
+
// run the wrong Modal image.
|
|
2820
|
+
modalImageId: void 0
|
|
2799
2821
|
};
|
|
2800
2822
|
}
|
|
2801
2823
|
function mergeRigDefaultVariableSetEnvironment(rigDefaultValues, sessionValues) {
|
|
@@ -7036,6 +7058,9 @@ async function ensureTurnModalRegistryImage(runSettings, sandboxCreationBackend,
|
|
|
7036
7058
|
if (sandboxCreationBackend !== "modal") {
|
|
7037
7059
|
return;
|
|
7038
7060
|
}
|
|
7061
|
+
if (runSettings.modalImageId) {
|
|
7062
|
+
return;
|
|
7063
|
+
}
|
|
7039
7064
|
if (!runSettings.modalImageRegistrySecret || !runSettings.modalImageRef) {
|
|
7040
7065
|
return;
|
|
7041
7066
|
}
|
|
@@ -7051,11 +7076,20 @@ function computerToolModeForTurn(resolvedModel) {
|
|
|
7051
7076
|
if (resolvedModel.provider.kind === "codex-subscription") {
|
|
7052
7077
|
return "function-image";
|
|
7053
7078
|
}
|
|
7079
|
+
if (resolvedModel.provider.kind === "vercel-gateway-managed" || resolvedModel.provider.kind === "vercel-gateway-workspace") {
|
|
7080
|
+
return "disabled";
|
|
7081
|
+
}
|
|
7054
7082
|
if (resolvedModel.provider.api === "chat") {
|
|
7055
7083
|
return "disabled";
|
|
7056
7084
|
}
|
|
7057
7085
|
return "hosted";
|
|
7058
7086
|
}
|
|
7087
|
+
function structuredToolTransportForTurn(resolvedModel) {
|
|
7088
|
+
if (!resolvedModel) return true;
|
|
7089
|
+
return !["codex-subscription", "vercel-gateway-managed", "vercel-gateway-workspace"].includes(
|
|
7090
|
+
resolvedModel.provider.kind
|
|
7091
|
+
);
|
|
7092
|
+
}
|
|
7059
7093
|
function hostedWebSearchForTurn(resolvedModel, deploymentWebSearchEnabled) {
|
|
7060
7094
|
return resolvedModel?.configured.hostedWebSearch ?? deploymentWebSearchEnabled;
|
|
7061
7095
|
}
|
|
@@ -7846,12 +7880,17 @@ function createRunAgentTurnActivity(services) {
|
|
|
7846
7880
|
mcpSettings,
|
|
7847
7881
|
input.workspaceId
|
|
7848
7882
|
);
|
|
7849
|
-
const
|
|
7883
|
+
const codexSettings = await settingsWithCodexCredential(
|
|
7850
7884
|
db,
|
|
7851
7885
|
input.workspaceId,
|
|
7852
7886
|
mcpSettings,
|
|
7853
7887
|
codexSubscriptionActive
|
|
7854
7888
|
);
|
|
7889
|
+
const capabilitySettings = await settingsWithWorkspaceGatewayCredential(
|
|
7890
|
+
db,
|
|
7891
|
+
input.workspaceId,
|
|
7892
|
+
codexSettings
|
|
7893
|
+
);
|
|
7855
7894
|
runtime.configure(capabilitySettings);
|
|
7856
7895
|
const session = await requireSession2(db, input.workspaceId, input.sessionId);
|
|
7857
7896
|
const claim = await claimSessionWorkForAttempt(db, input.workspaceId, {
|
|
@@ -8617,7 +8656,11 @@ function createRunAgentTurnActivity(services) {
|
|
|
8617
8656
|
// deployment default; a rig with no image (or a rig-less turn) is a
|
|
8618
8657
|
// pass-through, leaving the pack/deployment chain exactly as today.
|
|
8619
8658
|
...settingsWithRigImage(
|
|
8620
|
-
settingsWithPackSandboxImage(
|
|
8659
|
+
settingsWithPackSandboxImage(
|
|
8660
|
+
capabilitySettings,
|
|
8661
|
+
packRuntime.sandboxImage,
|
|
8662
|
+
packRuntime.sandboxProviderImages
|
|
8663
|
+
),
|
|
8621
8664
|
rigVersion?.image ?? null
|
|
8622
8665
|
),
|
|
8623
8666
|
openaiModel: turn.model,
|
|
@@ -8820,14 +8863,44 @@ function createRunAgentTurnActivity(services) {
|
|
|
8820
8863
|
...systemInstructions ? { systemInstructions } : {},
|
|
8821
8864
|
...promptCacheKey ? { promptCacheKey } : {}
|
|
8822
8865
|
});
|
|
8823
|
-
|
|
8824
|
-
|
|
8866
|
+
let remoteCompactionTools = [];
|
|
8867
|
+
let remoteCompactionInstructions = "";
|
|
8868
|
+
let remoteCompactionToolsReady = false;
|
|
8869
|
+
let remoteCompactionAgent = null;
|
|
8870
|
+
const remoteCompactionRequester = resolvedModel && isCodexTurn ? (s, m) => withCodexRemoteCompaction(async () => {
|
|
8871
|
+
if (!remoteCompactionInstructions.trim()) {
|
|
8872
|
+
throw new EmptyCompactionSummaryError2({
|
|
8873
|
+
stage: "remote_v2_instructions",
|
|
8874
|
+
reason: "agent_missing_system_instructions"
|
|
8875
|
+
});
|
|
8876
|
+
}
|
|
8877
|
+
if (!remoteCompactionToolsReady) {
|
|
8878
|
+
if (!remoteCompactionAgent) {
|
|
8879
|
+
throw new EmptyCompactionSummaryError2({
|
|
8880
|
+
stage: "remote_v2_tools",
|
|
8881
|
+
reason: "agent_missing_for_tools"
|
|
8882
|
+
});
|
|
8883
|
+
}
|
|
8884
|
+
try {
|
|
8885
|
+
remoteCompactionTools = await serializedToolsForRemoteCompaction(remoteCompactionAgent);
|
|
8886
|
+
} catch (error) {
|
|
8887
|
+
throw new EmptyCompactionSummaryError2({
|
|
8888
|
+
stage: "remote_v2_tools",
|
|
8889
|
+
reason: "serialize_tools_failed",
|
|
8890
|
+
error: String(error)
|
|
8891
|
+
});
|
|
8892
|
+
}
|
|
8893
|
+
remoteCompactionToolsReady = true;
|
|
8894
|
+
}
|
|
8895
|
+
return requestRemoteCompactionV2(s, m, {
|
|
8825
8896
|
client: resolvedModel.client,
|
|
8826
8897
|
model: turnExecutionPolicy.upstreamModelId,
|
|
8898
|
+
systemInstructions: remoteCompactionInstructions,
|
|
8827
8899
|
onUsage: recordCompactionUsage,
|
|
8900
|
+
tools: remoteCompactionTools,
|
|
8828
8901
|
...promptCacheKey ? { promptCacheKey } : {}
|
|
8829
|
-
})
|
|
8830
|
-
) : void 0;
|
|
8902
|
+
});
|
|
8903
|
+
}) : void 0;
|
|
8831
8904
|
const publishCompactionLiveEvents = async (events) => {
|
|
8832
8905
|
await publishDurableSessionEvents(bus, input.workspaceId, input.sessionId, events);
|
|
8833
8906
|
};
|
|
@@ -8846,7 +8919,9 @@ function createRunAgentTurnActivity(services) {
|
|
|
8846
8919
|
...remoteCompactionRequester ? { requestRemoteCompactionV2: remoteCompactionRequester } : {},
|
|
8847
8920
|
...effectiveCodexCredentialId ? { producerCodexCredentialId: effectiveCodexCredentialId } : {}
|
|
8848
8921
|
};
|
|
8849
|
-
|
|
8922
|
+
const compactionOnlyTurn = turn.source === "compaction";
|
|
8923
|
+
const remoteV2CompactionNeedsAgentPrefix = Boolean(remoteCompactionRequester) && session.codexCompactionMode === "remote_v2";
|
|
8924
|
+
if (compactionOnlyTurn && !remoteV2CompactionNeedsAgentPrefix) {
|
|
8850
8925
|
const persistentSessionSettings = {
|
|
8851
8926
|
titleIsSet: Boolean(session.title?.trim())
|
|
8852
8927
|
};
|
|
@@ -9710,6 +9785,29 @@ function createRunAgentTurnActivity(services) {
|
|
|
9710
9785
|
turnExecutionPolicy.providerId,
|
|
9711
9786
|
turnExecutionPolicy.latencyMode
|
|
9712
9787
|
);
|
|
9788
|
+
const connectorActionIdentity = {
|
|
9789
|
+
accountId: input.accountId,
|
|
9790
|
+
workspaceId: input.workspaceId,
|
|
9791
|
+
sessionId: input.sessionId,
|
|
9792
|
+
turnId,
|
|
9793
|
+
attemptId: input.attemptId,
|
|
9794
|
+
executionGeneration,
|
|
9795
|
+
initiator: {
|
|
9796
|
+
kind: turn.initiator.kind,
|
|
9797
|
+
subjectId: turn.initiator.subjectId
|
|
9798
|
+
}
|
|
9799
|
+
};
|
|
9800
|
+
const connectorActionPolicy = {
|
|
9801
|
+
prepare: async (call) => await prepareConnectorActionApproval(db, connectorActionIdentity, call),
|
|
9802
|
+
begin: async (call) => await beginConnectorActionExecution(db, connectorActionIdentity, call),
|
|
9803
|
+
complete: async ({ requestId, outcome }) => await completeConnectorActionExecution(db, {
|
|
9804
|
+
accountId: input.accountId,
|
|
9805
|
+
workspaceId: input.workspaceId,
|
|
9806
|
+
requestId,
|
|
9807
|
+
attemptId: input.attemptId,
|
|
9808
|
+
outcome
|
|
9809
|
+
})
|
|
9810
|
+
};
|
|
9713
9811
|
const agent = runtime.buildAgent(modelRunSettings, turnResources, {
|
|
9714
9812
|
reasoningEffort: turn.reasoningEffort,
|
|
9715
9813
|
latencyMode: turnExecutionPolicy.latencyMode,
|
|
@@ -9748,6 +9846,8 @@ function createRunAgentTurnActivity(services) {
|
|
|
9748
9846
|
...activeSandboxBackend ? { activeSandboxBackend } : {},
|
|
9749
9847
|
fileResourceDownloads,
|
|
9750
9848
|
mcpServers: preparedTools.mcpServers,
|
|
9849
|
+
resolvedMcpConnectionIds: preparedTools.resolvedMcpConnectionIds,
|
|
9850
|
+
connectorActionPolicy,
|
|
9751
9851
|
// LIVE by-reference connector namespaces (fills during this turn's
|
|
9752
9852
|
// codex_apps tools/list): the codex tool_search description reads it per
|
|
9753
9853
|
// model call so the model sees the account's real connected sources.
|
|
@@ -9779,7 +9879,7 @@ function createRunAgentTurnActivity(services) {
|
|
|
9779
9879
|
// (built-in OpenAI/Azure = real hosted support; registry "chat"
|
|
9780
9880
|
// providers = the SDK's own ChatCompletions detection) keeps the SDK
|
|
9781
9881
|
// default.
|
|
9782
|
-
structuredToolTransport: resolvedModel
|
|
9882
|
+
structuredToolTransport: structuredToolTransportForTurn(resolvedModel),
|
|
9783
9883
|
// EXPLICIT computer-use tool transport, derived from the resolved provider's
|
|
9784
9884
|
// authoritative wire identity (codex → function-image, chat → disabled,
|
|
9785
9885
|
// responses → hosted) so the runtime never string-sniffs the model instance's
|
|
@@ -10024,9 +10124,127 @@ function createRunAgentTurnActivity(services) {
|
|
|
10024
10124
|
}
|
|
10025
10125
|
);
|
|
10026
10126
|
}
|
|
10127
|
+
const agentInstructions = typeof agent.instructions === "string" ? agent.instructions : "";
|
|
10027
10128
|
const compactSummarizer = compactionSummarizerFor(
|
|
10028
|
-
|
|
10129
|
+
agentInstructions.trim() ? agentInstructions : void 0
|
|
10029
10130
|
);
|
|
10131
|
+
if (remoteCompactionRequester) {
|
|
10132
|
+
remoteCompactionInstructions = agentInstructions;
|
|
10133
|
+
remoteCompactionAgent = agent;
|
|
10134
|
+
}
|
|
10135
|
+
if (compactionOnlyTurn) {
|
|
10136
|
+
const requested = await isSessionCompactionRequested(
|
|
10137
|
+
db,
|
|
10138
|
+
input.workspaceId,
|
|
10139
|
+
input.sessionId
|
|
10140
|
+
);
|
|
10141
|
+
let outcome = null;
|
|
10142
|
+
if (requested) {
|
|
10143
|
+
try {
|
|
10144
|
+
outcome = await waitForTurnOperation(
|
|
10145
|
+
maybeCompactContext(
|
|
10146
|
+
db,
|
|
10147
|
+
modelRunSettings,
|
|
10148
|
+
{
|
|
10149
|
+
accountId: input.accountId,
|
|
10150
|
+
workspaceId: input.workspaceId,
|
|
10151
|
+
sessionId: input.sessionId,
|
|
10152
|
+
turnId: turn.id,
|
|
10153
|
+
executionGeneration,
|
|
10154
|
+
attemptId: input.attemptId
|
|
10155
|
+
},
|
|
10156
|
+
session.lastInputTokens,
|
|
10157
|
+
compactSummarizer,
|
|
10158
|
+
{
|
|
10159
|
+
force: true,
|
|
10160
|
+
clearRequestedCompaction: true,
|
|
10161
|
+
trigger: "operator",
|
|
10162
|
+
codexAccount: {
|
|
10163
|
+
currentCodexCredentialId: effectiveCodexCredentialId
|
|
10164
|
+
},
|
|
10165
|
+
...compactionModeOptions
|
|
10166
|
+
}
|
|
10167
|
+
),
|
|
10168
|
+
cancellationSignal,
|
|
10169
|
+
void 0
|
|
10170
|
+
);
|
|
10171
|
+
} catch (error) {
|
|
10172
|
+
if (shouldRecoverCompactionProviderFailure(error)) throw error;
|
|
10173
|
+
if (error instanceof TurnAttemptFencedError) throw error;
|
|
10174
|
+
const landmark = await settleFailedContextCompactionLandmark(
|
|
10175
|
+
db,
|
|
10176
|
+
{
|
|
10177
|
+
accountId: input.accountId,
|
|
10178
|
+
workspaceId: input.workspaceId,
|
|
10179
|
+
sessionId: input.sessionId,
|
|
10180
|
+
turnId: turn.id,
|
|
10181
|
+
executionGeneration,
|
|
10182
|
+
attemptId: input.attemptId
|
|
10183
|
+
},
|
|
10184
|
+
{
|
|
10185
|
+
clearRequestedCompaction: true,
|
|
10186
|
+
publishLiveEvents: publishCompactionLiveEvents
|
|
10187
|
+
}
|
|
10188
|
+
);
|
|
10189
|
+
if (!isCompactionSummaryFailure(error)) throw error;
|
|
10190
|
+
const errorMessage = String(redact(compactionFailureReasonFromError(error)));
|
|
10191
|
+
if (!await settle({
|
|
10192
|
+
events: [
|
|
10193
|
+
{
|
|
10194
|
+
type: "turn.failed",
|
|
10195
|
+
payload: {
|
|
10196
|
+
error: errorMessage,
|
|
10197
|
+
code: "context_compaction_failed",
|
|
10198
|
+
retryable: false,
|
|
10199
|
+
recovery: "user_message",
|
|
10200
|
+
compacted: false
|
|
10201
|
+
}
|
|
10202
|
+
},
|
|
10203
|
+
{
|
|
10204
|
+
type: "session.status.changed",
|
|
10205
|
+
payload: { status: "idle" }
|
|
10206
|
+
}
|
|
10207
|
+
],
|
|
10208
|
+
turnStatus: "failed",
|
|
10209
|
+
sessionStatus: "idle",
|
|
10210
|
+
activeTurnId: null,
|
|
10211
|
+
...landmark.requestConsumed ? {} : { consumeRequestedCompactionFailure: true }
|
|
10212
|
+
})) {
|
|
10213
|
+
return claimedResult({ status: "cancelled" });
|
|
10214
|
+
}
|
|
10215
|
+
turnMetricOutcome = "failed";
|
|
10216
|
+
activityStatus = "idle";
|
|
10217
|
+
activityError = error;
|
|
10218
|
+
return claimedResult({ status: "idle" });
|
|
10219
|
+
}
|
|
10220
|
+
if (outcome.events.length > 0) {
|
|
10221
|
+
if (outcome.compacted) {
|
|
10222
|
+
recordContextCompaction(observability, "operator");
|
|
10223
|
+
}
|
|
10224
|
+
await publishCompactionOutcomeEvents(outcome.events);
|
|
10225
|
+
}
|
|
10226
|
+
}
|
|
10227
|
+
if (!await settle({
|
|
10228
|
+
events: [
|
|
10229
|
+
{
|
|
10230
|
+
type: "turn.completed",
|
|
10231
|
+
payload: {
|
|
10232
|
+
maintenance: "context_compaction",
|
|
10233
|
+
result: outcome?.compacted ? "compacted" : outcome?.reason ?? "already_applied"
|
|
10234
|
+
}
|
|
10235
|
+
},
|
|
10236
|
+
{ type: "session.status.changed", payload: { status: "idle" } }
|
|
10237
|
+
],
|
|
10238
|
+
turnStatus: "completed",
|
|
10239
|
+
sessionStatus: "idle",
|
|
10240
|
+
activeTurnId: null
|
|
10241
|
+
})) {
|
|
10242
|
+
return claimedResult({ status: "cancelled" });
|
|
10243
|
+
}
|
|
10244
|
+
turnMetricOutcome = "completed";
|
|
10245
|
+
activityStatus = "idle";
|
|
10246
|
+
return claimedResult({ status: "idle" });
|
|
10247
|
+
}
|
|
10030
10248
|
if (triggerType === "user.message" || triggerType === "system.update.delivered") {
|
|
10031
10249
|
let forced = false;
|
|
10032
10250
|
try {
|