@opengeni/worker-bundle 0.16.13 → 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.
- package/dist/activities/agent-turn.d.ts +10 -33
- package/dist/activities/codex-rotation.d.ts +5 -9
- package/dist/activities/context-compaction.d.ts +0 -4
- package/dist/activities/run-input.d.ts +16 -73
- package/dist/index.js +202 -215
- package/dist/index.js.map +1 -1
- package/dist/workflow-bundle.js +44 -28
- package/package.json +12 -12
- package/src/activities/agent-turn.ts +165 -183
- package/src/activities/codex-capacity.ts +0 -1
- package/src/activities/codex-rotation.ts +10 -83
- package/src/activities/context-compaction.ts +2 -12
- package/src/activities/run-input.ts +90 -150
- package/src/workflows/session.ts +55 -32
package/src/workflows/session.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
587
|
+
const turnOutcome: Promise<
|
|
587
588
|
| { kind: "result"; result: activities.RunAgentTurnResult }
|
|
588
|
-
| { kind: "
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
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
|
-
|
|
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.
|