@opengeni/worker-bundle 0.22.4-canary.2 → 0.22.7-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/errors.d.ts +20 -0
- package/dist/activities/agent-turn/governance-model.d.ts +9 -0
- package/dist/activities/agent-turn/image-reference-sandbox.d.ts +14 -0
- package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +8 -0
- package/dist/activities/generated-images.d.ts +3 -1
- package/dist/activities/image-generation-references.d.ts +39 -7
- package/dist/activities/sandbox-lease.d.ts +12 -0
- package/dist/activities/types.d.ts +24 -0
- package/dist/{activities-control-4XVBA3Q5.js → activities-control-VZIIV7RX.js} +77 -12
- package/dist/activities-control-VZIIV7RX.js.map +1 -0
- package/dist/{activities-turn-J3CR27E6.js → activities-turn-5RGQDBFV.js} +253 -51
- package/dist/activities-turn-5RGQDBFV.js.map +1 -0
- package/dist/{chunk-FA35XBBC.js → chunk-NAVSAZ56.js} +1 -1
- package/dist/chunk-NAVSAZ56.js.map +1 -0
- package/dist/{chunk-XWQPS6GG.js → chunk-O4HDX5SC.js} +59 -10
- package/dist/{chunk-XWQPS6GG.js.map → chunk-O4HDX5SC.js.map} +1 -1
- package/dist/index.js +2 -2
- package/dist/observability-metrics.d.ts +1 -1
- package/dist/workflow-bundle.js +62 -9
- package/dist/workflows/session.d.ts +4 -1
- package/package.json +17 -17
- package/src/activities/agent-turn/agent-build.ts +29 -18
- package/src/activities/agent-turn/claim.ts +6 -6
- package/src/activities/agent-turn/errors.ts +104 -21
- package/src/activities/agent-turn/failure-settlement.ts +40 -0
- package/src/activities/agent-turn/governance-model.ts +31 -4
- package/src/activities/agent-turn/history.ts +7 -3
- package/src/activities/agent-turn/image-reference-sandbox.ts +35 -0
- package/src/activities/agent-turn/provider-dispatch-barrier.ts +13 -0
- package/src/activities/agent-turn/run.ts +7 -0
- package/src/activities/agent-turn/stream-attempt.ts +25 -2
- package/src/activities/generated-images.ts +5 -2
- package/src/activities/image-generation-references.ts +184 -37
- package/src/activities/sandbox-lease.ts +48 -9
- package/src/activities/session-state.ts +69 -1
- package/src/activities/types.ts +26 -0
- package/src/observability-metrics.ts +2 -0
- package/src/workflows/session.ts +95 -21
- package/dist/activities-control-4XVBA3Q5.js.map +0 -1
- package/dist/activities-turn-J3CR27E6.js.map +0 -1
- package/dist/chunk-FA35XBBC.js.map +0 -1
package/src/workflows/session.ts
CHANGED
|
@@ -16,9 +16,13 @@ import type * as activities from "../activities";
|
|
|
16
16
|
import {
|
|
17
17
|
ESCAPED_MCP_TIMEOUT_RECOVERY_FAILURE_MESSAGE,
|
|
18
18
|
ESCAPED_MCP_TIMEOUT_RECOVERY_FAILURE_TYPE,
|
|
19
|
+
POST_CLAIM_DATABASE_RECOVERY_FAILURE_MESSAGE,
|
|
20
|
+
POST_CLAIM_DATABASE_RECOVERY_FAILURE_TYPE,
|
|
19
21
|
PRE_CLAIM_FAILURE_MESSAGE,
|
|
20
22
|
PRE_CLAIM_FAILURE_TYPE,
|
|
21
23
|
type EscapedMcpTimeoutRecoveryDetail,
|
|
24
|
+
type PostClaimDatabaseRecoveryDetail,
|
|
25
|
+
type PreClaimFailureDetail,
|
|
22
26
|
type PreClaimFailureDisposition,
|
|
23
27
|
} from "../activities/types";
|
|
24
28
|
import {
|
|
@@ -205,7 +209,7 @@ export function escapedMcpTimeoutRecoveryDetail(
|
|
|
205
209
|
}
|
|
206
210
|
|
|
207
211
|
/** Read only the upgraded turn worker's explicit pre-claim wire contract. */
|
|
208
|
-
export function
|
|
212
|
+
export function preClaimFailureDetail(error: unknown): PreClaimFailureDetail | undefined {
|
|
209
213
|
if (!(error instanceof ActivityFailure) || error.activityType !== "runAgentTurn") {
|
|
210
214
|
return undefined;
|
|
211
215
|
}
|
|
@@ -235,7 +239,55 @@ export function preClaimFailureDisposition(error: unknown): PreClaimFailureDispo
|
|
|
235
239
|
return undefined;
|
|
236
240
|
}
|
|
237
241
|
if (detail.code === "claim_invariant" && disposition !== "permanent") return undefined;
|
|
238
|
-
return disposition;
|
|
242
|
+
return { disposition, code: detail.code };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function preClaimFailureDisposition(error: unknown): PreClaimFailureDisposition | undefined {
|
|
246
|
+
return preClaimFailureDetail(error)?.disposition;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Read only the upgraded turn worker's exact post-claim DB recovery wire. */
|
|
250
|
+
export function postClaimDatabaseRecoveryDetail(
|
|
251
|
+
error: unknown,
|
|
252
|
+
): PostClaimDatabaseRecoveryDetail | null {
|
|
253
|
+
if (!(error instanceof ActivityFailure) || error.activityType !== "runAgentTurn") {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
const cause = error.cause;
|
|
257
|
+
if (
|
|
258
|
+
!(cause instanceof ApplicationFailure) ||
|
|
259
|
+
cause.type !== POST_CLAIM_DATABASE_RECOVERY_FAILURE_TYPE ||
|
|
260
|
+
cause.message !== POST_CLAIM_DATABASE_RECOVERY_FAILURE_MESSAGE
|
|
261
|
+
) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
const detail = cause.details?.[0] as Partial<PostClaimDatabaseRecoveryDetail> | undefined;
|
|
265
|
+
if (
|
|
266
|
+
typeof detail?.turnId !== "string" ||
|
|
267
|
+
detail.turnId.length === 0 ||
|
|
268
|
+
typeof detail.triggerEventId !== "string" ||
|
|
269
|
+
detail.triggerEventId.length === 0 ||
|
|
270
|
+
!Number.isSafeInteger(detail.executionGeneration) ||
|
|
271
|
+
(detail.executionGeneration ?? 0) < 1 ||
|
|
272
|
+
(detail.code !== "db_deadlock" &&
|
|
273
|
+
detail.code !== "db_serialization_failure" &&
|
|
274
|
+
detail.code !== "db_failure")
|
|
275
|
+
) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
const hasProviderRecoveryCount = detail.providerRecoveryCount !== undefined;
|
|
279
|
+
const hasProviderFailureCode = detail.providerFailureCode !== undefined;
|
|
280
|
+
if (
|
|
281
|
+
hasProviderRecoveryCount !== hasProviderFailureCode ||
|
|
282
|
+
(hasProviderRecoveryCount &&
|
|
283
|
+
(!Number.isSafeInteger(detail.providerRecoveryCount) ||
|
|
284
|
+
(detail.providerRecoveryCount ?? 0) <= 0 ||
|
|
285
|
+
typeof detail.providerFailureCode !== "string" ||
|
|
286
|
+
!/^[a-z][a-z0-9_]{0,63}$/.test(detail.providerFailureCode)))
|
|
287
|
+
) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return detail as PostClaimDatabaseRecoveryDetail;
|
|
239
291
|
}
|
|
240
292
|
|
|
241
293
|
/**
|
|
@@ -911,17 +963,23 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
|
|
|
911
963
|
return true;
|
|
912
964
|
}
|
|
913
965
|
const retryDelayMs = unclaimedAttemptRetryDelayMs(unclaimedAttemptFailures + 1);
|
|
914
|
-
const
|
|
966
|
+
const admissionFailure = preClaimFailureDetail(outcome.error);
|
|
967
|
+
const admissionFailureDisposition = admissionFailure?.disposition;
|
|
968
|
+
const classifiedPostClaimDatabaseRecovery = patched("session-postclaim-database-recovery-v1");
|
|
969
|
+
const postClaimDatabaseRecovery = classifiedPostClaimDatabaseRecovery
|
|
970
|
+
? postClaimDatabaseRecoveryDetail(outcome.error)
|
|
971
|
+
: null;
|
|
915
972
|
// Keep this marker immediately adjacent to the changed command. A
|
|
916
|
-
// history that already recorded the
|
|
917
|
-
// an open history that has never reached this branch can record
|
|
973
|
+
// history that already recorded the v3 activity replays the old shape;
|
|
974
|
+
// an open history that has never reached this branch can record v4.
|
|
918
975
|
const classifiedPreClaimFailure = patched("session-preclaim-failure-classification-v1");
|
|
919
|
-
const retryWakeBaseline =
|
|
920
|
-
|
|
921
|
-
|
|
976
|
+
const retryWakeBaseline =
|
|
977
|
+
classifiedPostClaimDatabaseRecovery || classifiedPreClaimFailure
|
|
978
|
+
? preDispatchRetryWakeBaseline
|
|
979
|
+
: postDispatchRetryWakeBaseline;
|
|
922
980
|
const failure: activities.FailSessionAttemptResult | undefined =
|
|
923
981
|
await activity.failSessionAttempt(
|
|
924
|
-
|
|
982
|
+
classifiedPostClaimDatabaseRecovery
|
|
925
983
|
? {
|
|
926
984
|
accountId,
|
|
927
985
|
workspaceId,
|
|
@@ -932,20 +990,36 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
|
|
|
932
990
|
...(admissionFailureDisposition
|
|
933
991
|
? { preClaimFailureDisposition: admissionFailureDisposition }
|
|
934
992
|
: {}),
|
|
993
|
+
...(admissionFailure ? { preClaimFailure: admissionFailure } : {}),
|
|
994
|
+
...(postClaimDatabaseRecovery ? { postClaimDatabaseRecovery } : {}),
|
|
935
995
|
trigger,
|
|
936
996
|
error: workflowFailureMessage(outcome.error),
|
|
937
997
|
}
|
|
938
|
-
:
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
998
|
+
: classifiedPreClaimFailure
|
|
999
|
+
? {
|
|
1000
|
+
accountId,
|
|
1001
|
+
workspaceId,
|
|
1002
|
+
sessionId,
|
|
1003
|
+
attemptId,
|
|
1004
|
+
workflowId: workflowInfo().workflowId,
|
|
1005
|
+
retryDelayMs,
|
|
1006
|
+
...(admissionFailureDisposition
|
|
1007
|
+
? { preClaimFailureDisposition: admissionFailureDisposition }
|
|
1008
|
+
: {}),
|
|
1009
|
+
trigger,
|
|
1010
|
+
error: workflowFailureMessage(outcome.error),
|
|
1011
|
+
}
|
|
1012
|
+
: {
|
|
1013
|
+
// Replay the exact v2 command shape. Adding optional fields to
|
|
1014
|
+
// a Temporal activity argument still changes command history.
|
|
1015
|
+
accountId,
|
|
1016
|
+
workspaceId,
|
|
1017
|
+
sessionId,
|
|
1018
|
+
attemptId,
|
|
1019
|
+
workflowId: workflowInfo().workflowId,
|
|
1020
|
+
retryDelayMs,
|
|
1021
|
+
error: workflowFailureMessage(outcome.error),
|
|
1022
|
+
},
|
|
949
1023
|
);
|
|
950
1024
|
// During a rolling deploy an upgraded workflow worker can schedule this
|
|
951
1025
|
// activity on a legacy control worker whose wire result was void. Treat
|
|
@@ -953,7 +1027,7 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
|
|
|
953
1027
|
// re-read durable state. A legacy worker that settled the failure leaves
|
|
954
1028
|
// an idle turn; one that no-op'd before claim leaves recoverable work.
|
|
955
1029
|
// Neither path replays model or tool side effects speculatively.
|
|
956
|
-
if (!failure || failure.action === "unclaimed") {
|
|
1030
|
+
if (!failure || failure.action === "unclaimed" || failure.action === "recovering") {
|
|
957
1031
|
unclaimedAttemptFailures += 1;
|
|
958
1032
|
await condition(() => {
|
|
959
1033
|
const current = {
|