@opengeni/worker-bundle 2.2.0 → 2.2.1-canary.36919050519001
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 +1 -0
- package/dist/activities/agent-turn/claude-usage-observer.d.ts +13 -1
- package/dist/activities/agent-turn/compaction-prep.d.ts +20 -0
- package/dist/activities/agent-turn/final-reply.d.ts +18 -0
- package/dist/activities/agent-turn/governance-model.d.ts +6 -0
- package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +2 -0
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
- package/dist/activities/agent-turn/session-title.d.ts +3 -1
- package/dist/activities/agent-turn/stream-attempt.d.ts +1 -0
- package/dist/activities/agent-turn/turn-context.d.ts +1 -0
- package/dist/activities/automations.d.ts +3 -1
- package/dist/activities/browser-deadline-checkpoint.d.ts +29 -0
- package/dist/activities/goals.d.ts +8 -0
- package/dist/activities/run-credentials.d.ts +4 -2
- package/dist/activities/types.d.ts +1 -1
- package/dist/{activities-control-MHNA3CYV.js → activities-control-55ECL47G.js} +403 -116
- package/dist/activities-control-55ECL47G.js.map +1 -0
- package/dist/activities-control.d.ts +30 -0
- package/dist/{activities-turn-FQ5OO2WW.js → activities-turn-T7Y3BWYO.js} +678 -246
- package/dist/activities-turn-T7Y3BWYO.js.map +1 -0
- package/dist/activities.d.ts +30 -0
- package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
- package/dist/{chunk-RZAAGRFQ.js → chunk-OWNLATJL.js} +189 -80
- package/dist/chunk-OWNLATJL.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +45 -23
- package/dist/index.js.map +1 -1
- package/dist/sandbox-resume.d.ts +4 -1
- package/dist/workflow-bundle.js +72 -10
- package/dist/workflows/browser-deadline-checkpoint.d.ts +9 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +21 -20
- package/src/activities/agent-run-admission.ts +17 -1
- package/src/activities/agent-turn/admission.ts +64 -1
- package/src/activities/agent-turn/agent-build.ts +24 -3
- package/src/activities/agent-turn/claim.ts +56 -14
- package/src/activities/agent-turn/claude-usage-observer.ts +33 -1
- package/src/activities/agent-turn/compaction-prep.ts +67 -16
- package/src/activities/agent-turn/errors.ts +55 -0
- package/src/activities/agent-turn/failure-settlement.ts +26 -6
- package/src/activities/agent-turn/final-reply.ts +46 -0
- package/src/activities/agent-turn/governance-model.ts +12 -0
- package/src/activities/agent-turn/model-call-admission.ts +94 -0
- package/src/activities/agent-turn/run-credentials.ts +15 -3
- package/src/activities/agent-turn/run.ts +43 -5
- package/src/activities/agent-turn/sandbox-establish.ts +9 -5
- package/src/activities/agent-turn/session-title.ts +8 -2
- package/src/activities/agent-turn/stream-attempt.ts +144 -38
- package/src/activities/agent-turn/tool-environment.ts +51 -39
- package/src/activities/agent-turn/turn-context.ts +1 -0
- package/src/activities/automations.ts +55 -3
- package/src/activities/browser-deadline-checkpoint.ts +279 -0
- package/src/activities/capabilities.ts +52 -14
- package/src/activities/goals.ts +67 -95
- package/src/activities/knowledge-indexing.ts +29 -0
- package/src/activities/open-suffix-resume.ts +2 -1
- package/src/activities/run-credentials.ts +22 -16
- package/src/activities/scheduled-tasks.ts +83 -13
- package/src/activities/types.ts +1 -0
- package/src/activities/workspace-credential-provider.ts +12 -0
- package/src/activities-control.ts +2 -0
- package/src/activities.ts +3 -0
- package/src/browser-deadline-checkpoint-contract.ts +5 -0
- package/src/index.ts +53 -25
- package/src/sandbox-resume.ts +23 -8
- package/src/sandbox-routing.ts +4 -2
- package/src/workflows/browser-deadline-checkpoint.ts +50 -0
- package/src/workflows.ts +4 -0
- package/dist/activities-control-MHNA3CYV.js.map +0 -1
- package/dist/activities-turn-FQ5OO2WW.js.map +0 -1
- package/dist/chunk-RZAAGRFQ.js.map +0 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY,
|
|
10
10
|
MAX_AUTOMATIC_PROVIDER_RECOVERIES,
|
|
11
|
+
agentRunAdmissionDenial,
|
|
11
12
|
assertReusableSessionRevivable,
|
|
12
13
|
captureConnectedCommandOutput,
|
|
13
14
|
createCodexCapacityActivities,
|
|
@@ -33,7 +34,7 @@ import {
|
|
|
33
34
|
warnDrainSnapshotFailure,
|
|
34
35
|
withFirstPartyTools,
|
|
35
36
|
workflowIdForSession
|
|
36
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-OWNLATJL.js";
|
|
37
38
|
import {
|
|
38
39
|
inspectOpenSandboxKubernetesInventory,
|
|
39
40
|
recordCreditBalanceGauges,
|
|
@@ -67,8 +68,10 @@ import {
|
|
|
67
68
|
applyCreditDebitAfterUse,
|
|
68
69
|
appendKnowledgeIndexChunks,
|
|
69
70
|
claimKnowledgeIndexJobs,
|
|
71
|
+
checkWorkspaceAllowance,
|
|
70
72
|
completeKnowledgeIndexJob,
|
|
71
73
|
continueKnowledgeIndexJob,
|
|
74
|
+
creditDebitAttributionMetadata,
|
|
72
75
|
deferKnowledgeIndexJob,
|
|
73
76
|
freezeKnowledgeIndexBillingMode,
|
|
74
77
|
getBillingBalance,
|
|
@@ -213,6 +216,14 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
213
216
|
return;
|
|
214
217
|
}
|
|
215
218
|
const paid = frozenPolicy.mode === "credits";
|
|
219
|
+
if (paid && claim.billingAttribution.kind === "unknown") {
|
|
220
|
+
observability.warn("Paid Knowledge indexing awaits initiating attribution", {
|
|
221
|
+
errorCode: "knowledge_index_attribution_unavailable"
|
|
222
|
+
});
|
|
223
|
+
await deferKnowledgeIndexJob(lockedDb, claim);
|
|
224
|
+
result.deferred++;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
216
227
|
if (paid && current.nextIndex === 0) {
|
|
217
228
|
const balance = await getBillingBalance(lockedDb, claim.accountId);
|
|
218
229
|
if (balance.balanceMicros <= 0) {
|
|
@@ -221,6 +232,18 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
221
232
|
return;
|
|
222
233
|
}
|
|
223
234
|
}
|
|
235
|
+
if (paid) {
|
|
236
|
+
const refusal = await checkWorkspaceAllowance(lockedDb, {
|
|
237
|
+
accountId: claim.accountId,
|
|
238
|
+
workspaceId: current.billingWorkspaceId,
|
|
239
|
+
subjectId: claim.billingAttribution.kind === "turn" || claim.billingAttribution.kind === "human" ? claim.billingAttribution.initiatingHumanSubjectId : null
|
|
240
|
+
});
|
|
241
|
+
if (refusal) {
|
|
242
|
+
await deferKnowledgeIndexJob(lockedDb, claim);
|
|
243
|
+
result.deferred++;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
224
247
|
if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
|
|
225
248
|
const limit = configuredStaticUsageLimits(settings).maxDocumentIndexedChunksPerWorkspace;
|
|
226
249
|
if (limit) {
|
|
@@ -319,6 +342,7 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
319
342
|
sourceId: claim.revisionId,
|
|
320
343
|
idempotencyKey: `knowledge.embedding:${claim.revisionId}:${claim.generation}:${current.nextIndex}`,
|
|
321
344
|
metadata: {
|
|
345
|
+
...creditDebitAttributionMetadata(claim.billingAttribution),
|
|
322
346
|
model: claim.model,
|
|
323
347
|
bytes,
|
|
324
348
|
chunks: chunks.length,
|
|
@@ -444,6 +468,240 @@ function cleanupErrorCategory(error) {
|
|
|
444
468
|
return typeof code === "string" && SAFE_PROVIDER_ERROR_CODES.has(code) ? code : "unknown";
|
|
445
469
|
}
|
|
446
470
|
|
|
471
|
+
// src/activities/browser-deadline-checkpoint.ts
|
|
472
|
+
import { Context } from "@temporalio/activity";
|
|
473
|
+
import {
|
|
474
|
+
environmentsEncryptionKeyBytes,
|
|
475
|
+
resolveFirstPartyDelegationSecret
|
|
476
|
+
} from "@opengeni/config";
|
|
477
|
+
import { BROWSER_STATE_ARTIFACT_CONTENT_TYPE } from "@opengeni/contracts";
|
|
478
|
+
import {
|
|
479
|
+
browserDeadlineCheckpoint,
|
|
480
|
+
clearSuspendedBrowserSessionController,
|
|
481
|
+
commitBrowserSessionSuspension,
|
|
482
|
+
dispatchBrowserSessionOperation,
|
|
483
|
+
failBrowserSessionSuspension,
|
|
484
|
+
listBrowserDeadlineCheckpoints,
|
|
485
|
+
readLease,
|
|
486
|
+
releaseLeaseHolder,
|
|
487
|
+
withRlsContext
|
|
488
|
+
} from "@opengeni/db";
|
|
489
|
+
import { deriveBrowserControllerAdminToken } from "@opengeni/interaction/browser-controller-authority";
|
|
490
|
+
import {
|
|
491
|
+
browserStateArtifactAad,
|
|
492
|
+
browserStateManifestDigest,
|
|
493
|
+
browserStateObjectKey,
|
|
494
|
+
deriveBrowserStateDataKey,
|
|
495
|
+
wrapBrowserStateDataKey
|
|
496
|
+
} from "@opengeni/interaction/browser-state-authority";
|
|
497
|
+
import {
|
|
498
|
+
BrowserControlClient,
|
|
499
|
+
BrowserControlRequestError,
|
|
500
|
+
createSandboxClientForBackend,
|
|
501
|
+
deserializeSandboxSessionStateEnvelope,
|
|
502
|
+
resumeExactSandboxSession
|
|
503
|
+
} from "@opengeni/runtime";
|
|
504
|
+
var UPLOAD_CLEANUP_GRACE_MS = 24 * 60 * 6e4;
|
|
505
|
+
function heartbeat() {
|
|
506
|
+
try {
|
|
507
|
+
Context.current().heartbeat();
|
|
508
|
+
} catch {
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
async function withActivityHeartbeat(run) {
|
|
512
|
+
heartbeat();
|
|
513
|
+
const timer = setInterval(heartbeat, 5e3);
|
|
514
|
+
try {
|
|
515
|
+
return await run();
|
|
516
|
+
} finally {
|
|
517
|
+
clearInterval(timer);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async function resumeCheckpointController({
|
|
521
|
+
target,
|
|
522
|
+
lease,
|
|
523
|
+
settings,
|
|
524
|
+
controllerRoot
|
|
525
|
+
}) {
|
|
526
|
+
const provider = createSandboxClientForBackend("modal", settings);
|
|
527
|
+
const envelope = lease.resumeState;
|
|
528
|
+
const state = await deserializeSandboxSessionStateEnvelope(
|
|
529
|
+
provider,
|
|
530
|
+
envelope.sessionState ?? lease.resumeState,
|
|
531
|
+
target.instanceId
|
|
532
|
+
);
|
|
533
|
+
const resumed = await resumeExactSandboxSession(provider, "modal", state, target.instanceId);
|
|
534
|
+
return new BrowserControlClient(resumed.session, {
|
|
535
|
+
adminToken: deriveBrowserControllerAdminToken({
|
|
536
|
+
rootSecret: controllerRoot,
|
|
537
|
+
accountId: target.accountId,
|
|
538
|
+
workspaceId: target.workspaceId,
|
|
539
|
+
placement: { kind: "sandbox_group", sandboxGroupId: target.sandboxGroupId },
|
|
540
|
+
placementInstanceId: target.instanceId
|
|
541
|
+
})
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
function createBrowserDeadlineCheckpointActivities(services, connectController = resumeCheckpointController) {
|
|
545
|
+
return {
|
|
546
|
+
async listDueBrowserCheckpoints() {
|
|
547
|
+
return await withActivityHeartbeat(async () => {
|
|
548
|
+
const { db, settings, objectStorage } = await services();
|
|
549
|
+
if (!settings.sandboxOwnershipEnabled || !objectStorage || !resolveFirstPartyDelegationSecret(settings))
|
|
550
|
+
return [];
|
|
551
|
+
const root = environmentsEncryptionKeyBytes(settings);
|
|
552
|
+
if (!root) return [];
|
|
553
|
+
root.fill(0);
|
|
554
|
+
return await listBrowserDeadlineCheckpoints(db);
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
async checkpointBrowserBeforeDeadline(target) {
|
|
558
|
+
return await withActivityHeartbeat(async () => {
|
|
559
|
+
const { db, settings, objectStorage } = await services();
|
|
560
|
+
const rootKey = environmentsEncryptionKeyBytes(settings);
|
|
561
|
+
const controllerRoot = resolveFirstPartyDelegationSecret(settings);
|
|
562
|
+
if (!rootKey || !objectStorage || !controllerRoot) {
|
|
563
|
+
rootKey?.fill(0);
|
|
564
|
+
throw new Error("browser deadline checkpoint storage or encryption is unavailable");
|
|
565
|
+
}
|
|
566
|
+
let dataKey = null;
|
|
567
|
+
let aad = null;
|
|
568
|
+
let timer = null;
|
|
569
|
+
try {
|
|
570
|
+
const claim = await browserDeadlineCheckpoint(db, target, { prepare: true, touch: true });
|
|
571
|
+
if (!claim) return { status: "skipped" };
|
|
572
|
+
let pulseRunning = false;
|
|
573
|
+
let authorityLost = false;
|
|
574
|
+
const pulse = async () => {
|
|
575
|
+
if (pulseRunning) return;
|
|
576
|
+
pulseRunning = true;
|
|
577
|
+
try {
|
|
578
|
+
if (!await browserDeadlineCheckpoint(db, target, { touch: true }))
|
|
579
|
+
authorityLost = true;
|
|
580
|
+
} finally {
|
|
581
|
+
pulseRunning = false;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
timer = setInterval(() => {
|
|
585
|
+
void pulse().catch(() => void 0);
|
|
586
|
+
}, 5e3);
|
|
587
|
+
const lease = await readLease(db, target.workspaceId, target.sandboxGroupId);
|
|
588
|
+
if (!lease || lease.instanceId !== target.instanceId || lease.leaseEpoch !== target.leaseEpoch || !lease.resumeState) {
|
|
589
|
+
throw new Error("browser deadline checkpoint placement changed");
|
|
590
|
+
}
|
|
591
|
+
const placement = {
|
|
592
|
+
kind: "sandbox_group",
|
|
593
|
+
sandboxGroupId: target.sandboxGroupId
|
|
594
|
+
};
|
|
595
|
+
const client = await connectController({ target, lease, settings, controllerRoot });
|
|
596
|
+
if (authorityLost || !await browserDeadlineCheckpoint(db, target, { touch: true })) {
|
|
597
|
+
throw new Error("browser deadline checkpoint authority changed");
|
|
598
|
+
}
|
|
599
|
+
if (claim.state !== "completed") {
|
|
600
|
+
const scope = { ...target, operationId: claim.operationId };
|
|
601
|
+
const objectKey = browserStateObjectKey(target.workspaceId, claim.operationId);
|
|
602
|
+
dataKey = deriveBrowserStateDataKey(rootKey, { ...scope, objectKey });
|
|
603
|
+
aad = browserStateArtifactAad({ ...scope, objectKey });
|
|
604
|
+
await dispatchBrowserSessionOperation(db, {
|
|
605
|
+
...scope,
|
|
606
|
+
deadlineTarget: target,
|
|
607
|
+
stateUpload: {
|
|
608
|
+
objectKey,
|
|
609
|
+
cleanupAfter: new Date(Date.now() + UPLOAD_CLEANUP_GRACE_MS)
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
const signed = await objectStorage.createPutUrl({
|
|
613
|
+
key: objectKey,
|
|
614
|
+
contentType: BROWSER_STATE_ARTIFACT_CONTENT_TYPE,
|
|
615
|
+
audience: "sandbox"
|
|
616
|
+
});
|
|
617
|
+
const receipt = await client.captureState({
|
|
618
|
+
...scope,
|
|
619
|
+
objectKey,
|
|
620
|
+
afterCapture: "stop",
|
|
621
|
+
dataKey,
|
|
622
|
+
aad,
|
|
623
|
+
upload: {
|
|
624
|
+
url: signed.url,
|
|
625
|
+
requiredHeaders: signed.requiredHeaders,
|
|
626
|
+
expiresAt: signed.expiresAt.toISOString()
|
|
627
|
+
}
|
|
628
|
+
}).catch(async (error) => {
|
|
629
|
+
if (error instanceof BrowserControlRequestError && (error.error.code === "outcome_unknown" || !error.error.retryable)) {
|
|
630
|
+
await failBrowserSessionSuspension(db, { ...scope, error: error.error });
|
|
631
|
+
}
|
|
632
|
+
throw error;
|
|
633
|
+
});
|
|
634
|
+
if (authorityLost) throw new Error("browser deadline checkpoint authority changed");
|
|
635
|
+
const portable = receipt.manifest.profileCrypto !== "platform_bound";
|
|
636
|
+
await commitBrowserSessionSuspension(db, {
|
|
637
|
+
...scope,
|
|
638
|
+
deadlineTarget: target,
|
|
639
|
+
artifact: {
|
|
640
|
+
kind: "chromium_profile",
|
|
641
|
+
format: receipt.format,
|
|
642
|
+
objectKey,
|
|
643
|
+
artifactDigest: receipt.artifactDigest,
|
|
644
|
+
contentDigest: receipt.contentDigest,
|
|
645
|
+
manifestDigest: browserStateManifestDigest(receipt.manifest),
|
|
646
|
+
sizeBytes: receipt.sizeBytes,
|
|
647
|
+
encryptedDataKey: wrapBrowserStateDataKey(rootKey, dataKey, {
|
|
648
|
+
...scope,
|
|
649
|
+
objectKey,
|
|
650
|
+
artifactDigest: receipt.artifactDigest,
|
|
651
|
+
contentDigest: receipt.contentDigest
|
|
652
|
+
}),
|
|
653
|
+
materialization: {
|
|
654
|
+
portability: portable ? "portable" : "placement_bound",
|
|
655
|
+
reason: portable ? null : "Profile encryption depends on the source operating-system credential store.",
|
|
656
|
+
platform: receipt.manifest.platform,
|
|
657
|
+
architecture: receipt.manifest.architecture,
|
|
658
|
+
engine: receipt.manifest.engine,
|
|
659
|
+
engineVersion: receipt.manifest.engineVersion,
|
|
660
|
+
driverId: receipt.manifest.driverId,
|
|
661
|
+
driverSchemaVersion: receipt.manifest.driverSchemaVersion,
|
|
662
|
+
profileCrypto: receipt.manifest.profileCrypto,
|
|
663
|
+
providerId: null,
|
|
664
|
+
placement: portable ? null : placement
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
await client.endSession(target, { removeState: true }).catch((error) => {
|
|
670
|
+
if (!(error instanceof BrowserControlRequestError && error.status === 404)) throw error;
|
|
671
|
+
});
|
|
672
|
+
await withRlsContext(
|
|
673
|
+
db,
|
|
674
|
+
target,
|
|
675
|
+
async (tx) => {
|
|
676
|
+
if ((await browserDeadlineCheckpoint(tx, target))?.state !== "completed") {
|
|
677
|
+
throw new Error("browser deadline checkpoint cleanup authority changed");
|
|
678
|
+
}
|
|
679
|
+
await clearSuspendedBrowserSessionController(tx, {
|
|
680
|
+
...target,
|
|
681
|
+
expectedControllerGeneration: target.controllerGeneration
|
|
682
|
+
});
|
|
683
|
+
await releaseLeaseHolder(tx, {
|
|
684
|
+
...target,
|
|
685
|
+
kind: "interaction",
|
|
686
|
+
holderId: `browser-session:${target.browserSessionId}`,
|
|
687
|
+
idleGraceMs: settings.sandboxIdleGraceMs
|
|
688
|
+
});
|
|
689
|
+
},
|
|
690
|
+
void 0,
|
|
691
|
+
"none"
|
|
692
|
+
);
|
|
693
|
+
return { status: "suspended" };
|
|
694
|
+
} finally {
|
|
695
|
+
if (timer) clearInterval(timer);
|
|
696
|
+
dataKey?.fill(0);
|
|
697
|
+
aad?.fill(0);
|
|
698
|
+
rootKey.fill(0);
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
447
705
|
// src/activities/automations.ts
|
|
448
706
|
import {
|
|
449
707
|
resolveTurnExecutionPolicyV1,
|
|
@@ -451,8 +709,11 @@ import {
|
|
|
451
709
|
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX
|
|
452
710
|
} from "@opengeni/config";
|
|
453
711
|
import {
|
|
712
|
+
agentConfigMayResolve,
|
|
713
|
+
applySessionAgentConfigWriteThrough,
|
|
454
714
|
assertWorkspaceModelPolicyAllows,
|
|
455
715
|
canonicalConfiguredModel,
|
|
716
|
+
resolveSessionAgentConfigForCreate,
|
|
456
717
|
createAndStartSessionWithOutcome,
|
|
457
718
|
recordWorkspaceUsage,
|
|
458
719
|
resolveCatalogSettings,
|
|
@@ -462,77 +723,16 @@ import {
|
|
|
462
723
|
AutomationAuthorityRevokedError,
|
|
463
724
|
assertAutomationRunAuthorityInTransaction,
|
|
464
725
|
claimAutomationRun,
|
|
465
|
-
settleAutomationRun
|
|
726
|
+
settleAutomationRun,
|
|
727
|
+
requireWorkspace
|
|
466
728
|
} from "@opengeni/db";
|
|
467
729
|
import { SessionSkills } from "@opengeni/contracts";
|
|
468
|
-
|
|
469
|
-
// src/activities/agent-run-admission.ts
|
|
470
|
-
import { configuredStaticUsageLimits as configuredStaticUsageLimits2 } from "@opengeni/config";
|
|
471
|
-
import { modelFundingForAdmission } from "@opengeni/core";
|
|
472
|
-
import { getBillingBalance as getBillingBalance2, isCodexBilledTurn, sumUsageQuantity as sumUsageQuantity2 } from "@opengeni/db";
|
|
473
|
-
async function agentRunAdmissionDenial(services, input) {
|
|
474
|
-
const codexBilled = await isCodexBilledTurn({
|
|
475
|
-
db: services.db,
|
|
476
|
-
settings: services.settings,
|
|
477
|
-
workspaceId: input.workspaceId,
|
|
478
|
-
model: input.model
|
|
479
|
-
});
|
|
480
|
-
const externallyBilled = modelFundingForAdmission(
|
|
481
|
-
services.settings,
|
|
482
|
-
input.model,
|
|
483
|
-
codexBilled
|
|
484
|
-
).fundedWithoutCredits;
|
|
485
|
-
if (!externallyBilled && (services.settings.billingMode === "stripe" || services.settings.usageLimitsMode === "managed")) {
|
|
486
|
-
if (services.entitlements) {
|
|
487
|
-
const decision = await services.entitlements.admitRun({
|
|
488
|
-
accountId: input.accountId,
|
|
489
|
-
workspaceId: input.workspaceId,
|
|
490
|
-
action: "agent_run:create",
|
|
491
|
-
quantity: input.requestedAgentRuns
|
|
492
|
-
});
|
|
493
|
-
if (!decision.allowed) return "insufficient_credits";
|
|
494
|
-
} else {
|
|
495
|
-
const balance = await getBillingBalance2(services.db, input.accountId);
|
|
496
|
-
if (balance.balanceMicros <= 0) return "insufficient_credits";
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
if (services.settings.usageLimitsMode !== "static" && services.settings.usageLimitsMode !== "managed") {
|
|
500
|
-
return null;
|
|
501
|
-
}
|
|
502
|
-
const limits = configuredStaticUsageLimits2(services.settings);
|
|
503
|
-
if (!externallyBilled && limits.maxMonthlyCostMicrosPerAccount) {
|
|
504
|
-
const used = await sumUsageQuantity2(services.db, {
|
|
505
|
-
accountId: input.accountId,
|
|
506
|
-
eventType: "model.cost",
|
|
507
|
-
since: startOfUtcMonth()
|
|
508
|
-
});
|
|
509
|
-
if (used >= limits.maxMonthlyCostMicrosPerAccount) {
|
|
510
|
-
return "monthly_model_cost_limit";
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
514
|
-
const used = await sumUsageQuantity2(services.db, {
|
|
515
|
-
workspaceId: input.workspaceId,
|
|
516
|
-
eventType: "agent_run.created",
|
|
517
|
-
since: startOfUtcMonth()
|
|
518
|
-
});
|
|
519
|
-
if (used + input.requestedAgentRuns > limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
520
|
-
return "monthly_agent_run_limit";
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
return null;
|
|
524
|
-
}
|
|
525
|
-
function startOfUtcMonth() {
|
|
526
|
-
const now = /* @__PURE__ */ new Date();
|
|
527
|
-
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// src/activities/automations.ts
|
|
531
730
|
function createAutomationActivities(services, options = {}) {
|
|
532
731
|
const claim = options.claim ?? claimAutomationRun;
|
|
533
732
|
const settle = options.settle ?? settleAutomationRun;
|
|
534
733
|
const assertAuthority = options.assertAuthority ?? assertAutomationRunAuthorityInTransaction;
|
|
535
734
|
const createSession2 = options.createSession ?? createAndStartSessionWithOutcome;
|
|
735
|
+
const readWorkspace = options.readWorkspace ?? requireWorkspace;
|
|
536
736
|
const admit = options.admit ?? agentRunAdmissionDenial;
|
|
537
737
|
const assertModelPolicy = options.assertModelPolicy ?? assertWorkspaceModelPolicyAllows;
|
|
538
738
|
const recordUsage = options.recordUsage ?? recordWorkspaceUsage;
|
|
@@ -629,6 +829,41 @@ function createAutomationActivities(services, options = {}) {
|
|
|
629
829
|
reason: "interactive_compute_not_allowed"
|
|
630
830
|
};
|
|
631
831
|
}
|
|
832
|
+
let agentWriteThrough;
|
|
833
|
+
try {
|
|
834
|
+
const workspaceSettings = agentConfigMayResolve(catalogSettings, template.agent) ? (await readWorkspace(service.db, input.workspaceId)).settings : {};
|
|
835
|
+
const resolution = resolveSessionAgentConfigForCreate({
|
|
836
|
+
settings: catalogSettings,
|
|
837
|
+
creator: "automation",
|
|
838
|
+
request: template.agent,
|
|
839
|
+
instructions: template.instructions ?? void 0,
|
|
840
|
+
workspaceSettings,
|
|
841
|
+
parent: null,
|
|
842
|
+
goal: false
|
|
843
|
+
});
|
|
844
|
+
const written = applySessionAgentConfigWriteThrough({
|
|
845
|
+
config: resolution.config,
|
|
846
|
+
firstPartyMcpTools: template.firstPartyMcpTools,
|
|
847
|
+
tools: template.tools,
|
|
848
|
+
toolPolicy: { mode: "explicit", inheritedFromSessionId: null },
|
|
849
|
+
productServerIds: template.tools.map((tool) => tool.id)
|
|
850
|
+
});
|
|
851
|
+
agentWriteThrough = {
|
|
852
|
+
config: resolution.config,
|
|
853
|
+
instructions: resolution.instructions,
|
|
854
|
+
firstPartyMcpTools: written.firstPartyMcpTools,
|
|
855
|
+
tools: written.tools
|
|
856
|
+
};
|
|
857
|
+
} catch (error) {
|
|
858
|
+
if (!isUnprocessableEntity(error)) throw error;
|
|
859
|
+
await settle(service.db, {
|
|
860
|
+
workspaceId: input.workspaceId,
|
|
861
|
+
runId: run.id,
|
|
862
|
+
status: "failed",
|
|
863
|
+
errorCode: "dispatch_failed"
|
|
864
|
+
});
|
|
865
|
+
return { action: "failed", reason: "dispatch_failed" };
|
|
866
|
+
}
|
|
632
867
|
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(catalogSettings, {
|
|
633
868
|
modelId: model,
|
|
634
869
|
requestedModelId: template.model,
|
|
@@ -664,7 +899,7 @@ function createAutomationActivities(services, options = {}) {
|
|
|
664
899
|
resources: template.resources,
|
|
665
900
|
skills: SessionSkills.parse(template.skills),
|
|
666
901
|
bundledSkillIds: template.bundledSkillIds,
|
|
667
|
-
tools:
|
|
902
|
+
tools: agentWriteThrough.tools,
|
|
668
903
|
toolPolicy: { mode: "explicit", inheritedFromSessionId: null },
|
|
669
904
|
model,
|
|
670
905
|
reasoningEffort,
|
|
@@ -683,10 +918,11 @@ function createAutomationActivities(services, options = {}) {
|
|
|
683
918
|
label: accepted.serviceLabel
|
|
684
919
|
},
|
|
685
920
|
createdByContext: accepted.provenance,
|
|
686
|
-
instructions: template.instructions,
|
|
921
|
+
instructions: agentWriteThrough.instructions ?? template.instructions,
|
|
687
922
|
policyRole: template.policyRole,
|
|
688
923
|
firstPartyMcpPermissions: template.firstPartyMcpPermissions,
|
|
689
|
-
firstPartyMcpTools:
|
|
924
|
+
firstPartyMcpTools: agentWriteThrough.firstPartyMcpTools,
|
|
925
|
+
...agentWriteThrough.config ? { agentConfig: agentWriteThrough.config } : {},
|
|
690
926
|
retainWorkspaceCustomModel: model.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || model.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX),
|
|
691
927
|
createIdempotencyKey: `automation-run:${run.id}`,
|
|
692
928
|
subjectId: accepted.serviceSubjectId
|
|
@@ -1069,7 +1305,7 @@ import {
|
|
|
1069
1305
|
markSandboxCheckpointArtifactDeletePending,
|
|
1070
1306
|
recordWarmingSandboxCreated,
|
|
1071
1307
|
registerSandboxCheckpointArtifact,
|
|
1072
|
-
releaseLeaseHolder,
|
|
1308
|
+
releaseLeaseHolder as releaseLeaseHolder2,
|
|
1073
1309
|
touchLeaseHolder,
|
|
1074
1310
|
updateRigChangeStatus,
|
|
1075
1311
|
SandboxCheckpointArtifactRegistrationConflictError
|
|
@@ -1217,7 +1453,7 @@ function createRigVerificationActivityLifecycle(context = currentActivityContext
|
|
|
1217
1453
|
Math.max(1, startToCloseTimeoutMs - reserveMs)
|
|
1218
1454
|
);
|
|
1219
1455
|
}
|
|
1220
|
-
const
|
|
1456
|
+
const heartbeat2 = () => {
|
|
1221
1457
|
if (!context) return;
|
|
1222
1458
|
try {
|
|
1223
1459
|
context.heartbeat({
|
|
@@ -1230,13 +1466,13 @@ function createRigVerificationActivityLifecycle(context = currentActivityContext
|
|
|
1230
1466
|
if (!controller.signal.aborted) controller.abort(error);
|
|
1231
1467
|
}
|
|
1232
1468
|
};
|
|
1233
|
-
|
|
1469
|
+
heartbeat2();
|
|
1234
1470
|
const heartbeatTimeoutMs = context?.info.heartbeatTimeoutMs;
|
|
1235
1471
|
const heartbeatIntervalMs = typeof heartbeatTimeoutMs === "number" && heartbeatTimeoutMs > 0 ? Math.min(
|
|
1236
1472
|
RIG_VERIFICATION_HEARTBEAT_MAX_INTERVAL_MS,
|
|
1237
1473
|
Math.max(RIG_VERIFICATION_HEARTBEAT_MIN_INTERVAL_MS, Math.floor(heartbeatTimeoutMs / 3))
|
|
1238
1474
|
) : RIG_VERIFICATION_HEARTBEAT_MAX_INTERVAL_MS;
|
|
1239
|
-
const heartbeatTimer = context ? setInterval(
|
|
1475
|
+
const heartbeatTimer = context ? setInterval(heartbeat2, heartbeatIntervalMs) : null;
|
|
1240
1476
|
if (heartbeatTimer && "unref" in heartbeatTimer && typeof heartbeatTimer.unref === "function") {
|
|
1241
1477
|
heartbeatTimer.unref();
|
|
1242
1478
|
}
|
|
@@ -1321,7 +1557,7 @@ var defaultOwnershipDependencies = {
|
|
|
1321
1557
|
recordCreated: recordWarmingSandboxCreated,
|
|
1322
1558
|
commitWarm: commitWarmingToWarm,
|
|
1323
1559
|
touchHolder: touchLeaseHolder,
|
|
1324
|
-
releaseHolder:
|
|
1560
|
+
releaseHolder: releaseLeaseHolder2,
|
|
1325
1561
|
failWarming: failWarmingToCold,
|
|
1326
1562
|
markWarmLost: markWarmLeaseInstanceLost,
|
|
1327
1563
|
serialize: serializeEstablishedSandboxEnvelope,
|
|
@@ -2418,7 +2654,7 @@ function retainedProcessDeadlineRetryMs(process, lease, settings, retryAfterMs,
|
|
|
2418
2654
|
// src/activities/sandbox-lease.ts
|
|
2419
2655
|
import { createHash, randomUUID as randomUUID2 } from "crypto";
|
|
2420
2656
|
import { requestRetainedProcessDeadlineCancellation } from "@opengeni/db/retained-provider-commands";
|
|
2421
|
-
import { Context } from "@temporalio/activity";
|
|
2657
|
+
import { Context as Context2 } from "@temporalio/activity";
|
|
2422
2658
|
import { OpLostReason, OpState } from "@opengeni/agent-proto";
|
|
2423
2659
|
import {
|
|
2424
2660
|
accrueWarmSeconds,
|
|
@@ -2454,7 +2690,7 @@ import {
|
|
|
2454
2690
|
registerSandboxCheckpointArtifact as registerSandboxCheckpointArtifact2,
|
|
2455
2691
|
recordRetainedProcessReconciliationProof,
|
|
2456
2692
|
replaceWorkspaceArchiveCaptureAfterProof,
|
|
2457
|
-
readLease,
|
|
2693
|
+
readLease as readLease2,
|
|
2458
2694
|
readWorkspaceArchiveCapturePreflight,
|
|
2459
2695
|
reapExpiredSessionListSnapshots,
|
|
2460
2696
|
reapStaleLeaseHoldersGlobal,
|
|
@@ -2482,9 +2718,9 @@ import {
|
|
|
2482
2718
|
disposeWorkspaceArchive,
|
|
2483
2719
|
cancelSelfhostedOp,
|
|
2484
2720
|
assertConsistentSandboxProviderIdentity,
|
|
2485
|
-
createSandboxClientForBackend,
|
|
2721
|
+
createSandboxClientForBackend as createSandboxClientForBackend2,
|
|
2486
2722
|
deleteModalCheckpointSnapshot as deleteModalCheckpointSnapshot2,
|
|
2487
|
-
deserializeSandboxSessionStateEnvelope,
|
|
2723
|
+
deserializeSandboxSessionStateEnvelope as deserializeSandboxSessionStateEnvelope2,
|
|
2488
2724
|
establishSandboxSessionFromEnvelope as establishSandboxSessionFromEnvelope2,
|
|
2489
2725
|
inspectModalSandboxLifecycle,
|
|
2490
2726
|
isExecSessionLostBanner,
|
|
@@ -2503,7 +2739,7 @@ import {
|
|
|
2503
2739
|
findModalProviderCreateReceipt,
|
|
2504
2740
|
resolveModalCheckpointProviderBindingForSession,
|
|
2505
2741
|
querySelfhostedOp,
|
|
2506
|
-
resumeExactSandboxSession,
|
|
2742
|
+
resumeExactSandboxSession as resumeExactSandboxSession2,
|
|
2507
2743
|
sandboxProviderContinuityForState,
|
|
2508
2744
|
sandboxBackendForSdkBackendId,
|
|
2509
2745
|
sandboxProviderInstanceIdFromEnvelope,
|
|
@@ -2562,18 +2798,18 @@ async function awaitProviderCaptureWithLatePublication(input) {
|
|
|
2562
2798
|
function startSandboxReaperHeartbeat(details) {
|
|
2563
2799
|
let context;
|
|
2564
2800
|
try {
|
|
2565
|
-
context =
|
|
2801
|
+
context = Context2.current();
|
|
2566
2802
|
} catch {
|
|
2567
2803
|
return () => void 0;
|
|
2568
2804
|
}
|
|
2569
|
-
const
|
|
2805
|
+
const heartbeat2 = () => {
|
|
2570
2806
|
try {
|
|
2571
2807
|
context.heartbeat({ ...details, heartbeatAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
2572
2808
|
} catch {
|
|
2573
2809
|
}
|
|
2574
2810
|
};
|
|
2575
|
-
|
|
2576
|
-
const timer = setInterval(
|
|
2811
|
+
heartbeat2();
|
|
2812
|
+
const timer = setInterval(heartbeat2, SANDBOX_REAPER_ACTIVITY_HEARTBEAT_INTERVAL_MS);
|
|
2577
2813
|
if ("unref" in timer && typeof timer.unref === "function") timer.unref();
|
|
2578
2814
|
return () => clearInterval(timer);
|
|
2579
2815
|
}
|
|
@@ -2596,7 +2832,7 @@ function sandboxDrainCaptureId(operationId, attempt) {
|
|
|
2596
2832
|
}
|
|
2597
2833
|
function sandboxDrainActivityAttempt() {
|
|
2598
2834
|
try {
|
|
2599
|
-
const attempt =
|
|
2835
|
+
const attempt = Context2.current().info.attempt;
|
|
2600
2836
|
return Number.isSafeInteger(attempt) && attempt > 0 ? attempt : 1;
|
|
2601
2837
|
} catch {
|
|
2602
2838
|
return 1;
|
|
@@ -2611,7 +2847,7 @@ function createSandboxLeaseActivities(services, options = {}) {
|
|
|
2611
2847
|
lease,
|
|
2612
2848
|
observability,
|
|
2613
2849
|
persistArchive,
|
|
2614
|
-
|
|
2850
|
+
createSandboxClientForBackend2,
|
|
2615
2851
|
terminateModalSandboxById,
|
|
2616
2852
|
providerCaptureRequestId,
|
|
2617
2853
|
captureDisposition,
|
|
@@ -2729,7 +2965,7 @@ function createSandboxLeaseActivities(services, options = {}) {
|
|
|
2729
2965
|
);
|
|
2730
2966
|
return { status: drainedCold ? "terminated" : "skipped" };
|
|
2731
2967
|
} catch (error) {
|
|
2732
|
-
const lease = await
|
|
2968
|
+
const lease = await readLease2(db, row.workspaceId, row.sandboxGroupId).catch(() => null);
|
|
2733
2969
|
const details = {
|
|
2734
2970
|
sandboxLeaseKey: sandboxLeaseTelemetryKey(row.workspaceId, row.sandboxGroupId),
|
|
2735
2971
|
workspaceId: row.workspaceId,
|
|
@@ -3441,7 +3677,7 @@ async function reconcileTerminalRetainedProcesses(db, settings, observability, p
|
|
|
3441
3677
|
}
|
|
3442
3678
|
}
|
|
3443
3679
|
if (observation === null) {
|
|
3444
|
-
const lease = await
|
|
3680
|
+
const lease = await readLease2(db, process.workspaceId, process.sandboxGroupId).catch(
|
|
3445
3681
|
() => null
|
|
3446
3682
|
);
|
|
3447
3683
|
const currentLeaseIdentityMatches = Boolean(lease) && lease.id === process.leaseId && lease.leaseEpoch === process.leaseEpoch && lease.backend === process.providerBackend && lease.instanceId === process.providerInstanceId && process.routeTargetId === null;
|
|
@@ -3650,7 +3886,7 @@ async function reconcileTerminalRetainedProcesses(db, settings, observability, p
|
|
|
3650
3886
|
async function deferRetainedProcessClaim(db, settings, observability, process, expected, claimId, outcome, outputBacklog = false) {
|
|
3651
3887
|
const deferral = retainedProcessReconciliationDeferral(settings, process, outcome, outputBacklog);
|
|
3652
3888
|
try {
|
|
3653
|
-
const lease = process.providerBackend === "modal" && process.routeTargetId === null ? await
|
|
3889
|
+
const lease = process.providerBackend === "modal" && process.routeTargetId === null ? await readLease2(db, process.workspaceId, process.sandboxGroupId) : null;
|
|
3654
3890
|
await deferRetainedProcessReconciliation(db, {
|
|
3655
3891
|
accountId: process.accountId,
|
|
3656
3892
|
workspaceId: process.workspaceId,
|
|
@@ -3799,7 +4035,7 @@ async function probeRetainedProcessAtProvider(settings, lease, process, mode = "
|
|
|
3799
4035
|
}
|
|
3800
4036
|
let client;
|
|
3801
4037
|
try {
|
|
3802
|
-
client =
|
|
4038
|
+
client = createSandboxClientForBackend2(process.providerBackend, settings);
|
|
3803
4039
|
} catch {
|
|
3804
4040
|
return { status: "deferred", reason: "provider_error" };
|
|
3805
4041
|
}
|
|
@@ -3809,7 +4045,7 @@ async function probeRetainedProcessAtProvider(settings, lease, process, mode = "
|
|
|
3809
4045
|
const envelopeSessionState = lease.resumeState.sessionState ?? lease.resumeState;
|
|
3810
4046
|
let resumedState;
|
|
3811
4047
|
try {
|
|
3812
|
-
resumedState = await
|
|
4048
|
+
resumedState = await deserializeSandboxSessionStateEnvelope2(
|
|
3813
4049
|
client,
|
|
3814
4050
|
envelopeSessionState,
|
|
3815
4051
|
process.providerInstanceId
|
|
@@ -3823,7 +4059,7 @@ async function probeRetainedProcessAtProvider(settings, lease, process, mode = "
|
|
|
3823
4059
|
let session;
|
|
3824
4060
|
try {
|
|
3825
4061
|
const resumed = await withRetainedProcessProbeTimeout(
|
|
3826
|
-
|
|
4062
|
+
resumeExactSandboxSession2(
|
|
3827
4063
|
client,
|
|
3828
4064
|
process.providerBackend,
|
|
3829
4065
|
resumedState,
|
|
@@ -4335,7 +4571,7 @@ function sandboxDrainReason(lease) {
|
|
|
4335
4571
|
}
|
|
4336
4572
|
async function terminateDrainableBox(db, settings, row, observability, terminateBox, probeDrainableProvider, attempt, objectStorage) {
|
|
4337
4573
|
const { accountId } = await rlsContextForWorkspace(db, row.workspaceId);
|
|
4338
|
-
const lease = await
|
|
4574
|
+
const lease = await readLease2(db, row.workspaceId, row.sandboxGroupId);
|
|
4339
4575
|
if (!lease) {
|
|
4340
4576
|
return false;
|
|
4341
4577
|
}
|
|
@@ -4699,7 +4935,7 @@ function providerDrainLogIdentity(lease, backend) {
|
|
|
4699
4935
|
instanceId: lease.instanceId
|
|
4700
4936
|
};
|
|
4701
4937
|
}
|
|
4702
|
-
async function terminateProviderBox(settings, lease, observability, persistArchive, createClientForBackend =
|
|
4938
|
+
async function terminateProviderBox(settings, lease, observability, persistArchive, createClientForBackend = createSandboxClientForBackend2, terminateModalById = terminateModalSandboxById, providerCaptureRequestId, captureDisposition = "capture_required", claimedCapturePolicy, diskBackedArchives = false, releaseFailedCapture, workspaceId, beforeProviderStop) {
|
|
4703
4939
|
const durableBackendId = lease.resumeBackendId ?? lease.backend;
|
|
4704
4940
|
const backend = sandboxBackendForSdkBackendId(durableBackendId) ?? durableBackendId;
|
|
4705
4941
|
const logIdentity = providerDrainLogIdentity(lease, backend);
|
|
@@ -4801,7 +5037,7 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
4801
5037
|
throw new Error(`sandbox backend ${backend} cannot resume a drainable provider box`);
|
|
4802
5038
|
}
|
|
4803
5039
|
const envelopeSessionState = lease.resumeState.sessionState ?? lease.resumeState;
|
|
4804
|
-
const resumedState = await
|
|
5040
|
+
const resumedState = await deserializeSandboxSessionStateEnvelope2(
|
|
4805
5041
|
client,
|
|
4806
5042
|
envelopeSessionState,
|
|
4807
5043
|
lease.instanceId
|
|
@@ -4810,7 +5046,7 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
4810
5046
|
throw new Error(`sandbox backend ${backend} returned no resumable provider state`);
|
|
4811
5047
|
}
|
|
4812
5048
|
const continuity = sandboxProviderContinuityForState(backend, resumedState, lease.instanceId);
|
|
4813
|
-
const resumed = await
|
|
5049
|
+
const resumed = await resumeExactSandboxSession2(
|
|
4814
5050
|
client,
|
|
4815
5051
|
backend,
|
|
4816
5052
|
resumedState,
|
|
@@ -4972,7 +5208,8 @@ import {
|
|
|
4972
5208
|
normalizeAutomaticSessionTitle,
|
|
4973
5209
|
scheduledOccurrencePayloadUtf8Bytes,
|
|
4974
5210
|
stableJson,
|
|
4975
|
-
TurnExecutionPolicyV1
|
|
5211
|
+
TurnExecutionPolicyV1,
|
|
5212
|
+
AgentConfigError
|
|
4976
5213
|
} from "@opengeni/contracts";
|
|
4977
5214
|
import {
|
|
4978
5215
|
openGeniSlackBotMetadata,
|
|
@@ -4990,7 +5227,10 @@ import {
|
|
|
4990
5227
|
scheduledConnectionTools,
|
|
4991
5228
|
settingsWithEnabledCapabilityMcpServers,
|
|
4992
5229
|
settingsWithSessionMcpServerMetadata,
|
|
4993
|
-
swapActiveSandbox
|
|
5230
|
+
swapActiveSandbox,
|
|
5231
|
+
agentConfigMayResolve as agentConfigMayResolve2,
|
|
5232
|
+
applySessionAgentConfigWriteThrough as applySessionAgentConfigWriteThrough2,
|
|
5233
|
+
resolveSessionAgentConfigForCreate as resolveSessionAgentConfigForCreate2
|
|
4994
5234
|
} from "@opengeni/core";
|
|
4995
5235
|
import {
|
|
4996
5236
|
addSessionSystemUpdateWithSourceMutation,
|
|
@@ -5017,6 +5257,7 @@ import {
|
|
|
5017
5257
|
getNestedAgentDepthDeploymentPolicy,
|
|
5018
5258
|
getSessionByCreateIdempotencyKey,
|
|
5019
5259
|
getSessionCreationExecutionPolicy,
|
|
5260
|
+
metadataWithAgentConfigCreateIdentity,
|
|
5020
5261
|
getVariableSet,
|
|
5021
5262
|
isCodexBilledModel,
|
|
5022
5263
|
initializeSessionStartAtomically,
|
|
@@ -5027,7 +5268,7 @@ import {
|
|
|
5027
5268
|
recordUsageEvent as recordUsageEvent2,
|
|
5028
5269
|
requireScheduledTaskIncidentAuthorityInTransaction,
|
|
5029
5270
|
requireSession,
|
|
5030
|
-
requireWorkspace,
|
|
5271
|
+
requireWorkspace as requireWorkspace2,
|
|
5031
5272
|
settleScheduledTaskRunInTransaction,
|
|
5032
5273
|
SessionSpawnDeniedDbError,
|
|
5033
5274
|
updateSessionTitleWithEvent,
|
|
@@ -5040,7 +5281,7 @@ import {
|
|
|
5040
5281
|
resolveFirstPartyMcpToolPolicy,
|
|
5041
5282
|
resolveTurnExecutionPolicyV1 as resolveTurnExecutionPolicyV12
|
|
5042
5283
|
} from "@opengeni/config";
|
|
5043
|
-
import { Context as
|
|
5284
|
+
import { Context as Context3 } from "@temporalio/activity";
|
|
5044
5285
|
import { createHash as createHash3 } from "crypto";
|
|
5045
5286
|
|
|
5046
5287
|
// src/scheduled-alert-occurrence.ts
|
|
@@ -5162,7 +5403,7 @@ function scheduledTaskRunProducerKey(input, suppliedActivityIdentity) {
|
|
|
5162
5403
|
let info = suppliedActivityIdentity;
|
|
5163
5404
|
if (!info) {
|
|
5164
5405
|
try {
|
|
5165
|
-
info =
|
|
5406
|
+
info = Context3.current().info;
|
|
5166
5407
|
} catch {
|
|
5167
5408
|
throw new Error(
|
|
5168
5409
|
"scheduled task delivery without a producer key requires a Temporal activity execution"
|
|
@@ -5377,13 +5618,46 @@ function createScheduledTaskActivities(services) {
|
|
|
5377
5618
|
const reasoningEffort = task.agentConfig.reasoningEffort ?? resolvedDefault?.reasoningEffort ?? settings.openaiReasoningEffort;
|
|
5378
5619
|
let sandboxBackend = task.agentConfig.sandboxBackend ?? settings.sandboxBackend;
|
|
5379
5620
|
let sandboxOs = "linux";
|
|
5380
|
-
|
|
5621
|
+
let taskTools = withFirstPartyTools(settings, task.agentConfig.tools);
|
|
5381
5622
|
const creatorPolicy = await getScheduledTaskCreatorPolicy(db, task.workspaceId, task.id);
|
|
5382
|
-
|
|
5623
|
+
let firstPartyMcpTools = withScheduledSlackBotPostingTools(
|
|
5383
5624
|
creatorPolicy?.firstPartyMcpTools ? allowedFirstPartyMcpToolsForSession(settings, creatorPolicy.firstPartyMcpTools) : resolveFirstPartyMcpToolPolicy(settings).default,
|
|
5384
5625
|
task.agentConfig,
|
|
5385
5626
|
resolveFirstPartyMcpToolPolicy(settings).allowed
|
|
5386
5627
|
);
|
|
5628
|
+
let resolvedAgentConfig = null;
|
|
5629
|
+
let resolvedAgentInstructions;
|
|
5630
|
+
try {
|
|
5631
|
+
const agentResolution = resolveSessionAgentConfigForCreate2({
|
|
5632
|
+
settings,
|
|
5633
|
+
creator: "scheduled",
|
|
5634
|
+
request: task.agentConfig.agent,
|
|
5635
|
+
instructions: void 0,
|
|
5636
|
+
workspaceSettings: agentConfigMayResolve2(settings, task.agentConfig.agent) ? (await requireWorkspace2(db, task.workspaceId)).settings : {},
|
|
5637
|
+
parent: null,
|
|
5638
|
+
goal: task.agentConfig.goal !== void 0
|
|
5639
|
+
});
|
|
5640
|
+
resolvedAgentConfig = agentResolution.config;
|
|
5641
|
+
resolvedAgentInstructions = agentResolution.instructions;
|
|
5642
|
+
const written = applySessionAgentConfigWriteThrough2({
|
|
5643
|
+
config: resolvedAgentConfig,
|
|
5644
|
+
firstPartyMcpTools,
|
|
5645
|
+
tools: taskTools,
|
|
5646
|
+
toolPolicy: { mode: "explicit", inheritedFromSessionId: null },
|
|
5647
|
+
productServerIds: task.agentConfig.tools.map((tool) => tool.id)
|
|
5648
|
+
});
|
|
5649
|
+
firstPartyMcpTools = written.firstPartyMcpTools;
|
|
5650
|
+
taskTools = written.tools;
|
|
5651
|
+
} catch (error) {
|
|
5652
|
+
const status = error instanceof Error ? error.status : void 0;
|
|
5653
|
+
if (!(error instanceof Error) || status !== 422) throw error;
|
|
5654
|
+
const notEnabled = error.cause instanceof AgentConfigError && error.cause.code === "agent_config_not_enabled";
|
|
5655
|
+
return await refuseAdmission(
|
|
5656
|
+
"scheduled_authority_unavailable",
|
|
5657
|
+
notEnabled,
|
|
5658
|
+
`scheduled agent configuration is not admissible: ${error.message}`
|
|
5659
|
+
);
|
|
5660
|
+
}
|
|
5387
5661
|
const firstPartyMcpPermissions = creatorPolicy?.firstPartyMcpPermissions ? [...creatorPolicy.firstPartyMcpPermissions] : [...DEFAULT_FIRST_PARTY_MCP_PERMISSIONS];
|
|
5388
5662
|
const connectionSettings = await settingsWithEnabledCapabilityMcpServers(
|
|
5389
5663
|
db,
|
|
@@ -5488,7 +5762,7 @@ function createScheduledTaskActivities(services) {
|
|
|
5488
5762
|
);
|
|
5489
5763
|
}
|
|
5490
5764
|
const generatedSessionDepthPolicy = generatedTarget ? await (async () => {
|
|
5491
|
-
const workspace = await
|
|
5765
|
+
const workspace = await requireWorkspace2(db, task.workspaceId);
|
|
5492
5766
|
const deployment = await getNestedAgentDepthDeploymentPolicy(db);
|
|
5493
5767
|
const taskOverride = task.agentConfig.maxNestedAgentDepth ?? null;
|
|
5494
5768
|
const workspaceOverride = typeof workspace.settings.maxNestedAgentDepth === "number" ? workspace.settings.maxNestedAgentDepth : null;
|
|
@@ -5699,7 +5973,8 @@ function createScheduledTaskActivities(services) {
|
|
|
5699
5973
|
accountId: task.accountId,
|
|
5700
5974
|
workspaceId: task.workspaceId,
|
|
5701
5975
|
model: targetSessionExecution?.model ?? model,
|
|
5702
|
-
requestedAgentRuns: input.agentRunUsageIdempotencyKey ? 0 : 1
|
|
5976
|
+
requestedAgentRuns: input.agentRunUsageIdempotencyKey ? 0 : 1,
|
|
5977
|
+
initiatingHumanSubjectId: causalHumanSubjectId
|
|
5703
5978
|
}
|
|
5704
5979
|
);
|
|
5705
5980
|
if (admissionDenial) {
|
|
@@ -5752,6 +6027,10 @@ function createScheduledTaskActivities(services) {
|
|
|
5752
6027
|
resolvedTools: taskTools,
|
|
5753
6028
|
resolvedFirstPartyMcpTools: firstPartyMcpTools,
|
|
5754
6029
|
resolvedFirstPartyMcpPermissions: firstPartyMcpPermissions,
|
|
6030
|
+
...resolvedAgentConfig ? {
|
|
6031
|
+
resolvedAgentConfig,
|
|
6032
|
+
...resolvedAgentInstructions !== void 0 ? { resolvedAgentInstructions } : {}
|
|
6033
|
+
} : {},
|
|
5755
6034
|
resolvedVariableSet: acceptedVariableSet ? { id: acceptedVariableSet.id, generation: acceptedVariableSet.generation } : null,
|
|
5756
6035
|
resolvedRig: acceptedRig?.activeVersion ? {
|
|
5757
6036
|
id: acceptedRig.id,
|
|
@@ -5928,6 +6207,8 @@ function createScheduledTaskActivities(services) {
|
|
|
5928
6207
|
tools: taskTools,
|
|
5929
6208
|
firstPartyMcpTools,
|
|
5930
6209
|
firstPartyMcpPermissions,
|
|
6210
|
+
...resolvedAgentConfig ? { agentConfig: resolvedAgentConfig } : {},
|
|
6211
|
+
...resolvedAgentInstructions !== void 0 ? { instructions: resolvedAgentInstructions } : {},
|
|
5931
6212
|
...creatorSessionPolicy,
|
|
5932
6213
|
...task.agentConfig.knowledgeSource?.destination.kind === "personal" ? {
|
|
5933
6214
|
visibility: "user_private",
|
|
@@ -6797,6 +7078,8 @@ async function recoverBoundScheduledTaskDispatch(input) {
|
|
|
6797
7078
|
tools: input.acceptedExecution.resolvedTools,
|
|
6798
7079
|
firstPartyMcpTools: input.acceptedExecution.resolvedFirstPartyMcpTools,
|
|
6799
7080
|
firstPartyMcpPermissions: input.acceptedExecution.resolvedFirstPartyMcpPermissions,
|
|
7081
|
+
...input.acceptedExecution.resolvedAgentConfig ? { agentConfig: input.acceptedExecution.resolvedAgentConfig } : {},
|
|
7082
|
+
...input.acceptedExecution.resolvedAgentInstructions !== void 0 ? { instructions: input.acceptedExecution.resolvedAgentInstructions } : {},
|
|
6800
7083
|
...scheduledCreatorSessionPolicyInput(recoveredCreatorPolicy?.sessionPolicy ?? null),
|
|
6801
7084
|
...task.agentConfig.knowledgeSource?.destination.kind === "personal" ? {
|
|
6802
7085
|
visibility: "user_private",
|
|
@@ -6919,21 +7202,24 @@ async function recoverBoundScheduledTaskDispatch(input) {
|
|
|
6919
7202
|
);
|
|
6920
7203
|
const expectedTaskMetadata = { ...task.agentConfig.metadata };
|
|
6921
7204
|
delete expectedTaskMetadata[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY];
|
|
6922
|
-
const expectedMetadata =
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
7205
|
+
const expectedMetadata = metadataWithAgentConfigCreateIdentity(
|
|
7206
|
+
{
|
|
7207
|
+
...expectedTaskMetadata,
|
|
7208
|
+
model: input.acceptedExecution.resolvedModel,
|
|
7209
|
+
reasoningEffort: input.acceptedExecution.resolvedReasoningEffort,
|
|
7210
|
+
scheduledTaskId: task.id,
|
|
7211
|
+
scheduledTaskRunMode: task.runMode,
|
|
7212
|
+
...task.agentConfig.goal ? { scheduledTaskGoal: task.agentConfig.goal } : {},
|
|
7213
|
+
scheduledTaskRunId: canonicalGeneratedRunId,
|
|
7214
|
+
...frozenSlack ? { [OPENGENI_SLACK_BOT_SESSION_METADATA_KEY]: frozenSlack.id } : {}
|
|
7215
|
+
},
|
|
7216
|
+
input.acceptedExecution.resolvedAgentConfig
|
|
7217
|
+
);
|
|
7218
|
+
if (session.createIdempotencyKey !== expectedCreateKey || session.initialMessage !== task.agentConfig.prompt || session.instructions !== (input.acceptedExecution.resolvedAgentInstructions ?? null) || session.policyRole !== null || stableJson(session.skills) !== "[]" || stableJson(session.toolPolicy) !== stableJson({ mode: "explicit", inheritedFromSessionId: null }) || session.toolPolicyVersion !== 1 || session.mcpServers.length !== 0 || session.parentSessionId !== null || session.rootSessionId !== session.id || session.nestedAgentDepth !== 0 || session.effectiveMaxNestedAgentDepth !== generatedBinding.effectiveMaxNestedAgentDepth || session.nestedAgentDepthPolicySource !== generatedBinding.nestedAgentDepthPolicySource || session.nestedAgentDepthPolicySessionId !== (generatedBinding.nestedAgentDepthPolicySource === "session" ? session.id : null) || session.sandboxGroupId !== session.id || session.channelId !== null || session.codexCompactionMode !== generatedBinding.codexCompactionMode || stableJson(session.metadata) !== stableJson(expectedMetadata) || session.createdBy.kind !== "service" || session.createdBy.subjectId !== "scheduler" || stableJson(session.createdByContext) !== stableJson({
|
|
6933
7219
|
label: "OpenGeni scheduler",
|
|
6934
7220
|
scheduledTaskId: task.id,
|
|
6935
7221
|
scheduledTaskRunId: canonicalGeneratedRunId
|
|
6936
|
-
}) || task.runMode === "new_session_per_run" && input.acceptedExecution.alertOccurrenceLabels === null && (session.metadata.scheduledTaskRunId !== input.run.id || session.createdByContext.scheduledTaskRunId !== input.run.id) || creationPolicy?.model !== input.acceptedExecution.resolvedModel || creationPolicy.reasoningEffort !== input.acceptedExecution.resolvedReasoningEffort || creationPolicy.latencyMode !== input.acceptedExecution.resolvedLatencyMode || session.sandboxBackend !== input.acceptedExecution.resolvedSandboxBackend || session.sandboxOs !== input.acceptedExecution.resolvedSandboxOs || session.activeSandboxId !== (task.agentConfig.machineTarget?.targetSandboxId ?? null) || stableJson(session.resources) !== stableJson(task.agentConfig.resources) || stableJson(session.tools) !== stableJson(input.acceptedExecution.resolvedTools) || stableJson(session.firstPartyMcpTools) !== stableJson(input.acceptedExecution.resolvedFirstPartyMcpTools) || stableJson(session.firstPartyMcpPermissions) !== stableJson(input.acceptedExecution.resolvedFirstPartyMcpPermissions) || session.maxNestedAgentDepthOverride !== (task.agentConfig.maxNestedAgentDepth ?? null) || (session.variableSetId ?? null) !== (input.acceptedExecution.resolvedVariableSet?.id ?? null) || (session.rigId ?? null) !== (input.acceptedExecution.resolvedRig?.id ?? null) || (session.rigVersionId ?? null) !== (input.acceptedExecution.resolvedRig?.versionId ?? null) || scheduledSlackBotConnectionId(session.metadata) !== (frozenSlack?.id ?? null)) {
|
|
7222
|
+
}) || task.runMode === "new_session_per_run" && input.acceptedExecution.alertOccurrenceLabels === null && (session.metadata.scheduledTaskRunId !== input.run.id || session.createdByContext.scheduledTaskRunId !== input.run.id) || creationPolicy?.model !== input.acceptedExecution.resolvedModel || creationPolicy.reasoningEffort !== input.acceptedExecution.resolvedReasoningEffort || creationPolicy.latencyMode !== input.acceptedExecution.resolvedLatencyMode || session.sandboxBackend !== input.acceptedExecution.resolvedSandboxBackend || session.sandboxOs !== input.acceptedExecution.resolvedSandboxOs || session.activeSandboxId !== (task.agentConfig.machineTarget?.targetSandboxId ?? null) || stableJson(session.resources) !== stableJson(task.agentConfig.resources) || stableJson(session.tools) !== stableJson(input.acceptedExecution.resolvedTools) || stableJson(session.firstPartyMcpTools) !== stableJson(input.acceptedExecution.resolvedFirstPartyMcpTools) || stableJson(session.firstPartyMcpPermissions) !== stableJson(input.acceptedExecution.resolvedFirstPartyMcpPermissions) || stableJson(session.agent) !== stableJson(input.acceptedExecution.resolvedAgentConfig ?? null) || session.maxNestedAgentDepthOverride !== (task.agentConfig.maxNestedAgentDepth ?? null) || (session.variableSetId ?? null) !== (input.acceptedExecution.resolvedVariableSet?.id ?? null) || (session.rigId ?? null) !== (input.acceptedExecution.resolvedRig?.id ?? null) || (session.rigVersionId ?? null) !== (input.acceptedExecution.resolvedRig?.versionId ?? null) || scheduledSlackBotConnectionId(session.metadata) !== (frozenSlack?.id ?? null)) {
|
|
6937
7223
|
throw new ScheduledRunTerminalAuthorityError(
|
|
6938
7224
|
"scheduled_generated_session_changed",
|
|
6939
7225
|
"scheduled generated session differs from accepted execution"
|
|
@@ -7998,6 +8284,7 @@ function createControlActivitiesFromServices(services, resolveDocumentServices)
|
|
|
7998
8284
|
...createCodexCapacityActivities(services),
|
|
7999
8285
|
...createRigVerificationActivities(services),
|
|
8000
8286
|
...createBrowserStateArtifactMaintenanceActivities(services),
|
|
8287
|
+
...createBrowserDeadlineCheckpointActivities(services),
|
|
8001
8288
|
...createFileUploadReaperActivities(services),
|
|
8002
8289
|
...createRetainedScreenshotMaintenanceActivities(services),
|
|
8003
8290
|
...createWorkflowWakeActivities(services),
|
|
@@ -8019,4 +8306,4 @@ export {
|
|
|
8019
8306
|
createControlActivities,
|
|
8020
8307
|
createControlActivitiesFromServices
|
|
8021
8308
|
};
|
|
8022
|
-
//# sourceMappingURL=activities-control-
|
|
8309
|
+
//# sourceMappingURL=activities-control-55ECL47G.js.map
|