@opengeni/worker-bundle 0.22.8 → 0.23.4-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 +10 -2
- package/dist/activities/agent-turn/agent-build.d.ts +1 -4
- package/dist/activities/agent-turn/claim.d.ts +3 -4
- package/dist/activities/agent-turn/codex.d.ts +8 -7
- package/dist/activities/agent-turn/compaction-prep.d.ts +2 -0
- package/dist/activities/agent-turn/errors.d.ts +13 -0
- package/dist/activities/agent-turn/finalization.d.ts +1 -3
- package/dist/activities/agent-turn/list-models.d.ts +16 -0
- package/dist/activities/agent-turn/model-usage.d.ts +10 -1
- package/dist/activities/agent-turn/quiescence.d.ts +39 -0
- package/dist/activities/agent-turn/sandbox-route.d.ts +14 -24
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -4
- package/dist/activities/agent-turn/sandbox-shared-preparation.d.ts +30 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +7 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +1 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +7 -5
- package/dist/activities/agent-turn/turn-context.d.ts +3 -8
- package/dist/activities/agent-turn/turn-sandbox-access.d.ts +12 -0
- package/dist/activities/agent-turn/video-reference-sandbox.d.ts +7 -0
- package/dist/activities/automations.d.ts +1 -0
- package/dist/activities/capabilities.d.ts +2 -1
- package/dist/activities/codex-rotation.d.ts +2 -0
- package/dist/activities/goals.d.ts +11 -0
- 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 +2 -1
- package/dist/activities/types.d.ts +8 -0
- package/dist/{activities-control-VZIIV7RX.js → activities-control-SGU2WEVB.js} +328 -107
- package/dist/activities-control-SGU2WEVB.js.map +1 -0
- package/dist/activities-control.d.ts +2 -0
- package/dist/{activities-turn-5RGQDBFV.js → activities-turn-7EAQXW6Q.js} +828 -540
- package/dist/activities-turn-7EAQXW6Q.js.map +1 -0
- package/dist/activities.d.ts +2 -0
- package/dist/{chunk-O4HDX5SC.js → chunk-S2QVRVJW.js} +227 -36
- package/dist/chunk-S2QVRVJW.js.map +1 -0
- package/dist/{chunk-NAVSAZ56.js → chunk-TJIPCHMP.js} +162 -2
- package/dist/chunk-TJIPCHMP.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +69 -6
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +29 -0
- package/dist/personal-github-git-credentials.d.ts +1 -0
- package/dist/unhandled-rejection-boundary.d.ts +29 -0
- package/dist/workflow-bundle.js +26 -3
- package/dist/workflows/activities.d.ts +5 -0
- package/dist/workflows/automations.d.ts +5 -0
- package/package.json +18 -18
- package/src/activities/agent-run-admission.ts +7 -1
- package/src/activities/agent-turn/admission.ts +28 -6
- package/src/activities/agent-turn/agent-build.ts +15 -31
- package/src/activities/agent-turn/claim.ts +53 -72
- package/src/activities/agent-turn/codex.ts +21 -12
- package/src/activities/agent-turn/compaction-prep.ts +52 -1
- package/src/activities/agent-turn/errors.ts +78 -0
- package/src/activities/agent-turn/failure-settlement.ts +30 -19
- package/src/activities/agent-turn/finalization.ts +24 -21
- package/src/activities/agent-turn/history.ts +5 -1
- package/src/activities/agent-turn/list-models.ts +101 -0
- package/src/activities/agent-turn/model-usage.ts +88 -42
- package/src/activities/agent-turn/quiescence.ts +86 -0
- package/src/activities/agent-turn/run-credentials.ts +12 -1
- package/src/activities/agent-turn/run.ts +20 -14
- package/src/activities/agent-turn/sandbox-establish.ts +46 -11
- package/src/activities/agent-turn/sandbox-route.ts +21 -25
- package/src/activities/agent-turn/sandbox-runtime.ts +1 -116
- package/src/activities/agent-turn/sandbox-shared-preparation.ts +206 -0
- package/src/activities/agent-turn/stream-attempt.ts +106 -14
- package/src/activities/agent-turn/tool-environment.ts +72 -14
- package/src/activities/agent-turn/tool-policy.ts +7 -6
- package/src/activities/agent-turn/turn-context.ts +12 -14
- package/src/activities/agent-turn/{image-reference-sandbox.ts → turn-sandbox-access.ts} +15 -13
- package/src/activities/agent-turn/video-reference-sandbox.ts +23 -0
- package/src/activities/automations.ts +122 -67
- package/src/activities/capabilities.ts +72 -2
- package/src/activities/codex-capacity.ts +13 -5
- package/src/activities/codex-rotation.ts +17 -0
- package/src/activities/goals.ts +117 -35
- package/src/activities/image-generation-references.ts +9 -9
- package/src/activities/retained-screenshots.ts +104 -21
- package/src/activities/sandbox-lease.ts +7 -4
- package/src/activities/scheduled-tasks.ts +248 -30
- package/src/activities/session-state.ts +8 -1
- package/src/activities/site-auth-maintenance.ts +12 -12
- package/src/activities/types.ts +6 -0
- package/src/activities.ts +1 -0
- package/src/activity-services.ts +4 -1
- package/src/github-rest-mcp.ts +8 -4
- package/src/http.ts +3 -0
- package/src/index.ts +38 -4
- package/src/observability-metrics.ts +202 -0
- package/src/personal-github-git-credentials.ts +45 -4
- package/src/sandbox-resume.ts +1 -1
- package/src/sandbox-routing.ts +7 -4
- package/src/unhandled-rejection-boundary.ts +73 -0
- package/src/workflows/activities.ts +15 -0
- package/src/workflows/automations.ts +21 -2
- package/dist/activities/agent-turn/image-reference-sandbox.d.ts +0 -14
- package/dist/activities/recording.d.ts +0 -90
- package/dist/activities-control-VZIIV7RX.js.map +0 -1
- package/dist/activities-turn-5RGQDBFV.js.map +0 -1
- package/dist/chunk-NAVSAZ56.js.map +0 -1
- package/dist/chunk-O4HDX5SC.js.map +0 -1
- package/src/activities/recording.ts +0 -279
package/dist/activities.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function createActivityTestHarness(dependencies?: ActivityDepende
|
|
|
14
14
|
} | null>;
|
|
15
15
|
reconcileCodexCapacityWait: (input: import("./activities.js").ReconcileCodexCapacityWaitInput) => Promise<import("./activities.js").ReconcileCodexCapacityWaitResult>;
|
|
16
16
|
maintainBrowserStateArtifacts: () => Promise<import("./activities/browser-state-artifact-reaper.js").MaintainBrowserStateArtifactsResult>;
|
|
17
|
+
settleAutomationRunFailure: (input: import("./activities.js").DispatchAutomationRunInput) => Promise<void>;
|
|
17
18
|
dispatchAutomationRun: (input: import("./activities.js").DispatchAutomationRunInput) => Promise<import("./activities.js").DispatchAutomationRunResult>;
|
|
18
19
|
indexDocument: (input: import("./activities.js").IndexDocumentInput) => Promise<{
|
|
19
20
|
id: string;
|
|
@@ -222,6 +223,7 @@ export declare const expireSessionInteractionIntervention: (input: import("./act
|
|
|
222
223
|
export declare const markSessionIdle: (input: import("./activities/types.js").MarkSessionIdleInput) => Promise<void>;
|
|
223
224
|
export declare const dispatchScheduledTaskRun: (input: import("./activities.js").DispatchScheduledTaskRunInput) => Promise<import("./activities.js").DispatchScheduledTaskRunResult>;
|
|
224
225
|
export declare const dispatchAutomationRun: (input: import("./activities.js").DispatchAutomationRunInput) => Promise<import("./activities.js").DispatchAutomationRunResult>;
|
|
226
|
+
export declare const settleAutomationRunFailure: (input: import("./activities.js").DispatchAutomationRunInput) => Promise<void>;
|
|
225
227
|
export declare const runKnowledgeSourceSyncBatch: (input: import("./activities.js").RunKnowledgeSourceSyncBatchInput) => Promise<import("./activities.js").RunKnowledgeSourceSyncBatchResult>;
|
|
226
228
|
export declare const enqueueGoalRetryWake: (input: import("./activities.js").MaybeContinueGoalInput) => Promise<void>;
|
|
227
229
|
export declare const maybeContinueGoal: (input: import("./activities.js").MaybeContinueGoalInput) => Promise<import("./activities.js").MaybeContinueGoalResult>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
observabilityEventLogger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TJIPCHMP.js";
|
|
4
4
|
|
|
5
5
|
// src/activity-services.ts
|
|
6
6
|
import { dbSearchPath, getSettings, resolveNatsControlPlaneAuth } from "@opengeni/config";
|
|
7
7
|
import { configureChildLifecycleNotices, createDb } from "@opengeni/db";
|
|
8
8
|
import { createNatsEventBus } from "@opengeni/events";
|
|
9
9
|
import { createObservability } from "@opengeni/observability";
|
|
10
|
+
import { resolveCatalogSettings } from "@opengeni/core";
|
|
10
11
|
import { createObjectStorage } from "@opengeni/storage";
|
|
11
12
|
|
|
12
13
|
// src/personal-github-git-credentials.ts
|
|
@@ -27,12 +28,14 @@ import {
|
|
|
27
28
|
sealPersonalGitHubGitBrokerClaims
|
|
28
29
|
} from "@opengeni/github";
|
|
29
30
|
import { randomBytes, randomUUID } from "crypto";
|
|
31
|
+
import { execFileSync } from "child_process";
|
|
32
|
+
import { isIP } from "net";
|
|
30
33
|
import { isDeepStrictEqual } from "util";
|
|
31
34
|
var PERSONAL_GITHUB_SERVER_ID = "github:personal";
|
|
32
35
|
function buildPersonalGitHubGitCredentials(db, settings) {
|
|
33
36
|
if (!settings.githubPersonalOauthEnabled) return null;
|
|
34
37
|
const secret = settings.integrationsStateSecret?.trim();
|
|
35
|
-
const publicOrigin = personalGitBrokerOrigin(settings
|
|
38
|
+
const publicOrigin = personalGitBrokerOrigin(settings);
|
|
36
39
|
if (!secret || !publicOrigin) {
|
|
37
40
|
throw new Error("personal GitHub Git broker configuration is unavailable");
|
|
38
41
|
}
|
|
@@ -182,12 +185,34 @@ function personalGitHubCanRead(permissions) {
|
|
|
182
185
|
function personalGitHubCanWrite(permissions) {
|
|
183
186
|
return permissions.push || permissions.maintain || permissions.admin;
|
|
184
187
|
}
|
|
185
|
-
|
|
188
|
+
var cachedDockerBridgeGateway;
|
|
189
|
+
function dockerBridgeGateway() {
|
|
190
|
+
if (cachedDockerBridgeGateway !== void 0) return cachedDockerBridgeGateway;
|
|
191
|
+
try {
|
|
192
|
+
const value = execFileSync(
|
|
193
|
+
"docker",
|
|
194
|
+
["network", "inspect", "bridge", "--format", "{{(index .IPAM.Config 0).Gateway}}"],
|
|
195
|
+
{ encoding: "utf8", timeout: 2e3, maxBuffer: 16 * 1024 }
|
|
196
|
+
).trim();
|
|
197
|
+
cachedDockerBridgeGateway = isIP(value) ? value : null;
|
|
198
|
+
} catch {
|
|
199
|
+
cachedDockerBridgeGateway = null;
|
|
200
|
+
}
|
|
201
|
+
return cachedDockerBridgeGateway;
|
|
202
|
+
}
|
|
203
|
+
function personalGitBrokerOrigin(settings) {
|
|
204
|
+
const value = settings.opengeniMcpUrl ?? (settings.sandboxBackend === "docker" ? `http://host.docker.internal:${settings.apiPort}` : settings.sandboxBackend === "local" || settings.sandboxBackend === "none" ? `http://127.0.0.1:${settings.apiPort}` : settings.publicBaseUrl);
|
|
186
205
|
if (!value) return null;
|
|
187
206
|
const url = new URL(value);
|
|
188
|
-
if (
|
|
207
|
+
if (settings.sandboxBackend === "docker" && (url.hostname === "127.0.0.1" || url.hostname === "localhost")) {
|
|
208
|
+
url.hostname = dockerBridgeGateway() ?? "host.docker.internal";
|
|
209
|
+
}
|
|
210
|
+
const dockerPrivateOrigin = settings.sandboxBackend === "docker" && (url.hostname === "host.docker.internal" || url.hostname === cachedDockerBridgeGateway || /^[a-z][a-z0-9-]{0,62}$/iu.test(url.hostname));
|
|
211
|
+
const privateExecutionOrigin = url.protocol === "http:" && (url.hostname === "127.0.0.1" || url.hostname === "localhost" || dockerPrivateOrigin) || ["local", "test"].includes(settings.environment);
|
|
212
|
+
if (url.protocol !== "https:" && !privateExecutionOrigin || url.username || url.password || url.search || url.hash) {
|
|
189
213
|
return null;
|
|
190
214
|
}
|
|
215
|
+
url.pathname = "/";
|
|
191
216
|
return url.origin;
|
|
192
217
|
}
|
|
193
218
|
function exactPersonalGitHubDelegation(delegations, credentialBindingId) {
|
|
@@ -376,9 +401,11 @@ function createSharedActivityServices(dependencies) {
|
|
|
376
401
|
});
|
|
377
402
|
const controlPlaneAuth = resolveNatsControlPlaneAuth(settings);
|
|
378
403
|
const db = dependencies.db ?? dbClient.db;
|
|
404
|
+
const resolvedSettings = (await resolveCatalogSettings(db, settings)).settings;
|
|
379
405
|
configureChildLifecycleNotices({ enabled: settings.childLifecycleNoticesEnabled });
|
|
380
406
|
return {
|
|
381
|
-
settings,
|
|
407
|
+
settings: resolvedSettings,
|
|
408
|
+
catalogSourceSettings: settings,
|
|
382
409
|
db,
|
|
383
410
|
bus: dependencies.bus ?? await createNatsEventBus(
|
|
384
411
|
settings.natsUrl,
|
|
@@ -414,6 +441,9 @@ import {
|
|
|
414
441
|
} from "@opengeni/db";
|
|
415
442
|
|
|
416
443
|
// src/activities/codex-rotation.ts
|
|
444
|
+
function codexAccountNeedsLiveCapacityRefresh(account, now) {
|
|
445
|
+
return (account.primaryUsedPercent ?? 0) >= CODEX_USAGE_EXHAUSTED_PCT || (account.secondaryUsedPercent ?? 0) >= CODEX_USAGE_EXHAUSTED_PCT || account.exhaustedKind === "quota" && account.exhaustedUntil !== null && account.exhaustedUntil > now;
|
|
446
|
+
}
|
|
417
447
|
function effectiveRotationStrategy(_stored) {
|
|
418
448
|
return "sharded";
|
|
419
449
|
}
|
|
@@ -810,10 +840,13 @@ function codexCapacityDecision(context, settings) {
|
|
|
810
840
|
};
|
|
811
841
|
}
|
|
812
842
|
const authoritativeReset = authoritativeCodexCapacityResetAt(context.accounts, now);
|
|
843
|
+
const hasReconcilableQuotaCooldown = context.accounts.some(
|
|
844
|
+
(account) => account.status === "active" && account.allocatorEnabled && account.exhaustedKind === "quota" && account.exhaustedUntil !== null && account.exhaustedUntil > now
|
|
845
|
+
);
|
|
813
846
|
return {
|
|
814
847
|
kind: "unavailable",
|
|
815
848
|
earliestResetAt: authoritativeReset,
|
|
816
|
-
resetKind: authoritativeReset ? "authoritative" : "bounded_refresh",
|
|
849
|
+
resetKind: authoritativeReset && !hasReconcilableQuotaCooldown ? "authoritative" : "bounded_refresh",
|
|
817
850
|
diagnostic: {
|
|
818
851
|
connectedCount: context.accounts.length,
|
|
819
852
|
allocatorEnabledCount: context.accounts.filter((account) => account.allocatorEnabled).length,
|
|
@@ -823,8 +856,9 @@ function codexCapacityDecision(context, settings) {
|
|
|
823
856
|
}
|
|
824
857
|
async function refreshCapacityMetadata(services, workspaceId) {
|
|
825
858
|
const accounts = await listCodexAccountStatuses(services.db, workspaceId).catch(() => []);
|
|
859
|
+
const now = /* @__PURE__ */ new Date();
|
|
826
860
|
const stale = accounts.filter(
|
|
827
|
-
(account) => account.allocatorEnabled && account.status === "active" && ((account
|
|
861
|
+
(account) => account.allocatorEnabled && account.status === "active" && (codexAccountNeedsLiveCapacityRefresh(account, now) || account.usageCheckedAt === null)
|
|
828
862
|
);
|
|
829
863
|
await refreshCodexUsageAndRepairCapacityWaiters(
|
|
830
864
|
stale.map(
|
|
@@ -941,7 +975,13 @@ function createCodexCapacityActivities(services) {
|
|
|
941
975
|
import {
|
|
942
976
|
allowedFirstPartyMcpToolsForSession,
|
|
943
977
|
configuredStaticUsageLimits,
|
|
944
|
-
policyProviderIdForModel
|
|
978
|
+
policyProviderIdForModel,
|
|
979
|
+
resolveModelProvider,
|
|
980
|
+
resolveTurnExecutionPolicyV1,
|
|
981
|
+
withCodexCatalogProvider,
|
|
982
|
+
withXaiSubscriptionCatalogProvider,
|
|
983
|
+
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
984
|
+
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX
|
|
945
985
|
} from "@opengeni/config";
|
|
946
986
|
import {
|
|
947
987
|
evaluateWorkspaceModelPolicy,
|
|
@@ -959,6 +999,11 @@ import {
|
|
|
959
999
|
requireSession,
|
|
960
1000
|
sumUsageQuantity
|
|
961
1001
|
} from "@opengeni/db";
|
|
1002
|
+
import {
|
|
1003
|
+
modelFundingForAdmission,
|
|
1004
|
+
resolveCatalogSettings as resolveCatalogSettings2,
|
|
1005
|
+
resolveWorkspaceCatalogSettings
|
|
1006
|
+
} from "@opengeni/core";
|
|
962
1007
|
function createGoalActivities(services) {
|
|
963
1008
|
async function enqueueGoalRetryWake(input) {
|
|
964
1009
|
const { db } = await services();
|
|
@@ -974,35 +1019,40 @@ function createGoalActivities(services) {
|
|
|
974
1019
|
});
|
|
975
1020
|
}
|
|
976
1021
|
async function maybeContinueGoal(input) {
|
|
977
|
-
const
|
|
1022
|
+
const service = await services();
|
|
1023
|
+
const { db, bus } = service;
|
|
1024
|
+
const catalogSourceSettings = service.catalogSourceSettings ?? service.settings;
|
|
978
1025
|
const existingGoal = await getSessionGoal(db, input.workspaceId, input.sessionId);
|
|
979
1026
|
if (!existingGoal || existingGoal.status !== "active") {
|
|
980
1027
|
return { action: "none" };
|
|
981
1028
|
}
|
|
1029
|
+
let settings = (await resolveCatalogSettings2(db, catalogSourceSettings)).settings;
|
|
982
1030
|
const session = await requireSession(db, input.workspaceId, input.sessionId);
|
|
983
1031
|
const latestStartedTurn = await getLatestStartedSessionTurn(
|
|
984
1032
|
db,
|
|
985
1033
|
input.workspaceId,
|
|
986
1034
|
input.sessionId
|
|
987
1035
|
);
|
|
988
|
-
|
|
1036
|
+
const inheritedContinuationModel = latestStartedTurn?.model ?? session.model;
|
|
1037
|
+
let continuationModel = inheritedContinuationModel;
|
|
989
1038
|
const continuationReasoningEffort = latestStartedTurn?.reasoningEffort ?? session.reasoningEffort;
|
|
990
1039
|
const continuationLatencyMode = latestStartedTurn?.latencyMode ?? session.latencyMode;
|
|
991
|
-
let modelPolicyBlocked = null;
|
|
992
1040
|
const workspaceModelPolicy = await getWorkspaceModelPolicy(db, input.workspaceId);
|
|
993
|
-
if (
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (continuationModel !== session.model && !policyBlocks(session.model)) {
|
|
1000
|
-
continuationModel = session.model;
|
|
1001
|
-
} else {
|
|
1002
|
-
modelPolicyBlocked = `workspace model policy blocks model "${continuationModel}"; pick an allowed model or change the workspace model policy`;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1041
|
+
if (inheritedContinuationModel.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || inheritedContinuationModel.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX) || session.model.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || session.model.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX)) {
|
|
1042
|
+
settings = (await resolveWorkspaceCatalogSettings(db, catalogSourceSettings, {
|
|
1043
|
+
accountId: input.accountId,
|
|
1044
|
+
workspaceId: input.workspaceId,
|
|
1045
|
+
retainedProductModelIds: [inheritedContinuationModel, session.model]
|
|
1046
|
+
})).settings;
|
|
1005
1047
|
}
|
|
1048
|
+
const modelDecision = goalContinuationModelDecision({
|
|
1049
|
+
settings,
|
|
1050
|
+
workspaceModelPolicy,
|
|
1051
|
+
inheritedModel: inheritedContinuationModel,
|
|
1052
|
+
sessionModel: session.model
|
|
1053
|
+
});
|
|
1054
|
+
continuationModel = modelDecision.model;
|
|
1055
|
+
let modelPolicyBlocked = modelDecision.blocked;
|
|
1006
1056
|
if (!modelPolicyBlocked && session.codexCompactionMode === "remote_v2" && !isCodexBilledModel(continuationModel)) {
|
|
1007
1057
|
modelPolicyBlocked = `session is locked to Codex remote compaction v2; model "${continuationModel}" is not a Codex subscription model`;
|
|
1008
1058
|
}
|
|
@@ -1012,13 +1062,27 @@ function createGoalActivities(services) {
|
|
|
1012
1062
|
workspaceId: input.workspaceId,
|
|
1013
1063
|
model: continuationModel
|
|
1014
1064
|
});
|
|
1065
|
+
const fundedWithoutCredits = goalContinuationFundedWithoutCredits(
|
|
1066
|
+
settings,
|
|
1067
|
+
continuationModel,
|
|
1068
|
+
isCodexRun
|
|
1069
|
+
);
|
|
1015
1070
|
const budgetBlocked = await goalRunBudgetBlocked(
|
|
1016
1071
|
settings,
|
|
1017
1072
|
db,
|
|
1018
1073
|
input.accountId,
|
|
1019
1074
|
input.workspaceId,
|
|
1020
|
-
|
|
1075
|
+
fundedWithoutCredits
|
|
1021
1076
|
);
|
|
1077
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(settings, {
|
|
1078
|
+
modelId: continuationModel,
|
|
1079
|
+
requestedModelId: null,
|
|
1080
|
+
modelSource: "continuation",
|
|
1081
|
+
reasoningEffort: continuationReasoningEffort,
|
|
1082
|
+
reasoningSource: "continuation",
|
|
1083
|
+
latencyMode: continuationLatencyMode,
|
|
1084
|
+
latencyModeSource: "continuation"
|
|
1085
|
+
});
|
|
1022
1086
|
const decision = await materializeGoalContinuation(db, {
|
|
1023
1087
|
accountId: input.accountId,
|
|
1024
1088
|
workspaceId: input.workspaceId,
|
|
@@ -1039,6 +1103,7 @@ function createGoalActivities(services) {
|
|
|
1039
1103
|
model: continuationModel,
|
|
1040
1104
|
reasoningEffort: continuationReasoningEffort,
|
|
1041
1105
|
latencyMode: continuationLatencyMode,
|
|
1106
|
+
turnExecutionPolicy,
|
|
1042
1107
|
tools: withFirstPartyTools(settings, session.tools),
|
|
1043
1108
|
sandboxBackend: session.sandboxBackend
|
|
1044
1109
|
},
|
|
@@ -1069,6 +1134,34 @@ function createGoalActivities(services) {
|
|
|
1069
1134
|
maybeContinueGoal
|
|
1070
1135
|
};
|
|
1071
1136
|
}
|
|
1137
|
+
function goalContinuationModelDecision(input) {
|
|
1138
|
+
const catalogSettings = input.settings.supergrokSubscriptionEnabled ? withXaiSubscriptionCatalogProvider(
|
|
1139
|
+
input.settings.codexSubscriptionEnabled ? withCodexCatalogProvider(input.settings) : input.settings
|
|
1140
|
+
) : input.settings.codexSubscriptionEnabled ? withCodexCatalogProvider(input.settings) : input.settings;
|
|
1141
|
+
const policyBlocks = (modelId) => input.workspaceModelPolicy !== null && !evaluateWorkspaceModelPolicy(input.workspaceModelPolicy, {
|
|
1142
|
+
providerId: policyProviderIdForModel(catalogSettings, modelId),
|
|
1143
|
+
modelId
|
|
1144
|
+
}).allowed;
|
|
1145
|
+
const candidates = [.../* @__PURE__ */ new Set([input.inheritedModel, input.sessionModel])];
|
|
1146
|
+
for (const model of candidates) {
|
|
1147
|
+
if (resolveModelProvider(catalogSettings, model) && !policyBlocks(model)) {
|
|
1148
|
+
return { model, blocked: null };
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (!resolveModelProvider(catalogSettings, input.inheritedModel)) {
|
|
1152
|
+
return {
|
|
1153
|
+
model: input.inheritedModel,
|
|
1154
|
+
blocked: `model "${input.inheritedModel}" is no longer in the deployment or workspace catalog; choose an available model before resuming the goal`
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
return {
|
|
1158
|
+
model: input.inheritedModel,
|
|
1159
|
+
blocked: `workspace model policy blocks model "${input.inheritedModel}"; pick an allowed model or change the workspace model policy`
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
function goalContinuationFundedWithoutCredits(settings, model, codexBilled) {
|
|
1163
|
+
return modelFundingForAdmission(settings, model, codexBilled).fundedWithoutCredits;
|
|
1164
|
+
}
|
|
1072
1165
|
function goalContinuationPrompt(_goal, _autoContinuation, _cap, options = {}) {
|
|
1073
1166
|
const waitingGuidance = options.goalWaitAvailable ? [
|
|
1074
1167
|
"Waiting on child sessions or external events:",
|
|
@@ -1084,15 +1177,21 @@ function goalContinuationPrompt(_goal, _autoContinuation, _cap, options = {}) {
|
|
|
1084
1177
|
""
|
|
1085
1178
|
];
|
|
1086
1179
|
return [
|
|
1087
|
-
"
|
|
1180
|
+
"Reconcile the active session goal against authoritative current state, then carry the work through to the full requested end state and verify it.",
|
|
1181
|
+
"",
|
|
1182
|
+
"Goal recovery:",
|
|
1183
|
+
"- Treat this continuation as re-entry into the full objective, not as a request to perform one step and stop.",
|
|
1184
|
+
"- Do not rely on previous assistant claims of progress or completion; use them only to locate authoritative evidence.",
|
|
1185
|
+
"- If authoritative evidence already proves the full objective, call opengeni__goal_complete instead of manufacturing more work.",
|
|
1186
|
+
"- Before repeating a state-setting action, verify whether its desired state already holds. If it does, do not repeat it; continue reconciling the overall goal.",
|
|
1088
1187
|
"",
|
|
1089
1188
|
"Continuation behavior:",
|
|
1090
|
-
"- This goal persists across turns.
|
|
1091
|
-
"- Keep
|
|
1189
|
+
"- This goal persists across turns. A runtime boundary can end one turn without shrinking the objective; the next continuation resumes the same full objective.",
|
|
1190
|
+
"- Keep working until the requested end state is true and verified. Do not end the turn merely because one useful action completed, and do not redefine success around a smaller or easier task.",
|
|
1092
1191
|
"- Temporary rough edges are acceptable while the work is moving in the right direction. Completion still requires the requested end state to be true and verified.",
|
|
1093
1192
|
"",
|
|
1094
1193
|
"Work from evidence:",
|
|
1095
|
-
"Use the current workspace and external state as authoritative.
|
|
1194
|
+
"Use the current workspace and external state as authoritative. Conversation context can help locate relevant work, but it is not proof of the current state. Inspect the current state before relying on it. Improve, replace, or remove existing work as needed to satisfy the actual objective.",
|
|
1096
1195
|
"",
|
|
1097
1196
|
"Progress visibility:",
|
|
1098
1197
|
"If a planning tool is available and the next work is meaningfully multi-step, use it to show a concise plan tied to the real objective. Keep the plan current as steps complete or the next best action changes. Skip planning overhead for trivial one-step progress, and do not treat a plan update as a substitute for doing the work.",
|
|
@@ -1129,8 +1228,8 @@ function withFirstPartyTools(settings, tools) {
|
|
|
1129
1228
|
}
|
|
1130
1229
|
return mergeToolRefs(tools, [{ kind: "mcp", id: "opengeni" }]);
|
|
1131
1230
|
}
|
|
1132
|
-
async function goalRunBudgetBlocked(settings, db, accountId, workspaceId,
|
|
1133
|
-
if (!
|
|
1231
|
+
async function goalRunBudgetBlocked(settings, db, accountId, workspaceId, fundedWithoutCredits) {
|
|
1232
|
+
if (!fundedWithoutCredits && (settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")) {
|
|
1134
1233
|
const balance = await getBillingBalance(db, accountId);
|
|
1135
1234
|
if (balance.balanceMicros <= 0) {
|
|
1136
1235
|
return "insufficient OpenGeni credits";
|
|
@@ -1138,7 +1237,7 @@ async function goalRunBudgetBlocked(settings, db, accountId, workspaceId, isCode
|
|
|
1138
1237
|
}
|
|
1139
1238
|
if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
|
|
1140
1239
|
const limits = configuredStaticUsageLimits(settings);
|
|
1141
|
-
if (!
|
|
1240
|
+
if (!fundedWithoutCredits && limits.maxMonthlyCostMicrosPerAccount) {
|
|
1142
1241
|
const used = await sumUsageQuantity(db, {
|
|
1143
1242
|
accountId,
|
|
1144
1243
|
eventType: "model.cost",
|
|
@@ -3917,6 +4016,22 @@ function assertSessionAttemptQuiescenceRecoveryDurable(input) {
|
|
|
3917
4016
|
}
|
|
3918
4017
|
var QUIESCENCE_PROOF_SIGNAL_INITIAL_RETRY_MS = 250;
|
|
3919
4018
|
var QUIESCENCE_PROOF_SIGNAL_MAX_RETRY_MS = 5e3;
|
|
4019
|
+
var TURN_QUIESCENCE_WATCHDOG_MS = 5 * 6e4;
|
|
4020
|
+
function armTurnQuiescenceWatchdog(input) {
|
|
4021
|
+
if (!input.enabled) return () => void 0;
|
|
4022
|
+
let armed = true;
|
|
4023
|
+
const timer = setTimeout(() => {
|
|
4024
|
+
if (!armed) return;
|
|
4025
|
+
input.onTimeout?.();
|
|
4026
|
+
input.terminateWorker();
|
|
4027
|
+
}, input.timeoutMs ?? TURN_QUIESCENCE_WATCHDOG_MS);
|
|
4028
|
+
timer.unref?.();
|
|
4029
|
+
return () => {
|
|
4030
|
+
if (!armed) return;
|
|
4031
|
+
armed = false;
|
|
4032
|
+
clearTimeout(timer);
|
|
4033
|
+
};
|
|
4034
|
+
}
|
|
3920
4035
|
async function persistOrSignalSessionAttemptQuiescence(input) {
|
|
3921
4036
|
let receipt;
|
|
3922
4037
|
try {
|
|
@@ -4015,6 +4130,36 @@ async function waitForTurnStreamCleanup(batcherFlush, providerCompleted, signal)
|
|
|
4015
4130
|
await waitForTurnFinalizerStep(batcherFlush, signal);
|
|
4016
4131
|
await waitForTurnFinalizerStep(providerCompleted, signal);
|
|
4017
4132
|
}
|
|
4133
|
+
var IncompleteAgentStreamError = class extends Error {
|
|
4134
|
+
name = "IncompleteAgentStreamError";
|
|
4135
|
+
constructor(message = "Agent stream ended without a successful terminal output") {
|
|
4136
|
+
super(message);
|
|
4137
|
+
}
|
|
4138
|
+
};
|
|
4139
|
+
async function assertSuccessfulAgentStreamCompletion(input) {
|
|
4140
|
+
await waitForTurnStreamCleanup(
|
|
4141
|
+
input.batcherFlush,
|
|
4142
|
+
input.stream.completed,
|
|
4143
|
+
input.temporalCancellationSignal
|
|
4144
|
+
);
|
|
4145
|
+
if (input.runtimeCancellationSignal.aborted) {
|
|
4146
|
+
throw input.runtimeCancellationSignal.reason ?? new IncompleteAgentStreamError("Agent stream was cancelled without a terminal reason");
|
|
4147
|
+
}
|
|
4148
|
+
if (input.stream.error !== null && input.stream.error !== void 0) {
|
|
4149
|
+
throw input.stream.error;
|
|
4150
|
+
}
|
|
4151
|
+
}
|
|
4152
|
+
function assertAgentStreamNotCancelled(cancelled) {
|
|
4153
|
+
if (cancelled) {
|
|
4154
|
+
throw new IncompleteAgentStreamError("Agent stream was cancelled without a terminal result");
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
function requireAgentStreamFinalOutput(finalOutput) {
|
|
4158
|
+
if (finalOutput === void 0) {
|
|
4159
|
+
throw new IncompleteAgentStreamError();
|
|
4160
|
+
}
|
|
4161
|
+
return finalOutput;
|
|
4162
|
+
}
|
|
4018
4163
|
async function clearAttemptCredentialsWithSettledFence(input) {
|
|
4019
4164
|
try {
|
|
4020
4165
|
await input.runWorkspaceFencedClear();
|
|
@@ -4071,7 +4216,8 @@ import {
|
|
|
4071
4216
|
ActiveSessionHistoryLimitExceededError,
|
|
4072
4217
|
ApprovalRunStateLimitExceededError,
|
|
4073
4218
|
isRetryableDatabaseTransportFailure,
|
|
4074
|
-
isSessionEventPersistenceError
|
|
4219
|
+
isSessionEventPersistenceError,
|
|
4220
|
+
SandboxLeaseTransitionError as SandboxLeaseTransitionError3
|
|
4075
4221
|
} from "@opengeni/db";
|
|
4076
4222
|
import {
|
|
4077
4223
|
ActiveBackendUnresolvableError,
|
|
@@ -4079,6 +4225,7 @@ import {
|
|
|
4079
4225
|
EmptyCompactionSummaryError,
|
|
4080
4226
|
isMcpRequestTimeoutError,
|
|
4081
4227
|
isMcpTransportConnectivityError,
|
|
4228
|
+
isModalTaskExecStartDnsResolutionError,
|
|
4082
4229
|
RoutingWorkspaceRootChangedError,
|
|
4083
4230
|
SelfhostedWorkspaceRootChangedError,
|
|
4084
4231
|
UNKNOWN_MODEL_FINISH_REASON_CODE
|
|
@@ -4131,7 +4278,7 @@ function providerRecoveryResult(input) {
|
|
|
4131
4278
|
};
|
|
4132
4279
|
}
|
|
4133
4280
|
const providerDelay = input.retryAfterMs !== null && input.retryAfterMs !== void 0 && Number.isFinite(input.retryAfterMs) && input.retryAfterMs > 0 ? Math.ceil(input.retryAfterMs) : null;
|
|
4134
|
-
const continueDelayMs = input.failureCode === "provider_rate_limited" ? providerDelay ?? PROVIDER_BACKPRESSURE_DELAY_MS : input.failureCode === "provider_unavailable" || input.failureCode === "upstream_connectivity_unavailable" || input.failureCode === "mcp_transport_timeout" || input.failureCode === "mcp_transport_unavailable" || input.failureCode === POST_COMPACTION_CONTINUATION_EMPTY_CODE ? Math.max(
|
|
4281
|
+
const continueDelayMs = input.failureCode === "provider_rate_limited" ? providerDelay ?? PROVIDER_BACKPRESSURE_DELAY_MS : input.failureCode === "provider_unavailable" || input.failureCode === "upstream_connectivity_unavailable" || input.failureCode === "sandbox_command_start_unavailable" || input.failureCode === "mcp_transport_timeout" || input.failureCode === "mcp_transport_unavailable" || input.failureCode === POST_COMPACTION_CONTINUATION_EMPTY_CODE ? Math.max(
|
|
4135
4282
|
providerDelay ?? 0,
|
|
4136
4283
|
PROVIDER_CONNECTIVITY_BACKOFF_MS[Math.min(
|
|
4137
4284
|
Math.max(Math.trunc(input.attemptNumber) - 1, 0),
|
|
@@ -4158,6 +4305,9 @@ function providerRecoveryCountFromMetadata(metadata) {
|
|
|
4158
4305
|
const value = metadata.providerRecoveryCount;
|
|
4159
4306
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
4160
4307
|
}
|
|
4308
|
+
function providerRecoveryCountAfterModelRequestPhase(currentCount, phase) {
|
|
4309
|
+
return phase === "completed" ? 0 : currentCount;
|
|
4310
|
+
}
|
|
4161
4311
|
function headerValue(headers, name) {
|
|
4162
4312
|
if (!headers || typeof headers !== "object") return null;
|
|
4163
4313
|
const getter = headers.get;
|
|
@@ -4259,6 +4409,35 @@ function postClaimDatabaseRecoveryFailure(input) {
|
|
|
4259
4409
|
function isWorkerShutdownCancellation(error) {
|
|
4260
4410
|
return error instanceof CancelledFailure2 && error.message === "WORKER_SHUTDOWN";
|
|
4261
4411
|
}
|
|
4412
|
+
function sandboxLifecycleTransitionDiagnostic(error) {
|
|
4413
|
+
const pending = [error];
|
|
4414
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
4415
|
+
let inspected = 0;
|
|
4416
|
+
while (pending.length > 0 && inspected < 64) {
|
|
4417
|
+
const current = pending.shift();
|
|
4418
|
+
inspected += 1;
|
|
4419
|
+
if (!current || typeof current !== "object" || seen.has(current)) continue;
|
|
4420
|
+
seen.add(current);
|
|
4421
|
+
try {
|
|
4422
|
+
const record = current;
|
|
4423
|
+
const reason = record.reason;
|
|
4424
|
+
if ((current instanceof SandboxLeaseTransitionError3 || record.name === "SandboxLeaseTransitionError") && typeof record.sandboxGroupId === "string" && record.sandboxGroupId.length > 0 && typeof record.leaseEpoch === "number" && Number.isSafeInteger(record.leaseEpoch) && record.leaseEpoch >= 0 && (reason === "capture_in_progress" || reason === "rotation_in_progress" || reason === "provider_recovery_in_progress")) {
|
|
4425
|
+
return {
|
|
4426
|
+
sandboxGroupId: record.sandboxGroupId,
|
|
4427
|
+
leaseEpoch: record.leaseEpoch,
|
|
4428
|
+
reason
|
|
4429
|
+
};
|
|
4430
|
+
}
|
|
4431
|
+
for (const key of ["cause", "error"]) {
|
|
4432
|
+
const nested = record[key];
|
|
4433
|
+
if (nested && typeof nested === "object") pending.push(nested);
|
|
4434
|
+
}
|
|
4435
|
+
if (Array.isArray(record.errors)) pending.push(...record.errors.slice(0, 32));
|
|
4436
|
+
} catch {
|
|
4437
|
+
}
|
|
4438
|
+
}
|
|
4439
|
+
return null;
|
|
4440
|
+
}
|
|
4262
4441
|
function sandboxRouteTransitionCode(error) {
|
|
4263
4442
|
const pending = [error];
|
|
4264
4443
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
@@ -4494,6 +4673,13 @@ function agentRunFailurePayload(error, options = {}) {
|
|
|
4494
4673
|
retryable: true
|
|
4495
4674
|
};
|
|
4496
4675
|
}
|
|
4676
|
+
if (isModalTaskExecStartDnsResolutionError(error)) {
|
|
4677
|
+
return {
|
|
4678
|
+
error: "The managed sandbox command transport was temporarily unreachable before the command started. The same turn will retry after a short delay.",
|
|
4679
|
+
code: "sandbox_command_start_unavailable",
|
|
4680
|
+
retryable: true
|
|
4681
|
+
};
|
|
4682
|
+
}
|
|
4497
4683
|
if (isCodexTransportError(error) && code === "invalid_sse_terminal") {
|
|
4498
4684
|
return {
|
|
4499
4685
|
error: "The Codex response stream ended without a terminal response",
|
|
@@ -4707,8 +4893,8 @@ var CODEX_USAGE_LIMIT_MAX_RESUME_MS = 60 * 6e4;
|
|
|
4707
4893
|
|
|
4708
4894
|
export {
|
|
4709
4895
|
createSharedActivityServices,
|
|
4896
|
+
codexAccountNeedsLiveCapacityRefresh,
|
|
4710
4897
|
classifyCodexPin,
|
|
4711
|
-
CODEX_USAGE_EXHAUSTED_PCT,
|
|
4712
4898
|
isCodexCredentialEligible,
|
|
4713
4899
|
shardCredentialForSession,
|
|
4714
4900
|
earliestCodexReset,
|
|
@@ -4768,11 +4954,14 @@ export {
|
|
|
4768
4954
|
shouldStartPeriodicWorkspaceSnapshot,
|
|
4769
4955
|
assertPhysicalToolQuiescenceForCancellation,
|
|
4770
4956
|
assertSessionAttemptQuiescenceRecoveryDurable,
|
|
4957
|
+
armTurnQuiescenceWatchdog,
|
|
4771
4958
|
persistOrSignalSessionAttemptQuiescence,
|
|
4772
4959
|
drainAttemptOwnedSandboxWriters,
|
|
4773
4960
|
releaseTurnSandboxAfterWriterDrain,
|
|
4774
4961
|
waitForTurnFinalizerStep,
|
|
4775
|
-
|
|
4962
|
+
assertSuccessfulAgentStreamCompletion,
|
|
4963
|
+
assertAgentStreamNotCancelled,
|
|
4964
|
+
requireAgentStreamFinalOutput,
|
|
4776
4965
|
clearAttemptCredentialsWithSettledFence,
|
|
4777
4966
|
turnFinalizerCancellationSignal,
|
|
4778
4967
|
runMandatoryHistoryPersistenceStep,
|
|
@@ -4782,12 +4971,14 @@ export {
|
|
|
4782
4971
|
providerRecoveryResult,
|
|
4783
4972
|
providerRecoveryExhaustedFailure,
|
|
4784
4973
|
providerRecoveryCountFromMetadata,
|
|
4974
|
+
providerRecoveryCountAfterModelRequestPhase,
|
|
4785
4975
|
providerRetryAfterMs,
|
|
4786
4976
|
unavailableMcpOperationalContext,
|
|
4787
4977
|
escapedMcpTimeoutRecoveryFailure,
|
|
4788
4978
|
preClaimAdmissionFailure,
|
|
4789
4979
|
postClaimDatabaseRecoveryFailure,
|
|
4790
4980
|
isWorkerShutdownCancellation,
|
|
4981
|
+
sandboxLifecycleTransitionDiagnostic,
|
|
4791
4982
|
sandboxRouteTransitionCode,
|
|
4792
4983
|
compactionFailureReason,
|
|
4793
4984
|
safeErrorDiagnostic,
|
|
@@ -4803,4 +4994,4 @@ export {
|
|
|
4803
4994
|
codexUsageLimitFailurePayload,
|
|
4804
4995
|
CODEX_USAGE_LIMIT_MAX_RESUME_MS
|
|
4805
4996
|
};
|
|
4806
|
-
//# sourceMappingURL=chunk-
|
|
4997
|
+
//# sourceMappingURL=chunk-S2QVRVJW.js.map
|