@opengeni/worker-bundle 2.0.3 → 2.1.0-canary.36239117573001

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 (51) hide show
  1. package/dist/activities/agent-turn/agent-build.d.ts +2 -0
  2. package/dist/activities/agent-turn/code-search.d.ts +60 -0
  3. package/dist/activities/agent-turn/codex-capacity.d.ts +13 -0
  4. package/dist/activities/agent-turn/errors.d.ts +12 -1
  5. package/dist/activities/agent-turn/governance-model.d.ts +2 -0
  6. package/dist/activities/agent-turn/session-title.d.ts +32 -2
  7. package/dist/activities/agent-turn/tool-environment.d.ts +4 -0
  8. package/dist/activities/context-compaction.d.ts +10 -2
  9. package/dist/activities/knowledge-indexing.d.ts +19 -0
  10. package/dist/{activities-control-IVTL723D.js → activities-control-I72CRMAE.js} +81 -14
  11. package/dist/activities-control-I72CRMAE.js.map +1 -0
  12. package/dist/{activities-turn-EZEDZTEZ.js → activities-turn-CSDKK4N3.js} +425 -46
  13. package/dist/activities-turn-CSDKK4N3.js.map +1 -0
  14. package/dist/artifact-outbox-entry.js +3 -0
  15. package/dist/artifact-outbox-entry.js.map +1 -1
  16. package/dist/{chunk-JMO5ZUW3.js → chunk-7M6G2SCF.js} +159 -11
  17. package/dist/chunk-7M6G2SCF.js.map +1 -0
  18. package/dist/{chunk-I7HKKMUJ.js → chunk-DSPP6CZL.js} +48 -3
  19. package/dist/chunk-DSPP6CZL.js.map +1 -0
  20. package/dist/index.js +4 -4
  21. package/dist/index.js.map +1 -1
  22. package/dist/observability-metrics.d.ts +11 -1
  23. package/dist/sandbox-resume.d.ts +46 -0
  24. package/dist/workflow-bundle.js +77 -2
  25. package/dist/workflows/session.d.ts +30 -0
  26. package/package.json +20 -19
  27. package/src/activities/agent-turn/agent-build.ts +4 -0
  28. package/src/activities/agent-turn/code-search.ts +275 -0
  29. package/src/activities/agent-turn/codex-capacity.ts +37 -2
  30. package/src/activities/agent-turn/compaction-prep.ts +52 -16
  31. package/src/activities/agent-turn/errors.ts +59 -1
  32. package/src/activities/agent-turn/governance-model.ts +17 -1
  33. package/src/activities/agent-turn/run.ts +4 -0
  34. package/src/activities/agent-turn/sandbox-establish.ts +12 -1
  35. package/src/activities/agent-turn/session-title.ts +73 -3
  36. package/src/activities/agent-turn/stream-attempt.ts +14 -13
  37. package/src/activities/agent-turn/tool-environment.ts +65 -0
  38. package/src/activities/context-compaction.ts +49 -14
  39. package/src/activities/knowledge-indexing.ts +107 -9
  40. package/src/activities/scheduled-tasks.ts +18 -2
  41. package/src/activity-services.ts +16 -4
  42. package/src/editable-artifact-hint-broker.ts +3 -0
  43. package/src/index.ts +2 -2
  44. package/src/observability-metrics.ts +70 -1
  45. package/src/personal-github-git-credentials.ts +2 -0
  46. package/src/sandbox-resume.ts +205 -5
  47. package/src/workflows/session.ts +102 -6
  48. package/dist/activities-control-IVTL723D.js.map +0 -1
  49. package/dist/activities-turn-EZEDZTEZ.js.map +0 -1
  50. package/dist/chunk-I7HKKMUJ.js.map +0 -1
  51. package/dist/chunk-JMO5ZUW3.js.map +0 -1
@@ -58,6 +58,50 @@ const HUMAN_INPUT_EXPIRY_STALE_RETRY_MS = 1_000;
58
58
  */
59
59
  const ROTATION_IDLE_FLOOR_MS = 60_000; // 60s
60
60
 
61
+ /**
62
+ * Provider capacity waits are shared: every waiter of one exhausted pool learns
63
+ * the same authoritative reset time, and one capacity mutation (for example the
64
+ * bounded refresh that verifies a quota reset) wakes every waiter at once, both
65
+ * as the typed capacity signal and as the generic durable workflow wake. Without
66
+ * spread, a reset resumes the whole backlog in the same few seconds and its
67
+ * turns stampede sandbox creation and the provider. Each workflow therefore
68
+ * delays its reconciliation by a bounded, replay-deterministic (Temporal-seeded
69
+ * `Math.random`) jitter: up to one minute past a scheduled reset timer and up to
70
+ * 30 seconds after a capacity or queue wake or an already-due waiter. A wake
71
+ * that lands inside a waiter's timer spread does not shorten it. The Postgres
72
+ * waiter stays authoritative; jitter only delays the same reconciliation
73
+ * activity and never creates queue rows, input, or inference. Interruptions are
74
+ * never delayed.
75
+ *
76
+ * The patch marker is not understood by workers built before it: rolling the
77
+ * worker image back past this change while a session has recorded the marker
78
+ * (it waited on capacity in its current run) fails that workflow's tasks as
79
+ * nondeterministic until a patched worker returns.
80
+ */
81
+ export const CAPACITY_WAKE_JITTER_PATCH = "session-capacity-wake-jitter-v1";
82
+ export const CAPACITY_TIMER_WAKE_JITTER_MAX_MS = 60_000;
83
+ export const CAPACITY_WAKE_JITTER_MAX_MS = 30_000;
84
+
85
+ /**
86
+ * Pure + exported so the bound is unit-testable without a workflow environment.
87
+ * `overrideMaxMs` is the test-only SessionWorkflowInput ceiling; it can only
88
+ * narrow the production bound.
89
+ */
90
+ export function capacityWakeJitterMs(
91
+ kind: "timer" | "wake",
92
+ sample: number,
93
+ overrideMaxMs?: number,
94
+ ): number {
95
+ const productionMax =
96
+ kind === "timer" ? CAPACITY_TIMER_WAKE_JITTER_MAX_MS : CAPACITY_WAKE_JITTER_MAX_MS;
97
+ const max =
98
+ overrideMaxMs !== undefined && Number.isFinite(overrideMaxMs)
99
+ ? Math.min(productionMax, Math.max(0, Math.trunc(overrideMaxMs)))
100
+ : productionMax;
101
+ const unit = Number.isFinite(sample) ? Math.min(Math.max(sample, 0), 1 - Number.EPSILON) : 0;
102
+ return Math.floor(unit * max);
103
+ }
104
+
61
105
  /**
62
106
  * How long the continuation loop must hold before re-admitting the next turn. 0 ⇒ no
63
107
  * hold (re-dispatch immediately — a rotation candidate is ready, or no idle delay was
@@ -369,6 +413,9 @@ export type SessionWorkflowInput = {
369
413
  // Test-only override for the durable capacity-wait continue-as-new
370
414
  // backstop. Production uses CODEX_CAPACITY_CHECKS_PER_RUN_BACKSTOP.
371
415
  maxCapacityChecksPerRun?: number;
416
+ // Test-only ceiling for capacity-wake jitter (0 disables it) so real-server
417
+ // workflow tests stay fast. Production omits it and uses the bounds above.
418
+ capacityWakeJitterMaxMs?: number;
372
419
  };
373
420
 
374
421
  export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void> {
@@ -476,7 +523,14 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
476
523
  const timerMs = Number.isFinite(parsedDeadline)
477
524
  ? Math.max(0, parsedDeadline - Date.now())
478
525
  : 0;
526
+ const observedCause = (): activities.ReconcileCodexCapacityWaitInput["cause"] =>
527
+ wakeups !== seenWakeups
528
+ ? "queue"
529
+ : capacityWakeups !== seenCapacityWakeups
530
+ ? "signal"
531
+ : "timer";
479
532
  let cause: activities.ReconcileCodexCapacityWaitInput["cause"] = "timer";
533
+ let spread = false;
480
534
  if (wakeups !== seenWakeups) {
481
535
  cause = "queue";
482
536
  } else if (capacityWakeups !== seenCapacityWakeups) {
@@ -492,12 +546,48 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
492
546
  if (interruptionWakeups !== seenInterruptionWakeups) {
493
547
  return;
494
548
  }
495
- cause =
496
- wakeups !== seenWakeups
497
- ? "queue"
498
- : capacityWakeups !== seenCapacityWakeups
499
- ? "signal"
500
- : "timer";
549
+ cause = observedCause();
550
+ // Histories recorded before the jitter replay without the marker and
551
+ // reconcile right at the deadline, exactly as they did.
552
+ if (cause === "timer" && patched(CAPACITY_WAKE_JITTER_PATCH)) {
553
+ // The shared reset deadline itself fired. The first waiter to
554
+ // reconcile usually refreshes usage and wakes every other waiter; a
555
+ // waiter already inside its own spread keeps it instead of starting a
556
+ // second, shorter one, so the backlog resumes across the whole window.
557
+ spread = true;
558
+ const timerJitterMs = capacityWakeJitterMs(
559
+ "timer",
560
+ Math.random(),
561
+ input.capacityWakeJitterMaxMs,
562
+ );
563
+ if (timerJitterMs > 0) {
564
+ await condition(() => interruptionWakeups !== seenInterruptionWakeups, timerJitterMs);
565
+ if (interruptionWakeups !== seenInterruptionWakeups) {
566
+ return;
567
+ }
568
+ }
569
+ cause = observedCause();
570
+ }
571
+ }
572
+ if (!spread && patched(CAPACITY_WAKE_JITTER_PATCH)) {
573
+ // One capacity mutation wakes every waiter of the pool at once (the typed
574
+ // capacity signal and the generic durable wake), and a fresh run after
575
+ // continue-as-new, restart, or Resume sees every unobserved wake as an
576
+ // already-due waiter. Spread those reconciliations too. A later wake
577
+ // does not cut the pause short (that would re-synchronize the herd); a
578
+ // queued prompt stays behind the blocked turn either way, so only an
579
+ // interruption (Pause/Steer/Cancel) wins immediately.
580
+ const wakeJitterMs = capacityWakeJitterMs(
581
+ "wake",
582
+ Math.random(),
583
+ input.capacityWakeJitterMaxMs,
584
+ );
585
+ if (wakeJitterMs > 0) {
586
+ await condition(() => interruptionWakeups !== seenInterruptionWakeups, wakeJitterMs);
587
+ if (interruptionWakeups !== seenInterruptionWakeups) {
588
+ return;
589
+ }
590
+ }
501
591
  }
502
592
  const reconcileInput = {
503
593
  accountId: input.accountId,
@@ -536,6 +626,9 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
536
626
  ...(input.maxCapacityChecksPerRun !== undefined
537
627
  ? { maxCapacityChecksPerRun: input.maxCapacityChecksPerRun }
538
628
  : {}),
629
+ ...(input.capacityWakeJitterMaxMs !== undefined
630
+ ? { capacityWakeJitterMaxMs: input.capacityWakeJitterMaxMs }
631
+ : {}),
539
632
  });
540
633
  }
541
634
  current = result;
@@ -582,6 +675,9 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
582
675
  ...(input.maxCapacityChecksPerRun !== undefined
583
676
  ? { maxCapacityChecksPerRun: input.maxCapacityChecksPerRun }
584
677
  : {}),
678
+ ...(input.capacityWakeJitterMaxMs !== undefined
679
+ ? { capacityWakeJitterMaxMs: input.capacityWakeJitterMaxMs }
680
+ : {}),
585
681
  });
586
682
  }
587
683
  }