@opengeni/worker-bundle 0.22.7-canary.0 → 0.23.3-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.
Files changed (74) hide show
  1. package/dist/activities/agent-turn/agent-build.d.ts +1 -4
  2. package/dist/activities/agent-turn/claim.d.ts +2 -4
  3. package/dist/activities/agent-turn/codex.d.ts +6 -5
  4. package/dist/activities/agent-turn/compaction-prep.d.ts +2 -0
  5. package/dist/activities/agent-turn/errors.d.ts +13 -0
  6. package/dist/activities/agent-turn/finalization.d.ts +1 -3
  7. package/dist/activities/agent-turn/quiescence.d.ts +39 -0
  8. package/dist/activities/agent-turn/sandbox-route.d.ts +14 -24
  9. package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -4
  10. package/dist/activities/agent-turn/sandbox-shared-preparation.d.ts +30 -0
  11. package/dist/activities/agent-turn/stream-attempt.d.ts +7 -0
  12. package/dist/activities/agent-turn/tool-policy.d.ts +3 -32
  13. package/dist/activities/agent-turn/turn-context.d.ts +1 -8
  14. package/dist/activities/agent-turn/turn-sandbox-access.d.ts +12 -0
  15. package/dist/activities/agent-turn/video-reference-sandbox.d.ts +7 -0
  16. package/dist/activities/codex-rotation.d.ts +2 -0
  17. package/dist/activities/session-state.d.ts +2 -1
  18. package/dist/{activities-control-VZIIV7RX.js → activities-control-52W5IDWM.js} +125 -13
  19. package/dist/activities-control-52W5IDWM.js.map +1 -0
  20. package/dist/{activities-turn-5RGQDBFV.js → activities-turn-A2G2KLSY.js} +534 -482
  21. package/dist/activities-turn-A2G2KLSY.js.map +1 -0
  22. package/dist/{chunk-NAVSAZ56.js → chunk-GFNXVZVQ.js} +160 -1
  23. package/dist/chunk-GFNXVZVQ.js.map +1 -0
  24. package/dist/{chunk-O4HDX5SC.js → chunk-IPVMCAW5.js} +144 -15
  25. package/dist/chunk-IPVMCAW5.js.map +1 -0
  26. package/dist/index.js +42 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/observability-metrics.d.ts +28 -0
  29. package/dist/personal-github-git-credentials.d.ts +1 -0
  30. package/dist/unhandled-rejection-boundary.d.ts +29 -0
  31. package/package.json +18 -18
  32. package/src/activities/agent-turn/agent-build.ts +15 -31
  33. package/src/activities/agent-turn/claim.ts +29 -68
  34. package/src/activities/agent-turn/codex.ts +19 -10
  35. package/src/activities/agent-turn/compaction-prep.ts +50 -1
  36. package/src/activities/agent-turn/errors.ts +78 -0
  37. package/src/activities/agent-turn/failure-settlement.ts +30 -19
  38. package/src/activities/agent-turn/finalization.ts +24 -21
  39. package/src/activities/agent-turn/history.ts +5 -1
  40. package/src/activities/agent-turn/quiescence.ts +86 -0
  41. package/src/activities/agent-turn/run-credentials.ts +12 -1
  42. package/src/activities/agent-turn/run.ts +14 -11
  43. package/src/activities/agent-turn/sandbox-establish.ts +46 -11
  44. package/src/activities/agent-turn/sandbox-route.ts +21 -25
  45. package/src/activities/agent-turn/sandbox-runtime.ts +1 -116
  46. package/src/activities/agent-turn/sandbox-shared-preparation.ts +206 -0
  47. package/src/activities/agent-turn/stream-attempt.ts +98 -14
  48. package/src/activities/agent-turn/tool-environment.ts +10 -13
  49. package/src/activities/agent-turn/tool-policy.ts +3 -55
  50. package/src/activities/agent-turn/turn-context.ts +8 -14
  51. package/src/activities/agent-turn/{image-reference-sandbox.ts → turn-sandbox-access.ts} +15 -13
  52. package/src/activities/agent-turn/video-reference-sandbox.ts +23 -0
  53. package/src/activities/codex-capacity.ts +13 -5
  54. package/src/activities/codex-rotation.ts +17 -0
  55. package/src/activities/goals.ts +10 -4
  56. package/src/activities/retained-screenshots.ts +104 -21
  57. package/src/activities/sandbox-lease.ts +7 -4
  58. package/src/activities/scheduled-tasks.ts +128 -4
  59. package/src/activities/session-state.ts +8 -1
  60. package/src/github-rest-mcp.ts +6 -3
  61. package/src/http.ts +3 -0
  62. package/src/index.ts +19 -0
  63. package/src/observability-metrics.ts +200 -0
  64. package/src/personal-github-git-credentials.ts +45 -4
  65. package/src/sandbox-resume.ts +1 -1
  66. package/src/sandbox-routing.ts +7 -4
  67. package/src/unhandled-rejection-boundary.ts +73 -0
  68. package/dist/activities/agent-turn/image-reference-sandbox.d.ts +0 -14
  69. package/dist/activities/recording.d.ts +0 -90
  70. package/dist/activities-control-VZIIV7RX.js.map +0 -1
  71. package/dist/activities-turn-5RGQDBFV.js.map +0 -1
  72. package/dist/chunk-NAVSAZ56.js.map +0 -1
  73. package/dist/chunk-O4HDX5SC.js.map +0 -1
  74. package/src/activities/recording.ts +0 -279
@@ -1,279 +0,0 @@
1
- // apps/worker/src/activities/recording.ts — the recording finalize helper (P4.3).
2
- //
3
- // The "agent films itself proving the fix" finalize loop, run IN the process that
4
- // already holds the resumed-by-id box (the agent turn's own activity). A scoped
5
- // upload URL sends bytes box → object storage; the worker never buffers the
6
- // recording and no bytes enter a Temporal payload.
7
- //
8
- // Ordering invariant (F9): the box file is deleted ONLY after the storage PUT
9
- // confirms and the `available` row commits — so a failed upload leaves the bytes
10
- // recoverable on the box.
11
-
12
- import type { Settings } from "@opengeni/config";
13
- import type { Database } from "@opengeni/db";
14
- import { deleteRecording } from "@opengeni/db";
15
- import type {
16
- RecordingCodec,
17
- RecordingFailedReason,
18
- RecordingStartedPayload,
19
- } from "@opengeni/contracts";
20
- import {
21
- contentTypeForCodec,
22
- deleteRecordingArtifacts,
23
- RecordingError,
24
- recordingStorageKey,
25
- startRecording as startRecordingOnBox,
26
- stopRecording as stopRecordingOnBox,
27
- uploadRecordingArtifact,
28
- type RecordingProcess,
29
- } from "@opengeni/runtime";
30
- import type { ObjectStorage } from "@opengeni/storage";
31
- import { DOWNLOAD_URL_TTL_SECONDS } from "@opengeni/storage";
32
-
33
- export type RecordingMode = "manual" | "on-turn" | "on-verify";
34
-
35
- export type ActiveRecording = {
36
- recordingId: string;
37
- turnId: string | null;
38
- mode: RecordingMode;
39
- proc: RecordingProcess;
40
- dimensions: [number, number];
41
- framerate: number;
42
- };
43
-
44
- export const RECORDING_SETTLEMENT_PREP_TIMEOUT_MS = 100_000;
45
- const RECORDING_SETTLEMENT_UPLOAD_MAX_SECONDS = 45;
46
-
47
- export async function withRecordingPreparationTimeout(
48
- preparation: Promise<PreparedRecordingSettlement>,
49
- timeoutResult: PreparedRecordingSettlement,
50
- timeoutMs = RECORDING_SETTLEMENT_PREP_TIMEOUT_MS,
51
- ): Promise<PreparedRecordingSettlement> {
52
- let timer: ReturnType<typeof setTimeout> | undefined;
53
- try {
54
- return await Promise.race([
55
- preparation,
56
- new Promise<PreparedRecordingSettlement>((resolve) => {
57
- timer = setTimeout(() => resolve(timeoutResult), timeoutMs);
58
- }),
59
- ]);
60
- } finally {
61
- if (timer) clearTimeout(timer);
62
- }
63
- }
64
-
65
- /**
66
- * Insert the recording row, launch ffmpeg on the box, and return the live handle.
67
- * Emits the `recording.started` payload (the caller publishes it on the spine).
68
- */
69
- export async function beginRecording(args: {
70
- settings: Settings;
71
- db: Database;
72
- accountId: string;
73
- workspaceId: string;
74
- sessionId: string;
75
- turnId: string | null;
76
- recordingId: string;
77
- mode: RecordingMode;
78
- session: unknown;
79
- runAs?: string | undefined;
80
- reason?: string | null;
81
- }): Promise<{ active: ActiveRecording; started: RecordingStartedPayload }> {
82
- const { settings, db } = args;
83
- const codec = settings.recordingDefaultCodec as RecordingCodec;
84
- const dimensions: [number, number] = [
85
- settings.streamResolutionWidth,
86
- settings.streamResolutionHeight,
87
- ];
88
- const framerate = settings.recordingFramerate;
89
- await import("@opengeni/db").then(({ insertRecording }) =>
90
- insertRecording(db, {
91
- id: args.recordingId,
92
- accountId: args.accountId,
93
- workspaceId: args.workspaceId,
94
- sessionId: args.sessionId,
95
- turnId: args.turnId,
96
- mode: args.mode,
97
- codec,
98
- width: dimensions[0],
99
- height: dimensions[1],
100
- reason: scrubFreeText(args.reason),
101
- }),
102
- );
103
- let proc: RecordingProcess;
104
- try {
105
- proc = await startRecordingOnBox(args.session, {
106
- recordingId: args.recordingId,
107
- codec,
108
- framerate,
109
- maxSeconds: settings.recordingMaxSeconds,
110
- dimensions,
111
- ...(args.runAs ? { runAs: args.runAs } : {}),
112
- });
113
- } catch (error) {
114
- await deleteRecording(db, {
115
- accountId: args.accountId,
116
- workspaceId: args.workspaceId,
117
- recordingId: args.recordingId,
118
- }).catch(() => undefined);
119
- throw error;
120
- }
121
- const active: ActiveRecording = {
122
- recordingId: args.recordingId,
123
- turnId: args.turnId,
124
- mode: args.mode,
125
- proc,
126
- dimensions,
127
- framerate,
128
- };
129
- const started: RecordingStartedPayload = {
130
- recordingId: args.recordingId,
131
- turnId: args.turnId,
132
- mode: args.mode,
133
- codec,
134
- dimensions,
135
- framerate,
136
- startedAt: new Date().toISOString(),
137
- reason: scrubFreeText(args.reason),
138
- };
139
- return { active, started };
140
- }
141
-
142
- export type PreparedRecordingSettlement =
143
- | {
144
- mutation: {
145
- action: "available";
146
- recordingId: string;
147
- storageKey: string;
148
- sizeBytes: number;
149
- durationSeconds: number;
150
- };
151
- deleteArtifactsAfterCommit: true;
152
- }
153
- | {
154
- mutation: {
155
- action: "failed";
156
- recordingId: string;
157
- reason: RecordingFailedReason;
158
- detail: string | null;
159
- };
160
- deleteArtifactsAfterCommit: false;
161
- }
162
- | {
163
- mutation: { action: "discard"; recordingId: string };
164
- deleteArtifactsAfterCommit: true;
165
- };
166
-
167
- /**
168
- * Prepare an on-turn recording for the attempt-closing settlement. This performs
169
- * only bounded box/storage work; it does not mutate canonical database state and
170
- * never deletes the box artifact. The caller folds the returned mutation into the
171
- * exact attempt-fenced turn settlement, then deletes artifacts only after commit.
172
- * NEVER throws and never prevents turn truth from settling.
173
- */
174
- export async function prepareRecordingForSettlement(args: {
175
- settings: Settings;
176
- objectStorage: ObjectStorage | null;
177
- workspaceId: string;
178
- sessionId: string;
179
- active: ActiveRecording;
180
- session: unknown;
181
- didComputerUse: boolean;
182
- }): Promise<PreparedRecordingSettlement> {
183
- const { settings, objectStorage, active } = args;
184
- const codec = active.proc.codec;
185
- const fail = (
186
- reason: RecordingFailedReason,
187
- detail: string | null,
188
- ): PreparedRecordingSettlement => {
189
- return {
190
- mutation: {
191
- action: "failed",
192
- recordingId: active.recordingId,
193
- reason,
194
- detail: scrubFreeText(detail),
195
- },
196
- deleteArtifactsAfterCommit: false,
197
- };
198
- };
199
-
200
- const prepare = async (): Promise<PreparedRecordingSettlement> => {
201
- try {
202
- await stopRecordingOnBox(args.session, active.proc);
203
- if (!args.didComputerUse) {
204
- return {
205
- mutation: { action: "discard", recordingId: active.recordingId },
206
- deleteArtifactsAfterCommit: true,
207
- };
208
- }
209
- if (!objectStorage) {
210
- return fail("upload-failed", "object storage is not configured");
211
- }
212
- const key = recordingStorageKey(args.workspaceId, args.sessionId, active.recordingId, codec);
213
- const upload = await objectStorage.createPutUrl({
214
- key,
215
- contentType: contentTypeForCodec(codec),
216
- });
217
- const finalized = await uploadRecordingArtifact(args.session, active.proc, {
218
- url: upload.url,
219
- requiredHeaders: upload.requiredHeaders,
220
- maxBytes: settings.recordingMaxBytes,
221
- maxSeconds: RECORDING_SETTLEMENT_UPLOAD_MAX_SECONDS,
222
- });
223
- return {
224
- mutation: {
225
- action: "available",
226
- recordingId: active.recordingId,
227
- storageKey: key,
228
- sizeBytes: finalized.sizeBytes,
229
- durationSeconds: finalized.durationSeconds,
230
- },
231
- deleteArtifactsAfterCommit: true,
232
- };
233
- } catch (error) {
234
- const reason: RecordingFailedReason =
235
- error instanceof RecordingError ? error.reason : "upload-failed";
236
- return fail(reason, error instanceof Error ? error.message : String(error));
237
- }
238
- };
239
-
240
- return await withRecordingPreparationTimeout(
241
- prepare(),
242
- fail("upload-failed", "recording settlement preparation timed out"),
243
- );
244
- }
245
-
246
- /**
247
- * Compensate a start whose fenced `recording.started` event was rejected. Since
248
- * no canonical event was admitted, this exact recording id must leave no row,
249
- * process, or box artifact behind.
250
- */
251
- export async function discardUnpublishedRecording(args: {
252
- db: Database;
253
- accountId: string;
254
- workspaceId: string;
255
- active: ActiveRecording;
256
- session: unknown;
257
- }): Promise<void> {
258
- const { db, active } = args;
259
- try {
260
- await stopRecordingOnBox(args.session, active.proc).catch(() => undefined);
261
- await deleteRecordingArtifacts(args.session, active.proc).catch(() => undefined);
262
- } finally {
263
- await deleteRecording(db, {
264
- accountId: args.accountId,
265
- workspaceId: args.workspaceId,
266
- recordingId: active.recordingId,
267
- }).catch(() => undefined);
268
- }
269
- }
270
-
271
- export { DOWNLOAD_URL_TTL_SECONDS };
272
-
273
- // Recording diagnostics are canonical OpenGeni data. Preserve the exact text;
274
- // transport-specific byte limits must reject or paginate rather than rewrite it.
275
- function scrubFreeText(value: string | null | undefined): string | null {
276
- if (value === null || value === undefined) return null;
277
- const exact = String(value);
278
- return exact.length === 0 ? null : exact;
279
- }