@opengeni/worker-bundle 0.7.1 → 0.7.3

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 (44) hide show
  1. package/dist/index.d.ts +184 -68
  2. package/dist/index.js +7099 -1643
  3. package/dist/index.js.map +1 -1
  4. package/package.json +18 -18
  5. package/src/activities/agent-turn.ts +4332 -1068
  6. package/src/activities/capabilities.ts +43 -8
  7. package/src/activities/codex-capacity.ts +223 -0
  8. package/src/activities/codex-rotation.ts +550 -54
  9. package/src/activities/common.ts +14 -2
  10. package/src/activities/context-compaction.ts +152 -118
  11. package/src/activities/documents.ts +32 -27
  12. package/src/activities/environment.ts +318 -75
  13. package/src/activities/file-upload-reaper.ts +79 -0
  14. package/src/activities/git-credential-renewal.ts +183 -0
  15. package/src/activities/goals.ts +142 -123
  16. package/src/activities/packs.ts +55 -5
  17. package/src/activities/parent-wake.ts +216 -42
  18. package/src/activities/recording.ts +154 -122
  19. package/src/activities/redaction.ts +3 -1
  20. package/src/activities/rig-verification.ts +441 -0
  21. package/src/activities/run-input.ts +110 -122
  22. package/src/activities/sandbox-lease.ts +186 -51
  23. package/src/activities/scheduled-tasks.ts +287 -171
  24. package/src/activities/session-state.ts +165 -157
  25. package/src/activities/streaming.ts +143 -19
  26. package/src/activities/turn-attempt-fenced.ts +14 -0
  27. package/src/activities/types.ts +106 -36
  28. package/src/activities/workflow-wake.ts +44 -0
  29. package/src/activities/workspace-capture.ts +964 -0
  30. package/src/activities.ts +75 -35
  31. package/src/concurrency.ts +11 -0
  32. package/src/http.ts +16 -6
  33. package/src/index.ts +322 -49
  34. package/src/observability-metrics.ts +441 -8
  35. package/src/op-journal.ts +46 -0
  36. package/src/sandbox-resume.ts +431 -201
  37. package/src/sandbox-routing.ts +209 -22
  38. package/src/workflows/activities.ts +65 -8
  39. package/src/workflows/file-upload-reaper.ts +12 -0
  40. package/src/workflows/rig-verification.ts +28 -0
  41. package/src/workflows/scheduled-tasks.ts +12 -26
  42. package/src/workflows/session.ts +330 -192
  43. package/src/workflows/workflow-wake.ts +13 -0
  44. package/src/workflows.ts +9 -7
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Settings } from '@opengeni/config';
2
+ import * as _opengeni_db from '@opengeni/db';
3
+ import { Database } from '@opengeni/db';
2
4
  import { Observability } from '@opengeni/observability';
3
5
  import { Worker, NativeConnection } from '@temporalio/worker';
4
6
  import { EntitlementsPort, ConnectionCredentialsPort, ScheduledTaskTriggerType } from '@opengeni/contracts';
5
- import { Database } from '@opengeni/db';
6
7
  import { DocumentServices } from '@opengeni/documents';
7
8
  import { EventBus } from '@opengeni/events';
8
9
  import { OpenGeniRuntime } from '@opengeni/runtime';
@@ -13,6 +14,15 @@ type WakeSessionWorkflowSignal = (input: {
13
14
  workspaceId: string;
14
15
  sessionId: string;
15
16
  workflowId: string;
17
+ wakeRevision: number;
18
+ interruptionRequested?: boolean;
19
+ }) => Promise<void>;
20
+ type SignalCodexCapacityWorkflow = (input: {
21
+ accountId: string;
22
+ workspaceId: string;
23
+ sessionId: string;
24
+ workflowId: string;
25
+ wakeRevision: number;
16
26
  }) => Promise<void>;
17
27
  type ActivityServices = {
18
28
  settings: Settings;
@@ -23,39 +33,89 @@ type ActivityServices = {
23
33
  documentServices: DocumentServices;
24
34
  observability: Observability;
25
35
  wakeSessionWorkflow: WakeSessionWorkflowSignal | null;
36
+ /** Revision-carrying capacity nudge; generic outbox repair is also sufficient. */
37
+ signalCodexCapacityWorkflow?: SignalCodexCapacityWorkflow | null;
26
38
  entitlements?: EntitlementsPort | null;
27
39
  connectionCredentials?: ConnectionCredentialsPort | null;
28
40
  };
41
+ type CodexCapacityWaitRef = {
42
+ waiterId: string;
43
+ generation: number;
44
+ nextCheckAt: string;
45
+ wakeRevision: number;
46
+ };
47
+ type GetCodexCapacityWaitInput = {
48
+ workspaceId: string;
49
+ sessionId: string;
50
+ };
51
+ type ReconcileCodexCapacityWaitInput = {
52
+ accountId: string;
53
+ workspaceId: string;
54
+ sessionId: string;
55
+ waiterId: string;
56
+ generation: number;
57
+ cause: "timer" | "signal" | "queue" | "recovery";
58
+ };
59
+ type ReconcileCodexCapacityWaitResult = ({
60
+ action: "waiting";
61
+ } & CodexCapacityWaitRef) | {
62
+ action: "resumed";
63
+ updateId: string;
64
+ } | {
65
+ action: "superseded" | "stale";
66
+ };
29
67
  type ActivityDependencies = Partial<ActivityServices>;
30
68
  type RunAgentTurnInput = {
31
69
  accountId: string;
32
70
  workspaceId: string;
33
71
  sessionId: string;
34
- triggerEventId: string;
35
72
  workflowId: string;
36
- turnId?: string;
73
+ workflowRunId: string;
74
+ attemptId: string;
75
+ trigger: {
76
+ kind: "next";
77
+ } | {
78
+ kind: "approval";
79
+ triggerEventId: string;
80
+ };
37
81
  };
38
- type RequeueTurnAfterWorkerDeathInput = {
82
+ type SettleSessionInterruptionsInput = {
39
83
  accountId: string;
40
84
  workspaceId: string;
41
85
  sessionId: string;
42
- triggerEventId: string;
86
+ attemptId: string;
43
87
  workflowId: string;
44
- turnId: string;
45
88
  };
46
- type RequeueTurnAfterWorkerDeathResult = {
47
- action: "requeued";
89
+ type FailSessionAttemptInput = {
90
+ accountId: string;
91
+ workspaceId: string;
92
+ sessionId: string;
93
+ attemptId: string;
94
+ error?: string;
95
+ };
96
+ type RecoverDispatchInput = {
97
+ accountId: string;
98
+ workspaceId: string;
99
+ sessionId: string;
100
+ attemptId: string;
101
+ timeoutType: "HEARTBEAT" | "SCHEDULE_TO_START";
102
+ };
103
+ type RecoverDispatchResult = {
104
+ action: "unclaimed";
105
+ } | {
106
+ action: "recovering";
107
+ turnId: string;
48
108
  redispatches: number;
49
109
  } | {
50
110
  action: "stale";
51
111
  } | {
52
112
  action: "exceeded";
113
+ turnId: string;
53
114
  redispatches: number;
54
115
  };
55
- type ClaimNextQueuedTurnInput = {
116
+ type PeekSessionWorkInput = {
56
117
  workspaceId: string;
57
118
  sessionId: string;
58
- workflowId: string;
59
119
  };
60
120
  type MarkSessionIdleInput = {
61
121
  workspaceId: string;
@@ -70,15 +130,12 @@ type MaybeContinueGoalInput = {
70
130
  type MaybeContinueGoalResult = {
71
131
  action: "none" | "queue" | "continue" | "paused";
72
132
  };
73
- type PauseGoalForInterruptInput = {
74
- workspaceId: string;
75
- sessionId: string;
76
- triggerEventId?: string;
77
- };
78
133
  type DispatchScheduledTaskRunInput = {
79
134
  workspaceId: string;
80
135
  taskId: string;
81
136
  triggerType: ScheduledTaskTriggerType;
137
+ /** Stable Temporal workflow identity; retries must reuse the same source row. */
138
+ producerKey?: string;
82
139
  agentRunUsageIdempotencyKey?: string;
83
140
  };
84
141
  type DispatchScheduledTaskRunResult = {
@@ -88,16 +145,38 @@ type DispatchScheduledTaskRunResult = {
88
145
  sessionId: string;
89
146
  triggerEventId: string;
90
147
  workflowId: string;
148
+ workflowWakeRevision: number | null;
91
149
  };
92
150
  type IndexDocumentInput = {
93
151
  accountId: string;
94
152
  workspaceId: string;
95
153
  documentId: string;
96
154
  };
97
- type RunAgentTurnResult = {
98
- status: "idle" | "requires_action" | "failed" | "cancelled" | "preempted";
155
+ type ClaimedRunAgentTurnResult = {
156
+ status: "idle" | "requires_action" | "failed" | "cancelled" | "recovering";
157
+ turnId: string;
158
+ attemptId: string;
99
159
  continueDelayMs?: number;
100
160
  idleUntilReset?: boolean;
161
+ capacityWait?: CodexCapacityWaitRef;
162
+ deferredUntilWake?: boolean;
163
+ };
164
+ type RunAgentTurnResult = ClaimedRunAgentTurnResult | {
165
+ status: "unclaimed";
166
+ reason: "gate-closed" | "no-work" | "stale-approval" | "control-pending";
167
+ };
168
+
169
+ type ReapExpiredFileUploadsResult = {
170
+ claimed: number;
171
+ deleted: number;
172
+ failed: number;
173
+ };
174
+
175
+ type DispatchSessionWorkflowWakesResult = {
176
+ claimed: number;
177
+ delivered: number;
178
+ failed: number;
179
+ exhaustedBatchLimit: boolean;
101
180
  };
102
181
 
103
182
  type ReapSandboxLeasesResult = {
@@ -119,54 +198,66 @@ type ReapSandboxLeasesResult = {
119
198
  modalOrphansTerminated: number;
120
199
  };
121
200
 
122
- declare function createActivities(dependencies?: ActivityDependencies): {
201
+ declare function createControlActivities(dependencies?: ActivityDependencies): {
123
202
  reapSandboxLeases: () => Promise<ReapSandboxLeasesResult>;
124
- maybeContinueGoal: (input: MaybeContinueGoalInput) => Promise<MaybeContinueGoalResult>;
125
- pauseGoalForInterrupt: (input: PauseGoalForInterruptInput) => Promise<void>;
126
- dispatchScheduledTaskRun: (input: DispatchScheduledTaskRunInput) => Promise<DispatchScheduledTaskRunResult>;
127
- failSession: (input: RunAgentTurnInput & {
128
- error?: string;
129
- }) => Promise<void>;
130
- interruptActiveTurn: (input: RunAgentTurnInput) => Promise<void>;
131
- requeueTurnAfterWorkerDeath: (input: RequeueTurnAfterWorkerDeathInput) => Promise<RequeueTurnAfterWorkerDeathResult>;
132
- claimNextQueuedTurn: (input: ClaimNextQueuedTurnInput) => Promise<{
133
- id: string;
203
+ dispatchSessionWorkflowWakes(): Promise<DispatchSessionWorkflowWakesResult>;
204
+ reapExpiredFileUploads: () => Promise<ReapExpiredFileUploadsResult>;
205
+ verifyRigChange: (input: {
134
206
  workspaceId: string;
135
- sessionId: string;
136
- triggerEventId: string;
137
- temporalWorkflowId: string;
138
- status: "queued" | "running" | "requires_action" | "failed" | "cancelled" | "completed";
139
- source: "user" | "scheduled_task" | "api" | "goal";
140
- position: number;
141
- prompt: string;
142
- resources: ({
143
- kind: "repository";
144
- uri: string;
145
- ref: string;
146
- mountPath?: string | undefined;
147
- subpath?: string | undefined;
148
- githubInstallationId?: number | undefined;
149
- githubRepositoryId?: number | undefined;
150
- } | {
151
- kind: "file";
152
- fileId: string;
153
- mountPath?: string | undefined;
154
- })[];
155
- tools: {
156
- kind: "mcp";
157
- id: string;
158
- optional?: boolean | undefined;
159
- }[];
160
- model: string;
161
- reasoningEffort: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
162
- sandboxBackend: "local" | "none" | "docker" | "modal" | "daytona" | "runloop" | "e2b" | "blaxel" | "cloudflare" | "vercel" | "selfhosted";
163
- sandboxOs: "linux" | "macos" | "windows" | null;
164
- metadata: Record<string, unknown>;
165
- startedAt: string | null;
166
- finishedAt: string | null;
207
+ changeId: string;
208
+ }) => Promise<{
209
+ id: string;
210
+ rigId: string;
211
+ baseVersionId: string | null;
212
+ kind: "setup_append" | "definition_edit";
213
+ payload: Record<string, unknown>;
214
+ status: "failed" | "proposed" | "rejected" | "verifying" | "merged";
215
+ proposedBy: string | null;
216
+ verification: {
217
+ [x: string]: unknown;
218
+ startedAt?: string | undefined;
219
+ finishedAt?: string | undefined;
220
+ log?: string | undefined;
221
+ checkResults?: {
222
+ name: string;
223
+ command: string;
224
+ exitCode: number | null;
225
+ output?: string | undefined;
226
+ }[] | undefined;
227
+ } | null;
228
+ resultVersionId: string | null;
167
229
  createdAt: string;
168
230
  updatedAt: string;
231
+ }>;
232
+ verifyRigVersion: (input: {
233
+ workspaceId: string;
234
+ versionId: string;
235
+ }) => Promise<{
236
+ versionId: string;
237
+ passed: boolean;
238
+ checkResults: {
239
+ exitCode: number | null;
240
+ output: string;
241
+ name: string;
242
+ command: string;
243
+ }[];
244
+ }>;
245
+ getCodexCapacityWait: (input: GetCodexCapacityWaitInput) => Promise<{
246
+ waiterId: string;
247
+ generation: number;
248
+ nextCheckAt: string;
249
+ wakeRevision: number;
169
250
  } | null>;
251
+ reconcileCodexCapacityWait: (input: ReconcileCodexCapacityWaitInput) => Promise<ReconcileCodexCapacityWaitResult>;
252
+ enqueueGoalRetryWake: (input: MaybeContinueGoalInput) => Promise<void>;
253
+ maybeContinueGoal: (input: MaybeContinueGoalInput) => Promise<MaybeContinueGoalResult>;
254
+ dispatchScheduledTaskRun: (input: DispatchScheduledTaskRunInput) => Promise<DispatchScheduledTaskRunResult>;
255
+ failSessionAttempt: (input: FailSessionAttemptInput) => Promise<void>;
256
+ settleSessionInterruptions: (input: SettleSessionInterruptionsInput) => Promise<{
257
+ action: "paused" | "continue" | "stale";
258
+ }>;
259
+ recoverDispatch: (input: RecoverDispatchInput) => Promise<RecoverDispatchResult>;
260
+ peekSessionWork: (input: PeekSessionWorkInput) => Promise<_opengeni_db.SessionWorkPeek>;
170
261
  markSessionIdle: (input: MarkSessionIdleInput) => Promise<void>;
171
262
  indexDocument: (input: IndexDocumentInput) => Promise<{
172
263
  id: string;
@@ -190,30 +281,36 @@ declare function createActivities(dependencies?: ActivityDependencies): {
190
281
  createdAt: string;
191
282
  updatedAt: string;
192
283
  }>;
284
+ };
285
+ declare function createTurnActivities(dependencies?: ActivityDependencies): {
193
286
  runAgentTurn: (input: RunAgentTurnInput) => Promise<RunAgentTurnResult>;
194
- runAgentSegment: (input: RunAgentTurnInput) => Promise<RunAgentTurnResult>;
195
287
  };
196
288
 
289
+ declare const FILE_UPLOAD_REAPER_SCHEDULE_ID = "opengeni-file-upload-reaper";
290
+ declare const FILE_UPLOAD_REAPER_PERIOD_MS: number;
291
+ type OpenGeniWorkerRole = "control" | "turn";
197
292
  type WorkerOptions = {
293
+ role: OpenGeniWorkerRole;
198
294
  settings?: Settings;
199
- activities?: ReturnType<typeof createActivities>;
295
+ activities?: ReturnType<typeof createControlActivities> | ReturnType<typeof createTurnActivities>;
200
296
  activityDependencies?: ActivityDependencies;
201
297
  workflowsPath?: string;
202
298
  };
203
- declare function createOpenGeniWorker(options?: WorkerOptions): Promise<{
299
+ declare function createOpenGeniWorker(options: WorkerOptions): Promise<{
204
300
  worker: Worker;
205
301
  connection: NativeConnection;
206
302
  }>;
207
- declare function createWorkerWorkflowSignaler(settings: Settings): Promise<{
303
+ declare function createWorkerWorkflowSignaler(settings: Settings, db: Database): Promise<{
208
304
  wakeSessionWorkflow: WakeSessionWorkflowSignal;
305
+ signalCodexCapacityWorkflow: SignalCodexCapacityWorkflow;
209
306
  check: () => Promise<void>;
210
307
  close: () => Promise<void>;
211
308
  }>;
212
309
  /**
213
310
  * Register the ONE global reaper Temporal Schedule (the sole liveness/GC/cost-stop
214
- * driver — P1.3 / OD-3). Gated on sandboxOwnershipEnabled: with the flag off the
215
- * Schedule is never created, so the lease feature is fully dark (no sweeps, no
216
- * terminates).
311
+ * driver — P1.3 / OD-3) and durable system-update outbox repair cadence. With
312
+ * sandbox ownership off the activity performs only bounded DB outbox repair;
313
+ * it never reads/terminates sandbox leases.
217
314
  *
218
315
  * The Schedule fires sandboxReaperWorkflow on the worker's global task queue
219
316
  * every settings.sandboxLeaseReaperPeriodMs (the SAME cadence the boot invariant
@@ -230,6 +327,25 @@ declare function registerSandboxReaperSchedule(settings: Settings, observability
230
327
  registered: boolean;
231
328
  close: () => Promise<void>;
232
329
  }>;
330
+ /**
331
+ * Register the one provider-neutral expired direct-upload cleanup Schedule.
332
+ * Unlike sandbox GC this is always registered: file uploads can be enabled in
333
+ * deployments where sandbox ownership is disabled. The activity is a cheap
334
+ * no-op when object storage is not configured.
335
+ */
336
+ declare function registerFileUploadReaperSchedule(settings: Settings, observability: Observability): Promise<{
337
+ registered: boolean;
338
+ close: () => Promise<void>;
339
+ }>;
340
+ /**
341
+ * Register the one repair cadence for committed workflow-wake revisions. The
342
+ * activity only reads the transactional outbox and sends revision-scoped
343
+ * signals; it is independent of sandbox ownership and child-agent features.
344
+ */
345
+ declare function registerSessionWorkflowWakeDispatcherSchedule(settings: Settings, observability: Observability): Promise<{
346
+ registered: boolean;
347
+ close: () => Promise<void>;
348
+ }>;
233
349
  declare function startWorker(): Promise<void>;
234
350
 
235
- export { type WorkerOptions, createOpenGeniWorker, createWorkerWorkflowSignaler, registerSandboxReaperSchedule, startWorker };
351
+ export { FILE_UPLOAD_REAPER_PERIOD_MS, FILE_UPLOAD_REAPER_SCHEDULE_ID, type OpenGeniWorkerRole, type WorkerOptions, createOpenGeniWorker, createWorkerWorkflowSignaler, registerFileUploadReaperSchedule, registerSandboxReaperSchedule, registerSessionWorkflowWakeDispatcherSchedule, startWorker };