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