@opengeni/worker-bundle 1.0.0-canary.0 → 1.0.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.
- package/dist/activities/agent-run-admission.d.ts +3 -1
- package/dist/activities/agent-turn/admission.d.ts +24 -3
- package/dist/activities/agent-turn/agent-build.d.ts +4 -0
- package/dist/activities/agent-turn/claude-usage-observer.d.ts +58 -0
- package/dist/activities/agent-turn/code-search.d.ts +60 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +13 -0
- package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
- package/dist/activities/agent-turn/codex.d.ts +3 -2
- package/dist/activities/agent-turn/compaction-prep.d.ts +21 -5
- package/dist/activities/agent-turn/credential-leases.d.ts +19 -33
- package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
- package/dist/activities/agent-turn/errors.d.ts +82 -11
- package/dist/activities/agent-turn/failure-settlement.d.ts +6 -3
- package/dist/activities/agent-turn/final-reply.d.ts +18 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +17 -0
- package/dist/activities/agent-turn/finalization.d.ts +4 -2
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
- package/dist/activities/agent-turn/governance-model.d.ts +9 -2
- package/dist/activities/agent-turn/history-sink.d.ts +2 -0
- package/dist/activities/agent-turn/history.d.ts +2 -0
- package/dist/activities/agent-turn/input-wait-reply.d.ts +41 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
- package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
- package/dist/activities/agent-turn/model-usage.d.ts +6 -0
- package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
- package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
- package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
- package/dist/activities/agent-turn/quiescence.d.ts +7 -7
- package/dist/activities/agent-turn/recovery-warning.d.ts +9 -0
- package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +8 -3
- package/dist/activities/agent-turn/sandbox-establish.d.ts +2 -1
- package/dist/activities/agent-turn/sandbox-provision.d.ts +3 -1
- package/dist/activities/agent-turn/sandbox-route.d.ts +3 -20
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +2 -2
- package/dist/activities/agent-turn/session-title.d.ts +34 -2
- package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
- package/dist/activities/agent-turn/skill-read.d.ts +70 -2
- package/dist/activities/agent-turn/skill-remove.d.ts +14 -0
- package/dist/activities/agent-turn/skill-search.d.ts +3 -1
- package/dist/activities/agent-turn/skill-tools.d.ts +15 -2
- package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
- package/dist/activities/agent-turn/stream-attempt.d.ts +7 -3
- package/dist/activities/agent-turn/subscription-lease.d.ts +38 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +56 -6
- package/dist/activities/agent-turn/tool-policy.d.ts +43 -0
- package/dist/activities/agent-turn/turn-context.d.ts +29 -0
- package/dist/activities/agent-turn/turn-sandbox-access.d.ts +3 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +2 -1
- package/dist/activities/automations.d.ts +3 -1
- package/dist/activities/browser-deadline-checkpoint.d.ts +29 -0
- package/dist/activities/codemode-dispatcher.d.ts +9 -2
- package/dist/activities/codex-capacity.d.ts +18 -2
- package/dist/activities/codex-rotation.d.ts +7 -1
- package/dist/activities/context-compaction.d.ts +16 -2
- package/dist/activities/gmail-files.d.ts +32 -0
- package/dist/activities/goals.d.ts +8 -0
- package/dist/activities/knowledge-indexing.d.ts +19 -0
- package/dist/activities/mcp-account-routes.d.ts +3 -0
- package/dist/activities/mcp-credentials.d.ts +12 -13
- package/dist/activities/mcp-operation-authority.d.ts +0 -5
- package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
- package/dist/activities/open-suffix-resume.d.ts +13 -0
- package/dist/activities/parent-wake.d.ts +6 -12
- package/dist/activities/retained-screenshots.d.ts +7 -2
- package/dist/activities/rig-verification.d.ts +2 -3
- package/dist/activities/run-credential-renewal.d.ts +1 -0
- package/dist/activities/run-credentials.d.ts +15 -3
- package/dist/activities/sandbox-images.d.ts +1 -1
- package/dist/activities/sandbox-lease.d.ts +47 -9
- package/dist/activities/scheduled-tasks.d.ts +4 -35
- package/dist/activities/session-state.d.ts +70 -3
- package/dist/activities/types.d.ts +55 -6
- package/dist/activities/workspace-capture.d.ts +2 -0
- package/dist/activities/workspace-credential-provider.d.ts +46 -0
- package/dist/{activities-control-HMFGSKC5.js → activities-control-BNPTRTOE.js} +1896 -418
- package/dist/activities-control-BNPTRTOE.js.map +1 -0
- package/dist/activities-control.d.ts +182 -4
- package/dist/{activities-turn-AP67JADS.js → activities-turn-5LGZOSVU.js} +4476 -1327
- package/dist/activities-turn-5LGZOSVU.js.map +1 -0
- package/dist/activities.d.ts +182 -4
- package/dist/artifact-materializer-entry.js +5 -2
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/artifact-outbox-entry.js +5 -2
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
- package/dist/{chunk-A4XQWVZK.js → chunk-3ZTRWDMN.js} +307 -4
- package/dist/chunk-3ZTRWDMN.js.map +1 -0
- package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
- package/dist/chunk-4ER3YXOT.js.map +1 -0
- package/dist/{chunk-CYITU5UH.js → chunk-LJX7Z2KP.js} +1445 -343
- package/dist/chunk-LJX7Z2KP.js.map +1 -0
- package/dist/editable-artifact-materializer-service.d.ts +2 -2
- package/dist/editable-artifact-outbox-service.d.ts +2 -2
- package/dist/host-export-pump.d.ts +3 -1
- package/dist/host-export.d.ts +1 -1
- package/dist/host-export.js +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +95 -3
- package/dist/index.js +137 -43
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +118 -8
- package/dist/retained-process-diagnostics.d.ts +4 -0
- package/dist/retained-process-retry.d.ts +7 -0
- package/dist/sandbox-resume.d.ts +55 -13
- package/dist/sandbox-routing.d.ts +5 -3
- package/dist/sandbox-snapshot-diagnostics.d.ts +20 -0
- package/dist/session-event-fanout.d.ts +6 -0
- package/dist/warm-capture-holder.d.ts +3 -0
- package/dist/worker-service-lifecycle.d.ts +12 -0
- package/dist/workflow-bundle.js +273 -41
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/browser-deadline-checkpoint.d.ts +9 -0
- package/dist/workflows/scheduled-tasks.d.ts +4 -0
- package/dist/workflows/session.d.ts +36 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +21 -19
- package/src/activities/agent-run-admission.ts +17 -1
- package/src/activities/agent-turn/admission.ts +66 -3
- package/src/activities/agent-turn/agent-build.ts +84 -10
- package/src/activities/agent-turn/claim.ts +186 -43
- package/src/activities/agent-turn/claude-usage-observer.ts +221 -0
- package/src/activities/agent-turn/code-search.ts +275 -0
- package/src/activities/agent-turn/codex-capacity.ts +172 -8
- package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
- package/src/activities/agent-turn/codex.ts +13 -5
- package/src/activities/agent-turn/compaction-prep.ts +170 -102
- package/src/activities/agent-turn/credential-leases.ts +122 -216
- package/src/activities/agent-turn/credential-restriction.ts +14 -0
- package/src/activities/agent-turn/errors.ts +647 -48
- package/src/activities/agent-turn/failure-settlement.ts +682 -130
- package/src/activities/agent-turn/final-reply.ts +46 -0
- package/src/activities/agent-turn/finalization-monitor.ts +120 -0
- package/src/activities/agent-turn/finalization.ts +146 -43
- package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
- package/src/activities/agent-turn/governance-model.ts +69 -28
- package/src/activities/agent-turn/history-sink.ts +16 -2
- package/src/activities/agent-turn/history.ts +38 -11
- package/src/activities/agent-turn/input-wait-reply.ts +103 -0
- package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
- package/src/activities/agent-turn/media-artifacts.ts +2 -1
- package/src/activities/agent-turn/model-call-admission.ts +94 -0
- package/src/activities/agent-turn/model-usage.ts +64 -3
- package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
- package/src/activities/agent-turn/optional-repositories.ts +224 -0
- package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
- package/src/activities/agent-turn/quiescence.ts +10 -7
- package/src/activities/agent-turn/recovery-warning.ts +16 -0
- package/src/activities/agent-turn/refresh-credentials.ts +44 -0
- package/src/activities/agent-turn/run-credentials.ts +116 -55
- package/src/activities/agent-turn/run.ts +320 -93
- package/src/activities/agent-turn/sandbox-establish.ts +84 -8
- package/src/activities/agent-turn/sandbox-provision.ts +3 -1
- package/src/activities/agent-turn/sandbox-route.ts +4 -21
- package/src/activities/agent-turn/sandbox-runtime.ts +343 -18
- package/src/activities/agent-turn/session-title.ts +81 -5
- package/src/activities/agent-turn/skill-checkout.ts +111 -24
- package/src/activities/agent-turn/skill-install.ts +1 -1
- package/src/activities/agent-turn/skill-read.ts +374 -28
- package/src/activities/agent-turn/skill-remove.ts +46 -0
- package/src/activities/agent-turn/skill-save.ts +1 -1
- package/src/activities/agent-turn/skill-search.ts +10 -1
- package/src/activities/agent-turn/skill-selection.ts +4 -0
- package/src/activities/agent-turn/skill-tools.ts +112 -18
- package/src/activities/agent-turn/skill-transfer.ts +68 -23
- package/src/activities/agent-turn/stream-attempt.ts +313 -77
- package/src/activities/agent-turn/subscription-lease.ts +115 -0
- package/src/activities/agent-turn/tool-environment.ts +316 -167
- package/src/activities/agent-turn/tool-policy.ts +80 -1
- package/src/activities/agent-turn/turn-context.ts +35 -0
- package/src/activities/agent-turn/turn-sandbox-access.ts +7 -1
- package/src/activities/agent-turn/xai-capacity.ts +94 -51
- package/src/activities/automations.ts +76 -4
- package/src/activities/browser-deadline-checkpoint.ts +279 -0
- package/src/activities/capabilities.ts +108 -11
- package/src/activities/codemode-dispatcher.ts +36 -8
- package/src/activities/codex-capacity.ts +60 -25
- package/src/activities/codex-rotation.ts +39 -17
- package/src/activities/context-compaction.ts +75 -18
- package/src/activities/gmail-files.ts +88 -0
- package/src/activities/goals.ts +116 -121
- package/src/activities/google-drive-publication.ts +1 -3
- package/src/activities/image-generation-operation.ts +1 -1
- package/src/activities/knowledge-indexing.ts +269 -15
- package/src/activities/knowledge-source-sync.ts +10 -0
- package/src/activities/mcp-account-routes.ts +17 -0
- package/src/activities/mcp-credentials.ts +83 -194
- package/src/activities/mcp-operation-authority.ts +16 -41
- package/src/activities/model-call-fact-reconciler.ts +112 -0
- package/src/activities/open-suffix-resume.ts +15 -2
- package/src/activities/parent-wake.ts +46 -21
- package/src/activities/retained-screenshots.ts +82 -11
- package/src/activities/rig-verification.ts +38 -37
- package/src/activities/run-credential-renewal.ts +13 -1
- package/src/activities/run-credentials.ts +59 -17
- package/src/activities/run-input.ts +25 -16
- package/src/activities/sandbox-images.ts +0 -1
- package/src/activities/sandbox-lease.ts +798 -82
- package/src/activities/scheduled-tasks.ts +550 -178
- package/src/activities/session-state.ts +245 -6
- package/src/activities/site-auth-maintenance.ts +3 -0
- package/src/activities/types.ts +72 -5
- package/src/activities/workflow-wake.ts +2 -17
- package/src/activities/workspace-capture.ts +13 -2
- package/src/activities/workspace-credential-provider.ts +283 -0
- package/src/activities-control.ts +4 -0
- package/src/activities-turn.ts +5 -0
- package/src/activities.ts +13 -0
- package/src/activity-services.ts +16 -4
- package/src/browser-deadline-checkpoint-contract.ts +5 -0
- package/src/editable-artifact-hint-broker.ts +3 -0
- package/src/editable-artifact-materializer-service.ts +7 -3
- package/src/editable-artifact-outbox-service.ts +4 -4
- package/src/github-rest-mcp.ts +1 -2
- package/src/host-export-pump.ts +26 -4
- package/src/host-export.ts +3 -0
- package/src/http.ts +4 -2
- package/src/index.ts +99 -37
- package/src/observability-metrics.ts +510 -5
- package/src/personal-github-git-credentials.ts +2 -1
- package/src/pr-review-credentials.ts +1 -3
- package/src/retained-process-diagnostics.ts +50 -0
- package/src/retained-process-retry.ts +36 -0
- package/src/sandbox-resume.ts +388 -101
- package/src/sandbox-routing.ts +150 -25
- package/src/sandbox-snapshot-diagnostics.ts +112 -0
- package/src/session-event-fanout.ts +23 -0
- package/src/warm-capture-holder.ts +15 -0
- package/src/worker-service-lifecycle.ts +53 -0
- package/src/workflows/activities.ts +16 -1
- package/src/workflows/browser-deadline-checkpoint.ts +50 -0
- package/src/workflows/file-upload-reaper.ts +2 -0
- package/src/workflows/scheduled-tasks.ts +26 -13
- package/src/workflows/session.ts +242 -22
- package/src/workflows.ts +4 -0
- package/dist/activities/agent-turn/knowledge-sources.d.ts +0 -20
- package/dist/activities/packs.d.ts +0 -55
- package/dist/activities-control-HMFGSKC5.js.map +0 -1
- package/dist/activities-turn-AP67JADS.js.map +0 -1
- package/dist/chunk-A4XQWVZK.js.map +0 -1
- package/dist/chunk-CYITU5UH.js.map +0 -1
- package/dist/chunk-RAMNYSAW.js.map +0 -1
- package/src/activities/agent-turn/knowledge-sources.ts +0 -86
- package/src/activities/packs.ts +0 -166
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { withClaudeConnectionCredential } from "@opengeni/config";
|
|
2
|
+
import {
|
|
3
|
+
getSessionAuthorityProjection,
|
|
4
|
+
readActiveSandbox,
|
|
5
|
+
getWorkspaceCredentialProvider,
|
|
6
|
+
resolveClaudeAccountCredential,
|
|
7
|
+
ClaudeSubscriptionReconnectRequired,
|
|
8
|
+
} from "@opengeni/db";
|
|
9
|
+
import { routingEnabled } from "../../sandbox-routing";
|
|
10
|
+
import { resolveAgentToolFamilies } from "@opengeni/contracts";
|
|
1
11
|
import { createKnowledgeSourceSyncActivities } from "../knowledge-source-sync";
|
|
2
|
-
import { prepareTurnKnowledgeSources } from "./knowledge-sources";
|
|
3
12
|
import {
|
|
4
13
|
assertModelConnectionAllowsTurn,
|
|
5
14
|
freezeAgentLearningPolicy,
|
|
@@ -11,10 +20,16 @@ import {
|
|
|
11
20
|
getMaterializedSandboxFileResources,
|
|
12
21
|
markSandboxFileResourcesMaterialized,
|
|
13
22
|
} from "@opengeni/db";
|
|
14
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
sandboxOperationMetricObserver,
|
|
25
|
+
turnExecutionTelemetryKey,
|
|
26
|
+
withTraceContext,
|
|
27
|
+
withMcpTelemetry,
|
|
28
|
+
} from "@opengeni/observability";
|
|
15
29
|
import {
|
|
16
30
|
REMOTE_COMPACTION_V2_BETA_FEATURE,
|
|
17
31
|
REMOTE_COMPACTION_V2_IMPLEMENTATION,
|
|
32
|
+
awaitModelCallAdmission,
|
|
18
33
|
materializeSandboxFileDownloads,
|
|
19
34
|
sandboxFileDownloadFailureNote,
|
|
20
35
|
type SandboxFileDownload,
|
|
@@ -25,11 +40,14 @@ import { buildCodexTokenResolver } from "../codex-auth";
|
|
|
25
40
|
import {
|
|
26
41
|
buildModelResolver,
|
|
27
42
|
CODEX_CLIENT_VERSION,
|
|
28
|
-
CODEX_FALLBACK_MODEL_SLUGS,
|
|
29
43
|
codexRequestStorage,
|
|
30
44
|
withCodexRequestOverrides,
|
|
31
45
|
type CodexRequestContext,
|
|
32
46
|
} from "@opengeni/codex";
|
|
47
|
+
import { codexUpstreamModelSlugs } from "@opengeni/config";
|
|
48
|
+
import { parseModelProvidersJson } from "@opengeni/config";
|
|
49
|
+
import { withClaudeUsageObserver } from "@opengeni/runtime";
|
|
50
|
+
import { createClaudeUsageObserver } from "./claude-usage-observer";
|
|
33
51
|
import {
|
|
34
52
|
xaiSubscriptionRequestStorage,
|
|
35
53
|
type XaiSubscriptionRequestContext,
|
|
@@ -48,6 +66,7 @@ import {
|
|
|
48
66
|
recordModelRequestPhase,
|
|
49
67
|
recordCompanyBrainContributions,
|
|
50
68
|
recordTurnStartupPhase,
|
|
69
|
+
measureTurnStartupPhase,
|
|
51
70
|
runtimeMetricsHooksForObservability,
|
|
52
71
|
} from "../../observability-metrics";
|
|
53
72
|
import { summarizeCompanyBrainContributions } from "../../model-context-contributions";
|
|
@@ -84,10 +103,11 @@ import {
|
|
|
84
103
|
establishTurnSandbox,
|
|
85
104
|
bindLazySandboxProvisioner,
|
|
86
105
|
} from "./sandbox-establish";
|
|
87
|
-
import { selectXaiTurnCapacity } from "./xai-capacity";
|
|
106
|
+
import { selectXaiTurnCapacity, selectClaudeTurnCapacity } from "./xai-capacity";
|
|
88
107
|
import { prepareRunCredentials } from "./run-credentials";
|
|
89
108
|
import { prepareTurnToolPolicy, prepareTurnToolRuntime } from "./tool-environment";
|
|
90
109
|
import { applyTurnGitHubRepositoryBindings } from "./github-repository-bindings";
|
|
110
|
+
import { dropUnavailableOptionalRepositories } from "./optional-repositories";
|
|
91
111
|
import { buildTurnAgent } from "./agent-build";
|
|
92
112
|
|
|
93
113
|
/**
|
|
@@ -152,7 +172,11 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
152
172
|
// final model checkpoint happens while the activity still owns its complete
|
|
153
173
|
// turn graph and must not suppress collection after that graph is released.
|
|
154
174
|
const turnCompletionMemoryCollector = createModelCheckpointMemoryCollector();
|
|
155
|
-
|
|
175
|
+
const runAgentTurn = async (
|
|
176
|
+
input: RunAgentTurnInput,
|
|
177
|
+
resolvedServices: ActivityServices,
|
|
178
|
+
activitySpan: ReturnType<ActivityServices["observability"]["startSpan"]>,
|
|
179
|
+
): Promise<RunAgentTurnResult> => {
|
|
156
180
|
const {
|
|
157
181
|
settings,
|
|
158
182
|
catalogSourceSettings = settings,
|
|
@@ -160,6 +184,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
160
184
|
bus,
|
|
161
185
|
runtime,
|
|
162
186
|
summarizeContextForCompaction,
|
|
187
|
+
requestWorkerDrain,
|
|
188
|
+
turnFinalizationTimeoutMs,
|
|
163
189
|
objectStorage,
|
|
164
190
|
observability,
|
|
165
191
|
wakeSessionWorkflow,
|
|
@@ -169,7 +195,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
169
195
|
connectionCredentials,
|
|
170
196
|
personalGitHubCredentials,
|
|
171
197
|
startVideoGenerationWorkflow,
|
|
172
|
-
} =
|
|
198
|
+
} = resolvedServices;
|
|
173
199
|
const activityContext = currentActivityContext();
|
|
174
200
|
const cancellationSignal = activityContext?.cancellationSignal;
|
|
175
201
|
// Temporal cancellation is not the only way an activity loses ownership:
|
|
@@ -207,11 +233,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
207
233
|
});
|
|
208
234
|
const dispatchId = activityContext?.info.activityId ?? randomUUID();
|
|
209
235
|
const activityStarted = performance.now();
|
|
210
|
-
const activitySpan = observability.startSpan("worker.run_agent_segment", {
|
|
211
|
-
"opengeni.session_id": input.sessionId,
|
|
212
|
-
"opengeni.workflow_id": input.workflowId,
|
|
213
|
-
"opengeni.trigger_kind": input.trigger.kind,
|
|
214
|
-
});
|
|
215
236
|
const acknowledgeLostAttemptOwnership = (): void => {
|
|
216
237
|
// A stale terminal/recovery settlement can lose either to a benign
|
|
217
238
|
// successor or to Pause/Steer closing this exact attempt. Only the
|
|
@@ -364,6 +385,14 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
364
385
|
getModelRunSettings: () => eventing.modelRunSettings,
|
|
365
386
|
getExecutionGeneration: () => attempt.executionGeneration,
|
|
366
387
|
});
|
|
388
|
+
const checkpointBeforeProviderDispatch = async () => {
|
|
389
|
+
await awaitModelCallAdmission();
|
|
390
|
+
await checkpointHistoryBeforeProviderDispatch(historySink, {
|
|
391
|
+
effectiveSandboxBackend: eventing.modelRunSettings.sandboxBackend,
|
|
392
|
+
routingEnabled: routingEnabled(settings),
|
|
393
|
+
readActiveSandbox: () => readActiveSandbox(db, input.workspaceId, input.sessionId),
|
|
394
|
+
});
|
|
395
|
+
};
|
|
367
396
|
|
|
368
397
|
try {
|
|
369
398
|
const claimed = await claimTurnAttempt({
|
|
@@ -423,19 +452,51 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
423
452
|
if (!attempt.turnId) {
|
|
424
453
|
throw new Error("Turn id was not initialized");
|
|
425
454
|
}
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
455
|
+
const learningActor = {
|
|
456
|
+
kind: "agent" as const,
|
|
457
|
+
sessionId: input.sessionId,
|
|
458
|
+
turnId: attempt.turnId,
|
|
459
|
+
attemptId: input.attemptId,
|
|
460
|
+
executionGeneration: attempt.executionGeneration,
|
|
461
|
+
};
|
|
462
|
+
const learning = await measureTurnStartupPhase(
|
|
463
|
+
observability,
|
|
464
|
+
{
|
|
465
|
+
phase: "learning_policy_freeze",
|
|
466
|
+
provider: turnExecutionPolicy.providerId,
|
|
467
|
+
backend: turn.sandboxBackend,
|
|
435
468
|
},
|
|
436
|
-
|
|
469
|
+
() =>
|
|
470
|
+
freezeAgentLearningPolicy(db, {
|
|
471
|
+
accountId: input.accountId,
|
|
472
|
+
workspaceId: input.workspaceId,
|
|
473
|
+
actor: learningActor,
|
|
474
|
+
}),
|
|
475
|
+
);
|
|
476
|
+
const attachmentAuthority = await measureTurnStartupPhase(
|
|
477
|
+
observability,
|
|
478
|
+
{
|
|
479
|
+
phase: "attachment_authority_projection",
|
|
480
|
+
provider: turnExecutionPolicy.providerId,
|
|
481
|
+
backend: turn.sandboxBackend,
|
|
482
|
+
},
|
|
483
|
+
() => getSessionAuthorityProjection(db, input.workspaceId, input.sessionId),
|
|
484
|
+
);
|
|
485
|
+
if (!attachmentAuthority) throw new Error("Session attachment authority unavailable");
|
|
437
486
|
return await withSessionRlsActorContext(
|
|
438
487
|
{
|
|
488
|
+
sessionAttachmentReadAccess: {
|
|
489
|
+
sessionId: input.sessionId,
|
|
490
|
+
authorityEpoch: attachmentAuthority.authorityEpoch,
|
|
491
|
+
actor: {
|
|
492
|
+
kind: "agent_attempt",
|
|
493
|
+
subjectId: "service:agent-turn",
|
|
494
|
+
callerSessionId: input.sessionId,
|
|
495
|
+
turnId: attempt.turnId,
|
|
496
|
+
attemptId: input.attemptId,
|
|
497
|
+
executionGeneration: attempt.executionGeneration,
|
|
498
|
+
},
|
|
499
|
+
},
|
|
439
500
|
subjectId: "service:agent-turn",
|
|
440
501
|
initiatingHumanSubjectId: fileAuthoritySubjectId,
|
|
441
502
|
privateFileOwnerSubjectId:
|
|
@@ -483,11 +544,42 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
483
544
|
if ("exit" in codexCapacity) return codexCapacity.exit;
|
|
484
545
|
const xaiCapacity = await selectXaiTurnCapacity(capacityDeps);
|
|
485
546
|
if ("exit" in xaiCapacity) return xaiCapacity.exit;
|
|
547
|
+
const claudeCapacity = await selectClaudeTurnCapacity(capacityDeps);
|
|
548
|
+
if ("exit" in claudeCapacity) return claudeCapacity.exit;
|
|
486
549
|
}
|
|
487
550
|
|
|
551
|
+
let selectedCapabilitySettings = capabilitySettings;
|
|
552
|
+
if (billingState.isClaudeTurn) {
|
|
553
|
+
const credentialId = providerTurn.effectiveClaudeCredentialId;
|
|
554
|
+
const subjectId = leases.claude.subjectId;
|
|
555
|
+
const authoritySnapshot = providerTurn.claudeAuthoritySnapshot;
|
|
556
|
+
if (!credentialId || !subjectId || !authoritySnapshot)
|
|
557
|
+
throw new Error("Claude serving account has no accepted authority");
|
|
558
|
+
leases.claude.assertUsable();
|
|
559
|
+
const credential = await resolveClaudeAccountCredential(db, settings, {
|
|
560
|
+
accountId: input.accountId,
|
|
561
|
+
workspaceId: input.workspaceId,
|
|
562
|
+
subjectId,
|
|
563
|
+
credentialId,
|
|
564
|
+
authoritySnapshot,
|
|
565
|
+
});
|
|
566
|
+
providerTurn.effectiveClaudeCredentialVersion = credential.version;
|
|
567
|
+
if ("reconnectRequired" in credential) throw new ClaudeSubscriptionReconnectRequired();
|
|
568
|
+
selectedCapabilitySettings = withClaudeConnectionCredential(
|
|
569
|
+
capabilitySettings,
|
|
570
|
+
"claude_subscription",
|
|
571
|
+
JSON.stringify(credential.secret),
|
|
572
|
+
authoritySnapshot.scope === "organization" ? "organization" : "workspace",
|
|
573
|
+
{
|
|
574
|
+
connectionId: credentialId,
|
|
575
|
+
credentialVersion: credential.version,
|
|
576
|
+
},
|
|
577
|
+
);
|
|
578
|
+
}
|
|
488
579
|
const governance = await prepareGovernanceAndModel({
|
|
489
580
|
input,
|
|
490
581
|
db,
|
|
582
|
+
observability,
|
|
491
583
|
runtime,
|
|
492
584
|
objectStorage,
|
|
493
585
|
eventing,
|
|
@@ -495,7 +587,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
495
587
|
media,
|
|
496
588
|
turn,
|
|
497
589
|
session,
|
|
498
|
-
capabilitySettings,
|
|
590
|
+
capabilitySettings: selectedCapabilitySettings,
|
|
499
591
|
fileAuthoritySubjectId,
|
|
500
592
|
humanInputResume,
|
|
501
593
|
turnExecutionPolicy,
|
|
@@ -508,14 +600,17 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
508
600
|
modelId: turnExecutionPolicy.productModelId,
|
|
509
601
|
codexCredentialId: providerTurn.effectiveCodexCredentialId,
|
|
510
602
|
xaiCredentialId: providerTurn.effectiveXaiCredentialId,
|
|
603
|
+
claudeCredentialId: providerTurn.effectiveClaudeCredentialId,
|
|
604
|
+
claudeAuthoritySnapshot: turn.claudeProviderAccountAuthoritySnapshot,
|
|
511
605
|
});
|
|
512
606
|
const {
|
|
513
607
|
runtimePreparationStartedAt,
|
|
514
|
-
packRuntime,
|
|
515
608
|
rigVersion,
|
|
516
609
|
rigName,
|
|
517
610
|
agentHumanInputEnabled,
|
|
611
|
+
codeSearchEnabled,
|
|
518
612
|
workspaceAgentInstructions,
|
|
613
|
+
workspaceAgentIdentity,
|
|
519
614
|
workspaceGovernance,
|
|
520
615
|
structuredWorkspacePolicyActive,
|
|
521
616
|
workspaceMemory,
|
|
@@ -556,6 +651,12 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
556
651
|
runSettings,
|
|
557
652
|
input.workspaceId,
|
|
558
653
|
providerTurn.effectiveCodexCredentialId ?? "",
|
|
654
|
+
undefined,
|
|
655
|
+
{
|
|
656
|
+
turnId: turn.id,
|
|
657
|
+
holderId: leases.codex.holderId!,
|
|
658
|
+
generation: leases.codex.generation!,
|
|
659
|
+
},
|
|
559
660
|
);
|
|
560
661
|
const resolveTrackedToken = async (
|
|
561
662
|
resolve: () => ReturnType<typeof resolver.getToken>,
|
|
@@ -575,10 +676,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
575
676
|
sessionId: input.sessionId,
|
|
576
677
|
getToken: () => resolveTrackedToken(resolver.getToken),
|
|
577
678
|
refresh: () => resolveTrackedToken(resolver.refresh),
|
|
578
|
-
resolveModel: buildModelResolver(
|
|
579
|
-
CODEX_FALLBACK_MODEL_SLUGS,
|
|
580
|
-
CODEX_FALLBACK_MODEL_SLUGS[0],
|
|
581
|
-
),
|
|
679
|
+
resolveModel: buildModelResolver(codexUpstreamModelSlugs(runSettings)),
|
|
582
680
|
onUsageHeaders: (snapshot) => {
|
|
583
681
|
providerTurn.latestCodexUsage = snapshot;
|
|
584
682
|
}, // latest wins; flushed once in finally
|
|
@@ -665,7 +763,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
665
763
|
);
|
|
666
764
|
}
|
|
667
765
|
if (event.phase === "started") {
|
|
668
|
-
await
|
|
766
|
+
await checkpointBeforeProviderDispatch();
|
|
669
767
|
}
|
|
670
768
|
const shouldRecordStartedAudit =
|
|
671
769
|
event.phase === "started" && !firstModelRequestAuditRecorded;
|
|
@@ -745,8 +843,12 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
745
843
|
credentialId: providerTurn.effectiveXaiCredentialId,
|
|
746
844
|
authoritySnapshot: turn.xaiProviderAccountAuthoritySnapshot,
|
|
747
845
|
hostedSearch: {
|
|
748
|
-
webSearch:
|
|
749
|
-
|
|
846
|
+
webSearch: resolveAgentToolFamilies(session.agent, {
|
|
847
|
+
webSearch: runSettings.webSearchEnabled,
|
|
848
|
+
}).webSearch,
|
|
849
|
+
xSearch: resolveAgentToolFamilies(session.agent, {
|
|
850
|
+
webSearch: runSettings.webSearchEnabled,
|
|
851
|
+
}).webSearch,
|
|
750
852
|
},
|
|
751
853
|
streamIdleTimeoutMs: runSettings.supergrokResponseStreamIdleTimeoutMs,
|
|
752
854
|
nextRequestId: () => `${dispatchId}:xai:${++xaiModelRequestSequence}`,
|
|
@@ -818,7 +920,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
818
920
|
throw new Error("SuperGrok model request started before the turn event producer");
|
|
819
921
|
}
|
|
820
922
|
if (event.phase === "started") {
|
|
821
|
-
await
|
|
923
|
+
await checkpointBeforeProviderDispatch();
|
|
822
924
|
}
|
|
823
925
|
const shouldRecordStartedAudit =
|
|
824
926
|
event.phase === "started" && !firstModelRequestAuditRecorded;
|
|
@@ -880,12 +982,73 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
880
982
|
});
|
|
881
983
|
providerTurn.xaiRequestContext = authorization.context;
|
|
882
984
|
}
|
|
985
|
+
const claudeUsageObserver = await createClaudeUsageObserver(
|
|
986
|
+
parseModelProvidersJson(runSettings.modelProvidersJson),
|
|
987
|
+
providerTurn.latestClaudeUsage,
|
|
988
|
+
async () => null,
|
|
989
|
+
);
|
|
990
|
+
const withClaudeUsage = <T>(fn: () => Promise<T>): Promise<T> =>
|
|
991
|
+
withClaudeUsageObserver(claudeUsageObserver, fn, async (providerId, headers) => {
|
|
992
|
+
return claudeUsageObserver.prepareRequestWithObserver(
|
|
993
|
+
providerId,
|
|
994
|
+
headers,
|
|
995
|
+
async (binding) => {
|
|
996
|
+
const credentialId = providerTurn.effectiveClaudeCredentialId;
|
|
997
|
+
const authoritySnapshot = providerTurn.claudeAuthoritySnapshot;
|
|
998
|
+
const subjectId = leases.claude.subjectId;
|
|
999
|
+
if (
|
|
1000
|
+
!credentialId ||
|
|
1001
|
+
!authoritySnapshot ||
|
|
1002
|
+
!subjectId ||
|
|
1003
|
+
binding.expectedConnectionId !== credentialId ||
|
|
1004
|
+
binding.expectedCredentialVersion !==
|
|
1005
|
+
providerTurn.effectiveClaudeCredentialVersion ||
|
|
1006
|
+
binding.scope !==
|
|
1007
|
+
(authoritySnapshot.scope === "organization" ? "organization" : "workspace")
|
|
1008
|
+
)
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
"Claude physical request is outside its accepted serving account",
|
|
1011
|
+
);
|
|
1012
|
+
await leases.claude.renew("runtime_event");
|
|
1013
|
+
leases.claude.assertUsable();
|
|
1014
|
+
await assertModelConnectionAllowsTurn(db, {
|
|
1015
|
+
workspaceId: input.workspaceId,
|
|
1016
|
+
subjectId,
|
|
1017
|
+
modelId: turnExecutionPolicy.productModelId,
|
|
1018
|
+
claudeCredentialId: credentialId,
|
|
1019
|
+
claudeAuthoritySnapshot: authoritySnapshot,
|
|
1020
|
+
});
|
|
1021
|
+
const credential = await resolveClaudeAccountCredential(
|
|
1022
|
+
db,
|
|
1023
|
+
settings,
|
|
1024
|
+
{
|
|
1025
|
+
accountId: input.accountId,
|
|
1026
|
+
workspaceId: input.workspaceId,
|
|
1027
|
+
subjectId,
|
|
1028
|
+
credentialId,
|
|
1029
|
+
authoritySnapshot,
|
|
1030
|
+
},
|
|
1031
|
+
{ expectedCredentialVersion: binding.expectedCredentialVersion },
|
|
1032
|
+
);
|
|
1033
|
+
if ("reconnectRequired" in credential)
|
|
1034
|
+
throw new ClaudeSubscriptionReconnectRequired();
|
|
1035
|
+
leases.claude.assertUsable();
|
|
1036
|
+
return {
|
|
1037
|
+
token: credential.secret.token,
|
|
1038
|
+
connectionId: credential.id,
|
|
1039
|
+
credentialVersion: credential.version,
|
|
1040
|
+
};
|
|
1041
|
+
},
|
|
1042
|
+
);
|
|
1043
|
+
});
|
|
883
1044
|
const withCodex = <T>(fn: () => Promise<T>): Promise<T> =>
|
|
884
1045
|
codexContext ? codexRequestStorage.run(codexContext, fn) : fn();
|
|
885
1046
|
const withProviderRequestContext = <T>(fn: () => Promise<T>): Promise<T> =>
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1047
|
+
withClaudeUsage(() =>
|
|
1048
|
+
providerTurn.xaiRequestContext
|
|
1049
|
+
? xaiSubscriptionRequestStorage.run(providerTurn.xaiRequestContext, fn)
|
|
1050
|
+
: withCodex(fn),
|
|
1051
|
+
);
|
|
889
1052
|
let codexSessionTitleRequestSequence = 0;
|
|
890
1053
|
let xaiSessionTitleRequestSequence = 0;
|
|
891
1054
|
const codexSessionTitleContext = codexContext
|
|
@@ -901,25 +1064,29 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
901
1064
|
)
|
|
902
1065
|
: null;
|
|
903
1066
|
const withSessionTitleProviderRequestContext = <T>(fn: () => Promise<T>): Promise<T> =>
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1067
|
+
withClaudeUsage(() =>
|
|
1068
|
+
xaiSessionTitleContext
|
|
1069
|
+
? xaiSubscriptionRequestStorage.run(xaiSessionTitleContext, fn)
|
|
1070
|
+
: codexSessionTitleContext
|
|
1071
|
+
? codexRequestStorage.run(codexSessionTitleContext, fn)
|
|
1072
|
+
: fn(),
|
|
1073
|
+
);
|
|
909
1074
|
const withCodexRemoteCompaction = <T>(fn: () => Promise<T>): Promise<T> =>
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1075
|
+
withClaudeUsage(() =>
|
|
1076
|
+
withCodex(() =>
|
|
1077
|
+
withCodexRequestOverrides(
|
|
1078
|
+
{
|
|
1079
|
+
betaFeatures: [REMOTE_COMPACTION_V2_BETA_FEATURE],
|
|
1080
|
+
turnMetadata: {
|
|
1081
|
+
request_kind: "compaction",
|
|
1082
|
+
compaction: {
|
|
1083
|
+
implementation: REMOTE_COMPACTION_V2_IMPLEMENTATION,
|
|
1084
|
+
strategy: "memento",
|
|
1085
|
+
},
|
|
919
1086
|
},
|
|
920
1087
|
},
|
|
921
|
-
|
|
922
|
-
|
|
1088
|
+
fn,
|
|
1089
|
+
),
|
|
923
1090
|
),
|
|
924
1091
|
);
|
|
925
1092
|
const compactionPrep = await prepareCompaction({
|
|
@@ -945,6 +1112,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
945
1112
|
turnExecutionPolicy,
|
|
946
1113
|
resolvedModel,
|
|
947
1114
|
workspaceAgentInstructions,
|
|
1115
|
+
workspaceAgentIdentity,
|
|
948
1116
|
workspaceGovernance,
|
|
949
1117
|
structuredWorkspacePolicyActive,
|
|
950
1118
|
workspaceMemory,
|
|
@@ -1030,44 +1198,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1030
1198
|
knowledgeRecoveryNote =
|
|
1031
1199
|
"[OpenGeni confirmation recovery unavailable] Do not assume an earlier remember confirmation was published. Inspect the current Knowledge or instruction review.";
|
|
1032
1200
|
}
|
|
1033
|
-
const
|
|
1034
|
-
settings: runSettings,
|
|
1035
|
-
scope: {
|
|
1036
|
-
accountId: input.accountId,
|
|
1037
|
-
workspaceId: input.workspaceId,
|
|
1038
|
-
sessionId: input.sessionId,
|
|
1039
|
-
turnId: turn.id,
|
|
1040
|
-
attemptId: input.attemptId,
|
|
1041
|
-
executionGeneration: attempt.executionGeneration,
|
|
1042
|
-
},
|
|
1043
|
-
// Only attachments on this accepted turn are new source inputs.
|
|
1044
|
-
// Session-level file receipts remain historical context and must
|
|
1045
|
-
// never trigger metadata reads, downloads, or re-preparation.
|
|
1046
|
-
resources: turn.resources,
|
|
1047
|
-
selectedTools: session.firstPartyMcpTools,
|
|
1048
|
-
permissions: session.firstPartyMcpPermissions,
|
|
1049
|
-
learningMode: learning.effective.knowledge,
|
|
1050
|
-
signal: cancellationSignal,
|
|
1051
|
-
onOutcome: async (outcome) => {
|
|
1052
|
-
if (outcome.status === "disabled") return;
|
|
1053
|
-
await eventing.publish!(
|
|
1054
|
-
[
|
|
1055
|
-
{
|
|
1056
|
-
type:
|
|
1057
|
-
outcome.status === "failed"
|
|
1058
|
-
? "knowledge.source.failed"
|
|
1059
|
-
: "knowledge.source.prepared",
|
|
1060
|
-
payload: outcome,
|
|
1061
|
-
},
|
|
1062
|
-
],
|
|
1063
|
-
true,
|
|
1064
|
-
);
|
|
1065
|
-
},
|
|
1066
|
-
});
|
|
1067
|
-
|
|
1068
|
-
const knowledgeSourcePreparationNote =
|
|
1069
|
-
[knowledgeRecoveryNote, attachmentPreparationNote].filter(Boolean).join("\n\n") ||
|
|
1070
|
-
undefined;
|
|
1201
|
+
const knowledgeSourcePreparationNote = knowledgeRecoveryNote;
|
|
1071
1202
|
|
|
1072
1203
|
const sandboxRoute = await resolveSandboxRoute({
|
|
1073
1204
|
input,
|
|
@@ -1096,13 +1227,26 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1096
1227
|
// set. A Connected Machine receives no platform Git credential, so its
|
|
1097
1228
|
// resources stay exactly as stored. Resolution never fails the turn;
|
|
1098
1229
|
// an unusable bound repository stays bare and is reported visibly.
|
|
1099
|
-
const
|
|
1230
|
+
const hasCredentialProvider =
|
|
1231
|
+
activeSandboxBackend !== "selfhosted" &&
|
|
1232
|
+
(
|
|
1233
|
+
await waitForTurnOperation(
|
|
1234
|
+
getWorkspaceCredentialProvider(db, {
|
|
1235
|
+
accountId: input.accountId,
|
|
1236
|
+
workspaceId: input.workspaceId,
|
|
1237
|
+
}),
|
|
1238
|
+
cancellationSignal,
|
|
1239
|
+
undefined,
|
|
1240
|
+
)
|
|
1241
|
+
)?.enabled === true;
|
|
1242
|
+
const boundResources = await waitForTurnOperation(
|
|
1100
1243
|
applyTurnGitHubRepositoryBindings({
|
|
1101
1244
|
db,
|
|
1102
1245
|
settings: runSettings,
|
|
1103
1246
|
workspaceId: input.workspaceId,
|
|
1104
1247
|
sessionId: input.sessionId,
|
|
1105
1248
|
activeSandboxBackend,
|
|
1249
|
+
hasCredentialProvider,
|
|
1106
1250
|
claimedTurnResources,
|
|
1107
1251
|
claimedRuntimeResources,
|
|
1108
1252
|
publish: async (events) => {
|
|
@@ -1113,8 +1257,35 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1113
1257
|
cancellationSignal,
|
|
1114
1258
|
undefined,
|
|
1115
1259
|
);
|
|
1260
|
+
// An automatically attached (optional) repository that lost its
|
|
1261
|
+
// allowlist entry or its GitHub App access since the session started
|
|
1262
|
+
// sits this turn out with a warning, before the strict allowlist
|
|
1263
|
+
// recheck and token mint below would fail the whole turn for it.
|
|
1264
|
+
const {
|
|
1265
|
+
turnResources,
|
|
1266
|
+
runtimeResources,
|
|
1267
|
+
retainsResource: retainsOptionalRepository,
|
|
1268
|
+
} = await waitForTurnOperation(
|
|
1269
|
+
dropUnavailableOptionalRepositories({
|
|
1270
|
+
db,
|
|
1271
|
+
settings: runSettings,
|
|
1272
|
+
workspaceId: input.workspaceId,
|
|
1273
|
+
activeSandboxBackend,
|
|
1274
|
+
hostMintsGitCredentials: Boolean(connectionCredentials?.gitCredentials),
|
|
1275
|
+
turnResources: boundResources.turnResources,
|
|
1276
|
+
runtimeResources: boundResources.runtimeResources,
|
|
1277
|
+
publish: async (events) => {
|
|
1278
|
+
await eventing.publish!(events, true);
|
|
1279
|
+
},
|
|
1280
|
+
warn: (message, fields) => observability.warn(message, fields),
|
|
1281
|
+
}),
|
|
1282
|
+
cancellationSignal,
|
|
1283
|
+
undefined,
|
|
1284
|
+
);
|
|
1116
1285
|
|
|
1117
1286
|
const runCredentials = await prepareRunCredentials({
|
|
1287
|
+
turnTools,
|
|
1288
|
+
localMcpServerIds: installedApiIntegrations.map((integration) => integration.serverId),
|
|
1118
1289
|
input,
|
|
1119
1290
|
settings,
|
|
1120
1291
|
db,
|
|
@@ -1129,6 +1300,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1129
1300
|
sandboxRuntime,
|
|
1130
1301
|
turn,
|
|
1131
1302
|
session,
|
|
1303
|
+
turnExecutionPolicy,
|
|
1132
1304
|
fileAuthoritySubjectId,
|
|
1133
1305
|
runSettings,
|
|
1134
1306
|
workspaceVariableSet,
|
|
@@ -1145,10 +1317,10 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1145
1317
|
});
|
|
1146
1318
|
const {
|
|
1147
1319
|
runCredentialResolver,
|
|
1320
|
+
runMcpCredentials,
|
|
1148
1321
|
establishPolicy,
|
|
1149
1322
|
initialRunCredentialMaterial,
|
|
1150
1323
|
runCredentialsNote,
|
|
1151
|
-
hostCredentialRootSessionId,
|
|
1152
1324
|
codemodeAuthority,
|
|
1153
1325
|
sandboxArtifactRuntime,
|
|
1154
1326
|
sandboxEnvironment,
|
|
@@ -1268,7 +1440,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1268
1440
|
];
|
|
1269
1441
|
const toolRuntime = await prepareTurnToolRuntime({
|
|
1270
1442
|
fetchKnowledgeSource: sourceActivities.runKnowledgeSourceSyncBatch,
|
|
1271
|
-
|
|
1443
|
+
runCredentialRenewals: runCredentialResolver ? renewals : undefined,
|
|
1444
|
+
runMcpCredentials,
|
|
1272
1445
|
input,
|
|
1273
1446
|
catalogSourceSettings,
|
|
1274
1447
|
db,
|
|
@@ -1277,7 +1450,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1277
1450
|
objectStorage,
|
|
1278
1451
|
observability,
|
|
1279
1452
|
cancellationSignal,
|
|
1280
|
-
connectionCredentials,
|
|
1281
1453
|
eventing,
|
|
1282
1454
|
attempt,
|
|
1283
1455
|
sandboxState,
|
|
@@ -1292,10 +1464,10 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1292
1464
|
turnExecutionPolicy,
|
|
1293
1465
|
trigger,
|
|
1294
1466
|
runSettings,
|
|
1467
|
+
resolvedModel,
|
|
1295
1468
|
lazyToolTransport,
|
|
1296
1469
|
turnTools,
|
|
1297
1470
|
connectionScope,
|
|
1298
|
-
hostCredentialRootSessionId,
|
|
1299
1471
|
sandboxArtifactRuntime,
|
|
1300
1472
|
activeSandboxBackend,
|
|
1301
1473
|
groupBoxBackend,
|
|
@@ -1304,6 +1476,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1304
1476
|
credentialSubjectId,
|
|
1305
1477
|
interactionInterventionResume,
|
|
1306
1478
|
runWorkspaceMutationForSandbox,
|
|
1479
|
+
codeSearchEnabled,
|
|
1480
|
+
retainsOptionalRepository,
|
|
1307
1481
|
throwIfWorkerShuttingDown,
|
|
1308
1482
|
throwIfTurnCancelled,
|
|
1309
1483
|
});
|
|
@@ -1317,6 +1491,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1317
1491
|
|
|
1318
1492
|
const builtAgent = await buildTurnAgent({
|
|
1319
1493
|
skillCatalog: toolRuntime.skillCatalog,
|
|
1494
|
+
mcpServers: toolRuntime.mcpServers,
|
|
1320
1495
|
input,
|
|
1321
1496
|
db,
|
|
1322
1497
|
runtime,
|
|
@@ -1346,6 +1521,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1346
1521
|
supportsImageInput,
|
|
1347
1522
|
agentHumanInputEnabled,
|
|
1348
1523
|
workspaceAgentInstructions,
|
|
1524
|
+
workspaceAgentIdentity,
|
|
1349
1525
|
workspaceGovernance,
|
|
1350
1526
|
structuredWorkspacePolicyActive,
|
|
1351
1527
|
workspaceMemory,
|
|
@@ -1366,6 +1542,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1366
1542
|
connectorActionPolicy,
|
|
1367
1543
|
trigger,
|
|
1368
1544
|
preparationIndependentToolNames,
|
|
1545
|
+
codeSearchAvailable: toolRuntime.codeSearchAvailable,
|
|
1369
1546
|
videoGenerationAcceptancesByCallId,
|
|
1370
1547
|
activeSandboxBackend,
|
|
1371
1548
|
groupBoxBackend,
|
|
@@ -1474,6 +1651,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1474
1651
|
turnExecutionPolicy,
|
|
1475
1652
|
resolvedModel,
|
|
1476
1653
|
workspaceAgentInstructions,
|
|
1654
|
+
workspaceAgentIdentity,
|
|
1477
1655
|
workspaceGovernance,
|
|
1478
1656
|
structuredWorkspacePolicyActive,
|
|
1479
1657
|
workspaceMemory,
|
|
@@ -1647,6 +1825,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1647
1825
|
providerTurn,
|
|
1648
1826
|
leases,
|
|
1649
1827
|
historySink,
|
|
1828
|
+
checkpointBeforeProviderDispatch,
|
|
1650
1829
|
media,
|
|
1651
1830
|
toolResultSpill,
|
|
1652
1831
|
claimedResult,
|
|
@@ -1739,6 +1918,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1739
1918
|
});
|
|
1740
1919
|
} finally {
|
|
1741
1920
|
await finalizeTurnAttempt({
|
|
1921
|
+
turnFinalizationTimeoutMs,
|
|
1922
|
+
requestWorkerDrain,
|
|
1742
1923
|
input,
|
|
1743
1924
|
settings,
|
|
1744
1925
|
db,
|
|
@@ -1771,4 +1952,50 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
|
|
|
1771
1952
|
});
|
|
1772
1953
|
}
|
|
1773
1954
|
};
|
|
1955
|
+
return async (input: RunAgentTurnInput): Promise<RunAgentTurnResult> => {
|
|
1956
|
+
const servicesStartedAt = performance.now();
|
|
1957
|
+
const resolvedServices = await services();
|
|
1958
|
+
const servicesDurationSeconds = (performance.now() - servicesStartedAt) / 1_000;
|
|
1959
|
+
const correlationId = turnExecutionTelemetryKey(
|
|
1960
|
+
input.workspaceId,
|
|
1961
|
+
input.sessionId,
|
|
1962
|
+
input.attemptId,
|
|
1963
|
+
);
|
|
1964
|
+
const span = resolvedServices.observability.startSpan(
|
|
1965
|
+
"worker.run_agent_segment",
|
|
1966
|
+
{
|
|
1967
|
+
"opengeni.trigger_kind": input.trigger.kind,
|
|
1968
|
+
correlationId,
|
|
1969
|
+
},
|
|
1970
|
+
{ parent: null },
|
|
1971
|
+
);
|
|
1972
|
+
try {
|
|
1973
|
+
return await withMcpTelemetry(resolvedServices.observability, correlationId, () =>
|
|
1974
|
+
withTraceContext(span, () => {
|
|
1975
|
+
try {
|
|
1976
|
+
recordTurnStartupPhase(resolvedServices.observability, {
|
|
1977
|
+
phase: "services_initialization",
|
|
1978
|
+
provider: "unresolved",
|
|
1979
|
+
backend: "unresolved",
|
|
1980
|
+
outcome: "completed",
|
|
1981
|
+
durationSeconds: servicesDurationSeconds,
|
|
1982
|
+
});
|
|
1983
|
+
} catch {
|
|
1984
|
+
// Service initialization telemetry never gates a claimed attempt.
|
|
1985
|
+
}
|
|
1986
|
+
try {
|
|
1987
|
+
resolvedServices.observability.info("worker execution started", { correlationId });
|
|
1988
|
+
} catch {
|
|
1989
|
+
// Correlation diagnostics never affect execution or admission.
|
|
1990
|
+
}
|
|
1991
|
+
return runAgentTurn(input, resolvedServices, span);
|
|
1992
|
+
}),
|
|
1993
|
+
);
|
|
1994
|
+
} catch (error) {
|
|
1995
|
+
span.end({ error });
|
|
1996
|
+
throw error;
|
|
1997
|
+
} finally {
|
|
1998
|
+
span.end();
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
1774
2001
|
}
|