@opengeni/worker-bundle 0.16.14 → 0.16.17

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.
@@ -215,6 +215,7 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
215
215
  // every new run records v2 and uses the activity-owned receipt contract.
216
216
  const receiptGatedCancellation = patched("session-attempt-quiescence-v2");
217
217
  const writerSetQuiescenceRecovery = patched("session-attempt-writer-set-quiescence-v1");
218
+ const staleControlSignalIsOnlyWakeHint = patched("session-control-stale-wake-v1");
218
219
  const turnActivity = turnActivityForTaskQueue(workflowInfo().taskQueue, receiptGatedCancellation);
219
220
  let approvalWakeups = 0;
220
221
  let interruptionWakeups = 0;
@@ -565,7 +566,7 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
565
566
  ): Promise<boolean> {
566
567
  const capacityWaitEntryBaseline = { wakeups, capacityWakeups };
567
568
  const attemptId = uuid4();
568
- const interruptionBaseline = interruptionWakeups;
569
+ let interruptionBaseline = interruptionWakeups;
569
570
 
570
571
  const scope = new CancellationScope();
571
572
  const workflowExecution = workflowInfo();
@@ -583,39 +584,52 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
583
584
  trigger,
584
585
  }),
585
586
  );
586
- const racedOutcome:
587
+ const turnOutcome: Promise<
587
588
  | { kind: "result"; result: activities.RunAgentTurnResult }
588
- | { kind: "control" }
589
- | { kind: "failure"; error: unknown } = await Promise.race([
590
- turn.then(
591
- (result: activities.RunAgentTurnResult) => ({
592
- kind: "result" as const,
593
- result,
594
- }),
595
- (error: unknown) => ({ kind: "failure" as const, error }),
596
- ),
597
- condition(() => interruptionWakeups !== interruptionBaseline).then(() => ({
598
- kind: "control" as const,
599
- })),
600
- ]);
601
- // A Steer/Pause transaction fences the active attempt before its Temporal
602
- // signal is necessarily handled. That fence can make the activity's typed
603
- // cancellation win Promise.race by one workflow activation. Give only that
604
- // confirmed cancellation shape a short deterministic arbitration window;
605
- // the durable control signal is authoritative once observed. Ordinary
606
- // failures and timeouts never wait here, and a cancellation with no session
607
- // control still follows the failure/cancellation path below.
608
- if (
609
- racedOutcome.kind === "failure" &&
610
- isTurnActivityFenceCancellation(racedOutcome.error) &&
611
- interruptionWakeups === interruptionBaseline
612
- ) {
613
- await condition(() => interruptionWakeups !== interruptionBaseline, "250ms");
614
- }
615
- const outcome =
616
- interruptionWakeups !== interruptionBaseline ? ({ kind: "control" } as const) : racedOutcome;
589
+ | { kind: "failure"; error: unknown }
590
+ > = turn.then(
591
+ (result: activities.RunAgentTurnResult) => ({
592
+ kind: "result" as const,
593
+ result,
594
+ }),
595
+ (error: unknown) => ({ kind: "failure" as const, error }),
596
+ );
597
+ let outcome:
598
+ | { kind: "result"; result: activities.RunAgentTurnResult }
599
+ | { kind: "failure"; error: unknown };
600
+ while (true) {
601
+ const racedOutcome:
602
+ | { kind: "result"; result: activities.RunAgentTurnResult }
603
+ | { kind: "control" }
604
+ | { kind: "failure"; error: unknown } = await Promise.race([
605
+ turnOutcome,
606
+ condition(() => interruptionWakeups !== interruptionBaseline).then(() => ({
607
+ kind: "control" as const,
608
+ })),
609
+ ]);
610
+ // A Steer/Pause transaction fences the active attempt before its Temporal
611
+ // signal is necessarily handled. That fence can make the activity's typed
612
+ // cancellation win Promise.race by one workflow activation. Give only that
613
+ // confirmed cancellation shape a short deterministic arbitration window;
614
+ // the durable control signal is authoritative once observed. Ordinary
615
+ // failures and timeouts never wait here, and a cancellation with no session
616
+ // control still follows the failure/cancellation path below.
617
+ if (
618
+ racedOutcome.kind === "failure" &&
619
+ isTurnActivityFenceCancellation(racedOutcome.error) &&
620
+ interruptionWakeups === interruptionBaseline
621
+ ) {
622
+ await condition(() => interruptionWakeups !== interruptionBaseline, "250ms");
623
+ }
624
+ const observedOutcome =
625
+ interruptionWakeups !== interruptionBaseline
626
+ ? ({ kind: "control" } as const)
627
+ : racedOutcome;
617
628
 
618
- if (outcome.kind === "control") {
629
+ if (observedOutcome.kind !== "control") {
630
+ outcome = observedOutcome;
631
+ break;
632
+ }
619
633
  if (!receiptGatedCancellation) {
620
634
  // Replay-only v1 command order. New histories always take the v2 path
621
635
  // below. The current runAgentTurn still owns and writes the truthful
@@ -647,6 +661,7 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
647
661
  if (!physicalStopConfirmed) throw termination.error;
648
662
  return settlement.action !== "paused";
649
663
  }
664
+ const observedInterruptionWakeups = interruptionWakeups;
650
665
  const settlement = await activity.settleSessionInterruptions({
651
666
  accountId,
652
667
  workspaceId,
@@ -654,6 +669,14 @@ export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void
654
669
  attemptId,
655
670
  workflowId: workflowInfo().workflowId,
656
671
  });
672
+ if (staleControlSignalIsOnlyWakeHint && settlement.action === "stale") {
673
+ // sessionControl is replaceable transport, not authority. Keep
674
+ // observing the same activity when no durable interruption exists.
675
+ // Preserve signals received while settlement was in flight so a real
676
+ // concurrent Pause/Steer is evaluated on the next loop iteration.
677
+ interruptionBaseline = observedInterruptionWakeups;
678
+ continue;
679
+ }
657
680
  // The transaction above is the authority fence: every late model/tool/UI
658
681
  // write is rejected from this point onward. Request cancellation only
659
682
  // after it commits, then stop observing the Temporal activity promise.