@opengeni/worker-bundle 0.23.4 → 0.26.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-turn/admission.d.ts +17 -2
- package/dist/activities/agent-turn/agent-build.d.ts +3 -10
- package/dist/activities/agent-turn/claim.d.ts +8 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -2
- package/dist/activities/agent-turn/credential-leases.d.ts +8 -0
- package/dist/activities/agent-turn/errors.d.ts +1 -1
- package/dist/activities/agent-turn/failure-settlement.d.ts +43 -1
- package/dist/activities/agent-turn/list-models.d.ts +16 -0
- package/dist/activities/agent-turn/model-usage.d.ts +15 -1
- package/dist/activities/agent-turn/quiescence.d.ts +11 -6
- package/dist/activities/agent-turn/run.d.ts +9 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +15 -0
- package/dist/activities/agent-turn/session-title.d.ts +21 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +4 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +4 -13
- package/dist/activities/agent-turn/tool-policy.d.ts +40 -5
- package/dist/activities/agent-turn/turn-context.d.ts +13 -2
- package/dist/activities/agent-turn.d.ts +1 -1
- package/dist/activities/automations.d.ts +1 -0
- package/dist/activities/capabilities.d.ts +3 -1
- package/dist/activities/codemode-dispatcher.d.ts +10 -1
- package/dist/activities/codex-capacity.d.ts +32 -3
- package/dist/activities/codex-fleet-shadow.d.ts +1 -1
- package/dist/activities/codex-image-generation.d.ts +1 -1
- package/dist/activities/codex-rotation.d.ts +8 -67
- package/dist/activities/context-compaction.d.ts +2 -0
- package/dist/activities/goals.d.ts +12 -1
- package/dist/activities/google-drive-publication.d.ts +2 -13
- package/dist/activities/image-generation-operation.d.ts +13 -4
- package/dist/activities/image-generation-references.d.ts +2 -1
- package/dist/activities/scheduled-tasks.d.ts +1 -0
- package/dist/activities/session-state.d.ts +4 -2
- package/dist/activities/types.d.ts +19 -1
- package/dist/{activities-control-52W5IDWM.js → activities-control-CTEMLTHG.js} +339 -195
- package/dist/activities-control-CTEMLTHG.js.map +1 -0
- package/dist/activities-control.d.ts +4 -0
- package/dist/{activities-turn-A2G2KLSY.js → activities-turn-S5IU347A.js} +1846 -1136
- package/dist/activities-turn-S5IU347A.js.map +1 -0
- package/dist/activities.d.ts +4 -0
- package/dist/{chunk-GFNXVZVQ.js → chunk-D4ZEFOYH.js} +107 -7
- package/dist/chunk-D4ZEFOYH.js.map +1 -0
- package/dist/{chunk-GRFQTTSQ.js → chunk-GDCLDKSH.js} +7 -3
- package/dist/{chunk-GRFQTTSQ.js.map → chunk-GDCLDKSH.js.map} +1 -1
- package/dist/{chunk-IPVMCAW5.js → chunk-TAUE3GYT.js} +225 -154
- package/dist/chunk-TAUE3GYT.js.map +1 -0
- package/dist/github-rest-mcp.d.ts +0 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +35 -8
- package/dist/sandbox-reaper-timeout.d.ts +2 -2
- package/dist/sandbox-resume.d.ts +6 -1
- package/dist/workflow-bundle.js +96 -10
- package/dist/workflows/activities.d.ts +6 -1
- package/dist/workflows/automations.d.ts +5 -0
- package/dist/workflows/session.d.ts +3 -0
- package/package.json +17 -17
- package/src/activities/agent-run-admission.ts +7 -1
- package/src/activities/agent-turn/admission.ts +47 -6
- package/src/activities/agent-turn/agent-build.ts +20 -26
- package/src/activities/agent-turn/claim.ts +59 -6
- package/src/activities/agent-turn/codex-capacity.ts +311 -234
- package/src/activities/agent-turn/codex.ts +2 -2
- package/src/activities/agent-turn/compaction-prep.ts +8 -1
- package/src/activities/agent-turn/credential-leases.ts +36 -0
- package/src/activities/agent-turn/errors.ts +29 -1
- package/src/activities/agent-turn/failure-settlement.ts +451 -323
- package/src/activities/agent-turn/finalization.ts +31 -17
- package/src/activities/agent-turn/list-models.ts +101 -0
- package/src/activities/agent-turn/model-usage.ts +120 -45
- package/src/activities/agent-turn/quiescence.ts +32 -17
- package/src/activities/agent-turn/run.ts +98 -9
- package/src/activities/agent-turn/sandbox-runtime.ts +78 -81
- package/src/activities/agent-turn/session-title.ts +55 -2
- package/src/activities/agent-turn/stream-attempt.ts +281 -136
- package/src/activities/agent-turn/tool-environment.ts +132 -39
- package/src/activities/agent-turn/tool-policy.ts +71 -12
- package/src/activities/agent-turn/turn-context.ts +21 -2
- package/src/activities/agent-turn.ts +5 -1
- package/src/activities/automations.ts +122 -67
- package/src/activities/capabilities.ts +129 -2
- package/src/activities/codemode-dispatcher.ts +235 -59
- package/src/activities/codex-capacity.ts +89 -10
- package/src/activities/codex-fleet-shadow.ts +8 -1
- package/src/activities/codex-image-generation.ts +19 -2
- package/src/activities/codex-rotation.ts +45 -142
- package/src/activities/context-compaction.ts +3 -0
- package/src/activities/goals.ts +116 -39
- package/src/activities/google-drive-publication.ts +4 -81
- package/src/activities/image-generation-operation.ts +28 -3
- package/src/activities/image-generation-references.ts +9 -9
- package/src/activities/mcp-credentials.ts +53 -0
- package/src/activities/rig-verification.ts +5 -3
- package/src/activities/sandbox-lease.ts +29 -12
- package/src/activities/scheduled-tasks.ts +217 -110
- package/src/activities/session-state.ts +17 -0
- package/src/activities/site-auth-maintenance.ts +12 -12
- package/src/activities/types.ts +22 -8
- package/src/activities.ts +2 -0
- package/src/activity-services.ts +4 -1
- package/src/github-rest-mcp.ts +2 -83
- package/src/index.ts +34 -4
- package/src/observability-metrics.ts +158 -14
- package/src/sandbox-reaper-timeout.ts +10 -4
- package/src/sandbox-resume.ts +58 -8
- package/src/sandbox-routing.ts +71 -16
- package/src/workflows/activities.ts +16 -0
- package/src/workflows/automations.ts +21 -2
- package/src/workflows/session.ts +85 -7
- package/dist/activities/api-integrations.d.ts +0 -21
- package/dist/activities-control-52W5IDWM.js.map +0 -1
- package/dist/activities-turn-A2G2KLSY.js.map +0 -1
- package/dist/chunk-GFNXVZVQ.js.map +0 -1
- package/dist/chunk-IPVMCAW5.js.map +0 -1
- package/src/activities/api-integrations.ts +0 -141
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
SANDBOX_REAPER_CHILD_DISPATCH_LIMIT,
|
|
5
5
|
assertSandboxDrainInputTiming,
|
|
6
6
|
sandboxDrainTiming
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-GDCLDKSH.js";
|
|
8
8
|
import {
|
|
9
9
|
INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY,
|
|
10
10
|
MAX_AUTOMATIC_PROVIDER_RECOVERIES,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
scheduledUserMessagePayload,
|
|
33
33
|
withFirstPartyTools,
|
|
34
34
|
workflowIdForSession
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-TAUE3GYT.js";
|
|
36
36
|
import {
|
|
37
37
|
inspectOpenSandboxKubernetesInventory,
|
|
38
38
|
recordCreditBalanceGauges,
|
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
recordTurnsQueuedGauge,
|
|
53
53
|
recordWorkerDeathRecoveryMetrics,
|
|
54
54
|
runtimeMetricsHooksForObservability
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-D4ZEFOYH.js";
|
|
56
56
|
|
|
57
57
|
// src/activities/browser-state-artifact-reaper.ts
|
|
58
58
|
import {
|
|
@@ -139,12 +139,18 @@ function cleanupErrorCategory(error) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// src/activities/automations.ts
|
|
142
|
-
import {
|
|
142
|
+
import {
|
|
143
|
+
resolveTurnExecutionPolicyV1,
|
|
144
|
+
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
145
|
+
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX
|
|
146
|
+
} from "@opengeni/config";
|
|
143
147
|
import {
|
|
144
148
|
assertWorkspaceModelPolicyAllows,
|
|
145
149
|
canonicalConfiguredModel,
|
|
146
150
|
createAndStartSessionWithOutcome,
|
|
147
|
-
recordWorkspaceUsage
|
|
151
|
+
recordWorkspaceUsage,
|
|
152
|
+
resolveCatalogSettings,
|
|
153
|
+
resolveWorkspaceCatalogSettings
|
|
148
154
|
} from "@opengeni/core";
|
|
149
155
|
import {
|
|
150
156
|
AutomationAuthorityRevokedError,
|
|
@@ -155,14 +161,20 @@ import {
|
|
|
155
161
|
|
|
156
162
|
// src/activities/agent-run-admission.ts
|
|
157
163
|
import { configuredStaticUsageLimits } from "@opengeni/config";
|
|
164
|
+
import { modelFundingForAdmission } from "@opengeni/core";
|
|
158
165
|
import { getBillingBalance, isCodexBilledTurn, sumUsageQuantity } from "@opengeni/db";
|
|
159
166
|
async function agentRunAdmissionDenial(services, input) {
|
|
160
|
-
const
|
|
167
|
+
const codexBilled = await isCodexBilledTurn({
|
|
161
168
|
db: services.db,
|
|
162
169
|
settings: services.settings,
|
|
163
170
|
workspaceId: input.workspaceId,
|
|
164
171
|
model: input.model
|
|
165
172
|
});
|
|
173
|
+
const externallyBilled = modelFundingForAdmission(
|
|
174
|
+
services.settings,
|
|
175
|
+
input.model,
|
|
176
|
+
codexBilled
|
|
177
|
+
).fundedWithoutCredits;
|
|
166
178
|
if (!externallyBilled && (services.settings.billingMode === "stripe" || services.settings.usageLimitsMode === "managed")) {
|
|
167
179
|
if (services.entitlements) {
|
|
168
180
|
const decision = await services.entitlements.admitRun({
|
|
@@ -218,8 +230,19 @@ function createAutomationActivities(services, options = {}) {
|
|
|
218
230
|
const assertModelPolicy = options.assertModelPolicy ?? assertWorkspaceModelPolicyAllows;
|
|
219
231
|
const recordUsage = options.recordUsage ?? recordWorkspaceUsage;
|
|
220
232
|
return {
|
|
233
|
+
settleAutomationRunFailure: async (input) => {
|
|
234
|
+
const service = await services();
|
|
235
|
+
await settle(service.db, {
|
|
236
|
+
workspaceId: input.workspaceId,
|
|
237
|
+
runId: input.runId,
|
|
238
|
+
status: "failed",
|
|
239
|
+
errorCode: "dispatch_failed"
|
|
240
|
+
});
|
|
241
|
+
},
|
|
221
242
|
dispatchAutomationRun: async (input) => {
|
|
222
243
|
const service = await services();
|
|
244
|
+
const catalogSourceSettings = service.catalogSourceSettings ?? service.settings;
|
|
245
|
+
const deploymentCatalogSettings = (await resolveCatalogSettings(service.db, catalogSourceSettings)).settings;
|
|
223
246
|
const run = await claim(service.db, input);
|
|
224
247
|
if (!run) return { action: "not_found" };
|
|
225
248
|
if (run.status === "dispatched") {
|
|
@@ -227,61 +250,87 @@ function createAutomationActivities(services, options = {}) {
|
|
|
227
250
|
return { action: "already_dispatched", sessionId: run.sessionId };
|
|
228
251
|
}
|
|
229
252
|
if (run.status === "skipped") {
|
|
230
|
-
return {
|
|
253
|
+
return {
|
|
254
|
+
action: "skipped",
|
|
255
|
+
reason: run.errorCode ?? "authority_revoked"
|
|
256
|
+
};
|
|
231
257
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await settle(service.db, {
|
|
235
|
-
workspaceId: input.workspaceId,
|
|
236
|
-
runId: run.id,
|
|
237
|
-
status: "skipped",
|
|
238
|
-
errorCode: "accepted_execution_mismatch"
|
|
239
|
-
});
|
|
240
|
-
return { action: "skipped", reason: "accepted_execution_mismatch" };
|
|
258
|
+
if (run.status === "failed") {
|
|
259
|
+
return { action: "failed", reason: run.errorCode ?? "dispatch_failed" };
|
|
241
260
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
261
|
+
try {
|
|
262
|
+
const accepted = run.acceptedExecution;
|
|
263
|
+
if (accepted.accountId !== input.accountId || accepted.workspaceId !== input.workspaceId || accepted.sourceId !== run.sourceId || accepted.triggerId !== run.triggerId || accepted.triggerRevision !== run.triggerRevision || accepted.eventId !== run.eventId) {
|
|
264
|
+
await settle(service.db, {
|
|
265
|
+
workspaceId: input.workspaceId,
|
|
266
|
+
runId: run.id,
|
|
267
|
+
status: "skipped",
|
|
268
|
+
errorCode: "accepted_execution_mismatch"
|
|
269
|
+
});
|
|
270
|
+
return { action: "skipped", reason: "accepted_execution_mismatch" };
|
|
271
|
+
}
|
|
272
|
+
const template = accepted.sessionTemplate;
|
|
273
|
+
const requestedModel = template.model ?? deploymentCatalogSettings.openaiModel;
|
|
274
|
+
const catalogSettings = requestedModel.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || requestedModel.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX) ? (await resolveWorkspaceCatalogSettings(service.db, catalogSourceSettings, {
|
|
275
|
+
accountId: input.accountId,
|
|
257
276
|
workspaceId: input.workspaceId,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
retainedProductModelId: requestedModel
|
|
278
|
+
})).settings : deploymentCatalogSettings;
|
|
279
|
+
const catalogService = { ...service, settings: catalogSettings };
|
|
280
|
+
let model;
|
|
281
|
+
try {
|
|
282
|
+
const configuredModel = canonicalConfiguredModel(catalogSettings, requestedModel);
|
|
283
|
+
if (!configuredModel) throw new Error("automation has no configured model");
|
|
284
|
+
await assertModelPolicy(service.db, catalogSettings, input.workspaceId, configuredModel);
|
|
285
|
+
model = configuredModel;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (!isUnprocessableEntity(error)) throw error;
|
|
288
|
+
await settle(service.db, {
|
|
289
|
+
workspaceId: input.workspaceId,
|
|
290
|
+
runId: run.id,
|
|
291
|
+
status: "failed",
|
|
292
|
+
errorCode: "dispatch_failed"
|
|
293
|
+
});
|
|
294
|
+
return { action: "failed", reason: "dispatch_failed" };
|
|
295
|
+
}
|
|
296
|
+
const denial = await admit(catalogService, {
|
|
297
|
+
accountId: input.accountId,
|
|
268
298
|
workspaceId: input.workspaceId,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
299
|
+
model,
|
|
300
|
+
requestedAgentRuns: 1
|
|
301
|
+
});
|
|
302
|
+
if (denial) {
|
|
303
|
+
await settle(service.db, {
|
|
304
|
+
workspaceId: input.workspaceId,
|
|
305
|
+
runId: run.id,
|
|
306
|
+
status: "failed",
|
|
307
|
+
errorCode: denial
|
|
308
|
+
});
|
|
309
|
+
return { action: "failed", reason: denial };
|
|
310
|
+
}
|
|
311
|
+
const reasoningEffort = template.reasoningEffort ?? catalogSettings.openaiReasoningEffort;
|
|
312
|
+
const sandboxBackend = template.sandboxBackend ?? catalogSettings.sandboxBackend;
|
|
313
|
+
if (sandboxBackend === "selfhosted") {
|
|
314
|
+
await settle(service.db, {
|
|
315
|
+
workspaceId: input.workspaceId,
|
|
316
|
+
runId: run.id,
|
|
317
|
+
status: "skipped",
|
|
318
|
+
errorCode: "interactive_compute_not_allowed"
|
|
319
|
+
});
|
|
320
|
+
return {
|
|
321
|
+
action: "skipped",
|
|
322
|
+
reason: "interactive_compute_not_allowed"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(catalogSettings, {
|
|
326
|
+
modelId: model,
|
|
327
|
+
requestedModelId: template.model,
|
|
328
|
+
modelSource: template.model ? "explicit" : "deployment",
|
|
329
|
+
reasoningEffort,
|
|
330
|
+
reasoningSource: template.reasoningEffort ? "explicit" : "deployment",
|
|
331
|
+
latencyMode: "standard",
|
|
332
|
+
latencyModeSource: "deployment"
|
|
272
333
|
});
|
|
273
|
-
return { action: "skipped", reason: "interactive_compute_not_allowed" };
|
|
274
|
-
}
|
|
275
|
-
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(service.settings, {
|
|
276
|
-
modelId: model,
|
|
277
|
-
requestedModelId: template.model,
|
|
278
|
-
modelSource: template.model ? "explicit" : "deployment",
|
|
279
|
-
reasoningEffort,
|
|
280
|
-
reasoningSource: template.reasoningEffort ? "explicit" : "deployment",
|
|
281
|
-
latencyMode: "standard",
|
|
282
|
-
latencyModeSource: "deployment"
|
|
283
|
-
});
|
|
284
|
-
try {
|
|
285
334
|
const created = await createSession2({
|
|
286
335
|
db: service.db,
|
|
287
336
|
bus: service.bus,
|
|
@@ -329,11 +378,12 @@ function createAutomationActivities(services, options = {}) {
|
|
|
329
378
|
policyRole: template.policyRole,
|
|
330
379
|
firstPartyMcpPermissions: template.firstPartyMcpPermissions,
|
|
331
380
|
firstPartyMcpTools: template.firstPartyMcpTools,
|
|
381
|
+
retainWorkspaceCustomModel: model.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || model.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX),
|
|
332
382
|
createIdempotencyKey: `automation-run:${run.id}`,
|
|
333
383
|
subjectId: accepted.serviceSubjectId
|
|
334
384
|
});
|
|
335
385
|
await recordUsage(
|
|
336
|
-
{ db: service.db, settings:
|
|
386
|
+
{ db: service.db, settings: catalogSettings },
|
|
337
387
|
{
|
|
338
388
|
accountId: input.accountId,
|
|
339
389
|
workspaceId: input.workspaceId,
|
|
@@ -367,17 +417,14 @@ function createAutomationActivities(services, options = {}) {
|
|
|
367
417
|
});
|
|
368
418
|
return { action: "skipped", reason: "authority_revoked" };
|
|
369
419
|
}
|
|
370
|
-
await settle(service.db, {
|
|
371
|
-
workspaceId: input.workspaceId,
|
|
372
|
-
runId: run.id,
|
|
373
|
-
status: "failed",
|
|
374
|
-
errorCode: "dispatch_failed"
|
|
375
|
-
});
|
|
376
420
|
throw error;
|
|
377
421
|
}
|
|
378
422
|
}
|
|
379
423
|
};
|
|
380
424
|
}
|
|
425
|
+
function isUnprocessableEntity(error) {
|
|
426
|
+
return error instanceof Error && "status" in error && error.status === 422;
|
|
427
|
+
}
|
|
381
428
|
|
|
382
429
|
// src/activities/documents.ts
|
|
383
430
|
import { configuredStaticUsageLimits as configuredStaticUsageLimits2 } from "@opengeni/config";
|
|
@@ -3885,11 +3932,13 @@ function rigPlatformChecksForSettings(settings) {
|
|
|
3885
3932
|
'test -x "$__og_browser_engine"',
|
|
3886
3933
|
'__og_browser_token="$(mktemp)"',
|
|
3887
3934
|
`trap 'opengeni-browserd-down >/dev/null 2>&1 || true; rm -f "$__og_browser_token"' EXIT`,
|
|
3888
|
-
`
|
|
3935
|
+
`__og_browser_token_value="$(od -An -N32 -tx1 /dev/urandom | tr -d '[:space:]')"`,
|
|
3936
|
+
'test "${#__og_browser_token_value}" -eq 64',
|
|
3937
|
+
`printf '%s\\n' "$__og_browser_token_value" > "$__og_browser_token"`,
|
|
3889
3938
|
'chmod 0600 "$__og_browser_token"',
|
|
3890
3939
|
'OPENGENI_BROWSERD_ADMIN_TOKEN_FILE="$__og_browser_token" OPENGENI_BROWSERD_PORT=7682 OPENGENI_BROWSERD_ALLOWED_ORIGINS= opengeni-browserd-up',
|
|
3891
3940
|
"curl --noproxy '*' -fsS http://127.0.0.1:7682/healthz >/dev/null",
|
|
3892
|
-
|
|
3941
|
+
`curl --noproxy '*' -fsS -H "Authorization: Bearer $__og_browser_token_value" http://127.0.0.1:7682/v1/browser-sessions >/dev/null`
|
|
3893
3942
|
].join("\n")
|
|
3894
3943
|
}
|
|
3895
3944
|
];
|
|
@@ -3916,7 +3965,7 @@ function rigPlatformChecksForSettings(settings) {
|
|
|
3916
3965
|
"test -x /usr/local/bin/opengeni-desktop-down",
|
|
3917
3966
|
"command -v Xvfb >/dev/null",
|
|
3918
3967
|
"command -v x11vnc >/dev/null",
|
|
3919
|
-
"
|
|
3968
|
+
"test -x /opt/noVNC/utils/novnc_proxy",
|
|
3920
3969
|
"command -v scrot >/dev/null",
|
|
3921
3970
|
"command -v xdotool >/dev/null",
|
|
3922
3971
|
'__og_desktop_home="$(mktemp -d)"',
|
|
@@ -5176,6 +5225,7 @@ import {
|
|
|
5176
5225
|
workspaceArchiveCaptureDeadlineElapsed,
|
|
5177
5226
|
retainedProcessReconciliationProof,
|
|
5178
5227
|
retainedProcessSettlementIdentity,
|
|
5228
|
+
settleClaimedConnectedMachineBackgroundCommand,
|
|
5179
5229
|
settleSandboxCheckpointArtifactGc,
|
|
5180
5230
|
rlsContextForWorkspace as rlsContextForWorkspace2,
|
|
5181
5231
|
settleRetainedProcess
|
|
@@ -5183,9 +5233,7 @@ import {
|
|
|
5183
5233
|
import {
|
|
5184
5234
|
claimConnectedMachineSessionBackgroundCommands,
|
|
5185
5235
|
deferConnectedMachineBackgroundCommandReconciliation,
|
|
5186
|
-
recordConnectedMachineBackgroundCommandProof
|
|
5187
|
-
settleClaimedConnectedMachineBackgroundCommand,
|
|
5188
|
-
settleSessionBackgroundCommandForRetainedProcess
|
|
5236
|
+
recordConnectedMachineBackgroundCommandProof
|
|
5189
5237
|
} from "@opengeni/db/session-background-commands";
|
|
5190
5238
|
import { sandboxWarmRateMicrosPerSecond } from "@opengeni/config";
|
|
5191
5239
|
import { sandboxLeaseTelemetryKey } from "@opengeni/observability";
|
|
@@ -5521,7 +5569,8 @@ function createSandboxLeaseActivities(services, options = {}) {
|
|
|
5521
5569
|
settings,
|
|
5522
5570
|
observability,
|
|
5523
5571
|
probeRetainedProcess,
|
|
5524
|
-
options.inspectHistoricalModalSandbox ?? inspectModalSandboxLifecycle
|
|
5572
|
+
options.inspectHistoricalModalSandbox ?? inspectModalSandboxLifecycle,
|
|
5573
|
+
service.bus
|
|
5525
5574
|
);
|
|
5526
5575
|
try {
|
|
5527
5576
|
modalOrphansTerminated = await sweepModalOrphans(settings, db, observability);
|
|
@@ -5827,9 +5876,20 @@ async function reconcileConnectedMachineBackgroundCommands(db, settings, observa
|
|
|
5827
5876
|
}
|
|
5828
5877
|
}
|
|
5829
5878
|
try {
|
|
5830
|
-
|
|
5879
|
+
const settlement = await settleClaimedConnectedMachineBackgroundCommand(db, { claim });
|
|
5880
|
+
if (!settlement.settled) {
|
|
5831
5881
|
throw new Error("Connected command settlement lost its exact claim or proof");
|
|
5832
5882
|
}
|
|
5883
|
+
if (settlement.events.length > 0) {
|
|
5884
|
+
try {
|
|
5885
|
+
await bus.publish(claim.workspaceId, claim.sessionId, settlement.events);
|
|
5886
|
+
} catch (error) {
|
|
5887
|
+
observability.warn("sandbox reaper: connected-command event fanout failed", {
|
|
5888
|
+
commandId: claim.commandId,
|
|
5889
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5890
|
+
});
|
|
5891
|
+
}
|
|
5892
|
+
}
|
|
5833
5893
|
recordConnectedCommandReconciliation(observability, `settled_${proof.outcome}`);
|
|
5834
5894
|
} catch (error) {
|
|
5835
5895
|
recordConnectedCommandReconciliation(observability, "settlement_failed");
|
|
@@ -5908,7 +5968,7 @@ async function deferConnectedCommandClaim(db, settings, observability, claim, ou
|
|
|
5908
5968
|
});
|
|
5909
5969
|
}
|
|
5910
5970
|
}
|
|
5911
|
-
async function reconcileTerminalRetainedProcesses(db, settings, observability, probe, inspectHistoricalModalSandbox) {
|
|
5971
|
+
async function reconcileTerminalRetainedProcesses(db, settings, observability, probe, inspectHistoricalModalSandbox, bus) {
|
|
5912
5972
|
const claimId = crypto.randomUUID();
|
|
5913
5973
|
let claims;
|
|
5914
5974
|
try {
|
|
@@ -6098,15 +6158,20 @@ async function reconcileTerminalRetainedProcesses(db, settings, observability, p
|
|
|
6098
6158
|
if (settlement.process.state === "active") {
|
|
6099
6159
|
throw new Error("Retained-process reconciliation returned an active durable process");
|
|
6100
6160
|
}
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6161
|
+
if (settlement.backgroundCommandEvents.length > 0) {
|
|
6162
|
+
try {
|
|
6163
|
+
await bus.publish(
|
|
6164
|
+
process.workspaceId,
|
|
6165
|
+
process.sessionId,
|
|
6166
|
+
settlement.backgroundCommandEvents
|
|
6167
|
+
);
|
|
6168
|
+
} catch (error) {
|
|
6169
|
+
observability.warn("sandbox reaper: retained-command event fanout failed", {
|
|
6170
|
+
processId: process.id,
|
|
6171
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6172
|
+
});
|
|
6173
|
+
}
|
|
6174
|
+
}
|
|
6110
6175
|
recordRetainedProcessReconciliation(observability, `settled_${proof.outcome}`);
|
|
6111
6176
|
} catch (error) {
|
|
6112
6177
|
recordRetainedProcessReconciliation(observability, "settlement_failed");
|
|
@@ -7229,13 +7294,17 @@ import {
|
|
|
7229
7294
|
ScheduledTaskRunAcceptedExecution,
|
|
7230
7295
|
normalizeAutomaticSessionTitle,
|
|
7231
7296
|
scheduledOccurrencePayloadUtf8Bytes,
|
|
7232
|
-
stableJson
|
|
7297
|
+
stableJson,
|
|
7298
|
+
TurnExecutionPolicyV1
|
|
7233
7299
|
} from "@opengeni/contracts";
|
|
7234
7300
|
import {
|
|
7235
7301
|
defaultSessionMcpServerIds,
|
|
7236
7302
|
openGeniSlackBotMetadata,
|
|
7237
7303
|
requireOpenGeniSlackBotConnection,
|
|
7304
|
+
resolveWorkspaceCatalogSettings as resolveWorkspaceCatalogSettings2,
|
|
7238
7305
|
resolveSessionToolPolicy,
|
|
7306
|
+
workspaceCustomModelReference,
|
|
7307
|
+
lockActiveCustomModelForAdmission,
|
|
7239
7308
|
scheduledSlackBotConnectionId,
|
|
7240
7309
|
swapActiveSandbox
|
|
7241
7310
|
} from "@opengeni/core";
|
|
@@ -7283,8 +7352,9 @@ import {
|
|
|
7283
7352
|
withSessionActivityRlsContext
|
|
7284
7353
|
} from "@opengeni/db";
|
|
7285
7354
|
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
7286
|
-
import { resolveFirstPartyMcpToolPolicy } from "@opengeni/config";
|
|
7355
|
+
import { resolveFirstPartyMcpToolPolicy, resolveTurnExecutionPolicyV1 as resolveTurnExecutionPolicyV12 } from "@opengeni/config";
|
|
7287
7356
|
import { Context as Context2 } from "@temporalio/activity";
|
|
7357
|
+
import { createHash as createHash5 } from "crypto";
|
|
7288
7358
|
|
|
7289
7359
|
// src/scheduled-alert-occurrence.ts
|
|
7290
7360
|
import { createHash as createHash4 } from "crypto";
|
|
@@ -7420,6 +7490,10 @@ function scheduledTaskRunProducerKey(input, suppliedActivityIdentity) {
|
|
|
7420
7490
|
workflowId: info.workflowExecution.workflowId
|
|
7421
7491
|
})}`;
|
|
7422
7492
|
}
|
|
7493
|
+
function scheduledTaskGeneratedSessionCreateIdempotencyKey(producerKey) {
|
|
7494
|
+
const digest = createHash5("sha256").update("scheduled-task-run\0", "utf8").update(producerKey, "utf8").digest("hex");
|
|
7495
|
+
return `scheduled-task-run:${digest}`;
|
|
7496
|
+
}
|
|
7423
7497
|
function scheduledTaskSessionTitle(taskName) {
|
|
7424
7498
|
return normalizeAutomaticSessionTitle(taskName) ?? "Scheduled run";
|
|
7425
7499
|
}
|
|
@@ -7440,11 +7514,20 @@ async function stampScheduledSessionTitle(db, input) {
|
|
|
7440
7514
|
function createScheduledTaskActivities(services) {
|
|
7441
7515
|
return {
|
|
7442
7516
|
dispatchScheduledTaskRun: async (input) => {
|
|
7443
|
-
const
|
|
7444
|
-
const { settings, db, bus, wakeSessionWorkflow } = service;
|
|
7517
|
+
const baseService = await services();
|
|
7445
7518
|
if (input.triggerType !== "scheduled" && !input.initiator) {
|
|
7446
7519
|
return { action: "blocked", reason: "malformed_manual_trigger" };
|
|
7447
7520
|
}
|
|
7521
|
+
const { db, bus, wakeSessionWorkflow } = baseService;
|
|
7522
|
+
const settingsForTask = async (task2, retainedProductModelId) => (await resolveWorkspaceCatalogSettings2(
|
|
7523
|
+
db,
|
|
7524
|
+
baseService.catalogSourceSettings ?? baseService.settings,
|
|
7525
|
+
{
|
|
7526
|
+
accountId: task2.accountId,
|
|
7527
|
+
workspaceId: task2.workspaceId,
|
|
7528
|
+
...retainedProductModelId !== void 0 ? { retainedProductModelId } : {}
|
|
7529
|
+
}
|
|
7530
|
+
)).settings;
|
|
7448
7531
|
const stableProducerKey = scheduledTaskRunProducerKey(input);
|
|
7449
7532
|
const priorRun = await getScheduledTaskRunByProducerKey(db, {
|
|
7450
7533
|
workspaceId: input.workspaceId,
|
|
@@ -7474,11 +7557,16 @@ function createScheduledTaskActivities(services) {
|
|
|
7474
7557
|
});
|
|
7475
7558
|
}
|
|
7476
7559
|
if (priorRun.status === "queued") {
|
|
7560
|
+
const acceptedPolicy = acceptedExecution.turnExecutionPolicy ? TurnExecutionPolicyV1.parse(acceptedExecution.turnExecutionPolicy) : null;
|
|
7561
|
+
const settings2 = await settingsForTask(
|
|
7562
|
+
acceptedExecution.task,
|
|
7563
|
+
acceptedPolicy?.productModelId ?? acceptedExecution.targetSessionExecution?.model ?? acceptedExecution.resolvedModel
|
|
7564
|
+
);
|
|
7477
7565
|
try {
|
|
7478
7566
|
return await recoverBoundScheduledTaskDispatch({
|
|
7479
7567
|
db,
|
|
7480
7568
|
bus,
|
|
7481
|
-
settings,
|
|
7569
|
+
settings: settings2,
|
|
7482
7570
|
wakeSessionWorkflow,
|
|
7483
7571
|
run: priorRun,
|
|
7484
7572
|
acceptedExecution,
|
|
@@ -7629,6 +7717,14 @@ function createScheduledTaskActivities(services) {
|
|
|
7629
7717
|
throw new Error("scheduled authority classes have different causal humans");
|
|
7630
7718
|
}
|
|
7631
7719
|
const taskAuthoritySubjectId = taskRevisionAuthority?.subjectId ?? taskPersonalResourceAuthoritySubjectId ?? taskConnectionAuthoritySubjectId;
|
|
7720
|
+
const acceptedTargetSessionId = task.runMode === "existing_session" ? task.targetSessionId : task.runMode === "reusable_session" ? task.reusableSessionId : null;
|
|
7721
|
+
const targetSessionExecutionBase = acceptedTargetSessionId ? await getScheduledTargetSessionExecution(
|
|
7722
|
+
db,
|
|
7723
|
+
task.workspaceId,
|
|
7724
|
+
acceptedTargetSessionId,
|
|
7725
|
+
taskAuthoritySubjectId
|
|
7726
|
+
) : null;
|
|
7727
|
+
const settings = await settingsForTask(task, targetSessionExecutionBase?.model);
|
|
7632
7728
|
const model = task.agentConfig.model ?? settings.openaiModel;
|
|
7633
7729
|
const reasoningEffort = task.agentConfig.reasoningEffort ?? settings.openaiReasoningEffort;
|
|
7634
7730
|
let sandboxBackend = task.agentConfig.sandboxBackend ?? settings.sandboxBackend;
|
|
@@ -7678,13 +7774,6 @@ function createScheduledTaskActivities(services) {
|
|
|
7678
7774
|
codexCompactionMode: isCodexBilledModel(model) ? resolveWorkspaceCodexCompactionDefault(workspace.settings) : "portable"
|
|
7679
7775
|
};
|
|
7680
7776
|
})() : null;
|
|
7681
|
-
const acceptedTargetSessionId = generatedTarget ? null : task.runMode === "existing_session" ? task.targetSessionId : task.reusableSessionId;
|
|
7682
|
-
const targetSessionExecutionBase = acceptedTargetSessionId ? await getScheduledTargetSessionExecution(
|
|
7683
|
-
db,
|
|
7684
|
-
task.workspaceId,
|
|
7685
|
-
acceptedTargetSessionId,
|
|
7686
|
-
taskAuthoritySubjectId
|
|
7687
|
-
) : null;
|
|
7688
7777
|
const targetSessionExecution = targetSessionExecutionBase ? await (async () => {
|
|
7689
7778
|
const [capabilityServerIds, apiIntegrationServerIds] = await Promise.all([
|
|
7690
7779
|
listEnabledMcpCapabilityServerIds(db, task.workspaceId),
|
|
@@ -7839,20 +7928,49 @@ function createScheduledTaskActivities(services) {
|
|
|
7839
7928
|
if ((acceptedVariableSet?.scope === "user" || acceptedRig?.scope === "user") && !causalHumanSubjectId) {
|
|
7840
7929
|
throw new Error("scheduled personal-resource execution has no causal human");
|
|
7841
7930
|
}
|
|
7842
|
-
const admissionDenial = await agentRunAdmissionDenial(
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7931
|
+
const admissionDenial = await agentRunAdmissionDenial(
|
|
7932
|
+
{ ...baseService, settings },
|
|
7933
|
+
{
|
|
7934
|
+
accountId: task.accountId,
|
|
7935
|
+
workspaceId: task.workspaceId,
|
|
7936
|
+
model: targetSessionExecution?.model ?? model,
|
|
7937
|
+
requestedAgentRuns: input.agentRunUsageIdempotencyKey ? 0 : 1
|
|
7938
|
+
}
|
|
7939
|
+
);
|
|
7848
7940
|
if (admissionDenial) {
|
|
7849
7941
|
return { action: "blocked", reason: admissionDenial };
|
|
7850
7942
|
}
|
|
7943
|
+
const acceptedModel = targetSessionExecution?.model ?? model;
|
|
7944
|
+
const acceptedReasoningEffort = targetSessionExecution?.reasoningEffort ?? reasoningEffort;
|
|
7945
|
+
const acceptedLatencyMode = targetSessionExecution?.latencyMode ?? "standard";
|
|
7946
|
+
const acceptedCustomModel = generatedTarget ? workspaceCustomModelReference(settings, acceptedModel) : null;
|
|
7947
|
+
const beforeFreshAgentRunCommit = acceptedCustomModel ? async (tx) => {
|
|
7948
|
+
const active = await lockActiveCustomModelForAdmission(tx, {
|
|
7949
|
+
accountId: task.accountId,
|
|
7950
|
+
workspaceId: task.workspaceId,
|
|
7951
|
+
reference: acceptedCustomModel
|
|
7952
|
+
});
|
|
7953
|
+
if (!active) {
|
|
7954
|
+
throw new ScheduledRunTerminalAuthorityError(
|
|
7955
|
+
"scheduled_model_unavailable",
|
|
7956
|
+
`model is not available: ${acceptedModel}`
|
|
7957
|
+
);
|
|
7958
|
+
}
|
|
7959
|
+
} : void 0;
|
|
7960
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV12(settings, {
|
|
7961
|
+
modelId: acceptedModel,
|
|
7962
|
+
requestedModelId: generatedTarget && task.agentConfig.model ? task.agentConfig.model : null,
|
|
7963
|
+
modelSource: generatedTarget ? task.agentConfig.model ? "explicit" : "deployment" : "session",
|
|
7964
|
+
reasoningEffort: acceptedReasoningEffort,
|
|
7965
|
+
reasoningSource: generatedTarget ? task.agentConfig.reasoningEffort ? "explicit" : "deployment" : "session",
|
|
7966
|
+
latencyMode: acceptedLatencyMode,
|
|
7967
|
+
latencyModeSource: generatedTarget ? "deployment" : "session"
|
|
7968
|
+
});
|
|
7851
7969
|
const deferredEvents = [];
|
|
7852
7970
|
const executeDispatch = async (dispatchDb, deferPublications) => {
|
|
7853
7971
|
const admittedRunId = crypto.randomUUID();
|
|
7854
7972
|
const generatedSessionBinding = generatedTarget ? {
|
|
7855
|
-
createIdempotencyKey: alertResponderSessionCreateIdempotencyKey ?? (task.runMode === "reusable_session" ? `scheduled-task-reusable:${task.id}:${task.authorityRevision}:${task.executionDigest}` :
|
|
7973
|
+
createIdempotencyKey: alertResponderSessionCreateIdempotencyKey ?? (task.runMode === "reusable_session" ? `scheduled-task-reusable:${task.id}:${task.authorityRevision}:${task.executionDigest}` : scheduledTaskGeneratedSessionCreateIdempotencyKey(stableProducerKey)),
|
|
7856
7974
|
effectiveMaxNestedAgentDepth: generatedSessionDepthPolicy.effectiveMaxNestedAgentDepth,
|
|
7857
7975
|
nestedAgentDepthPolicySource: generatedSessionDepthPolicy.nestedAgentDepthPolicySource,
|
|
7858
7976
|
codexCompactionMode: generatedSessionDepthPolicy.codexCompactionMode
|
|
@@ -7863,6 +7981,7 @@ function createScheduledTaskActivities(services) {
|
|
|
7863
7981
|
resolvedModel: model,
|
|
7864
7982
|
resolvedReasoningEffort: reasoningEffort,
|
|
7865
7983
|
resolvedLatencyMode: "standard",
|
|
7984
|
+
turnExecutionPolicy,
|
|
7866
7985
|
resolvedSandboxBackend: sandboxBackend,
|
|
7867
7986
|
resolvedSandboxOs: sandboxOs,
|
|
7868
7987
|
resolvedTools: taskTools,
|
|
@@ -7917,7 +8036,8 @@ function createScheduledTaskActivities(services) {
|
|
|
7917
8036
|
triggerType: input.triggerType,
|
|
7918
8037
|
producerKey: stableProducerKey,
|
|
7919
8038
|
scheduledAt: null,
|
|
7920
|
-
acceptedExecutionSnapshot: acceptedExecution
|
|
8039
|
+
acceptedExecutionSnapshot: acceptedExecution,
|
|
8040
|
+
...beforeFreshAgentRunCommit ? { beforeFreshAgentRunCommit } : {}
|
|
7921
8041
|
});
|
|
7922
8042
|
await recordScheduledTaskFiredUsage(dispatchDb, acceptedExecution, run);
|
|
7923
8043
|
if (run.status === "failed" && run.error === "scheduled_authority_exhausted") {
|
|
@@ -8326,15 +8446,16 @@ function createScheduledTaskActivities(services) {
|
|
|
8326
8446
|
xaiProviderAccountAuthoritySnapshot: taskXaiProviderAccountAuthoritySnapshot,
|
|
8327
8447
|
scheduledTaskRunId: run.id
|
|
8328
8448
|
},
|
|
8329
|
-
async (tx, wakeEventId) => {
|
|
8449
|
+
async (tx, wakeEventId, _updateId, rejectionReason) => {
|
|
8330
8450
|
if (!wakeEventId) {
|
|
8451
|
+
const error = scheduledSessionRejectionError(rejectionReason);
|
|
8331
8452
|
await settleScheduledTaskRunInTransaction(tx, {
|
|
8332
8453
|
workspaceId: task.workspaceId,
|
|
8333
8454
|
runId: scheduledRun.id,
|
|
8334
8455
|
sessionId: session.id,
|
|
8335
8456
|
triggerEventId: null,
|
|
8336
8457
|
status: "skipped",
|
|
8337
|
-
error
|
|
8458
|
+
error
|
|
8338
8459
|
});
|
|
8339
8460
|
return;
|
|
8340
8461
|
}
|
|
@@ -8346,23 +8467,27 @@ function createScheduledTaskActivities(services) {
|
|
|
8346
8467
|
status: "dispatched"
|
|
8347
8468
|
});
|
|
8348
8469
|
},
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8470
|
+
{
|
|
8471
|
+
requireIdleSession: task.overlapPolicy === "skip" && !sessionCreated,
|
|
8472
|
+
...incidentPreflightRequired ? {
|
|
8473
|
+
prepareSource: async (tx, sessionId) => await prepareIncidentTelemetrySource({
|
|
8474
|
+
tx,
|
|
8475
|
+
settings,
|
|
8476
|
+
taskId: task.id,
|
|
8477
|
+
workspaceId: task.workspaceId,
|
|
8478
|
+
sessionId,
|
|
8479
|
+
alertOccurrenceLabels: structuredAlertOccurrence?.labels ?? null,
|
|
8480
|
+
acceptedExecution
|
|
8481
|
+
})
|
|
8482
|
+
} : {}
|
|
8483
|
+
}
|
|
8360
8484
|
);
|
|
8361
|
-
if (scheduledUpdate.reason === "session_cancelled") {
|
|
8485
|
+
if (scheduledUpdate.reason === "session_cancelled" || scheduledUpdate.reason === "session_not_idle") {
|
|
8486
|
+
const error = scheduledSessionRejectionError(scheduledUpdate.reason);
|
|
8362
8487
|
return {
|
|
8363
8488
|
kind: "blocked",
|
|
8364
8489
|
result: { action: "blocked", reason: "scheduled_run_terminal" },
|
|
8365
|
-
run: { ...run, status: "skipped", error
|
|
8490
|
+
run: { ...run, status: "skipped", error }
|
|
8366
8491
|
};
|
|
8367
8492
|
}
|
|
8368
8493
|
if (scheduledUpdate.added && scheduledUpdate.events.length > 0) {
|
|
@@ -8401,26 +8526,6 @@ function createScheduledTaskActivities(services) {
|
|
|
8401
8526
|
});
|
|
8402
8527
|
assertReusableSessionRevivable(session.status);
|
|
8403
8528
|
assertReusableSessionBindingMatches(session, task);
|
|
8404
|
-
const goalEvents = task.runMode === "reusable_session" && goalSpec && run.status === "queued" ? await upsertScheduledSessionGoalForRun(dispatchDb, {
|
|
8405
|
-
accountId: task.accountId,
|
|
8406
|
-
workspaceId: task.workspaceId,
|
|
8407
|
-
sessionId: session.id,
|
|
8408
|
-
runId: run.id,
|
|
8409
|
-
text: goalSpec.text,
|
|
8410
|
-
successCriteria: goalSpec.successCriteria ?? null,
|
|
8411
|
-
maxAutoContinuations: goalSpec.maxAutoContinuations ?? null,
|
|
8412
|
-
...goalSpec.mutationPolicy ? { mutationPolicy: goalSpec.mutationPolicy } : {}
|
|
8413
|
-
}) : [];
|
|
8414
|
-
if (goalEvents.length > 0) {
|
|
8415
|
-
if (deferPublications) {
|
|
8416
|
-
deferredEvents.push({
|
|
8417
|
-
sessionId: session.id,
|
|
8418
|
-
events: goalEvents
|
|
8419
|
-
});
|
|
8420
|
-
} else {
|
|
8421
|
-
await publishDurableSessionEvents(bus, task.workspaceId, session.id, goalEvents);
|
|
8422
|
-
}
|
|
8423
|
-
}
|
|
8424
8529
|
const bundled = await addSessionSystemUpdateWithSourceMutation(
|
|
8425
8530
|
dispatchDb,
|
|
8426
8531
|
{
|
|
@@ -8450,15 +8555,16 @@ function createScheduledTaskActivities(services) {
|
|
|
8450
8555
|
xaiProviderAccountAuthoritySnapshot: taskXaiProviderAccountAuthoritySnapshot,
|
|
8451
8556
|
scheduledTaskRunId: run.id
|
|
8452
8557
|
},
|
|
8453
|
-
async (tx, wakeEventId) => {
|
|
8558
|
+
async (tx, wakeEventId, _updateId, rejectionReason) => {
|
|
8454
8559
|
if (!wakeEventId) {
|
|
8560
|
+
const error = scheduledSessionRejectionError(rejectionReason);
|
|
8455
8561
|
await settleScheduledTaskRunInTransaction(tx, {
|
|
8456
8562
|
workspaceId: task.workspaceId,
|
|
8457
8563
|
runId: scheduledRun.id,
|
|
8458
8564
|
sessionId: session.id,
|
|
8459
8565
|
triggerEventId: null,
|
|
8460
8566
|
status: "skipped",
|
|
8461
|
-
error
|
|
8567
|
+
error
|
|
8462
8568
|
});
|
|
8463
8569
|
return;
|
|
8464
8570
|
}
|
|
@@ -8470,23 +8576,41 @@ function createScheduledTaskActivities(services) {
|
|
|
8470
8576
|
status: "dispatched"
|
|
8471
8577
|
});
|
|
8472
8578
|
},
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8579
|
+
{
|
|
8580
|
+
requireIdleSession: task.overlapPolicy === "skip",
|
|
8581
|
+
prepareSource: async (tx, sessionId) => {
|
|
8582
|
+
const goalEvents = task.runMode === "reusable_session" && goalSpec && run.status === "queued" ? await upsertScheduledSessionGoalForRun(tx, {
|
|
8583
|
+
accountId: task.accountId,
|
|
8584
|
+
workspaceId: task.workspaceId,
|
|
8585
|
+
sessionId,
|
|
8586
|
+
runId: run.id,
|
|
8587
|
+
text: goalSpec.text,
|
|
8588
|
+
successCriteria: goalSpec.successCriteria ?? null,
|
|
8589
|
+
maxAutoContinuations: goalSpec.maxAutoContinuations ?? null,
|
|
8590
|
+
...goalSpec.mutationPolicy ? { mutationPolicy: goalSpec.mutationPolicy } : {}
|
|
8591
|
+
}) : [];
|
|
8592
|
+
const incidentSource = incidentPreflightRequired ? await prepareIncidentTelemetrySource({
|
|
8593
|
+
tx,
|
|
8594
|
+
settings,
|
|
8595
|
+
taskId: task.id,
|
|
8596
|
+
workspaceId: task.workspaceId,
|
|
8597
|
+
sessionId,
|
|
8598
|
+
alertOccurrenceLabels: structuredAlertOccurrence?.labels ?? null,
|
|
8599
|
+
acceptedExecution
|
|
8600
|
+
}) : void 0;
|
|
8601
|
+
return {
|
|
8602
|
+
...incidentSource ?? {},
|
|
8603
|
+
...goalEvents.length > 0 ? { events: goalEvents } : {}
|
|
8604
|
+
};
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8484
8607
|
);
|
|
8485
|
-
if (bundled.reason === "session_cancelled") {
|
|
8608
|
+
if (bundled.reason === "session_cancelled" || bundled.reason === "session_not_idle") {
|
|
8609
|
+
const error = scheduledSessionRejectionError(bundled.reason);
|
|
8486
8610
|
return {
|
|
8487
8611
|
kind: "blocked",
|
|
8488
8612
|
result: { action: "blocked", reason: "scheduled_run_terminal" },
|
|
8489
|
-
run: { ...run, status: "skipped", error
|
|
8613
|
+
run: { ...run, status: "skipped", error }
|
|
8490
8614
|
};
|
|
8491
8615
|
}
|
|
8492
8616
|
if (bundled.added && bundled.events.length > 0) {
|
|
@@ -8562,6 +8686,10 @@ function createScheduledTaskActivities(services) {
|
|
|
8562
8686
|
if (error instanceof IncidentTelemetryPreflightBlockedError) {
|
|
8563
8687
|
return { action: "blocked", reason: error.reason };
|
|
8564
8688
|
}
|
|
8689
|
+
const terminalError = scheduledRunRecoveryTerminalError(error);
|
|
8690
|
+
if (terminalError?.code === "scheduled_model_unavailable") {
|
|
8691
|
+
return scheduledRunTerminalResult(terminalError.code);
|
|
8692
|
+
}
|
|
8565
8693
|
throw error;
|
|
8566
8694
|
}
|
|
8567
8695
|
if (dispatchOutcome.kind === "replay") {
|
|
@@ -8674,6 +8802,9 @@ function scheduledRunTerminalResult(error) {
|
|
|
8674
8802
|
}
|
|
8675
8803
|
return { action: "blocked", reason: "scheduled_run_terminal" };
|
|
8676
8804
|
}
|
|
8805
|
+
function scheduledSessionRejectionError(rejectionReason) {
|
|
8806
|
+
return rejectionReason === "session_not_idle" ? "scheduled_session_not_idle" : "session_cancelled";
|
|
8807
|
+
}
|
|
8677
8808
|
async function prepareIncidentTelemetrySource(input) {
|
|
8678
8809
|
const session = await requireSession(input.tx, input.workspaceId, input.sessionId);
|
|
8679
8810
|
const { task, personalConnectionDelegations } = input.acceptedExecution ? {
|
|
@@ -9061,21 +9192,6 @@ async function recoverBoundScheduledTaskDispatch(input) {
|
|
|
9061
9192
|
await publishDurableSessionEvents(input.bus, task.workspaceId, session.id, titleEvents);
|
|
9062
9193
|
}
|
|
9063
9194
|
}
|
|
9064
|
-
if (!generatedSession && task.runMode === "reusable_session" && task.agentConfig.goal) {
|
|
9065
|
-
const goalEvents = await upsertScheduledSessionGoalForRun(input.db, {
|
|
9066
|
-
accountId: task.accountId,
|
|
9067
|
-
workspaceId: task.workspaceId,
|
|
9068
|
-
sessionId: session.id,
|
|
9069
|
-
runId: input.run.id,
|
|
9070
|
-
text: task.agentConfig.goal.text,
|
|
9071
|
-
successCriteria: task.agentConfig.goal.successCriteria ?? null,
|
|
9072
|
-
maxAutoContinuations: task.agentConfig.goal.maxAutoContinuations ?? null,
|
|
9073
|
-
...task.agentConfig.goal.mutationPolicy ? { mutationPolicy: task.agentConfig.goal.mutationPolicy } : {}
|
|
9074
|
-
});
|
|
9075
|
-
if (goalEvents.length > 0) {
|
|
9076
|
-
await publishDurableSessionEvents(input.bus, task.workspaceId, session.id, goalEvents);
|
|
9077
|
-
}
|
|
9078
|
-
}
|
|
9079
9195
|
const scheduledUpdate = await addSessionSystemUpdateWithSourceMutation(
|
|
9080
9196
|
input.db,
|
|
9081
9197
|
{
|
|
@@ -9107,15 +9223,16 @@ async function recoverBoundScheduledTaskDispatch(input) {
|
|
|
9107
9223
|
xaiProviderAccountAuthoritySnapshot: input.acceptedExecution.xaiProviderAccountAuthoritySnapshot,
|
|
9108
9224
|
scheduledTaskRunId: input.run.id
|
|
9109
9225
|
},
|
|
9110
|
-
async (tx, wakeEventId) => {
|
|
9226
|
+
async (tx, wakeEventId, _updateId, rejectionReason) => {
|
|
9111
9227
|
if (!wakeEventId) {
|
|
9228
|
+
const error = scheduledSessionRejectionError(rejectionReason);
|
|
9112
9229
|
await settleScheduledTaskRunInTransaction(tx, {
|
|
9113
9230
|
workspaceId: task.workspaceId,
|
|
9114
9231
|
runId: input.run.id,
|
|
9115
9232
|
sessionId: session.id,
|
|
9116
9233
|
triggerEventId: null,
|
|
9117
9234
|
status: "skipped",
|
|
9118
|
-
error
|
|
9235
|
+
error
|
|
9119
9236
|
});
|
|
9120
9237
|
return;
|
|
9121
9238
|
}
|
|
@@ -9127,19 +9244,37 @@ async function recoverBoundScheduledTaskDispatch(input) {
|
|
|
9127
9244
|
status: "dispatched"
|
|
9128
9245
|
});
|
|
9129
9246
|
},
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9247
|
+
{
|
|
9248
|
+
requireIdleSession: task.overlapPolicy === "skip" && !generatedSession,
|
|
9249
|
+
prepareSource: async (tx, sessionId) => {
|
|
9250
|
+
const goal = task.agentConfig.goal;
|
|
9251
|
+
const goalEvents = !generatedSession && task.runMode === "reusable_session" && goal ? await upsertScheduledSessionGoalForRun(tx, {
|
|
9252
|
+
accountId: task.accountId,
|
|
9253
|
+
workspaceId: task.workspaceId,
|
|
9254
|
+
sessionId,
|
|
9255
|
+
runId: input.run.id,
|
|
9256
|
+
text: goal.text,
|
|
9257
|
+
successCriteria: goal.successCriteria ?? null,
|
|
9258
|
+
maxAutoContinuations: goal.maxAutoContinuations ?? null,
|
|
9259
|
+
...goal.mutationPolicy ? { mutationPolicy: goal.mutationPolicy } : {}
|
|
9260
|
+
}) : [];
|
|
9261
|
+
const incidentSource = input.acceptedExecution.incidentPreflightRequired ? await prepareIncidentTelemetrySource({
|
|
9262
|
+
tx,
|
|
9263
|
+
settings: input.settings,
|
|
9264
|
+
taskId: task.id,
|
|
9265
|
+
workspaceId: task.workspaceId,
|
|
9266
|
+
sessionId,
|
|
9267
|
+
alertOccurrenceLabels: input.acceptedExecution.alertOccurrenceLabels,
|
|
9268
|
+
acceptedExecution: input.acceptedExecution
|
|
9269
|
+
}) : void 0;
|
|
9270
|
+
return {
|
|
9271
|
+
...incidentSource ?? {},
|
|
9272
|
+
...goalEvents.length > 0 ? { events: goalEvents } : {}
|
|
9273
|
+
};
|
|
9274
|
+
}
|
|
9275
|
+
}
|
|
9141
9276
|
);
|
|
9142
|
-
if (scheduledUpdate.reason === "session_cancelled") {
|
|
9277
|
+
if (scheduledUpdate.reason === "session_cancelled" || scheduledUpdate.reason === "session_not_idle") {
|
|
9143
9278
|
return { action: "blocked", reason: "scheduled_run_terminal" };
|
|
9144
9279
|
}
|
|
9145
9280
|
if (scheduledUpdate.added && scheduledUpdate.events.length > 0) {
|
|
@@ -9252,7 +9387,7 @@ function knowledgeSourceSyncEffectivelyPaused(task) {
|
|
|
9252
9387
|
}
|
|
9253
9388
|
|
|
9254
9389
|
// src/activities/site-auth-maintenance.ts
|
|
9255
|
-
import { resolveTurnExecutionPolicyV1 as
|
|
9390
|
+
import { resolveTurnExecutionPolicyV1 as resolveTurnExecutionPolicyV13 } from "@opengeni/config";
|
|
9256
9391
|
import {
|
|
9257
9392
|
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS as DEFAULT_FIRST_PARTY_MCP_PERMISSIONS2,
|
|
9258
9393
|
SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY,
|
|
@@ -9262,7 +9397,8 @@ import {
|
|
|
9262
9397
|
assertWorkspaceModelPolicyAllows as assertWorkspaceModelPolicyAllows2,
|
|
9263
9398
|
canonicalConfiguredModel as canonicalConfiguredModel2,
|
|
9264
9399
|
createAndStartSessionWithOutcome as createAndStartSessionWithOutcome2,
|
|
9265
|
-
recordWorkspaceUsage as recordWorkspaceUsage2
|
|
9400
|
+
recordWorkspaceUsage as recordWorkspaceUsage2,
|
|
9401
|
+
resolveCatalogSettings as resolveCatalogSettings2
|
|
9266
9402
|
} from "@opengeni/core";
|
|
9267
9403
|
import {
|
|
9268
9404
|
claimSiteAuthMaintenance,
|
|
@@ -9338,23 +9474,20 @@ function createSiteAuthMaintenanceActivities(services, options = {}) {
|
|
|
9338
9474
|
return { maintainSiteAuthConnections };
|
|
9339
9475
|
}
|
|
9340
9476
|
async function dispatchMaintenanceSession(service, maintenance, dependencies) {
|
|
9341
|
-
const
|
|
9477
|
+
const catalogSettings = (await resolveCatalogSettings2(service.db, service.catalogSourceSettings ?? service.settings)).settings;
|
|
9478
|
+
const catalogService = { ...service, settings: catalogSettings };
|
|
9479
|
+
const model = canonicalConfiguredModel2(catalogSettings, catalogSettings.openaiModel);
|
|
9342
9480
|
if (!model) throw new Error("site auth maintenance has no configured model");
|
|
9343
|
-
await dependencies.assertModelPolicy(
|
|
9344
|
-
|
|
9345
|
-
service.settings,
|
|
9346
|
-
maintenance.workspaceId,
|
|
9347
|
-
model
|
|
9348
|
-
);
|
|
9349
|
-
const denial = await dependencies.admit(service, {
|
|
9481
|
+
await dependencies.assertModelPolicy(service.db, catalogSettings, maintenance.workspaceId, model);
|
|
9482
|
+
const denial = await dependencies.admit(catalogService, {
|
|
9350
9483
|
accountId: maintenance.accountId,
|
|
9351
9484
|
workspaceId: maintenance.workspaceId,
|
|
9352
9485
|
model,
|
|
9353
9486
|
requestedAgentRuns: 1
|
|
9354
9487
|
});
|
|
9355
9488
|
if (denial) throw new Error(`site auth maintenance admission denied: ${denial}`);
|
|
9356
|
-
const reasoningEffort =
|
|
9357
|
-
const turnExecutionPolicy =
|
|
9489
|
+
const reasoningEffort = catalogSettings.openaiReasoningEffort;
|
|
9490
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV13(catalogSettings, {
|
|
9358
9491
|
modelId: model,
|
|
9359
9492
|
requestedModelId: null,
|
|
9360
9493
|
modelSource: "deployment",
|
|
@@ -9391,7 +9524,7 @@ async function dispatchMaintenanceSession(service, maintenance, dependencies) {
|
|
|
9391
9524
|
model,
|
|
9392
9525
|
reasoningEffort,
|
|
9393
9526
|
turnExecutionPolicy,
|
|
9394
|
-
sandboxBackend:
|
|
9527
|
+
sandboxBackend: catalogSettings.sandboxBackend,
|
|
9395
9528
|
metadata: {
|
|
9396
9529
|
role: "site_auth_maintenance",
|
|
9397
9530
|
[SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY]: maintenance.siteAuthConnectionId,
|
|
@@ -9415,7 +9548,7 @@ async function dispatchMaintenanceSession(service, maintenance, dependencies) {
|
|
|
9415
9548
|
});
|
|
9416
9549
|
try {
|
|
9417
9550
|
await dependencies.recordUsage(
|
|
9418
|
-
{ db: service.db, settings:
|
|
9551
|
+
{ db: service.db, settings: catalogSettings },
|
|
9419
9552
|
{
|
|
9420
9553
|
accountId: maintenance.accountId,
|
|
9421
9554
|
workspaceId: maintenance.workspaceId,
|
|
@@ -9475,6 +9608,7 @@ import {
|
|
|
9475
9608
|
recoverSessionDispatch,
|
|
9476
9609
|
reconcileSessionAttemptQuiescence,
|
|
9477
9610
|
peekSessionWork as peekSessionWorkDb,
|
|
9611
|
+
settleSessionInputWait as settleSessionInputWaitDb,
|
|
9478
9612
|
countQueuedTurns as countQueuedTurns2,
|
|
9479
9613
|
getSessionAttemptActivityRef,
|
|
9480
9614
|
getSessionEvent,
|
|
@@ -9496,6 +9630,7 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9496
9630
|
const recoverSessionDispatchFn = overrides.recoverSessionDispatch ?? recoverSessionDispatch;
|
|
9497
9631
|
const reconcileSessionAttemptQuiescenceFn = overrides.reconcileSessionAttemptQuiescence ?? reconcileSessionAttemptQuiescence;
|
|
9498
9632
|
const peekSessionWorkFn = overrides.peekSessionWork ?? peekSessionWorkDb;
|
|
9633
|
+
const settleSessionInputWaitFn = overrides.settleSessionInputWait ?? settleSessionInputWaitDb;
|
|
9499
9634
|
const countQueuedTurnsFn = overrides.countQueuedTurns ?? countQueuedTurns2;
|
|
9500
9635
|
const getSessionAttemptActivityRefFn = overrides.getSessionAttemptActivityRef ?? getSessionAttemptActivityRef;
|
|
9501
9636
|
const getSessionEventFn = overrides.getSessionEvent ?? getSessionEvent;
|
|
@@ -9798,6 +9933,14 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9798
9933
|
await refreshQueuedTurnsGauge(db, observability, countQueuedTurnsFn, recordTurnsQueuedGaugeFn);
|
|
9799
9934
|
return peek;
|
|
9800
9935
|
}
|
|
9936
|
+
async function settleSessionInputWait(input) {
|
|
9937
|
+
const { db, bus } = await services();
|
|
9938
|
+
const result = await settleSessionInputWaitFn(db, input);
|
|
9939
|
+
if (result.events.length > 0) {
|
|
9940
|
+
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
|
|
9941
|
+
}
|
|
9942
|
+
return { action: result.action };
|
|
9943
|
+
}
|
|
9801
9944
|
async function expireSessionHumanInput(input) {
|
|
9802
9945
|
const { db, bus } = await services();
|
|
9803
9946
|
const result = await expireSessionHumanInputRequestFn(db, input);
|
|
@@ -9846,6 +9989,7 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9846
9989
|
recoverDispatch,
|
|
9847
9990
|
recoverEscapedMcpTimeout,
|
|
9848
9991
|
peekSessionWork,
|
|
9992
|
+
settleSessionInputWait,
|
|
9849
9993
|
expireSessionHumanInput,
|
|
9850
9994
|
expireSessionInteractionIntervention,
|
|
9851
9995
|
markSessionIdle
|
|
@@ -9937,4 +10081,4 @@ export {
|
|
|
9937
10081
|
createControlActivities,
|
|
9938
10082
|
createControlActivitiesFromServices
|
|
9939
10083
|
};
|
|
9940
|
-
//# sourceMappingURL=activities-control-
|
|
10084
|
+
//# sourceMappingURL=activities-control-CTEMLTHG.js.map
|