@opengeni/worker-bundle 0.24.2-canary.0 → 0.26.0-canary.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.
Files changed (83) hide show
  1. package/dist/activities/agent-turn/agent-build.d.ts +3 -10
  2. package/dist/activities/agent-turn/claim.d.ts +7 -0
  3. package/dist/activities/agent-turn/credential-leases.d.ts +8 -0
  4. package/dist/activities/agent-turn/errors.d.ts +6 -5
  5. package/dist/activities/agent-turn/failure-settlement.d.ts +43 -1
  6. package/dist/activities/agent-turn/history-prefix.d.ts +8 -0
  7. package/dist/activities/agent-turn/history-sink.d.ts +6 -2
  8. package/dist/activities/agent-turn/quiescence.d.ts +13 -8
  9. package/dist/activities/agent-turn/tool-environment.d.ts +2 -13
  10. package/dist/activities/agent-turn/tool-policy.d.ts +4 -0
  11. package/dist/activities/agent-turn/turn-context.d.ts +9 -1
  12. package/dist/activities/codemode-dispatcher.d.ts +10 -1
  13. package/dist/activities/codex-capacity.d.ts +32 -3
  14. package/dist/activities/codex-fleet-shadow.d.ts +1 -1
  15. package/dist/activities/codex-image-generation.d.ts +1 -1
  16. package/dist/activities/codex-rotation.d.ts +8 -67
  17. package/dist/activities/goals.d.ts +1 -1
  18. package/dist/activities/google-drive-publication.d.ts +2 -13
  19. package/dist/activities/image-generation-operation.d.ts +13 -4
  20. package/dist/activities/sandbox-lease.d.ts +7 -2
  21. package/dist/activities/session-state.d.ts +4 -2
  22. package/dist/activities/types.d.ts +11 -1
  23. package/dist/activities/xai-quota.d.ts +3 -0
  24. package/dist/{activities-control-ZWH7J4KZ.js → activities-control-KS3ZPQVY.js} +233 -88
  25. package/dist/activities-control-KS3ZPQVY.js.map +1 -0
  26. package/dist/activities-control.d.ts +2 -0
  27. package/dist/{activities-turn-I4OPLQLS.js → activities-turn-GHSFZB64.js} +1109 -1865
  28. package/dist/activities-turn-GHSFZB64.js.map +1 -0
  29. package/dist/activities.d.ts +2 -0
  30. package/dist/{chunk-65JEWP2Q.js → chunk-D4ZEFOYH.js} +1 -1
  31. package/dist/chunk-D4ZEFOYH.js.map +1 -0
  32. package/dist/{chunk-RQNH6CGR.js → chunk-O2LQWJIK.js} +3250 -2061
  33. package/dist/chunk-O2LQWJIK.js.map +1 -0
  34. package/dist/github-rest-mcp.d.ts +0 -2
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +2 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/observability-metrics.d.ts +1 -1
  39. package/dist/sandbox-routing.d.ts +6 -0
  40. package/dist/workflow-bundle.js +94 -9
  41. package/dist/workflows/activities.d.ts +1 -1
  42. package/dist/workflows/session.d.ts +3 -0
  43. package/package.json +17 -17
  44. package/src/activities/agent-turn/agent-build.ts +21 -26
  45. package/src/activities/agent-turn/claim.ts +26 -1
  46. package/src/activities/agent-turn/codex-capacity.ts +311 -234
  47. package/src/activities/agent-turn/credential-leases.ts +36 -0
  48. package/src/activities/agent-turn/errors.ts +73 -12
  49. package/src/activities/agent-turn/failure-settlement.ts +472 -331
  50. package/src/activities/agent-turn/history-prefix.ts +51 -0
  51. package/src/activities/agent-turn/history-sink.ts +30 -6
  52. package/src/activities/agent-turn/quiescence.ts +29 -17
  53. package/src/activities/agent-turn/run.ts +22 -5
  54. package/src/activities/agent-turn/stream-attempt.ts +35 -8
  55. package/src/activities/agent-turn/tool-environment.ts +42 -32
  56. package/src/activities/agent-turn/tool-policy.ts +14 -8
  57. package/src/activities/agent-turn/turn-context.ts +13 -0
  58. package/src/activities/agent-turn/xai-capacity.ts +11 -0
  59. package/src/activities/codemode-dispatcher.ts +235 -59
  60. package/src/activities/codex-capacity.ts +107 -10
  61. package/src/activities/codex-fleet-shadow.ts +8 -1
  62. package/src/activities/codex-image-generation.ts +19 -2
  63. package/src/activities/codex-rotation.ts +45 -142
  64. package/src/activities/goals.ts +9 -9
  65. package/src/activities/google-drive-publication.ts +4 -81
  66. package/src/activities/image-generation-operation.ts +28 -3
  67. package/src/activities/run-input.ts +6 -7
  68. package/src/activities/sandbox-lease.ts +246 -87
  69. package/src/activities/session-state.ts +20 -1
  70. package/src/activities/types.ts +16 -8
  71. package/src/activities/xai-quota.ts +35 -0
  72. package/src/activities.ts +1 -0
  73. package/src/github-rest-mcp.ts +0 -82
  74. package/src/observability-metrics.ts +4 -0
  75. package/src/sandbox-routing.ts +186 -16
  76. package/src/workflows/activities.ts +1 -0
  77. package/src/workflows/session.ts +114 -8
  78. package/dist/activities/api-integrations.d.ts +0 -21
  79. package/dist/activities-control-ZWH7J4KZ.js.map +0 -1
  80. package/dist/activities-turn-I4OPLQLS.js.map +0 -1
  81. package/dist/chunk-65JEWP2Q.js.map +0 -1
  82. package/dist/chunk-RQNH6CGR.js.map +0 -1
  83. package/src/activities/api-integrations.ts +0 -151
@@ -1,5 +1,5 @@
1
1
  import type * as activities from "../activities.js";
2
- type WorkflowControlActivities = Pick<typeof activities, "enqueueGoalRetryWake" | "expireSessionHumanInput" | "expireSessionInteractionIntervention" | "failSessionAttempt" | "getCodexCapacityWait" | "markSessionIdle" | "peekSessionWork" | "persistSessionAttemptQuiescence" | "reconcileSessionAttemptQuiescence" | "reconcileCodexCapacityWait" | "recoverDispatch" | "recoverEscapedMcpTimeout" | "settleSessionInterruptions">;
2
+ type WorkflowControlActivities = Pick<typeof activities, "enqueueGoalRetryWake" | "expireSessionHumanInput" | "expireSessionInteractionIntervention" | "failSessionAttempt" | "getCodexCapacityWait" | "markSessionIdle" | "peekSessionWork" | "persistSessionAttemptQuiescence" | "reconcileSessionAttemptQuiescence" | "reconcileCodexCapacityWait" | "recoverDispatch" | "recoverEscapedMcpTimeout" | "settleSessionInterruptions" | "settleSessionInputWait">;
3
3
  /**
4
4
  * Session/schedule workflow control activities are bounded, idempotent database
5
5
  * and provider-metadata operations. They must not inherit the agent turn's
@@ -21,6 +21,9 @@ export declare function continuationHoldMs(result: {
21
21
  * signal-version and interruption paths in `sessionWorkflow`.
22
22
  */
23
23
  export declare function deferredResultMayContinue(entryWakeups: number, currentWakeups: number): boolean;
24
+ /** A typed activity cancellation is recoverable unless its exact-attempt
25
+ * redispatch budget was atomically exhausted. */
26
+ export declare function cancelledAttemptRecoveryMayContinue(action: activities.RecoverDispatchResult["action"]): boolean;
24
27
  /**
25
28
  * Bound repeated failures that happen before an attempt row exists. The
26
29
  * activity mirrors this deterministic delay into the durable wake outbox, so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "0.24.2-canary.0",
3
+ "version": "0.26.0-canary.1",
4
4
  "description": "OpenGeni worker entry and reusable embedded lifecycle, shipped with a release-coherent pre-bundled Temporal workflow artifact.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -54,22 +54,22 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@llamaindex/liteparse": "2.14.2",
57
- "@opengeni/agent-proto": "^0.5.1-canary.8",
58
- "@opengeni/capabilities": "^0.3.1-canary.7",
59
- "@opengeni/codemode": "^0.4.25-canary.0",
60
- "@opengeni/codex": "^0.2.20-canary.2",
61
- "@opengeni/config": "^0.23.2-canary.0",
62
- "@opengeni/contracts": "^2.11.1-canary.0",
63
- "@opengeni/core": "^2.7.2-canary.0",
64
- "@opengeni/db": "^3.8.2-canary.0",
65
- "@opengeni/documents": "^0.8.17-canary.0",
66
- "@opengeni/events": "^0.4.15-canary.0",
67
- "@opengeni/github": "^0.7.1-canary.0",
68
- "@opengeni/network": "^0.2.3-canary.7",
69
- "@opengeni/observability": "^0.8.17-canary.0",
70
- "@opengeni/runtime": "^2.1.2-canary.0",
71
- "@opengeni/storage": "^0.2.118-canary.0",
72
- "@opengeni/xai-subscription": "^0.1.2-canary.7",
57
+ "@opengeni/agent-proto": "^0.5.1-canary.10",
58
+ "@opengeni/capabilities": "^0.3.2-canary.1",
59
+ "@opengeni/codemode": "^0.4.27-canary.1",
60
+ "@opengeni/codex": "^0.2.21-canary.1",
61
+ "@opengeni/config": "^1.0.0-canary.1",
62
+ "@opengeni/contracts": "^2.13.0-canary.1",
63
+ "@opengeni/core": "^2.7.5-canary.1",
64
+ "@opengeni/db": "^4.0.0-canary.1",
65
+ "@opengeni/documents": "^0.8.19-canary.1",
66
+ "@opengeni/events": "^0.4.17-canary.1",
67
+ "@opengeni/github": "^0.7.3-canary.1",
68
+ "@opengeni/network": "^0.3.0-canary.1",
69
+ "@opengeni/observability": "^0.8.19-canary.1",
70
+ "@opengeni/runtime": "^2.3.0-canary.1",
71
+ "@opengeni/storage": "^0.2.120-canary.1",
72
+ "@opengeni/xai-subscription": "^0.1.3-canary.1",
73
73
  "@temporalio/activity": "^1.17.0",
74
74
  "@temporalio/client": "^1.17.0",
75
75
  "@temporalio/worker": "^1.17.0",
@@ -6,9 +6,6 @@ import {
6
6
  setXaiSessionAccountPin,
7
7
  getWorkspaceVideoGenerationPolicy,
8
8
  loadWorkspaceVercelAiGatewayCredentialLease,
9
- beginConnectorActionExecution,
10
- completeConnectorActionExecution,
11
- prepareConnectorActionApproval,
12
9
  } from "@opengeni/db";
13
10
  import {
14
11
  type AttemptConnectorActionBinding,
@@ -128,15 +125,8 @@ export type BuildTurnAgentDeps = {
128
125
  sandboxCodemodeToken: string | undefined;
129
126
  fileResourceDownloads: SandboxFileDownload[];
130
127
  attemptConnectorActionBindings: readonly AttemptConnectorActionBinding[];
131
- connectorActionIdentity: {
132
- accountId: string;
133
- workspaceId: string;
134
- sessionId: string;
135
- turnId: string;
136
- attemptId: string;
137
- executionGeneration: number;
138
- initiator: Pick<ClaimTurnOk["turn"]["initiator"], "kind" | "subjectId">;
139
- };
128
+ connectorActionPolicy: ConnectorActionPolicyHooks;
129
+ trigger: ClaimTurnOk["trigger"];
140
130
  preparationIndependentToolNames: readonly string[];
141
131
  videoGenerationAcceptancesByCallId: Map<string, { operationId: string; requestDigest: string }>;
142
132
  activeSandboxBackend: Settings["sandboxBackend"] | undefined;
@@ -194,7 +184,8 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
194
184
  sandboxCodemodeToken,
195
185
  fileResourceDownloads,
196
186
  attemptConnectorActionBindings,
197
- connectorActionIdentity,
187
+ connectorActionPolicy,
188
+ trigger,
198
189
  preparationIndependentToolNames,
199
190
  videoGenerationAcceptancesByCallId,
200
191
  activeSandboxBackend,
@@ -567,19 +558,7 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
567
558
  turnExecutionPolicy.providerId,
568
559
  turnExecutionPolicy.latencyMode,
569
560
  );
570
- const connectorActionPolicy: ConnectorActionPolicyHooks = {
571
- prepare: async (call) =>
572
- await prepareConnectorActionApproval(db, connectorActionIdentity, call),
573
- begin: async (call) => await beginConnectorActionExecution(db, connectorActionIdentity, call),
574
- complete: async ({ requestId, outcome }) =>
575
- await completeConnectorActionExecution(db, {
576
- accountId: input.accountId,
577
- workspaceId: input.workspaceId,
578
- requestId,
579
- attemptId: input.attemptId,
580
- outcome,
581
- }),
582
- };
561
+ const approvedToolCallId = approvedConnectorActionCallId(trigger);
583
562
  const runtimeSkillActivations = [
584
563
  ...installedSkillRuntime.activations,
585
564
  ...packRuntime.skillActivations,
@@ -620,6 +599,7 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
620
599
  let agentConstructionOutcome: "completed" | "failed" = "completed";
621
600
  try {
622
601
  return runtime.buildAgent(eventing.modelRunSettings, runtimeResources, {
602
+ ...(preparedTools.inputWaitYield ? { inputWaitYield: preparedTools.inputWaitYield } : {}),
623
603
  reasoningEffort: turn.reasoningEffort,
624
604
  latencyMode: turnExecutionPolicy.latencyMode,
625
605
  ...(serviceTier ? { serviceTier } : {}),
@@ -669,6 +649,7 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
669
649
  resolvedMcpConnectionIds: preparedTools.resolvedMcpConnectionIds,
670
650
  connectorActionPolicy,
671
651
  attemptConnectorActionBindings,
652
+ ...(approvedToolCallId ? { approvedToolCallId } : {}),
672
653
  // LIVE by-reference connector namespaces (fills during this turn's
673
654
  // codex_apps tools/list): the codex tool_search description reads it per
674
655
  // model call so the model sees the account's real connected sources.
@@ -796,4 +777,18 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
796
777
  };
797
778
  }
798
779
 
780
+ function approvedConnectorActionCallId(trigger: ClaimTurnOk["trigger"]): string | null {
781
+ if (trigger.type !== "user.approvalDecision") {
782
+ return null;
783
+ }
784
+
785
+ const payload = trigger.payload as {
786
+ approvalId?: unknown;
787
+ decision?: unknown;
788
+ };
789
+ return payload.decision === "approve" && typeof payload.approvalId === "string"
790
+ ? payload.approvalId
791
+ : null;
792
+ }
793
+
799
794
  export type BuildTurnAgentOk = Awaited<ReturnType<typeof buildTurnAgent>>;
@@ -133,6 +133,23 @@ export function turnAttemptProducerId(
133
133
  return `${input.workflowId}:${turnId}:${input.attemptId}`;
134
134
  }
135
135
 
136
+ /**
137
+ * Durable Codex lease holder for one accepted turn attempt. Temporal activity
138
+ * ids may repeat after workflow restart or continue-as-new, so they are not
139
+ * owner identity. The attempt id is generated by the workflow for each
140
+ * redispatch and remains stable when the same activity input is retried.
141
+ */
142
+ export function codexCredentialLeaseHolderId(
143
+ input: Pick<RunAgentTurnInput, "workflowId" | "attemptId">,
144
+ turnId: string,
145
+ ): string {
146
+ const parts = [input.workflowId, turnId, input.attemptId];
147
+ if (parts.some((part) => part.trim().length === 0)) {
148
+ throw new Error("Codex credential lease holder requires a complete turn attempt identity");
149
+ }
150
+ return `codex-turn:${parts.map((part) => encodeURIComponent(part)).join(":")}`;
151
+ }
152
+
136
153
  export type ClaimTurnOutcome = { exit: RunAgentTurnResult } | { ok: ClaimTurnOk };
137
154
 
138
155
  export async function claimTurnAttempt(deps: ClaimTurnDeps): Promise<ClaimTurnOutcome> {
@@ -189,9 +206,15 @@ export async function claimTurnAttempt(deps: ClaimTurnDeps): Promise<ClaimTurnOu
189
206
  }
190
207
  const turn = claim.turn;
191
208
  attempt.turnId = turn.id;
209
+ attempt.dispatchId = dispatchId;
192
210
  attempt.executionGeneration = turn.executionGeneration;
193
211
  attempt.providerRecoveryCount = providerRecoveryCountFromMetadata(turn.metadata);
194
212
  attempt.triggerEventId = turn.triggerEventId;
213
+ // The durable attempt UUID is stable for a Temporal retry of this activity
214
+ // input and freshly generated for worker-death redispatch/continue-as-new.
215
+ // Keep dispatchId separate: it remains the Temporal activity identity used
216
+ // by attempt fencing, audit, and observability.
217
+ leases.codex.holderId = codexCredentialLeaseHolderId(input, turn.id);
195
218
  attempt.redispatchesAtDispatch = Number(
196
219
  (turn.metadata as { workerDeathRedispatches?: number } | null)?.workerDeathRedispatches ?? 0,
197
220
  );
@@ -375,7 +398,6 @@ export async function claimTurnAttempt(deps: ClaimTurnDeps): Promise<ClaimTurnOu
375
398
  const producerId = turnAttemptProducerId(input, attempt.turnId);
376
399
  // Fold the same durable attempt identity into positional usage source keys.
377
400
  // A retry dedupes; a re-dispatch cannot collide with the prior attempt.
378
- leases.codex.holderId = dispatchId;
379
401
  const modelUsageDispatchId = input.attemptId;
380
402
  const claimedModelUsageSourceKeys = new Set<string>();
381
403
  const emittedModelUsageSourceKeys = new Set<string>();
@@ -472,6 +494,9 @@ export async function claimTurnAttempt(deps: ClaimTurnDeps): Promise<ClaimTurnOu
472
494
  turnStatus: inputSettlement.turnStatus,
473
495
  sessionStatus: inputSettlement.sessionStatus,
474
496
  activeTurnId: inputSettlement.activeTurnId,
497
+ ...(inputSettlement.suppressGoalContinuation !== undefined
498
+ ? { suppressGoalContinuation: inputSettlement.suppressGoalContinuation }
499
+ : {}),
475
500
  events: inputs,
476
501
  ...(runState ? { runState } : {}),
477
502
  ...(compactionRequestFailure ? { compactionRequestFailure } : {}),