@opengeni/worker-bundle 0.12.0 → 0.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
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": {
@@ -41,16 +41,16 @@
41
41
  "dependencies": {
42
42
  "@opengeni/agent-proto": "^0.3.0",
43
43
  "@opengeni/codex": "^0.2.7",
44
- "@opengeni/config": "^0.7.7",
45
- "@opengeni/contracts": "^0.20.0",
46
- "@opengeni/core": "^0.12.0",
47
- "@opengeni/db": "^0.13.0",
48
- "@opengeni/documents": "^0.2.37",
49
- "@opengeni/events": "^0.3.28",
50
- "@opengeni/github": "^0.3.19",
44
+ "@opengeni/config": "^0.7.8",
45
+ "@opengeni/contracts": "^0.20.1",
46
+ "@opengeni/core": "^0.12.2",
47
+ "@opengeni/db": "^0.13.1",
48
+ "@opengeni/documents": "^0.2.38",
49
+ "@opengeni/events": "^0.3.29",
50
+ "@opengeni/github": "^0.3.20",
51
51
  "@opengeni/observability": "^0.3.0",
52
- "@opengeni/runtime": "^0.13.11",
53
- "@opengeni/storage": "^0.2.31",
52
+ "@opengeni/runtime": "^0.13.13",
53
+ "@opengeni/storage": "^0.2.32",
54
54
  "@temporalio/activity": "^1.17.0",
55
55
  "@temporalio/client": "^1.17.0",
56
56
  "@temporalio/worker": "^1.17.0",
@@ -2902,7 +2902,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
2902
2902
  producerSeq,
2903
2903
  });
2904
2904
  if (immediate) {
2905
- await Bun.sleep(0);
2905
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
2906
2906
  }
2907
2907
  return appended;
2908
2908
  };
@@ -203,6 +203,49 @@ export type CaptureWorkspaceRevisionInput = {
203
203
  keepLatest?: number;
204
204
  };
205
205
 
206
+ type CaptureRepositoryReadResult =
207
+ | {
208
+ complete: true;
209
+ status: Awaited<ReturnType<SandboxChannelAService["gitStatus"]>>;
210
+ diff: Awaited<ReturnType<SandboxChannelAService["gitDiff"]>>;
211
+ }
212
+ | { complete: false; degradedReason: "repository_read_unavailable" };
213
+
214
+ /** One discovered repository is all-or-nothing capture authority. A provider
215
+ * transport failure must never be represented as an authoritative empty diff. */
216
+ export async function readCaptureRepository(
217
+ svc: Pick<SandboxChannelAService, "gitStatus" | "gitDiff">,
218
+ root: string,
219
+ ): Promise<CaptureRepositoryReadResult> {
220
+ let status: Awaited<ReturnType<SandboxChannelAService["gitStatus"]>>;
221
+ try {
222
+ status = await svc.gitStatus({ path: root });
223
+ } catch (error) {
224
+ const boxExiting = classifyCaptureEntryError(error);
225
+ if (boxExiting) throw boxExiting;
226
+ return { complete: false, degradedReason: "repository_read_unavailable" };
227
+ }
228
+ if (!status.isRepo) {
229
+ return { complete: false, degradedReason: "repository_read_unavailable" };
230
+ }
231
+ try {
232
+ const diff = await svc.gitDiff({
233
+ path: root,
234
+ staged: false,
235
+ includeUntracked: true,
236
+ fromRef: "HEAD",
237
+ pathspec: [],
238
+ contextLines: 3,
239
+ maxBytesPerFile: PER_FILE_DIFF_GUARD_BYTES,
240
+ });
241
+ return { complete: true, status, diff };
242
+ } catch (error) {
243
+ const boxExiting = classifyCaptureEntryError(error);
244
+ if (boxExiting) throw boxExiting;
245
+ return { complete: false, degradedReason: "repository_read_unavailable" };
246
+ }
247
+ }
248
+
206
249
  let loggedStorageNullOnce = false;
207
250
 
208
251
  /**
@@ -338,46 +381,15 @@ async function runCapture(
338
381
  );
339
382
  }
340
383
  if (!discovery.complete) {
341
- const capturedAt = new Date();
342
384
  const reason = captureDegradedReason(discovery.degradedReason);
343
- const stats = {
344
- degradedReason: reason,
345
- discoveredRepoCount: discovery.repos.length,
346
- durationMs: Date.now() - startedAt,
347
- };
348
- const inserted = await insertFailedWorkspaceCapture(input.db, {
349
- accountId: input.accountId,
350
- workspaceId: input.workspaceId,
351
- sessionId: input.sessionId,
352
- turnId: input.turnId,
353
- attemptId: input.attemptId,
354
- sandboxGroupId: input.sandboxGroupId,
355
- expectedEpoch: input.leaseEpoch,
385
+ await persistDegradedCapture(
386
+ input,
387
+ startedAt,
388
+ signal,
356
389
  revision,
357
- stats,
358
- capturedAt,
359
- });
360
- throwIfCaptureAborted(signal);
361
- if (!inserted) {
362
- observability.incrementCounter({
363
- name: "opengeni_workspace_capture_total",
364
- labels: { result: "superseded" },
365
- });
366
- return;
367
- }
368
- observability.warn("workspace capture degraded — repository discovery incomplete", {
369
- "opengeni.session_id": input.sessionId,
370
- "opengeni.turn_id": input.turnId ?? "",
371
- "workspace_capture.degraded_reason": reason,
372
- "workspace_capture.discovered_repo_count": discovery.repos.length,
373
- });
374
- observability.incrementCounter({
375
- name: "opengeni_workspace_capture_total",
376
- labels: { result: "degraded_repository_discovery" },
377
- });
378
- if (input.publish) {
379
- await input.publish(inserted.events).catch(() => undefined);
380
- }
390
+ reason,
391
+ discovery.repos.length,
392
+ );
381
393
  return;
382
394
  }
383
395
  const repoRoots = discovery.repos;
@@ -389,41 +401,24 @@ async function runCapture(
389
401
 
390
402
  for (const root of repoRoots) {
391
403
  throwIfCaptureAborted(signal);
392
- // Per-repo resilience: a box death aborts the whole capture (BoxExitingError
393
- // propagates); any other single-repo failure (a repo that vanished, a
394
- // transient git error) SKIPS that repo and the capture continues with the
395
- // rest. One flaky repo must never kill the capture.
396
- let status: Awaited<ReturnType<typeof svc.gitStatus>>;
397
- try {
398
- status = await svc.gitStatus({ path: root });
399
- throwIfCaptureAborted(signal);
400
- } catch (error) {
401
- const boxExiting = classifyCaptureEntryError(error);
402
- if (boxExiting) throw boxExiting;
403
- continue;
404
- }
405
- if (!status.isRepo) continue;
406
- // `git diff HEAD`: combined staged+unstaged tracked changes vs HEAD (the
407
- // review diff). Untracked files are absent here but present in status.files
408
- // and captured as after-images. A repo with no commits yields an empty diff
409
- // (git diff HEAD errors → empty numstat) and everything reads as untracked.
410
- let diff: Awaited<ReturnType<typeof svc.gitDiff>>;
411
- try {
412
- diff = await svc.gitDiff({
413
- path: root,
414
- staged: false,
415
- includeUntracked: true,
416
- fromRef: "HEAD",
417
- pathspec: [],
418
- contextLines: 3,
419
- maxBytesPerFile: PER_FILE_DIFF_GUARD_BYTES,
420
- });
421
- throwIfCaptureAborted(signal);
422
- } catch (error) {
423
- const boxExiting = classifyCaptureEntryError(error);
424
- if (boxExiting) throw boxExiting;
425
- diff = { files: [], revision: 0 };
404
+ // Repository discovery defines the authoritative set. Once a root is in
405
+ // that set, status/diff failure must degrade the entire revision rather than
406
+ // publish a partial or false-empty change surface. Box death still aborts
407
+ // through the outer best-effort boundary.
408
+ const repository = await readCaptureRepository(svc, root);
409
+ throwIfCaptureAborted(signal);
410
+ if (!repository.complete) {
411
+ await persistDegradedCapture(
412
+ input,
413
+ startedAt,
414
+ signal,
415
+ revision,
416
+ repository.degradedReason,
417
+ repoRoots.length,
418
+ );
419
+ return;
426
420
  }
421
+ const { status, diff } = repository;
427
422
  // Drop residue churn from the review diff too. On a desktop box the seed's
428
423
  // `git add -A` in $HOME commits ~/.config/xfce4/* into HEAD, so `git diff HEAD`
429
424
  // lists the continuously-rewritten desktop dotfiles as changed — noise the
@@ -851,6 +846,63 @@ function captureDegradedReason(
851
846
  }
852
847
  }
853
848
 
849
+ async function persistDegradedCapture(
850
+ input: CaptureWorkspaceRevisionInput,
851
+ startedAt: number,
852
+ signal: AbortSignal,
853
+ revision: number,
854
+ reason: WorkspaceCaptureDegradedReason,
855
+ discoveredRepoCount: number,
856
+ ): Promise<void> {
857
+ const capturedAt = new Date();
858
+ const stats = {
859
+ degradedReason: reason,
860
+ discoveredRepoCount,
861
+ durationMs: Date.now() - startedAt,
862
+ };
863
+ const inserted = await insertFailedWorkspaceCapture(input.db, {
864
+ accountId: input.accountId,
865
+ workspaceId: input.workspaceId,
866
+ sessionId: input.sessionId,
867
+ turnId: input.turnId,
868
+ attemptId: input.attemptId,
869
+ sandboxGroupId: input.sandboxGroupId,
870
+ expectedEpoch: input.leaseEpoch,
871
+ revision,
872
+ stats,
873
+ capturedAt,
874
+ });
875
+ throwIfCaptureAborted(signal);
876
+ if (!inserted) {
877
+ input.observability.incrementCounter({
878
+ name: "opengeni_workspace_capture_total",
879
+ labels: { result: "superseded" },
880
+ });
881
+ return;
882
+ }
883
+ const discoveryFailure = reason.startsWith("repository_discovery_");
884
+ input.observability.warn(
885
+ discoveryFailure
886
+ ? "workspace capture degraded — repository discovery incomplete"
887
+ : "workspace capture degraded — repository read incomplete",
888
+ {
889
+ "opengeni.session_id": input.sessionId,
890
+ "opengeni.turn_id": input.turnId ?? "",
891
+ "workspace_capture.degraded_reason": reason,
892
+ "workspace_capture.discovered_repo_count": discoveredRepoCount,
893
+ },
894
+ );
895
+ input.observability.incrementCounter({
896
+ name: "opengeni_workspace_capture_total",
897
+ labels: {
898
+ result: discoveryFailure ? "degraded_repository_discovery" : "degraded_repository_read",
899
+ },
900
+ });
901
+ if (input.publish) {
902
+ await input.publish(inserted.events).catch(() => undefined);
903
+ }
904
+ }
905
+
854
906
  function throwIfCaptureAborted(signal: AbortSignal): void {
855
907
  if (signal.aborted) {
856
908
  throw new Error("workspace capture cancelled after its deadline");