@opengeni/worker-bundle 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-turn.d.ts +24 -1
- package/dist/activities/run-input.d.ts +8 -0
- package/dist/activities/session-state.d.ts +5 -3
- package/dist/activities/types.d.ts +27 -0
- package/dist/{activities-control-XURE4VKN.js → activities-control-SMKF2OBE.js} +54 -7
- package/dist/{activities-control-XURE4VKN.js.map → activities-control-SMKF2OBE.js.map} +1 -1
- package/dist/activities-control.d.ts +2 -2
- package/dist/{activities-turn-6EBXGGLS.js → activities-turn-IDS3WEHA.js} +1471 -975
- package/dist/activities-turn-IDS3WEHA.js.map +1 -0
- package/dist/activities.d.ts +3 -3
- package/dist/{chunk-TYNPCG4U.js → chunk-N5TJIFCE.js} +69 -1
- package/dist/chunk-N5TJIFCE.js.map +1 -0
- package/dist/{chunk-5GRJIP5H.js → chunk-P6Z2SLAA.js} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/observability-metrics.d.ts +37 -0
- package/dist/workflow-bundle.js +174 -4
- package/dist/workflows/session.d.ts +17 -1
- package/package.json +11 -11
- package/src/activities/agent-turn.ts +1675 -1175
- package/src/activities/run-input.ts +137 -45
- package/src/activities/session-state.ts +69 -5
- package/src/activities/types.ts +27 -0
- package/src/activities.ts +2 -0
- package/src/observability-metrics.ts +184 -3
- package/src/workflows/session.ts +199 -8
- package/dist/activities-turn-6EBXGGLS.js.map +0 -1
- package/dist/chunk-TYNPCG4U.js.map +0 -1
- /package/dist/{chunk-5GRJIP5H.js.map → chunk-P6Z2SLAA.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AppendEventInput, type ActiveSandboxPointer, type SandboxRecord, type SessionAttemptQuiescenceCommit } from "@opengeni/db";
|
|
2
|
-
import { modelResponseServiceTierFromSdkEvent, modelTerminalResponseFromSdkEvent, type SandboxFileDownload, type ComputerToolMode, type ModelResponseUsage, type ModelCallUsageInput, type ModelCallUsageNormalization, type TurnToolCancellationFence, type BackendUnresolvableCode, type LazyToolTransport } from "@opengeni/runtime";
|
|
2
|
+
import { modelResponseServiceTierFromSdkEvent, modelTerminalResponseFromSdkEvent, type SandboxFileDownload, type SandboxFileDownloadFailure, type ComputerToolMode, type ModelResponseUsage, type ModelCallUsageInput, type ModelCallUsageNormalization, type TurnToolCancellationFence, type BackendUnresolvableCode, type LazyToolTransport } from "@opengeni/runtime";
|
|
3
3
|
import { resolveTurnExecutionPolicyV1, type ModelUsageInput, type ModelProviderApi, type RegistryProviderKind, type Settings } from "@opengeni/config";
|
|
4
4
|
import { ApplicationFailure, CancelledFailure } from "@temporalio/activity";
|
|
5
5
|
import type { CodexAccountStatus } from "@opengeni/db";
|
|
@@ -9,6 +9,7 @@ import { type CodemodeTokenRenewalController } from "./codemode-token-renewal.js
|
|
|
9
9
|
import { type ModelAttachmentInputPolicy } from "./run-input.js";
|
|
10
10
|
import type { TurnActivityServices as ActivityServices, EscapedMcpTimeoutRecoveryDetail, RunAgentTurnInput, RunAgentTurnResult, SessionAttemptQuiescenceProof } from "./types.js";
|
|
11
11
|
import { type ResumedTurnSandbox, type TurnSandboxLeaseHolderId } from "../sandbox-resume.js";
|
|
12
|
+
import { type TurnSandboxEstablishReason } from "../observability-metrics.js";
|
|
12
13
|
import { type LatencyMode, type SessionEvent, type SessionEventType, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1 } from "@opengeni/contracts";
|
|
13
14
|
export declare const PROVIDER_BACKPRESSURE_DELAY_MS = 60000;
|
|
14
15
|
export declare class WorkspaceHumanInputDisabledError extends Error {
|
|
@@ -75,6 +76,16 @@ export declare function escapedMcpTimeoutRecoveryFailure(input: {
|
|
|
75
76
|
modelRequestStarted: boolean;
|
|
76
77
|
detail: EscapedMcpTimeoutRecoveryDetail;
|
|
77
78
|
}): ApplicationFailure | null;
|
|
79
|
+
/**
|
|
80
|
+
* Convert the atomic claim transaction's failure into a small, stable
|
|
81
|
+
* Temporal wire contract. The original error remains in activity diagnostics,
|
|
82
|
+
* but SQL text, parameters, and arbitrary invariant messages never enter
|
|
83
|
+
* workflow history. Contention and operational database unavailability are
|
|
84
|
+
* safe to re-read after backoff because the claim transaction contains no
|
|
85
|
+
* model/tool effects; permanent database and state failures require terminal
|
|
86
|
+
* settlement.
|
|
87
|
+
*/
|
|
88
|
+
export declare function preClaimAdmissionFailure(error: unknown): ApplicationFailure;
|
|
78
89
|
/**
|
|
79
90
|
* Resolve which Codex account a turn runs on (multi-account P1): session-pin >
|
|
80
91
|
* workspace-active. No rotation in P1. The selected id must still be in the
|
|
@@ -88,6 +99,7 @@ export declare function selectCodexCredentialForTurn(args: {
|
|
|
88
99
|
connectedIds: Set<string>;
|
|
89
100
|
}): string | null;
|
|
90
101
|
export declare function filterUnmaterializedSandboxFileDownloads(downloads: SandboxFileDownload[], materializedFileIds: Set<string>): SandboxFileDownload[];
|
|
102
|
+
export declare function sandboxFileMaterializationOutcome(failures: readonly SandboxFileDownloadFailure[]): "completed" | "failed";
|
|
91
103
|
/** Fixed-length one-way tenant correlation for metrics/alerts; never a raw id. */
|
|
92
104
|
export declare function codexWorkspaceMetricKey(workspaceId: string): string;
|
|
93
105
|
/** Stable public request identity across partial resumes and activity retries. */
|
|
@@ -511,6 +523,17 @@ export declare function managedSandboxOwnershipForTurn(machinePrimary: boolean,
|
|
|
511
523
|
} | null;
|
|
512
524
|
/** A sandboxless home still establishes an explicitly attached Connected Machine. */
|
|
513
525
|
export declare function shouldEstablishSandboxForTurn(sandboxOwnershipEnabled: boolean, homeBackend: Settings["sandboxBackend"], machinePrimary: boolean): boolean;
|
|
526
|
+
export declare function sandboxEstablishPolicyDecision(input: {
|
|
527
|
+
lazyEnabled: boolean;
|
|
528
|
+
machinePrimary: boolean;
|
|
529
|
+
sandboxBackend: Settings["sandboxBackend"];
|
|
530
|
+
hasInitialRunCredentialMaterial: boolean;
|
|
531
|
+
generatedVideoFileCount: number;
|
|
532
|
+
hasSignedFileResources: boolean;
|
|
533
|
+
}): {
|
|
534
|
+
policy: "eager" | "on-demand";
|
|
535
|
+
reason: TurnSandboxEstablishReason;
|
|
536
|
+
};
|
|
514
537
|
/**
|
|
515
538
|
* Classify a persisted active-sandbox pointer for TURN-START RECONCILE (issue #341
|
|
516
539
|
* invariant B). Returns the typed reason to RESET the pointer to the session HOME,
|
|
@@ -32,6 +32,14 @@ export type TurnInputOptions = {
|
|
|
32
32
|
materializeSerializedRunState?: (serialized: string) => Promise<string>;
|
|
33
33
|
projectModelHistory?: ModelHistoryAttachmentProjector;
|
|
34
34
|
loadActiveHistory?: typeof getActiveSessionHistoryItemsPaged;
|
|
35
|
+
/** Bounded critical-path timings; telemetry failures never affect preparation. */
|
|
36
|
+
onPreparationPhase?: (measurement: HistoryPreparationPhaseMeasurement) => void;
|
|
37
|
+
};
|
|
38
|
+
export type HistoryPreparationPhase = "system_update_load" | "current_attachment_resolution" | "durable_history_load" | "sandbox_envelope_load" | "canonical_projection" | "provider_projection" | "attachment_ref_projection" | "screenshot_materialization" | "model_attachment_projection" | "runtime_input_assembly" | "artifact_candidate_scan";
|
|
39
|
+
export type HistoryPreparationPhaseMeasurement = {
|
|
40
|
+
phase: HistoryPreparationPhase;
|
|
41
|
+
outcome: "completed" | "failed";
|
|
42
|
+
durationSeconds: number;
|
|
35
43
|
};
|
|
36
44
|
export declare const MAX_INLINE_MODEL_ATTACHMENT_BYTES: number;
|
|
37
45
|
export type ModelAttachmentContent = {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { settleSessionAttemptInterruptions, applySessionTurnSettlement, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionInteractionIntervention as expireSessionInteractionInterventionDb, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
|
|
1
|
+
import { settleSessionAttemptInterruptions, applySessionTurnSettlement, enqueueSessionWorkflowWake, failSessionWorkBeforeAttemptClaim, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionInteractionIntervention as expireSessionInteractionInterventionDb, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
|
|
2
2
|
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
3
3
|
import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake.js";
|
|
4
4
|
import { recordTurnsQueuedGauge } from "../observability-metrics.js";
|
|
5
|
-
import type { ControlActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, ExpireSessionInteractionInterventionInput, ExpireSessionInteractionInterventionResult, PeekSessionWorkInput, FailSessionAttemptInput, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types.js";
|
|
5
|
+
import type { ControlActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, ExpireSessionInteractionInterventionInput, ExpireSessionInteractionInterventionResult, PeekSessionWorkInput, FailSessionAttemptInput, FailSessionAttemptResult, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types.js";
|
|
6
6
|
export type SessionStateActivityOverrides = Partial<{
|
|
7
7
|
settleSessionAttemptInterruptions: typeof settleSessionAttemptInterruptions;
|
|
8
8
|
applySessionTurnSettlement: typeof applySessionTurnSettlement;
|
|
9
|
+
enqueueSessionWorkflowWake: typeof enqueueSessionWorkflowWake;
|
|
10
|
+
failSessionWorkBeforeAttemptClaim: typeof failSessionWorkBeforeAttemptClaim;
|
|
9
11
|
requestSessionTurnRecovery: typeof requestSessionTurnRecovery;
|
|
10
12
|
recoverSessionDispatch: typeof recoverSessionDispatch;
|
|
11
13
|
reconcileSessionAttemptQuiescence: typeof reconcileSessionAttemptQuiescence;
|
|
@@ -26,7 +28,7 @@ export type SessionStateActivityOverrides = Partial<{
|
|
|
26
28
|
}>;
|
|
27
29
|
export declare const WORKER_DEATH_MAX_REDISPATCHES = 3;
|
|
28
30
|
export declare function createSessionStateActivities(services: () => Promise<ControlActivityServices>, overrides?: SessionStateActivityOverrides): {
|
|
29
|
-
failSessionAttempt: (input: FailSessionAttemptInput) => Promise<
|
|
31
|
+
failSessionAttempt: (input: FailSessionAttemptInput) => Promise<FailSessionAttemptResult>;
|
|
30
32
|
settleSessionInterruptions: (input: SettleSessionInterruptionsInput) => Promise<{
|
|
31
33
|
action: "paused" | "continue" | "stale";
|
|
32
34
|
}>;
|
|
@@ -170,8 +170,35 @@ export type FailSessionAttemptInput = {
|
|
|
170
170
|
workspaceId: string;
|
|
171
171
|
sessionId: string;
|
|
172
172
|
attemptId: string;
|
|
173
|
+
/** Added in v2; old Temporal histories derive the session's canonical id. */
|
|
174
|
+
workflowId?: string;
|
|
175
|
+
/** Added in v2; old Temporal histories use the bounded 60-second floor. */
|
|
176
|
+
retryDelayMs?: number;
|
|
177
|
+
/** Added in v3. Upgraded turn workers classify failures from the atomic
|
|
178
|
+
* admission transaction; omission is a rolling-deploy/legacy unknown and
|
|
179
|
+
* deliberately keeps the recoverable wake behavior. */
|
|
180
|
+
preClaimFailureDisposition?: PreClaimFailureDisposition;
|
|
181
|
+
/** The workflow admission trigger is required to re-evaluate the same
|
|
182
|
+
* durable admission branch before terminally settling a permanent failure. */
|
|
183
|
+
trigger?: RunAgentTurnInput["trigger"];
|
|
173
184
|
error?: string;
|
|
174
185
|
};
|
|
186
|
+
export type FailSessionAttemptResult = {
|
|
187
|
+
action: "failed";
|
|
188
|
+
} | {
|
|
189
|
+
action: "unclaimed";
|
|
190
|
+
} | {
|
|
191
|
+
action: "terminal";
|
|
192
|
+
} | {
|
|
193
|
+
action: "stale";
|
|
194
|
+
};
|
|
195
|
+
export type PreClaimFailureDisposition = "retryable" | "permanent";
|
|
196
|
+
export type PreClaimFailureDetail = {
|
|
197
|
+
disposition: PreClaimFailureDisposition;
|
|
198
|
+
code: "db_deadlock" | "db_serialization_failure" | "db_failure" | "claim_invariant";
|
|
199
|
+
};
|
|
200
|
+
export declare const PRE_CLAIM_FAILURE_TYPE = "OpenGeniPreClaimFailure";
|
|
201
|
+
export declare const PRE_CLAIM_FAILURE_MESSAGE = "Agent turn admission failed before attempt claim.";
|
|
175
202
|
export type RecoverDispatchInput = {
|
|
176
203
|
accountId: string;
|
|
177
204
|
workspaceId: string;
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
settingsWithRigImage,
|
|
24
24
|
withFirstPartyTools,
|
|
25
25
|
workflowIdForSession
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-P6Z2SLAA.js";
|
|
27
27
|
import {
|
|
28
28
|
recordCreditBalanceGauges,
|
|
29
29
|
recordCreditMicros,
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
recordSandboxOrphansTerminated,
|
|
40
40
|
recordSandboxRotationBacklogGauges,
|
|
41
41
|
recordTurnsQueuedGauge
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-N5TJIFCE.js";
|
|
43
43
|
|
|
44
44
|
// src/activities/browser-state-artifact-reaper.ts
|
|
45
45
|
import {
|
|
@@ -6861,6 +6861,8 @@ function maintenanceErrorCategory(error) {
|
|
|
6861
6861
|
import {
|
|
6862
6862
|
settleSessionAttemptInterruptions,
|
|
6863
6863
|
applySessionTurnSettlement,
|
|
6864
|
+
enqueueSessionWorkflowWake,
|
|
6865
|
+
failSessionWorkBeforeAttemptClaim,
|
|
6864
6866
|
requestSessionTurnRecovery,
|
|
6865
6867
|
recoverSessionDispatch,
|
|
6866
6868
|
reconcileSessionAttemptQuiescence,
|
|
@@ -6880,6 +6882,8 @@ var WORKER_DEATH_MAX_REDISPATCHES = 3;
|
|
|
6880
6882
|
function createSessionStateActivities(services, overrides = {}) {
|
|
6881
6883
|
const settleSessionAttemptInterruptionsFn = overrides.settleSessionAttemptInterruptions ?? settleSessionAttemptInterruptions;
|
|
6882
6884
|
const applySessionTurnSettlementFn = overrides.applySessionTurnSettlement ?? applySessionTurnSettlement;
|
|
6885
|
+
const enqueueSessionWorkflowWakeFn = overrides.enqueueSessionWorkflowWake ?? enqueueSessionWorkflowWake;
|
|
6886
|
+
const failSessionWorkBeforeAttemptClaimFn = overrides.failSessionWorkBeforeAttemptClaim ?? failSessionWorkBeforeAttemptClaim;
|
|
6883
6887
|
const requestSessionTurnRecoveryFn = overrides.requestSessionTurnRecovery ?? requestSessionTurnRecovery;
|
|
6884
6888
|
const recoverSessionDispatchFn = overrides.recoverSessionDispatch ?? recoverSessionDispatch;
|
|
6885
6889
|
const reconcileSessionAttemptQuiescenceFn = overrides.reconcileSessionAttemptQuiescence ?? reconcileSessionAttemptQuiescence;
|
|
@@ -6900,16 +6904,58 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
6900
6904
|
async function failSessionAttempt(input) {
|
|
6901
6905
|
const { db, bus, settings, observability, wakeSessionWorkflow } = await services();
|
|
6902
6906
|
const session = await requireSessionFn(db, input.workspaceId, input.sessionId);
|
|
6903
|
-
if (session.status === "failed") {
|
|
6904
|
-
return;
|
|
6907
|
+
if (session.status === "failed" || session.status === "cancelled") {
|
|
6908
|
+
return { action: "terminal" };
|
|
6905
6909
|
}
|
|
6910
|
+
const workflowId = input.workflowId ?? session.temporalWorkflowId ?? `session-${input.sessionId}`;
|
|
6906
6911
|
const turn = await getSessionTurnForAttemptFn(
|
|
6907
6912
|
db,
|
|
6908
6913
|
input.workspaceId,
|
|
6909
6914
|
input.sessionId,
|
|
6910
6915
|
input.attemptId
|
|
6911
6916
|
);
|
|
6912
|
-
if (!turn)
|
|
6917
|
+
if (!turn) {
|
|
6918
|
+
const attempt = await getSessionAttemptActivityRefFn(db, {
|
|
6919
|
+
accountId: input.accountId,
|
|
6920
|
+
workspaceId: input.workspaceId,
|
|
6921
|
+
sessionId: input.sessionId,
|
|
6922
|
+
attemptId: input.attemptId,
|
|
6923
|
+
temporalWorkflowId: workflowId
|
|
6924
|
+
});
|
|
6925
|
+
if (attempt) return { action: "stale" };
|
|
6926
|
+
if (input.preClaimFailureDisposition === "permanent" && input.trigger) {
|
|
6927
|
+
const failed = await failSessionWorkBeforeAttemptClaimFn(db, input.workspaceId, {
|
|
6928
|
+
accountId: input.accountId,
|
|
6929
|
+
sessionId: input.sessionId,
|
|
6930
|
+
workflowId,
|
|
6931
|
+
trigger: input.trigger,
|
|
6932
|
+
error: input.error ?? "Agent turn admission failed before attempt claim."
|
|
6933
|
+
});
|
|
6934
|
+
if (failed.action === "terminal") return { action: "terminal" };
|
|
6935
|
+
if (failed.action === "stale") return { action: "stale" };
|
|
6936
|
+
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, failed.events);
|
|
6937
|
+
if (failed.turnId) {
|
|
6938
|
+
await deliverFailedChildTurnToParentFn(
|
|
6939
|
+
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
6940
|
+
input.workspaceId,
|
|
6941
|
+
input.sessionId,
|
|
6942
|
+
failed.turnId
|
|
6943
|
+
);
|
|
6944
|
+
}
|
|
6945
|
+
return { action: "failed" };
|
|
6946
|
+
}
|
|
6947
|
+
const requestedRetryDelayMs = input.retryDelayMs;
|
|
6948
|
+
const retryDelayMs = typeof requestedRetryDelayMs === "number" && Number.isFinite(requestedRetryDelayMs) ? Math.max(1e3, Math.min(6e4, Math.trunc(requestedRetryDelayMs))) : 6e4;
|
|
6949
|
+
await enqueueSessionWorkflowWakeFn(db, {
|
|
6950
|
+
accountId: input.accountId,
|
|
6951
|
+
workspaceId: input.workspaceId,
|
|
6952
|
+
sessionId: input.sessionId,
|
|
6953
|
+
temporalWorkflowId: workflowId,
|
|
6954
|
+
reason: "turn_activity_failed_before_attempt_claim",
|
|
6955
|
+
notBefore: new Date(Date.now() + retryDelayMs)
|
|
6956
|
+
});
|
|
6957
|
+
return { action: "unclaimed" };
|
|
6958
|
+
}
|
|
6913
6959
|
const trigger = await getSessionEventFn(db, input.workspaceId, turn.triggerEventId);
|
|
6914
6960
|
const result = await applySessionTurnSettlementFn(db, input.workspaceId, {
|
|
6915
6961
|
sessionId: input.sessionId,
|
|
@@ -6932,7 +6978,7 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
6932
6978
|
]
|
|
6933
6979
|
});
|
|
6934
6980
|
if (result.action === "stale") {
|
|
6935
|
-
return;
|
|
6981
|
+
return { action: "stale" };
|
|
6936
6982
|
}
|
|
6937
6983
|
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
|
|
6938
6984
|
await deliverFailedChildTurnToParentFn(
|
|
@@ -6941,6 +6987,7 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
6941
6987
|
input.sessionId,
|
|
6942
6988
|
turn.id
|
|
6943
6989
|
);
|
|
6990
|
+
return { action: "failed" };
|
|
6944
6991
|
}
|
|
6945
6992
|
async function settleSessionInterruptions(input) {
|
|
6946
6993
|
const { db, bus, observability } = await services();
|
|
@@ -7218,4 +7265,4 @@ export {
|
|
|
7218
7265
|
createControlActivities,
|
|
7219
7266
|
createControlActivitiesFromServices
|
|
7220
7267
|
};
|
|
7221
|
-
//# sourceMappingURL=activities-control-
|
|
7268
|
+
//# sourceMappingURL=activities-control-SMKF2OBE.js.map
|