@orkestrel/workflow 0.0.17 → 0.0.18
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/README.md +9 -3
- package/dist/src/browser/index.d.ts +16 -12
- package/dist/src/browser/index.js +13 -9
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/core/index.cjs +267 -230
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +657 -547
- package/dist/src/core/index.d.ts +657 -547
- package/dist/src/core/index.js +267 -230
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +5 -3
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +7 -5
- package/dist/src/server/index.d.ts +7 -5
- package/dist/src/server/index.js +5 -3
- package/dist/src/server/index.js.map +1 -1
- package/package.json +20 -21
package/dist/src/core/index.js
CHANGED
|
@@ -6,11 +6,12 @@ import { createTimeout } from "@orkestrel/timeout";
|
|
|
6
6
|
import { createQueue } from "@orkestrel/queue";
|
|
7
7
|
//#region src/core/errors.ts
|
|
8
8
|
/**
|
|
9
|
-
* Represents an error
|
|
9
|
+
* Represents an error the workflow runtime raises for an operation it refuses — a
|
|
10
|
+
* {@link WorkflowErrorCode} (`TRANSITION`, `RESTORE`, `MUTATION`, `SCHEDULE`, or `INVARIANT`)
|
|
11
|
+
* beside an optional `context` naming the node or the parameter at fault.
|
|
10
12
|
*
|
|
11
13
|
* @remarks
|
|
12
|
-
*
|
|
13
|
-
* offending node id / status / parameter. Raised for an illegal lifecycle transition
|
|
14
|
+
* Raised for an illegal lifecycle transition
|
|
14
15
|
* (`TRANSITION`), a structurally invalid {@link import('./types.js').WorkflowSnapshot}
|
|
15
16
|
* boundary (`RESTORE`), a refused structural/activity edit (`MUTATION`), a host
|
|
16
17
|
* schedule refused before arming because the caller's `signal` is not a native
|
|
@@ -51,10 +52,14 @@ function isWorkflowError(value) {
|
|
|
51
52
|
}
|
|
52
53
|
//#endregion
|
|
53
54
|
//#region src/core/constants.ts
|
|
54
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Names the default {@link import('./types.js').WorkflowDefinition.bail}, `false` — the graceful
|
|
57
|
+
* policy that records a leaf failure and finishes every phase.
|
|
58
|
+
*/
|
|
55
59
|
var DEFAULT_BAIL = false;
|
|
56
60
|
/**
|
|
57
|
-
* Lists every {@link LifecycleStatus} value, frozen — the vocabulary every tier draws from
|
|
61
|
+
* Lists every {@link LifecycleStatus} value, frozen — the vocabulary every tier draws from,
|
|
62
|
+
* in the order `pending`, `running`, `completed`, `failed`, `skipped`, `stopped`.
|
|
58
63
|
*
|
|
59
64
|
* @remarks
|
|
60
65
|
* Ordered pending → running → terminal (`completed` / `failed` / `skipped` /
|
|
@@ -70,8 +75,8 @@ var LIFECYCLE_STATUSES = Object.freeze([
|
|
|
70
75
|
"stopped"
|
|
71
76
|
]);
|
|
72
77
|
/**
|
|
73
|
-
* Lists the {@link LifecycleStatus} values
|
|
74
|
-
*
|
|
78
|
+
* Lists the terminal {@link LifecycleStatus} values, frozen — `completed`, `failed`, `skipped`,
|
|
79
|
+
* and `stopped`, each a state a node never transitions out of.
|
|
75
80
|
*
|
|
76
81
|
* @remarks
|
|
77
82
|
* The source of truth behind {@link import('./helpers.js').isTerminalStatus}.
|
|
@@ -116,30 +121,32 @@ var TASK_TRANSITIONS = Object.freeze({
|
|
|
116
121
|
/**
|
|
117
122
|
* Names the default per-phase task concurrency the {@link import('./factories.js').createWorkflowRunner}
|
|
118
123
|
* runner applies when a {@link import('./types.js').PhaseDefinition} omits its `concurrency`
|
|
119
|
-
* throttle — a cap that is effectively unbounded for any realistic phase.
|
|
124
|
+
* throttle — `1024`, a cap that is effectively unbounded for any realistic phase.
|
|
120
125
|
*
|
|
121
126
|
* @remarks
|
|
122
|
-
* The determinism principle fixes that a phase's tasks run
|
|
127
|
+
* The determinism principle fixes that a phase's tasks run concurrently; `concurrency` is
|
|
123
128
|
* only an optional resource throttle (max-in-flight). With none declared, the runner runs
|
|
124
129
|
* all of a phase's tasks at once — modelled as this finite cap so the value flows straight
|
|
125
130
|
* into the substrate {@link import('./types.js').RunnerInterface}'s `concurrency` (which
|
|
126
131
|
* expects a positive integer) without a special unbounded branch. No realistic phase
|
|
127
132
|
* declares enough tasks to reach it, so it behaves as "run them all".
|
|
128
133
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
134
|
+
* why `1024` and not a huge sentinel like `1_000_000`: the backing `@orkestrel/queue` Runner
|
|
135
|
+
* eagerly spawns one parked worker loop per concurrency unit at construction, so this default
|
|
131
136
|
* must be a value whose eager allocation cost is negligible for every default-concurrency
|
|
132
137
|
* phase — a million-unit default meant ~1e6 promise/closure allocations per such phase. A
|
|
133
|
-
* phase may still
|
|
138
|
+
* phase may still declare a larger explicit `concurrency` and pays that allocation knowingly.
|
|
134
139
|
*/
|
|
135
140
|
var DEFAULT_PHASE_CONCURRENCY = 1024;
|
|
136
141
|
/**
|
|
137
|
-
* Names the largest delay representable by the host timer APIs without overflow or clamping
|
|
142
|
+
* Names the largest delay representable by the host timer APIs without overflow or clamping,
|
|
143
|
+
* `2_147_483_647` milliseconds.
|
|
138
144
|
*/
|
|
139
145
|
var MAX_TIMER_MS = 2147483647;
|
|
140
146
|
/**
|
|
141
147
|
* Lists the {@link WorkflowEventMap} / {@link PhaseEventMap} events that make a durable observer
|
|
142
|
-
* re-persist the live tree, frozen
|
|
148
|
+
* re-persist the live tree, frozen — `start`, `complete`, `fail`, `skip`, `stop`, `move`, and
|
|
149
|
+
* `update`.
|
|
143
150
|
*
|
|
144
151
|
* @remarks
|
|
145
152
|
* The two maps carry the same event names, so one list serves both tiers. It is the source of
|
|
@@ -158,7 +165,8 @@ var PERSISTED_NODE_EVENTS = Object.freeze([
|
|
|
158
165
|
"update"
|
|
159
166
|
]);
|
|
160
167
|
/**
|
|
161
|
-
* Lists the {@link TaskEventMap} events that make a durable observer re-persist the live tree,
|
|
168
|
+
* Lists the {@link TaskEventMap} events that make a durable observer re-persist the live tree,
|
|
169
|
+
* frozen — `start`, `complete`, `fail`, `skip`, `stop`, `report`, and `pulse`.
|
|
162
170
|
*
|
|
163
171
|
* @remarks
|
|
164
172
|
* The leaf counterpart of {@link PERSISTED_NODE_EVENTS}, and the source of truth behind the task
|
|
@@ -229,8 +237,8 @@ function isTaskFailure(value) {
|
|
|
229
237
|
* The discriminator behind the overloaded
|
|
230
238
|
* {@link import('./types.js').WorkflowRunnerInterface.execute}: a
|
|
231
239
|
* {@link import('./types.js').WorkflowInterface} is the only one of the two carrying `destroyed`
|
|
232
|
-
* (
|
|
233
|
-
* {@link import('./types.js').WorkflowDefinition})
|
|
240
|
+
* (runtime-only, never a field on the pure-JSON
|
|
241
|
+
* {@link import('./types.js').WorkflowDefinition}) and a callable `snapshot`. Requiring both is
|
|
234
242
|
* sturdier than `destroyed` alone — a definition could coincidentally carry a `destroyed` field as
|
|
235
243
|
* arbitrary data, and pairing it with a function-typed `snapshot` narrows to the actual entity
|
|
236
244
|
* shape without an `as`. It reads a live class instance, so it tests object identity rather than a
|
|
@@ -422,7 +430,7 @@ function isTaskActivityInput(value) {
|
|
|
422
430
|
* Tests whether an unknown value is valid persisted task activity.
|
|
423
431
|
*
|
|
424
432
|
* @remarks
|
|
425
|
-
* The persisted counterpart of {@link isTaskActivityInput}: the same frame plus the
|
|
433
|
+
* The persisted counterpart of {@link isTaskActivityInput}: the same frame plus the required
|
|
426
434
|
* `operations`, `constraints`, and a finite non-negative `updated` stamp, because a stored frame
|
|
427
435
|
* has already been accepted and normalized. Total — a hostile prototype or accessor answers
|
|
428
436
|
* `false` rather than throwing.
|
|
@@ -494,11 +502,11 @@ function captureWorkflowOptions(options) {
|
|
|
494
502
|
});
|
|
495
503
|
}
|
|
496
504
|
/**
|
|
497
|
-
* Tests whether a {@link LifecycleStatus} is
|
|
498
|
-
*
|
|
505
|
+
* Tests whether a {@link LifecycleStatus} is terminal — `completed`, `failed`, `skipped`, or
|
|
506
|
+
* `stopped`, the states a node never transitions out of.
|
|
499
507
|
*
|
|
500
508
|
* @remarks
|
|
501
|
-
* The
|
|
509
|
+
* The one terminal check across every tier (AGENTS.md § Design laws, "one concept, one term"):
|
|
502
510
|
* a task, a phase, and a workflow share the same {@link LifecycleStatus} vocabulary, so a
|
|
503
511
|
* single predicate covers them — {@link derivePhaseStatus} and {@link deriveWorkflowStatus}
|
|
504
512
|
* both consult it to tell a settled node from an in-flight one. It reads the terminal set from
|
|
@@ -513,12 +521,13 @@ function isTerminalStatus(status) {
|
|
|
513
521
|
return TERMINAL_STATUSES.includes(status);
|
|
514
522
|
}
|
|
515
523
|
/**
|
|
516
|
-
* Tests whether a driving run must stop giving a workflow
|
|
524
|
+
* Tests whether a driving run must stop giving a workflow — or one forced phase of it —
|
|
525
|
+
* more work.
|
|
517
526
|
*
|
|
518
527
|
* @remarks
|
|
519
528
|
* The halt gate a {@link import('./WorkflowRunner.js').WorkflowRunner} consults before starting a
|
|
520
529
|
* phase, before dispatching a task, and after every cooperative gate. A workflow is halted after
|
|
521
|
-
* its derived status is terminal but
|
|
530
|
+
* its derived status is terminal but not `completed` — a `bail: true` failure, a caller's own
|
|
522
531
|
* graceful `stop()`, or a forced `skip`. `completed` is excluded deliberately: a workflow that
|
|
523
532
|
* completed vacuously is settled, not halted, and the distinction is what keeps the run from
|
|
524
533
|
* sweeping a finished tree. When a `phase` is supplied, its own forced `skipped` / `stopped` halts
|
|
@@ -541,11 +550,11 @@ function isHalted(workflow, phase) {
|
|
|
541
550
|
return isTerminalStatus(status) && status !== "completed" || phase?.status === "skipped" || phase?.status === "stopped";
|
|
542
551
|
}
|
|
543
552
|
/**
|
|
544
|
-
* Tests whether forcing a workflow `stopped` would still record
|
|
553
|
+
* Tests whether forcing a workflow `stopped` would still record the cancellation.
|
|
545
554
|
*
|
|
546
555
|
* @remarks
|
|
547
556
|
* `stop()` is a no-op after a workflow's status becomes terminal, so a run that must record a
|
|
548
|
-
* cancellation forces it only while this holds. It is
|
|
557
|
+
* cancellation forces it only while this holds. It is not the negation of
|
|
549
558
|
* {@link isTerminalStatus}: `completed` and `skipped` both pass, because a run-level cancel that
|
|
550
559
|
* lands on a vacuously-completed or fully-skipped tree still records `stopped` as the outcome the
|
|
551
560
|
* caller asked for. Only an already-`failed` or already-`stopped` workflow has a terminal state
|
|
@@ -571,7 +580,7 @@ function isStoppable(workflow) {
|
|
|
571
580
|
* @remarks
|
|
572
581
|
* A run that walked every phase and still derives `pending` executed nothing — zero phases, or
|
|
573
582
|
* every phase empty — so it is vacuously done and the run settles it `completed`. Gated on
|
|
574
|
-
*
|
|
583
|
+
* exactly `pending` so a real `completed`, a `bail: true` `failed`, a `stopped`, or a derived
|
|
575
584
|
* `skipped` is never overridden. The tree-is-empty half of the rule is
|
|
576
585
|
* {@link WorkflowInterface.complete}'s own guard, which refuses a pending tree that still holds
|
|
577
586
|
* tasks.
|
|
@@ -595,7 +604,7 @@ function isCompletable(workflow) {
|
|
|
595
604
|
* running task's folded signal, and only two of them mean "skip this task": the task's own
|
|
596
605
|
* `signal` (its `stop` / `skip`), and the unit or run signal (a sibling fail-fast under
|
|
597
606
|
* `bail: true`, or a run-level abort / timeout / budget / `destroy`). A bare per-attempt timeout
|
|
598
|
-
* fires
|
|
607
|
+
* fires neither — it aborts only the deadline portion of the attempt signal — so it stays a
|
|
599
608
|
* retryable failure of that attempt instead of skipping the leaf and losing the recorded fault.
|
|
600
609
|
* Read fresh at each call so a cancel that lands mid-dispatch is seen.
|
|
601
610
|
*
|
|
@@ -617,7 +626,7 @@ function isSkipping(task, controller, runSignal) {
|
|
|
617
626
|
*
|
|
618
627
|
* @remarks
|
|
619
628
|
* A retried task is re-dispatched while an earlier attempt's handler may still be resolving, so
|
|
620
|
-
* every settlement path re-checks ownership before touching the leaf. Ownership needs
|
|
629
|
+
* every settlement path re-checks ownership before touching the leaf. Ownership needs both
|
|
621
630
|
* halves: the run-local `owners` ledger must still name this attempt, and the live task's own
|
|
622
631
|
* `attempts` tally must still match it. A superseded attempt reads `false` and returns without
|
|
623
632
|
* recording anything, so a late resolution can never overwrite the newer attempt's outcome.
|
|
@@ -638,14 +647,14 @@ function ownsAttempt(owners, task, attempt) {
|
|
|
638
647
|
return owners.get(task.id) === attempt && task.attempts === attempt;
|
|
639
648
|
}
|
|
640
649
|
/**
|
|
641
|
-
* Derives a phase's status from its tasks' statuses
|
|
642
|
-
* is an order-insensitive reduction).
|
|
650
|
+
* Derives a phase's status from its tasks' statuses, the most severe terminal status winning
|
|
651
|
+
* (tasks are concurrent, so this is an order-insensitive reduction).
|
|
643
652
|
*
|
|
644
653
|
* @remarks
|
|
645
654
|
* The truth table (most-severe terminal wins; `bail`-agnostic — a phase surfaces a
|
|
646
655
|
* task failure as `failed` so the workflow's `bail` policy can decide):
|
|
647
656
|
* - no tasks ⇒ `pending`.
|
|
648
|
-
* - any task `running`,
|
|
657
|
+
* - any task `running`, or a mix of started-and-unsettled tasks (some non-`pending`
|
|
649
658
|
* but not all terminal) ⇒ `running`.
|
|
650
659
|
* - every task `pending` ⇒ `pending`.
|
|
651
660
|
* - all terminal: any `failed` ⇒ `failed`; else any `stopped` ⇒ `stopped`; else any
|
|
@@ -669,23 +678,24 @@ function derivePhaseStatus(tasks) {
|
|
|
669
678
|
}
|
|
670
679
|
/**
|
|
671
680
|
* Derives a workflow's status from its phases' {@link PhaseDerivation}s — each phase's status
|
|
672
|
-
* paired with the
|
|
673
|
-
* failure outcome is
|
|
674
|
-
*
|
|
681
|
+
* paired with the effective `bail` it ran under (`phase.bail ?? workflow.bail`) — so the
|
|
682
|
+
* failure outcome is aware of each phase's own policy, and `failed` is reachable only where
|
|
683
|
+
* that policy is `true` (phases are sequential, but the derivation is an order-insensitive
|
|
684
|
+
* reduction over the settled set).
|
|
675
685
|
*
|
|
676
686
|
* @remarks
|
|
677
687
|
* `bail` is a per-phase override, so it is carried on each
|
|
678
|
-
* {@link PhaseDerivation} rather than passed as one scalar. It is the
|
|
688
|
+
* {@link PhaseDerivation} rather than passed as one scalar. It is the only axis that changes
|
|
679
689
|
* the failure outcome, decided per phase:
|
|
680
690
|
* - **A `failed` phase whose effective `bail` is `true` (halt)** propagates ⇒ the workflow is
|
|
681
691
|
* `failed` (the database-transaction halt) — even when the workflow default is graceful.
|
|
682
|
-
* - **A `failed` phase whose effective `bail` is `false` (graceful)** is
|
|
683
|
-
* failure — it folds into completion like a settled phase. A graceful failed phase
|
|
692
|
+
* - **A `failed` phase whose effective `bail` is `false` (graceful)** is data, not a workflow
|
|
693
|
+
* failure — it folds into completion like a settled phase. A graceful failed phase never
|
|
684
694
|
* makes the workflow `failed` — even when the workflow default is strict.
|
|
685
695
|
*
|
|
686
696
|
* The rest of the table is shared:
|
|
687
697
|
* - no phases ⇒ `pending`.
|
|
688
|
-
* - any phase `running`,
|
|
698
|
+
* - any phase `running`, or a mix of started-and-unsettled phases (some non-`pending`
|
|
689
699
|
* but not all terminal) ⇒ `running`.
|
|
690
700
|
* - every phase `pending` ⇒ `pending`.
|
|
691
701
|
* - all terminal (a `failed` phase counts as terminal here): any `stopped` ⇒ `stopped`; else
|
|
@@ -705,18 +715,19 @@ function deriveWorkflowStatus(phases) {
|
|
|
705
715
|
return "skipped";
|
|
706
716
|
}
|
|
707
717
|
/**
|
|
708
|
-
* Derives the
|
|
709
|
-
* the index of the first entry in the contiguous trailing run of `pending` entries
|
|
718
|
+
* Derives the pending-suffix boundary of a positional list of {@link LifecycleStatus}es —
|
|
719
|
+
* the index of the first entry in the contiguous trailing run of `pending` entries, or the
|
|
720
|
+
* list's length where it has none.
|
|
710
721
|
*
|
|
711
722
|
* @remarks
|
|
712
723
|
* The native, hook-free replacement for a runner-installed cursor: a
|
|
713
724
|
* {@link import('./types.js').WorkflowInterface}'s `add` / `remove` / `move` / `update`
|
|
714
725
|
* reads this over its live phases' statuses to decide which positions are safe to edit.
|
|
715
|
-
* Because entries run
|
|
716
|
-
* already-started entry forms a contiguous
|
|
726
|
+
* Because entries run sequentially (phases sequential, AGENTS determinism), every
|
|
727
|
+
* already-started entry forms a contiguous leading prefix and every still-`pending`
|
|
717
728
|
* entry forms the trailing suffix — so the boundary is the count of leading
|
|
718
729
|
* non-`pending` entries: the index of the first `pending` entry, or the full length when
|
|
719
|
-
* none is `pending` (nothing is safely editable). A `pending` container's entries are
|
|
730
|
+
* none is `pending` (nothing is safely editable). A `pending` container's entries are all
|
|
720
731
|
* `pending`, so the boundary is `0` and every position is naturally accepted — callers
|
|
721
732
|
* need no special case for that.
|
|
722
733
|
*
|
|
@@ -752,7 +763,8 @@ function canTransitionTask(from, to) {
|
|
|
752
763
|
return TASK_TRANSITIONS[from].includes(to);
|
|
753
764
|
}
|
|
754
765
|
/**
|
|
755
|
-
* Resolves a task's runtime silence window against its workflow default
|
|
766
|
+
* Resolves a task's runtime silence window against its workflow default, to a host-safe
|
|
767
|
+
* `1..MAX_TIMER_MS` window or to `undefined` where the task disables it.
|
|
756
768
|
*
|
|
757
769
|
* @param value - The task-level override; any present non-positive or non-finite value disables
|
|
758
770
|
* @param fallback - The workflow-level default
|
|
@@ -819,7 +831,7 @@ function errorToMessage(error) {
|
|
|
819
831
|
*
|
|
820
832
|
* @remarks
|
|
821
833
|
* The shared leaf behind {@link import('./phases/Phase.js').Phase} and
|
|
822
|
-
* {@link import('./Workflow.js').Workflow}'s own `#failure` — each gathers
|
|
834
|
+
* {@link import('./Workflow.js').Workflow}'s own `#failure` — each gathers its tier's
|
|
823
835
|
* results (a phase's own settled tasks, a workflow's flattened `results()`) and feeds
|
|
824
836
|
* them here; the tier-local method keeps the invariant throw (a derived `failed`
|
|
825
837
|
* status means a failing result exists) because throwing on `undefined` is
|
|
@@ -859,7 +871,7 @@ function buildWorkflowContext(node) {
|
|
|
859
871
|
* Builds a {@link PhaseContext} — a phase's own identity plus a back-reference to its
|
|
860
872
|
* workflow — from the parent {@link WorkflowContext} and the phase node's identity.
|
|
861
873
|
*
|
|
862
|
-
* @param workflow - The parent workflow context (the lineage pointer
|
|
874
|
+
* @param workflow - The parent workflow context (the lineage pointer up the tree)
|
|
863
875
|
* @param node - The phase's identity (`id` / `name` / optional `description`)
|
|
864
876
|
* @returns The {@link PhaseContext}
|
|
865
877
|
*/
|
|
@@ -874,7 +886,7 @@ function buildPhaseContext(workflow, node) {
|
|
|
874
886
|
* (and, transitively, its workflow) — from the parent {@link PhaseContext} and the task
|
|
875
887
|
* node's identity.
|
|
876
888
|
*
|
|
877
|
-
* @param phase - The parent phase context (carrying the full lineage
|
|
889
|
+
* @param phase - The parent phase context (carrying the full lineage up the tree)
|
|
878
890
|
* @param node - The task's identity (`id` / `name` / optional `description`)
|
|
879
891
|
* @returns The {@link TaskContext}
|
|
880
892
|
*/
|
|
@@ -885,9 +897,9 @@ function buildTaskContext(phase, node) {
|
|
|
885
897
|
});
|
|
886
898
|
}
|
|
887
899
|
/**
|
|
888
|
-
* Converts a {@link WorkflowDefinition} into an
|
|
889
|
-
* node `pending`, no results, empty metadata — so the live W-b tree has
|
|
890
|
-
* path
|
|
900
|
+
* Converts a {@link WorkflowDefinition} into an initial {@link WorkflowSnapshot} — every
|
|
901
|
+
* node `pending`, no results, empty metadata — so the live W-b tree has one construction
|
|
902
|
+
* path, snapshot-driven, for a fresh build and for a restore alike.
|
|
891
903
|
*
|
|
892
904
|
* @remarks
|
|
893
905
|
* The structural fields (`id` / `name` / `description` + the ordered phases / tasks)
|
|
@@ -896,20 +908,20 @@ function buildTaskContext(phase, node) {
|
|
|
896
908
|
* `retries` / `timeout` (persisted on the {@link TaskSnapshot}, like `bail` / `concurrency`,
|
|
897
909
|
* so a restore + a {@link import('./types.js').WorkflowOptions.functions} registry resumes
|
|
898
910
|
* real work). The `bail` policy carries over — at the
|
|
899
|
-
* workflow tier
|
|
900
|
-
*
|
|
911
|
+
* workflow tier and, per phase, the
|
|
912
|
+
* effective policy (`phase.bail ?? workflowBail`) on each {@link PhaseSnapshot} — so the seeded
|
|
901
913
|
* snapshot is self-contained; a fresh seed has no `override`. `created` / `updated` are stamped at that point.
|
|
902
914
|
* {@link import('./factories.js').createWorkflow} builds from this.
|
|
903
915
|
*
|
|
904
|
-
* The optional `bail` override is the
|
|
916
|
+
* The optional `bail` override is the effective workflow policy the tree will run under
|
|
905
917
|
* (`createWorkflow` / the runner resolve `options.bail ?? definition.bail ?? DEFAULT_BAIL` and
|
|
906
|
-
* pass it here), so an `options.bail` override reaches
|
|
918
|
+
* pass it here), so an `options.bail` override reaches both the workflow tier and the
|
|
907
919
|
* inheritance default of every phase that declares no `bail` of its own — otherwise the
|
|
908
920
|
* per-phase seeds would silently ignore the override. Omitted ⇒ the definition's own `bail`
|
|
909
921
|
* (defaulting to the graceful {@link import('./constants.js').DEFAULT_BAIL}).
|
|
910
922
|
*
|
|
911
923
|
* @param definition - The workflow definition to seed from
|
|
912
|
-
* @param bail - The
|
|
924
|
+
* @param bail - The effective workflow bail to seed both tiers with (defaults to the definition's)
|
|
913
925
|
* @returns An initial, all-`pending` {@link WorkflowSnapshot}
|
|
914
926
|
*/
|
|
915
927
|
function definitionToSnapshot(definition, bail) {
|
|
@@ -931,7 +943,7 @@ function definitionToSnapshot(definition, bail) {
|
|
|
931
943
|
* {@link PhaseSnapshot} — the per-phase step of {@link definitionToSnapshot}.
|
|
932
944
|
*
|
|
933
945
|
* @remarks
|
|
934
|
-
* The snapshot persists the
|
|
946
|
+
* The snapshot persists the effective failure policy this phase runs under: the phase's own
|
|
935
947
|
* `bail` when it declares one, else the `workflowBail` it inherits — so a restore reinstates
|
|
936
948
|
* the same per-phase policy without a silent default (`effectiveBail = phase.bail ?? workflowBail`).
|
|
937
949
|
* `concurrency` (the resource throttle) carries over verbatim, omitted when undefined.
|
|
@@ -1061,7 +1073,7 @@ function recoverWorkflowSnapshot(snapshot) {
|
|
|
1061
1073
|
*
|
|
1062
1074
|
* @remarks
|
|
1063
1075
|
* The equality rule a lineage check needs: two descriptions match when they are the same value
|
|
1064
|
-
*
|
|
1076
|
+
* and that value is either a string or genuine absence. Anything else — a number, an object, a
|
|
1065
1077
|
* `null` — never matches, even against itself, so a lineage stamped with a non-string description
|
|
1066
1078
|
* is rejected rather than silently accepted.
|
|
1067
1079
|
*
|
|
@@ -1084,7 +1096,7 @@ function matchesDescription(left, right) {
|
|
|
1084
1096
|
*
|
|
1085
1097
|
* @remarks
|
|
1086
1098
|
* The four arguments are the result and the three snapshot nodes it claims to belong to, read
|
|
1087
|
-
* from the
|
|
1099
|
+
* from the outside in: a {@link TaskResult} is self-describing, so restoring one is only safe
|
|
1088
1100
|
* when every identity it carries agrees with the tree it was found in. It checks the exact key
|
|
1089
1101
|
* set at each level, that `status` equals the owning task's, and that the `task` / `phase` /
|
|
1090
1102
|
* `workflow` contexts — including the nested `task.phase.workflow` lineage — carry the same `id`,
|
|
@@ -1311,7 +1323,7 @@ function scheduleHost(start, signal) {
|
|
|
1311
1323
|
* {@link import('./Scheduler.js').Scheduler}, both Node primitives, and every browser backend's
|
|
1312
1324
|
* `delay` and macrotask fallback route here, so the timer is armed and cleared in one place. It
|
|
1313
1325
|
* composes {@link scheduleHost}, which owns listener safety, the cancellation race, the exact
|
|
1314
|
-
* caller reason, and once-only settlement. It does
|
|
1326
|
+
* caller reason, and once-only settlement. It does not validate `ms`: the value passes straight to
|
|
1315
1327
|
* the host `setTimeout`, which clamps a negative value or `NaN` to about zero, so an
|
|
1316
1328
|
* out-of-domain `ms` resumes on the next host turn rather than throwing. Pass a non-negative
|
|
1317
1329
|
* finite `ms`.
|
|
@@ -1334,10 +1346,10 @@ function delayHost(ms, signal) {
|
|
|
1334
1346
|
}
|
|
1335
1347
|
/**
|
|
1336
1348
|
* Parks until `signal` aborts — a promise-parked wait, never a timer or
|
|
1337
|
-
* busy-loop, that
|
|
1349
|
+
* busy-loop, that resolves on the abort event and never rejects.
|
|
1338
1350
|
*
|
|
1339
1351
|
* @remarks
|
|
1340
|
-
* Resolves
|
|
1352
|
+
* Resolves immediately when `signal` is already aborted; otherwise attaches a one-shot
|
|
1341
1353
|
* `abort` listener and resolves when it fires, removing the listener either way. The
|
|
1342
1354
|
* shared leaf behind the duplicate abort-wiring an execution engine otherwise hand-rolls
|
|
1343
1355
|
* at every fold point.
|
|
@@ -1372,9 +1384,9 @@ function parkSignal(signal) {
|
|
|
1372
1384
|
* (`task` / `tasks`, `phase` / `phases`). The `Map`'s insertion order is the single source of
|
|
1373
1385
|
* positional truth; `add` and `move` rebuild it through the pure
|
|
1374
1386
|
* {@link import('./helpers.js').insertEntry} / {@link import('./helpers.js').moveEntry} leaves.
|
|
1375
|
-
* - **Gated mutation API.** `append` is the build-time wiring path and
|
|
1387
|
+
* - **Gated mutation API.** `append` is the build-time wiring path and throws on a
|
|
1376
1388
|
* duplicate id; `add` / `remove` / `move` / `update` return a graceful `MUTATION`
|
|
1377
|
-
* {@link WorkflowError} failure instead. Gating reads
|
|
1389
|
+
* {@link WorkflowError} failure instead. Gating reads only the target's own existence, `pending`
|
|
1378
1390
|
* status, id, and bounds — a container's own status is the owning entity's gate, applied before
|
|
1379
1391
|
* it delegates here.
|
|
1380
1392
|
* - **Event-free.** A purely structural container; the entity that owns it emits on success.
|
|
@@ -1467,13 +1479,13 @@ var Collection = class {
|
|
|
1467
1479
|
* browser and Node.
|
|
1468
1480
|
*
|
|
1469
1481
|
* @remarks
|
|
1470
|
-
* - **Cross-environment.** Uses
|
|
1482
|
+
* - **Cross-environment.** Uses only `setTimeout` / `clearTimeout` — universally
|
|
1471
1483
|
* available. It deliberately avoids env-specific fast paths (`setImmediate`,
|
|
1472
1484
|
* `scheduler.yield`, `requestAnimationFrame`, `node:timers/promises`,
|
|
1473
1485
|
* `MessageChannel`); those belong to the environment backends, built with the
|
|
1474
1486
|
* agent loop that consumes them.
|
|
1475
1487
|
* - **`yield` is a macrotask host-turn, not a microtask.** `yield()` waits on a
|
|
1476
|
-
* `setTimeout(0)`,
|
|
1488
|
+
* `setTimeout(0)`, not `queueMicrotask`. A microtask drains before the host
|
|
1477
1489
|
* regains control, so it would not actually let pending I/O, timers, or
|
|
1478
1490
|
* rendering run — it only defers within the current task. A zero-delay timer is
|
|
1479
1491
|
* the correct cross-environment "give the host a turn".
|
|
@@ -1498,7 +1510,7 @@ var Collection = class {
|
|
|
1498
1510
|
var Scheduler = class {
|
|
1499
1511
|
/**
|
|
1500
1512
|
* Yields control back to the host so other tasks (I/O, timers, rendering) can
|
|
1501
|
-
* run, then resumes — a macrotask turn through `setTimeout(0)` (
|
|
1513
|
+
* run, then resumes — a macrotask turn through `setTimeout(0)` (not a microtask,
|
|
1502
1514
|
* which would resume before the host regains control).
|
|
1503
1515
|
*/
|
|
1504
1516
|
yield(options) {
|
|
@@ -1753,28 +1765,28 @@ var phaseUpdateShape = objectShape({
|
|
|
1753
1765
|
//#region src/core/stores/DatabaseWorkflowStore.ts
|
|
1754
1766
|
/**
|
|
1755
1767
|
* Implements a {@link WorkflowStoreInterface} backed by one table of the `databases` layer — a
|
|
1756
|
-
* workflow's durable run
|
|
1768
|
+
* workflow's durable run state is a row, so persistence reduces to keyed point-access
|
|
1757
1769
|
* (`get` / `set` / `delete`) over a `TableInterface`, the driver-pluggable twin of the
|
|
1758
1770
|
* plain-`Map` {@link import('./MemoryWorkflowStore.js').MemoryWorkflowStore}.
|
|
1759
1771
|
*
|
|
1760
1772
|
* @remarks
|
|
1761
1773
|
* The store is driver-agnostic: it holds a single {@link TableInterface} whose backend
|
|
1762
1774
|
* (memory, JSON, SQLite, IndexedDB) is chosen by whoever builds it (the factories), so a
|
|
1763
|
-
* JSON / SQLite / IndexedDB backend swaps in
|
|
1775
|
+
* JSON / SQLite / IndexedDB backend swaps in without touching the runner or the entity tree
|
|
1764
1776
|
* — the same seam as `@orkestrel/queue`'s `DatabaseQueueStore`.
|
|
1765
1777
|
* The driver defaults to memory ({@link import('../factories.js').createDatabaseWorkflowStore}
|
|
1766
|
-
* passes `createMemoryDriver()`), so it
|
|
1778
|
+
* passes `createMemoryDriver()`), so it also works in memory out of the box; you opt into the
|
|
1767
1779
|
* durable plumbing by passing a JSON / SQLite / IndexedDB driver.
|
|
1768
1780
|
*
|
|
1769
|
-
* The {@link WorkflowSnapshot} is stored as
|
|
1781
|
+
* The {@link WorkflowSnapshot} is stored as one opaque JSON column — the table is a row of
|
|
1770
1782
|
* `{ id; snapshot }` ({@link WorkflowSnapshotRow}), the snapshot the whole JSON blob (a `rawShape`
|
|
1771
1783
|
* column the factory builds) — exactly as `DatabaseQueueStore` stores its `input`. The snapshot is
|
|
1772
|
-
* already a
|
|
1784
|
+
* already a complete, self-contained, pure-JSON payload, so storing it whole is lossless and
|
|
1773
1785
|
* sidesteps a TS2589 instantiation-depth blow-up: a structured multi-column table would force the
|
|
1774
1786
|
* contract to `Infer` the deeply-nested snapshot shape (workflow → phases → tasks → results),
|
|
1775
1787
|
* tripping the compiler — one JSON column keeps the row type flat (`snapshot` reads back as `unknown`).
|
|
1776
1788
|
*
|
|
1777
|
-
* - **`set(snapshot)` upserts under the snapshot's
|
|
1789
|
+
* - **`set(snapshot)` upserts under the snapshot's own `id`** (no separate id param) — it writes
|
|
1778
1790
|
* the row `{ id: snapshot.id, snapshot }`.
|
|
1779
1791
|
* - **`get(id)` resolves the stored snapshot for an id**, owning and narrowing the opaque JSON
|
|
1780
1792
|
* column back to a {@link WorkflowSnapshot} through
|
|
@@ -1784,9 +1796,9 @@ var phaseUpdateShape = objectShape({
|
|
|
1784
1796
|
* differs from the requested key rejects with normalized `RESTORE` evidence.
|
|
1785
1797
|
* - **`delete(id)` drops a snapshot by id**; an absent id is a no-op (no throw).
|
|
1786
1798
|
*
|
|
1787
|
-
*
|
|
1799
|
+
* unlike the server package's `SessionStoreInterface` there is no
|
|
1788
1800
|
* idle-TTL / eviction — a persisted run-state is durable orchestration state that lives until an
|
|
1789
|
-
* explicit `delete`. The public surface is
|
|
1801
|
+
* explicit `delete`. The public surface is exactly `get` / `set` / `delete` — no extra members (the
|
|
1790
1802
|
* guide's method bijection with {@link WorkflowStoreInterface}). Restore stays a caller concern: read a
|
|
1791
1803
|
* snapshot back and rebuild the live tree with {@link import('../factories.js').createRestoredWorkflow}.
|
|
1792
1804
|
*
|
|
@@ -1820,7 +1832,7 @@ var DatabaseWorkflowStore = class {
|
|
|
1820
1832
|
if (row === void 0) return void 0;
|
|
1821
1833
|
return cloneWorkflowSnapshot(row.snapshot, id);
|
|
1822
1834
|
}
|
|
1823
|
-
/** Inserts or replaces under the snapshot's
|
|
1835
|
+
/** Inserts or replaces under the snapshot's own `id` (no separate id param) — the row is `{ id, snapshot }`. */
|
|
1824
1836
|
async set(snapshot) {
|
|
1825
1837
|
const owned = cloneWorkflowSnapshot(snapshot);
|
|
1826
1838
|
await this.#table.set({
|
|
@@ -1837,27 +1849,24 @@ var DatabaseWorkflowStore = class {
|
|
|
1837
1849
|
//#region src/core/stores/MemoryWorkflowStore.ts
|
|
1838
1850
|
/**
|
|
1839
1851
|
* Implements the in-memory {@link WorkflowStoreInterface} — a process-lifetime `Map` of
|
|
1840
|
-
* {@link WorkflowSnapshot}s keyed by workflow id, the
|
|
1841
|
-
* {@link import('../factories.js').createMemoryWorkflowStore} builds.
|
|
1852
|
+
* {@link WorkflowSnapshot}s keyed by workflow id, the default store
|
|
1853
|
+
* {@link import('../factories.js').createMemoryWorkflowStore} builds. It expires nothing: a
|
|
1854
|
+
* persisted snapshot lives until an explicit `delete`.
|
|
1842
1855
|
*
|
|
1843
1856
|
* @remarks
|
|
1844
1857
|
* A plain `Map<string, WorkflowSnapshot>` (the snapshot is already pure,
|
|
1845
|
-
* self-contained JSON, so no encoding is needed for the memory tier).
|
|
1846
|
-
*
|
|
1847
|
-
* NO idle-TTL and NO eviction: a persisted workflow run-state is durable orchestration state
|
|
1848
|
-
* that lives until an explicit `delete`, never silently aging out (a run that vanished
|
|
1849
|
-
* mid-flight would be a silent data loss, not a freed session). A durable backend (JSON /
|
|
1850
|
-
* SQLite / IndexedDB) swaps in through the SAME interface without touching the runner or the
|
|
1858
|
+
* self-contained JSON, so no encoding is needed for the memory tier). A durable backend (JSON /
|
|
1859
|
+
* SQLite / IndexedDB) swaps in through the same interface without touching the runner or the
|
|
1851
1860
|
* entity tree — its driver-pluggable twin is
|
|
1852
1861
|
* {@link import('./DatabaseWorkflowStore.js').DatabaseWorkflowStore} (the snapshot as one opaque
|
|
1853
1862
|
* JSON column), exactly as `@orkestrel/queue`'s `MemoryQueueStore`
|
|
1854
1863
|
* twins `DatabaseQueueStore`.
|
|
1855
1864
|
*
|
|
1856
1865
|
* - **`get` resolves the persisted snapshot for an id**, or `undefined` if none is stored.
|
|
1857
|
-
* - **`set` inserts / replaces under the snapshot's
|
|
1866
|
+
* - **`set` inserts / replaces under the snapshot's own `id`** (no separate id param).
|
|
1858
1867
|
* - **`delete` drops a snapshot by id**; an absent id is a no-op (no throw).
|
|
1859
1868
|
*
|
|
1860
|
-
* The public surface is
|
|
1869
|
+
* The public surface is exactly `get` / `set` / `delete` — no extra members (the guide's method
|
|
1861
1870
|
* bijection with {@link WorkflowStoreInterface}). Restore is a caller concern: read a snapshot
|
|
1862
1871
|
* back and rebuild the live tree with {@link import('../factories.js').createRestoredWorkflow}.
|
|
1863
1872
|
*
|
|
@@ -1900,27 +1909,27 @@ var MemoryWorkflowStore = class {
|
|
|
1900
1909
|
* - **Guarded transitions.** `start` (→ `running`), then `complete(value)`
|
|
1901
1910
|
* (→ `completed`, records a {@link import('@orkestrel/contract').Success}), `fail(error)`
|
|
1902
1911
|
* (→ `failed`, records a {@link import('@orkestrel/contract').Failure}), `skip` (→ `skipped`),
|
|
1903
|
-
* `stop` (→ `stopped`). Each consults {@link canTransitionTask}
|
|
1912
|
+
* `stop` (→ `stopped`). Each consults {@link canTransitionTask} first and throws a
|
|
1904
1913
|
* `TRANSITION` {@link WorkflowError} on an illegal move (for example, completing a
|
|
1905
1914
|
* non-`running` task) — the legal graph is the single source of truth, so the leaf can never
|
|
1906
1915
|
* reach an impossible state.
|
|
1907
1916
|
* - **Snapshot fidelity.** A leaf needs no override: `skipped` / `stopped` are explicit terminal
|
|
1908
1917
|
* statuses, and restore reinstates the leaf directly from {@link TaskSnapshot.status}.
|
|
1909
1918
|
* - **The cascade.** Every status change records its boxed result (when any), fires the leaf's
|
|
1910
|
-
*
|
|
1911
|
-
* transition propagates
|
|
1912
|
-
* order means an observer sees the
|
|
1919
|
+
* own event, then calls the parent phase's `#recompute` (injected at construction) so the
|
|
1920
|
+
* transition propagates up (Task → Phase → Workflow re-derive). The own-event-before-cascade
|
|
1921
|
+
* order means an observer sees the cause (this leaf changed) before the effect (the parents
|
|
1913
1922
|
* re-derive) — the project precedent (`Runner.#settle` emits its own `fail` before propagating).
|
|
1914
1923
|
* - **Observable.** The owned {@link emitter} ({@link TaskEventMap}) fires the
|
|
1915
|
-
* matching event strictly
|
|
1924
|
+
* matching event strictly after the state change, before the cascade; the emitter isolates
|
|
1916
1925
|
* a listener throw and routes it to its `error` handler (the `error` option), so a buggy
|
|
1917
1926
|
* observer can never corrupt a transition.
|
|
1918
|
-
* - **Declarative config.** `behavior` / `retries` / `timeout`
|
|
1927
|
+
* - **Declarative config.** `behavior` / `retries` / `timeout` persist in a
|
|
1919
1928
|
* {@link TaskSnapshot} (like a phase's `bail` / `concurrency`), carried verbatim from the
|
|
1920
1929
|
* matching {@link import('../types.js').TaskDefinition} / {@link TaskSnapshot} field. `handler`
|
|
1921
|
-
* is the
|
|
1930
|
+
* is the runtime-only counterpart — `behavior` resolved once at construction against the
|
|
1922
1931
|
* workflow-level {@link import('../types.js').WorkflowOptions.functions} registry — and is
|
|
1923
|
-
*
|
|
1932
|
+
* never persisted; `undefined` when `behavior` is omitted or unregistered. Only omission is a
|
|
1924
1933
|
* deliberate no-op; unresolved named work is rejected before dispatch.
|
|
1925
1934
|
*/
|
|
1926
1935
|
var Task = class {
|
|
@@ -2144,12 +2153,12 @@ var Task = class {
|
|
|
2144
2153
|
return this.#paused && this.#gate !== void 0 ? this.#gate.promise : Promise.resolve();
|
|
2145
2154
|
}
|
|
2146
2155
|
/**
|
|
2147
|
-
* Applies a validated declarative patch to
|
|
2156
|
+
* Applies a validated declarative patch to self (`name` / `description`).
|
|
2148
2157
|
*
|
|
2149
2158
|
* @remarks
|
|
2150
2159
|
* Defense-in-depth: the owning
|
|
2151
|
-
* {@link import('../types.js').TaskManagerInterface.update} gates
|
|
2152
|
-
* exists + `pending`), so this is the second, redundant check — it
|
|
2160
|
+
* {@link import('../types.js').TaskManagerInterface.update} gates first (target
|
|
2161
|
+
* exists + `pending`), so this is the second, redundant check — it throws a
|
|
2153
2162
|
* `MUTATION` {@link WorkflowError} unless this task's own `status` is `pending`.
|
|
2154
2163
|
*
|
|
2155
2164
|
* @param value - The {@link TaskUpdate} fields to apply
|
|
@@ -2258,10 +2267,10 @@ var Task = class {
|
|
|
2258
2267
|
* drift apart.
|
|
2259
2268
|
* - **Positional store.** `append` adds one live {@link TaskInterface} at the end (the build-time
|
|
2260
2269
|
* wiring path), `task(id)` looks one up, `tasks()` lists them in positional order, `count` is
|
|
2261
|
-
* the tally. A `skip` is a
|
|
2270
|
+
* the tally. A `skip` is a status change on a stored task (never a removal), so order survives
|
|
2262
2271
|
* it; a snapshot RESTORE re-`append`s in the snapshot's order, reproducing it exactly.
|
|
2263
2272
|
* - **Gated mutation API.** `add` / `remove` / `move` / `update` are the graceful
|
|
2264
|
-
* `Result` counterparts to `append`, gating
|
|
2273
|
+
* `Result` counterparts to `append`, gating only on the target's own existence/status/id/bounds
|
|
2265
2274
|
* — a duplicate id, an absent/non-`pending` target, an out-of-bounds `index`, or a patch that
|
|
2266
2275
|
* fails {@link taskUpdateShape} validation all fail gracefully with a `MUTATION`
|
|
2267
2276
|
* {@link WorkflowError} instead of throwing.
|
|
@@ -2309,47 +2318,47 @@ var TaskManager = class {
|
|
|
2309
2318
|
//#endregion
|
|
2310
2319
|
//#region src/core/phases/Phase.ts
|
|
2311
2320
|
/**
|
|
2312
|
-
* Implements the live
|
|
2321
|
+
* Implements the live derived state machine (W-b) for one phase — an observable whose
|
|
2313
2322
|
* {@link LifecycleStatus} is computed from its tasks (never set directly) and recomputed
|
|
2314
2323
|
* reactively as a task transitions (the middle tier of the cascade).
|
|
2315
2324
|
*
|
|
2316
2325
|
* @remarks
|
|
2317
2326
|
* - **Derived status.** `status` is `#override` when one is in force, else
|
|
2318
2327
|
* {@link derivePhaseStatus} over the live tasks' statuses. `#recompute` (passed to
|
|
2319
|
-
* each child {@link Task}) re-derives on every child transition; a
|
|
2320
|
-
* event
|
|
2321
|
-
* - **Override.** `skip` / `stop`
|
|
2322
|
-
* phase), overriding the derived value; the override is
|
|
2323
|
-
* `override` field and restored
|
|
2328
|
+
* each child {@link Task}) re-derives on every child transition; a change emits the matching
|
|
2329
|
+
* event and escalates to the workflow (`#escalate`, the upward step of the cascade).
|
|
2330
|
+
* - **Override.** `skip` / `stop` force the phase's status (for example, skipping a whole
|
|
2331
|
+
* phase), overriding the derived value; the override is persisted in the snapshot's own
|
|
2332
|
+
* `override` field and restored directly (no divergence guess), so a forced phase round-trips.
|
|
2324
2333
|
* - **Children.** `tasks` is the lean {@link TaskManager} (an accessor + `count`,
|
|
2325
2334
|
* no batch matrix); built positionally from the snapshot so order survives an interior `skip`.
|
|
2326
2335
|
* `results()` collects the settled tasks' {@link TaskResult}s (the phase tier of the result
|
|
2327
|
-
* tree); `workflow` navigates
|
|
2336
|
+
* tree); `workflow` navigates up to the live parent.
|
|
2328
2337
|
* - **Observable.** The owned {@link emitter} ({@link PhaseEventMap}) fires
|
|
2329
2338
|
* `start` / `complete` / `fail` / `pause` / `resume` / `skip` / `stop` after the
|
|
2330
2339
|
* corresponding status or runtime-gate change. Status events fire after the phase recomputes
|
|
2331
2340
|
* and before it escalates to the workflow, preserving child/phase cause before parent effect.
|
|
2332
2341
|
* The emitter isolates a listener throw and routes it to its `error` handler (the `error`
|
|
2333
2342
|
* option); `fail` carries the failing task's {@link TaskResult}.
|
|
2334
|
-
* - **Structural API.** `add` / `remove` / `move` / `update` gate
|
|
2343
|
+
* - **Structural API.** `add` / `remove` / `move` / `update` gate before
|
|
2335
2344
|
* delegating to {@link tasks} (the manager gates the target's own existence/status/id/
|
|
2336
|
-
* bounds), then emit the matching {@link PhaseEventMap} event on success only.
|
|
2345
|
+
* bounds), then emit the matching {@link PhaseEventMap} event on success only. Native
|
|
2337
2346
|
* gating, purely from this phase's own derived `status` (no runner-installed hook): while
|
|
2338
|
-
* `pending`, any valid `index` is accepted; while `running`, `add` accepts
|
|
2347
|
+
* `pending`, any valid `index` is accepted; while `running`, `add` accepts only a pure
|
|
2339
2348
|
* append (a live runner subscribed to the `add` event picks it up), and `remove` / `move` /
|
|
2340
2349
|
* `update` always fail gracefully (the tasks are already handed to the execution
|
|
2341
2350
|
* substrate); while terminal, everything is refused.
|
|
2342
|
-
* - **Patch.** `patch` applies a validated {@link PhaseUpdate} to
|
|
2351
|
+
* - **Patch.** `patch` applies a validated {@link PhaseUpdate} to self
|
|
2343
2352
|
* (`name` / `description` / `concurrency` / `bail`) — defense-in-depth: it throws a
|
|
2344
2353
|
* `MUTATION` {@link WorkflowError} unless this phase's own `status` is `pending`, mirroring
|
|
2345
2354
|
* the owning {@link WorkflowInterface.update}'s gate.
|
|
2346
|
-
* - **Minting.** {@link add}
|
|
2347
|
-
* (converts it to a {@link TaskSnapshot}, builds the task wired to
|
|
2355
|
+
* - **Minting.** {@link add} mints a live {@link Task} from a {@link TaskDefinition}
|
|
2356
|
+
* (converts it to a {@link TaskSnapshot}, builds the task wired to this phase) — the same
|
|
2348
2357
|
* construction path {@link #append} uses at build time, so a live mint and a restored/built
|
|
2349
|
-
* task are wired
|
|
2358
|
+
* task are wired identically. At construction, the workflow-level
|
|
2350
2359
|
* {@link import('../types.js').WorkflowRegistry} registry (threaded from
|
|
2351
2360
|
* {@link import('../types.js').WorkflowOptions.functions}) resolves every unique initial `behavior`
|
|
2352
|
-
* name
|
|
2361
|
+
* name once before any task is built; siblings sharing a name receive the exact same captured
|
|
2353
2362
|
* runtime {@link import('../types.js').TaskInterface.handler}. A later live {@link add} reads
|
|
2354
2363
|
* that name once from the retained registry at its own mint moment. An omitted or unregistered
|
|
2355
2364
|
* `behavior` resolves to no handler; only omission is a no-op, while an unresolved present name makes
|
|
@@ -2357,7 +2366,7 @@ var TaskManager = class {
|
|
|
2357
2366
|
* - **Runtime lifecycle.** `pause` / `resume` / `wait` mirror the workflow's own
|
|
2358
2367
|
* quartet, scoped to this phase — a driving
|
|
2359
2368
|
* {@link import('../types.js').WorkflowRunnerInterface.execute} gates a task's own
|
|
2360
|
-
* pre-dispatch on the workflow's gate
|
|
2369
|
+
* pre-dispatch on the workflow's gate first, then this phase's gate, without touching
|
|
2361
2370
|
* {@link status} — `paused` is runtime-only, never persisted. `skip` / `stop` (this phase's
|
|
2362
2371
|
* own terminal forcing) always release a parked {@link wait} waiter, mirroring
|
|
2363
2372
|
* {@link import('../Workflow.js').Workflow.destroy}'s cascade — a permanently-ended phase
|
|
@@ -2616,7 +2625,7 @@ var Phase = class {
|
|
|
2616
2625
|
* looks one up, `phases()` lists them in positional order, `count` is the tally. A snapshot
|
|
2617
2626
|
* RESTORE re-`append`s in the snapshot's order, reproducing it exactly.
|
|
2618
2627
|
* - **Gated mutation API.** `add` / `remove` / `move` / `update` are the graceful
|
|
2619
|
-
* `Result` counterparts to `append`, gating
|
|
2628
|
+
* `Result` counterparts to `append`, gating only on the target's own existence/status/id/bounds
|
|
2620
2629
|
* — a duplicate id, an absent/non-`pending` target, an out-of-bounds `index`, or a patch that
|
|
2621
2630
|
* fails {@link phaseUpdateShape} validation all fail gracefully with a `MUTATION`
|
|
2622
2631
|
* {@link WorkflowError} instead of throwing.
|
|
@@ -2664,7 +2673,7 @@ var PhaseManager = class {
|
|
|
2664
2673
|
//#endregion
|
|
2665
2674
|
//#region src/core/Workflow.ts
|
|
2666
2675
|
/**
|
|
2667
|
-
* Implements the live
|
|
2676
|
+
* Implements the live derived state machine (W-b) for a whole workflow — the observable root
|
|
2668
2677
|
* whose {@link LifecycleStatus} is computed from its phases under the `bail` policy and
|
|
2669
2678
|
* recomputed reactively as the cascade propagates up from a task transition.
|
|
2670
2679
|
*
|
|
@@ -2675,16 +2684,16 @@ var PhaseManager = class {
|
|
|
2675
2684
|
* passes a persisted one). Each child {@link Phase} is wired to escalate to `#recompute`.
|
|
2676
2685
|
* - **Derived status.** `status` is `#override` when forced, else
|
|
2677
2686
|
* {@link deriveWorkflowStatus} over the live phases' statuses feeding `bail`. `failed` is
|
|
2678
|
-
* reachable
|
|
2687
|
+
* reachable only under `bail: true` (a single failed task halts the workflow); under
|
|
2679
2688
|
* `bail: false` a failed phase folds into `completed`. `#recompute` diffs on each phase
|
|
2680
|
-
* change; a
|
|
2681
|
-
* - **Override.** `skip` / `stop`
|
|
2682
|
-
* may also be force-completed vacuously. The override is
|
|
2683
|
-
* `override` field and restored
|
|
2689
|
+
* change; a change emits.
|
|
2690
|
+
* - **Override.** `skip` / `stop` force the status; an executed task-free pending tree
|
|
2691
|
+
* may also be force-completed vacuously. The override is persisted in the snapshot's own
|
|
2692
|
+
* `override` field and restored directly (no divergence guess). The snapshot also persists
|
|
2684
2693
|
* `bail`, so a restore re-derives status identically without a silent policy default.
|
|
2685
2694
|
* - **Result tree.** `results()` flattens every phase's `results()` ({@link collectResults}) — the
|
|
2686
|
-
* workflow tier; `phase(id)` + each `phase.task(id)` navigate
|
|
2687
|
-
* navigate
|
|
2695
|
+
* workflow tier; `phase(id)` + each `phase.task(id)` navigate down, a task's `phase` / `workflow`
|
|
2696
|
+
* navigate up.
|
|
2688
2697
|
* - **Snapshot.** `snapshot()` serializes the whole live tree to a {@link WorkflowSnapshot} (pure
|
|
2689
2698
|
* JSON); {@link import('./factories.js').createRestoredWorkflow} rebuilds an equivalent live tree.
|
|
2690
2699
|
* - **Observable.** The owned {@link emitter} ({@link WorkflowEventMap}) fires
|
|
@@ -2692,17 +2701,17 @@ var PhaseManager = class {
|
|
|
2692
2701
|
* corresponding status or runtime-gate change; the emitter isolates a listener throw and
|
|
2693
2702
|
* routes it to its `error` handler (the `error` option); `fail` carries the failing task's
|
|
2694
2703
|
* {@link TaskResult}.
|
|
2695
|
-
* - **Structural API.** `add` / `remove` / `move` / `update` gate
|
|
2704
|
+
* - **Structural API.** `add` / `remove` / `move` / `update` gate before
|
|
2696
2705
|
* delegating to {@link phases} (the manager gates the target's own existence/status/id/
|
|
2697
|
-
* bounds), then emit the matching {@link WorkflowEventMap} event on success only.
|
|
2706
|
+
* bounds), then emit the matching {@link WorkflowEventMap} event on success only. Native,
|
|
2698
2707
|
* bottom-up gating (no runner-installed hook): refused outright while this workflow's own
|
|
2699
|
-
* `status` is terminal; otherwise a target position must fall within the
|
|
2708
|
+
* `status` is terminal; otherwise a target position must fall within the pending suffix —
|
|
2700
2709
|
* the contiguous trailing run of `pending` phases — whose boundary is
|
|
2701
2710
|
* {@link import('./helpers.js').deriveBoundary} over the live phases' statuses. A `pending`
|
|
2702
2711
|
* workflow's phases are all `pending`, so the boundary is `0` and every position is
|
|
2703
2712
|
* naturally accepted.
|
|
2704
2713
|
* - **Runtime lifecycle.** `pause` / `resume` / `wait` gate execution at the runner's
|
|
2705
|
-
* phase/task boundaries
|
|
2714
|
+
* phase/task boundaries without touching {@link status} — `paused` is runtime-only, never
|
|
2706
2715
|
* persisted. `destroy` is a terminal teardown: it `stop`s every non-terminal task and
|
|
2707
2716
|
* phase (releasing their gates and liveness resources), aborts {@link signal}, forces the
|
|
2708
2717
|
* workflow `stop` override when needed, releases its parked waiter, and marks
|
|
@@ -2991,14 +3000,14 @@ var Workflow = class {
|
|
|
2991
3000
|
* mints a live {@link WorkflowInterface} through the same construction path
|
|
2992
3001
|
* {@link import('./factories.js').createWorkflow} takes (flowing the manager's
|
|
2993
3002
|
* `functions` registry in) and stores it under `definition.id` — an already-present id
|
|
2994
|
-
*
|
|
3003
|
+
* overwrites (last write wins). `count` is the map size, `workflow(id)` looks one up,
|
|
2995
3004
|
* `workflows()` lists them in insertion order.
|
|
2996
3005
|
* - **Durable open / save.** `open(id)` returns an already-registered workflow directly; same-id
|
|
2997
3006
|
* misses share one hydration. A concurrent `add` wins, while `remove` / `clear` invalidate
|
|
2998
3007
|
* earlier reads; wrong-key payloads reject with `RESTORE`. `save(id)` captures a registered
|
|
2999
3008
|
* workflow's snapshot at invocation and serializes same-id writes without coupling other ids.
|
|
3000
3009
|
* Both remain lenient without a store or registered id.
|
|
3001
|
-
* - **Removal.** `remove` drops one by id, or a batch (array overload
|
|
3010
|
+
* - **Removal.** `remove` drops one by id, or a batch (array overload first) — `true` only when
|
|
3002
3011
|
* every id was removed. `clear` empties the registry.
|
|
3003
3012
|
* - **No active pointer.** Unlike its `ConversationManager` / `WorkspaceManager` twins, there is
|
|
3004
3013
|
* no `active` / `switch` — nothing in the workflow domain renders "the current workflow".
|
|
@@ -3008,7 +3017,7 @@ var Workflow = class {
|
|
|
3008
3017
|
* const manager = new WorkflowManager({
|
|
3009
3018
|
* functions: { compile: async (controller) => `built ${controller.task.id}` },
|
|
3010
3019
|
* })
|
|
3011
|
-
* const workflow = manager.add(definition) // minted, registered,
|
|
3020
|
+
* const workflow = manager.add(definition) // minted, registered, runnable
|
|
3012
3021
|
* manager.workflow(workflow.id) // the same workflow
|
|
3013
3022
|
* manager.count // 1
|
|
3014
3023
|
* ```
|
|
@@ -3234,11 +3243,11 @@ var RunHolder = class {
|
|
|
3234
3243
|
* unit it dispatches, handing it the unit's `id`, `input`, the unit's `Abort`
|
|
3235
3244
|
* handle, the queue attempt's `signal`, and a `spawn` callback that launches a
|
|
3236
3245
|
* sibling through the same queue.
|
|
3237
|
-
* - **Signal.** `signal` is the queue attempt's signal, which
|
|
3246
|
+
* - **Signal.** `signal` is the queue attempt's signal, which any-combines the
|
|
3238
3247
|
* unit's own abort, the runner-level abort (the runner aborts every unit), and
|
|
3239
3248
|
* the per-attempt timeout — so it fires on any of the three. `aborted` and
|
|
3240
3249
|
* `abort(reason)` delegate to the unit's `Abort` (the cancellation source of
|
|
3241
|
-
* truth); because the attempt signal
|
|
3250
|
+
* truth); because the attempt signal any-includes that abort, `abort()` fires
|
|
3242
3251
|
* `signal` too.
|
|
3243
3252
|
* - **`wait` promise-parks (never a timer).** It resolves the instant the unit's
|
|
3244
3253
|
* `signal` fires (immediately if already aborted) through a one-shot listener — no
|
|
@@ -3298,13 +3307,13 @@ var Controller = class {
|
|
|
3298
3307
|
* bounded concurrency, retries, and the per-attempt timeout are all the Queue's —
|
|
3299
3308
|
* the Runner adds only orchestration (launching, ordering, draining, fail-fast).
|
|
3300
3309
|
* - **Spawns actually run, results stay ordered (the B2 fix).** Declared inputs and
|
|
3301
|
-
* `spawn`ed siblings flow through the
|
|
3310
|
+
* `spawn`ed siblings flow through the same `#launch`, which appends the unit's `id`
|
|
3302
3311
|
* to an ordered `#order` list and records its settled value into `#values` by `id`.
|
|
3303
3312
|
* Results are read back as `#order.map(id => #values.get(id))` — declared first (in
|
|
3304
3313
|
* input order), then spawns (in spawn order). There is no one-time task snapshot,
|
|
3305
3314
|
* so a unit spawned mid-handler is run and ordered like any other.
|
|
3306
3315
|
* - **`execute` awaits the full spawn closure through a count gate.** `#launch` increments
|
|
3307
|
-
* an outstanding-unit `#count`
|
|
3316
|
+
* an outstanding-unit `#count` before enqueuing and every settle decrements it,
|
|
3308
3317
|
* resolving the `#drained` deferred at zero. Because `spawn` calls `#launch` (so
|
|
3309
3318
|
* `#count += 1`) before the parent handler returns, the count never reaches zero
|
|
3310
3319
|
* mid-run — `execute` parks on `#drained` and so awaits the entire transitive
|
|
@@ -3316,26 +3325,26 @@ var Controller = class {
|
|
|
3316
3325
|
* spawn by a bounded handler can still deadlock — that caveat is the caller's.)
|
|
3317
3326
|
* - **Per-unit Controller + signal.** Each unit gets a `Controller` carrying its `id`,
|
|
3318
3327
|
* `input`, the unit's `Abort` (so `aborted` / `abort` delegate to it), and the queue
|
|
3319
|
-
* attempt's `signal` (which
|
|
3328
|
+
* attempt's `signal` (which any-combines the unit abort + runner abort + timeout). A
|
|
3320
3329
|
* `spawn` callback is injected so `controller.spawn(input)` delegates to `#launch`.
|
|
3321
3330
|
* - **One-shot + fail-fast.** `execute` runs once (a second call throws). The first
|
|
3322
3331
|
* unit failure (after its retries) records the error and `abort()`s the run, so every
|
|
3323
3332
|
* sibling's signal fires; later failures are ignored and `execute` rejects with the
|
|
3324
3333
|
* first error. A user `abort(reason)` likewise rejects a running `execute`.
|
|
3325
3334
|
* - **`pause` / `resume` / `stop` ride the backing Queue.** `pause` / `resume`
|
|
3326
|
-
* delegate straight to the Queue's own pause/resume (holding/releasing the
|
|
3335
|
+
* delegate straight to the Queue's own pause/resume (holding/releasing the next
|
|
3327
3336
|
* dispatch while an in-flight unit finishes); `paused` mirrors the Queue's. `stop` is a
|
|
3328
|
-
*
|
|
3329
|
-
* units are rejected by the Queue's own stop
|
|
3337
|
+
* graceful permanent end, distinct from `abort`: still-pending (never-dispatched)
|
|
3338
|
+
* units are rejected by the Queue's own stop without their handler ever running, and
|
|
3330
3339
|
* `#settle` reads that fact (`#dispatched`) to treat the rejection as a stop artifact —
|
|
3331
3340
|
* not a failure, never tripping fail-fast — while an in-flight unit still runs to
|
|
3332
|
-
* completion and settles normally. `execute`
|
|
3341
|
+
* completion and settles normally. `execute` resolves (never rejects) after every unit
|
|
3333
3342
|
* has settled, with whatever results actually completed.
|
|
3334
3343
|
* - **Observable.** The owned {@link emitter} ({@link RunnerEventMap}) carries the run
|
|
3335
3344
|
* lifecycle — `start` / `unit` / `spawn` / `settle` / `fail` / `finish` / `abort` — for
|
|
3336
|
-
* fire-and-forget observers. Every event is emitted directly, strictly
|
|
3345
|
+
* fire-and-forget observers. Every event is emitted directly, strictly after the relevant
|
|
3337
3346
|
* launch / settle / drain transition; the emitter isolates a listener throw and routes it
|
|
3338
|
-
* to its `error` handler (the `error` option), so a buggy observer can
|
|
3347
|
+
* to its `error` handler (the `error` option), so a buggy observer can never reorder, throw
|
|
3339
3348
|
* into, or corrupt the one-shot / fail-fast / spawn-tracking engine: the outstanding-unit
|
|
3340
3349
|
* count gate stays balanced and fail-fast still fires regardless of what a listener does.
|
|
3341
3350
|
* Observation is purely a side-channel.
|
|
@@ -3394,15 +3403,15 @@ var Runner = class {
|
|
|
3394
3403
|
return this.#queue.paused;
|
|
3395
3404
|
}
|
|
3396
3405
|
/**
|
|
3397
|
-
* Injects one more unit into an
|
|
3398
|
-
* `Controller.spawn`, called from
|
|
3406
|
+
* Injects one more unit into an in-flight `execute` run — a live counterpart to a
|
|
3407
|
+
* `Controller.spawn`, called from outside any unit's handler.
|
|
3399
3408
|
*
|
|
3400
3409
|
* @remarks
|
|
3401
3410
|
* Returns `undefined` synchronously (graceful, non-throwing) unless the
|
|
3402
3411
|
* runner is mid-`execute` and not yet stopped — covering "never started",
|
|
3403
3412
|
* "already drained", "aborted", and "destroyed". Otherwise the unit is routed through
|
|
3404
|
-
* the
|
|
3405
|
-
* unit count gate increments
|
|
3413
|
+
* the same backing queue as a declared/`spawn`ed unit through `#launch` — the outstanding-
|
|
3414
|
+
* unit count gate increments before this call returns, so an in-flight `execute`
|
|
3406
3415
|
* keeps awaiting it (the drain race: `#running` flips to `false` as the very first
|
|
3407
3416
|
* step after `execute`'s `await drained.promise` settles, so a `spawn` reaching this
|
|
3408
3417
|
* method after the run has fully drained is cleanly rejected with `undefined` —
|
|
@@ -3462,7 +3471,7 @@ var Runner = class {
|
|
|
3462
3471
|
}
|
|
3463
3472
|
/**
|
|
3464
3473
|
* Suspends dispatch (resumable): delegates to the backing queue's own
|
|
3465
|
-
* `pause`, which holds the
|
|
3474
|
+
* `pause`, which holds the next dispatch while any in-flight unit finishes.
|
|
3466
3475
|
*
|
|
3467
3476
|
* @remarks
|
|
3468
3477
|
* A no-op after the runner is `stopped` — a stopped runner has no dispatch left to
|
|
@@ -3486,10 +3495,10 @@ var Runner = class {
|
|
|
3486
3495
|
this.#queue.resume();
|
|
3487
3496
|
}
|
|
3488
3497
|
/**
|
|
3489
|
-
* Ends the runner permanently — a
|
|
3498
|
+
* Ends the runner permanently — a graceful stop, distinct from `abort`.
|
|
3490
3499
|
* Marks the runner `stopping` + `stopped`, then stops the backing queue: every
|
|
3491
|
-
* still-
|
|
3492
|
-
* "queue is stopped" error,
|
|
3500
|
+
* still-pending (never-dispatched) unit is rejected by the queue with its own
|
|
3501
|
+
* "queue is stopped" error, without running its handler; every already-in-flight unit
|
|
3493
3502
|
* keeps running to completion and settles normally. `#settle` reads `#stopping` to
|
|
3494
3503
|
* classify a never-dispatched unit's rejection as a stop artifact (decrement the count
|
|
3495
3504
|
* gate, no recorded failure, no fail-fast trip) rather than a genuine failure — a
|
|
@@ -3618,21 +3627,21 @@ var Runner = class {
|
|
|
3618
3627
|
* Implements the attempt-scoped handle a {@link import('./types.js').WorkflowFunction} receives.
|
|
3619
3628
|
*
|
|
3620
3629
|
* @remarks
|
|
3621
|
-
* - **A leaf handle,
|
|
3630
|
+
* - **A leaf handle, not the runner `Controller`.** A workflow task is a leaf of the
|
|
3622
3631
|
* declarative W-b tree, not a fan-out unit, so it has no `spawn`; its `wait` instead
|
|
3623
3632
|
* checkpoints the workflow, phase, and task cooperative gates.
|
|
3624
|
-
* - **Folded signal.** `signal` is the cancellation folded for
|
|
3633
|
+
* - **Folded signal.** `signal` is the cancellation folded for this attempt: its per-attempt
|
|
3625
3634
|
* deadline, task stop/skip, workflow abort/timeout/budget/destroy, or a sibling fail-fast.
|
|
3626
3635
|
* A handler races its work against it; `aborted` reads it.
|
|
3627
3636
|
* - **Attempt ownership.** `report` / `pulse` are closures supplied by the runner and refuse
|
|
3628
3637
|
* after this signal aborts or a retry token supersedes this handle.
|
|
3629
3638
|
* - **Input + lineage.** `input` is the task's open `metadata` bag (its
|
|
3630
3639
|
* {@link import('./types.js').TaskInput} payload, `{}` when none); `task` is the full
|
|
3631
|
-
* {@link TaskContext}, so `task.phase` / `task.phase.workflow` navigate
|
|
3640
|
+
* {@link TaskContext}, so `task.phase` / `task.phase.workflow` navigate up the lineage.
|
|
3632
3641
|
* - **Read-up results.** `results()` returns every settled task's {@link TaskResult} across
|
|
3633
3642
|
* the phases that have already finished (a closure over the live
|
|
3634
3643
|
* {@link import('./types.js').WorkflowInterface}), so a `function` task can read an earlier
|
|
3635
|
-
* phase's output. Read-only — a task records its
|
|
3644
|
+
* phase's output. Read-only — a task records its own outcome by returning / throwing, not
|
|
3636
3645
|
* by mutating the tree.
|
|
3637
3646
|
* - **Event-free.** Like the runner `Controller`, the per-task handle carries no Emitter;
|
|
3638
3647
|
* observe the W-b entities' own emitters (`task.emitter` / `phase.emitter`) instead.
|
|
@@ -3726,11 +3735,12 @@ var TaskController = class {
|
|
|
3726
3735
|
//#endregion
|
|
3727
3736
|
//#region src/core/WorkflowPersistence.ts
|
|
3728
3737
|
/**
|
|
3729
|
-
* Coordinates advanced run-local snapshot persistence with one writer and one coalesced most
|
|
3738
|
+
* Coordinates advanced run-local snapshot persistence with one writer and one coalesced most
|
|
3739
|
+
* recent obligation, normally composed through `execute({ store })` rather than built directly.
|
|
3730
3740
|
*
|
|
3731
3741
|
* @remarks
|
|
3732
|
-
*
|
|
3733
|
-
*
|
|
3742
|
+
* Exported for hosts that need to coordinate the same required boundaries around their own runner
|
|
3743
|
+
* integration.
|
|
3734
3744
|
*
|
|
3735
3745
|
* @example
|
|
3736
3746
|
* ```ts
|
|
@@ -3896,8 +3906,8 @@ var WorkflowPersistence = class {
|
|
|
3896
3906
|
//#endregion
|
|
3897
3907
|
//#region src/core/WorkflowRunner.ts
|
|
3898
3908
|
/**
|
|
3899
|
-
* Implements the thin orchestrator that
|
|
3900
|
-
* substrate — phases sequential, tasks concurrent — dispatching each task through its
|
|
3909
|
+
* Implements the thin orchestrator that executes a live W-b workflow tree by composing the shipped
|
|
3910
|
+
* substrate — phases sequential, tasks concurrent — dispatching each task through its own
|
|
3901
3911
|
* resolved handler under the `bail` policy.
|
|
3902
3912
|
*
|
|
3903
3913
|
* @remarks
|
|
@@ -3908,33 +3918,33 @@ var WorkflowPersistence = class {
|
|
|
3908
3918
|
* timeout / budget / entity `signal` fold through the `@orkestrel/abort` signal contract,
|
|
3909
3919
|
* {@link createTimeout}, and `AbortSignal.any` (exactly as the agent runtime folds its bounds);
|
|
3910
3920
|
* pacing is the shipped
|
|
3911
|
-
* {@link SchedulerInterface}. The runner writes
|
|
3921
|
+
* {@link SchedulerInterface}. The runner writes zero concurrency / retry / abort logic of
|
|
3912
3922
|
* its own — it only sequences phases, dispatches a task's own handler, and drives the live
|
|
3913
3923
|
* entity. The workflow layer owns per-task deadlines because timeout settlement must
|
|
3914
3924
|
* update the live leaf under the phase's `bail` policy before the substrate unit settles.
|
|
3915
3925
|
* - **Pure engine — no integration registry.** The runner carries no behavior or provider
|
|
3916
3926
|
* registry: each live {@link TaskInterface} already
|
|
3917
3927
|
* resolved its own {@link import('./types.js').WorkflowFunction} into
|
|
3918
|
-
* {@link import('./types.js').TaskInterface.handler}
|
|
3928
|
+
* {@link import('./types.js').TaskInterface.handler} once at construction (build, restore,
|
|
3919
3929
|
* or a live mint all resolve it identically, from {@link WorkflowOptions.functions}), so
|
|
3920
3930
|
* dispatch is "invoke the task's own handler". Provider, protocol, and tool
|
|
3921
3931
|
* integrations remain application-owned {@link import('./types.js').WorkflowFunction}s
|
|
3922
3932
|
* composed into {@link WorkflowOptions.functions}. This module imports none of them.
|
|
3923
|
-
* - **Two `execute` forms, one engine.** `execute(definition, options)`
|
|
3933
|
+
* - **Two `execute` forms, one engine.** `execute(definition, options)` builds the live tree
|
|
3924
3934
|
* from a {@link WorkflowDefinition} (single source of truth for the `behavior` / `concurrency`
|
|
3925
|
-
* metadata); `execute(workflow, options)`
|
|
3935
|
+
* metadata); `execute(workflow, options)` drives a caller-owned, already-built
|
|
3926
3936
|
* {@link WorkflowInterface} instead — the entity-native control surface
|
|
3927
3937
|
* (`pause` / `resume` / `add` / `stop` / `destroy` live on the entity itself). Both forms
|
|
3928
|
-
* converge on the
|
|
3929
|
-
* exists — `#runTask` reads each task's
|
|
3930
|
-
* / `retries` / `timeout`, and `#runPhase` reads each phase's
|
|
3938
|
+
* converge on the same `#execute` engine: neither reads a `WorkflowDefinition` after the tree
|
|
3939
|
+
* exists — `#runTask` reads each task's own {@link import('./types.js').TaskInterface.handler}
|
|
3940
|
+
* / `retries` / `timeout`, and `#runPhase` reads each phase's own
|
|
3931
3941
|
* {@link PhaseInterface.concurrency} / `bail`, so a live `add`-minted phase or task (V5)
|
|
3932
|
-
* runs under
|
|
3933
|
-
* - **Phases sequential, tasks concurrent —
|
|
3934
|
-
* order,
|
|
3942
|
+
* runs under exactly the same rules as one built from the original definition.
|
|
3943
|
+
* - **Phases sequential, tasks concurrent — live continuity.** `#execute` drives the phases in
|
|
3944
|
+
* order, re-reading `workflow.phases.phases()` every iteration (a cursor over the live
|
|
3935
3945
|
* manager, not a one-time snapshot) so a caller's `workflow.add(phaseDefinition)` mid-run is
|
|
3936
|
-
* picked up. Within a phase, `#runPhase` subscribes to that phase's `add` event
|
|
3937
|
-
* capturing its task list, then `spawn`s any task added mid-phase onto the
|
|
3946
|
+
* picked up. Within a phase, `#runPhase` subscribes to that phase's `add` event before
|
|
3947
|
+
* capturing its task list, then `spawn`s any task added mid-phase onto the same substrate
|
|
3938
3948
|
* Runner (so it is actually dispatched, under the same `concurrency`); a task added too late
|
|
3939
3949
|
* for `spawn` to accept (the runner already drained) is swept `skip`ped afterward so the
|
|
3940
3950
|
* phase always reaches a coherent terminal state.
|
|
@@ -3943,30 +3953,30 @@ var WorkflowPersistence = class {
|
|
|
3943
3953
|
* auto-completes with JSON `null`; a present unresolved name is rejected by the synchronous
|
|
3944
3954
|
* execution claim and never false-completes.
|
|
3945
3955
|
* - **`bail` → substrate.** Under `bail: true` (halt) a genuine task failure `fail`s the leaf
|
|
3946
|
-
*
|
|
3956
|
+
* then re-throws, so the substrate Runner fail-fasts — it aborts the in-flight siblings
|
|
3947
3957
|
* (their `controller.signal` fires; a mid-flight sibling `skip`s) and rejects the phase run;
|
|
3948
3958
|
* `#execute` then `skip`s the remaining tasks / phases (the workflow derives `failed`).
|
|
3949
|
-
* Under `bail: false` (graceful) a failure `fail`s the leaf and
|
|
3959
|
+
* Under `bail: false` (graceful) a failure `fail`s the leaf and resolves (never throws), so
|
|
3950
3960
|
* the Runner settles every unit (allSettled) and the run finishes (the workflow derives
|
|
3951
3961
|
* `completed`, the failure recorded in the result tree).
|
|
3952
3962
|
* - **Pause / stop / destroy gates.** Workflow, phase, and task gates are checked before
|
|
3953
3963
|
* dispatch, and a running handler can checkpoint their folded state through
|
|
3954
3964
|
* {@link import('./types.js').TaskControllerInterface.wait}. Because the substrate acquires
|
|
3955
3965
|
* concurrency before this handler gate, a paused task occupies one phase slot until resume;
|
|
3956
|
-
* already-running siblings continue and its per-attempt timeout keeps counting. A
|
|
3966
|
+
* already-running siblings continue and its per-attempt timeout keeps counting. A graceful
|
|
3957
3967
|
* `workflow.stop()` (no signal involved) is caught at
|
|
3958
3968
|
* those same gates: not-yet-started work is `skip`ped, in-flight work finishes naturally. A
|
|
3959
|
-
*
|
|
3969
|
+
* hard `workflow.destroy()` aborts {@link WorkflowInterface.signal}, which `#fold` has folded
|
|
3960
3970
|
* into the run's composed signal — so it cancels the active phase Runner (and every
|
|
3961
|
-
* in-flight task) exactly like an external abort / timeout / budget fire.
|
|
3962
|
-
* `wait()` gate is
|
|
3963
|
-
*
|
|
3971
|
+
* in-flight task) exactly like an external abort / timeout / budget fire. Every park on a
|
|
3972
|
+
* `wait()` gate is raced against that same run signal (`#raceWait`, S2) — so a cancel firing
|
|
3973
|
+
* while parked unparks the engine promptly instead of hanging until `resume`; the existing
|
|
3964
3974
|
* halt / abort re-checks after the gate then decide the outcome.
|
|
3965
3975
|
* - **Abort / Timeout / Budget / entity-signal fold.** `#execute` folds the live workflow's
|
|
3966
3976
|
* own {@link WorkflowInterface.signal}, the run's external `signal`, a
|
|
3967
3977
|
* {@link TimeoutInterface}, and the `@orkestrel/budget` package's `BudgetInterface`'s
|
|
3968
3978
|
* `signal` into one `runSignal` (`AbortSignal.any`); a fire aborts the active phase's Runner
|
|
3969
|
-
* (cancelling every in-flight task) and
|
|
3979
|
+
* (cancelling every in-flight task) and halts the run — the remaining tasks / phases `skip`
|
|
3970
3980
|
* and the workflow is force-`stop`ped (settles `stopped`). Each task's
|
|
3971
3981
|
* {@link TaskController} signal `AbortSignal.any`-combines the substrate per-unit signal with
|
|
3972
3982
|
* `runSignal`, so a handler observes either cause directly.
|
|
@@ -4384,20 +4394,20 @@ function createWorkflowContract() {
|
|
|
4384
4394
|
* Builds the live W-b entity tree from a {@link WorkflowDefinition} — the whole
|
|
4385
4395
|
* {@link WorkflowInterface} → {@link import('./types.js').PhaseInterface} →
|
|
4386
4396
|
* {@link import('./types.js').TaskInterface} tree, each level wired with its lineage
|
|
4387
|
-
* context, its emitter, and the cascade
|
|
4397
|
+
* context, its emitter, and the cascade, and every node born `pending`.
|
|
4388
4398
|
*
|
|
4389
4399
|
* @remarks
|
|
4390
|
-
* The definition is the
|
|
4400
|
+
* The definition is the declarative blueprint; this seeds an initial all-`pending`
|
|
4391
4401
|
* {@link WorkflowSnapshot} from it ({@link definitionToSnapshot}) and constructs the live
|
|
4392
4402
|
* tree over that one path. The `bail` failure policy resolves to `options.bail`, else the
|
|
4393
4403
|
* definition's `bail`, else the graceful {@link import('./constants.js').DEFAULT_BAIL}; it
|
|
4394
4404
|
* feeds {@link import('./helpers.js').deriveWorkflowStatus}. Per-phase / per-task initial
|
|
4395
4405
|
* listeners + metadata travel through `options.phases[id].on` /
|
|
4396
4406
|
* `options.phases[id].tasks[id]` (the nested-by-id bag). The W-b tree is the
|
|
4397
|
-
* state machine
|
|
4407
|
+
* state machine only — it does not execute tasks (W-c drives the transitions).
|
|
4398
4408
|
*
|
|
4399
4409
|
* `options.functions` is the {@link import('./types.js').WorkflowRegistry} registry each live
|
|
4400
|
-
* task's `behavior` name resolves against
|
|
4410
|
+
* task's `behavior` name resolves against once at construction into its runtime
|
|
4401
4411
|
* {@link import('./types.js').TaskInterface.handler}. An omitted name is the deliberate no-op;
|
|
4402
4412
|
* an unresolved present name remains inspectable but is rejected if execution is attempted.
|
|
4403
4413
|
*
|
|
@@ -4424,14 +4434,14 @@ function createWorkflow(definition, options) {
|
|
|
4424
4434
|
* @remarks
|
|
4425
4435
|
* Seeds an initial all-`pending` {@link WorkflowSnapshot} from the definition and constructs the
|
|
4426
4436
|
* live {@link WorkflowInterface} over it. `bail` is the caller's own override, forwarded to
|
|
4427
|
-
* {@link definitionToSnapshot} so it reaches
|
|
4437
|
+
* {@link definitionToSnapshot} so it reaches both tiers: the workflow snapshot and the inheritance
|
|
4428
4438
|
* default of every phase that declares no `bail` of its own, while a phase declaring one still
|
|
4429
4439
|
* wins. Omitted, the definition's own `bail` governs, defaulting to the graceful
|
|
4430
4440
|
* {@link import('./constants.js').DEFAULT_BAIL}.
|
|
4431
4441
|
*
|
|
4432
|
-
* `captured` is forwarded to the entity
|
|
4442
|
+
* `captured` is forwarded to the entity unchanged — its own `bail` is deliberately not replaced
|
|
4433
4443
|
* with the resolved policy, because the snapshot already carries the resolved value at both tiers
|
|
4434
|
-
* and an injected one would make `Workflow` read it as an
|
|
4444
|
+
* and an injected one would make `Workflow` read it as an explicit uniform override and clobber
|
|
4435
4445
|
* the per-phase overrides. Each task's `behavior` / `retries` / `timeout` travel onto the snapshot
|
|
4436
4446
|
* too, so `captured.functions` resolves every handler identically whether the tree is built fresh
|
|
4437
4447
|
* or restored. Pass a bag {@link captureWorkflowOptions} already owns: this constructs over it
|
|
@@ -4461,11 +4471,11 @@ function createWorkflowTree(definition, captured) {
|
|
|
4461
4471
|
*
|
|
4462
4472
|
* @remarks
|
|
4463
4473
|
* Round-trip fidelity is paramount: a `snapshot()` → `createRestoredWorkflow()` reproduces the
|
|
4464
|
-
* same status at every node (each `#override` restored
|
|
4474
|
+
* same status at every node (each `#override` restored directly from the snapshot's own
|
|
4465
4475
|
* `override` field, not guessed from a status divergence), the same recorded
|
|
4466
4476
|
* {@link import('./types.js').TaskResult}s, and the same positional order (an interior
|
|
4467
|
-
* `skip` / `remove` survives). The snapshot is
|
|
4468
|
-
* policy it ran under, so the restore re-derives status
|
|
4477
|
+
* `skip` / `remove` survives). The snapshot is self-contained — it persists the `bail`
|
|
4478
|
+
* policy it ran under, so the restore re-derives status identically without a silent
|
|
4469
4479
|
* default; the snapshot's `bail` is the source of truth, while an explicit `options.bail`
|
|
4470
4480
|
* still wins when supplied (to deliberately re-run under a different policy). A structurally
|
|
4471
4481
|
* invalid snapshot (a status — or override — outside the lifecycle vocabulary, or a
|
|
@@ -4491,7 +4501,8 @@ function createRestoredWorkflow(snapshot, options) {
|
|
|
4491
4501
|
return new Workflow(cloneWorkflowSnapshot(snapshot), captured);
|
|
4492
4502
|
}
|
|
4493
4503
|
/**
|
|
4494
|
-
* Builds an interrupted workflow back to life at its remaining retry budget
|
|
4504
|
+
* Builds an interrupted workflow back to life at its remaining retry budget, normalizing a
|
|
4505
|
+
* leaf whose attempts are exhausted into a recovery failure.
|
|
4495
4506
|
*
|
|
4496
4507
|
* @remarks
|
|
4497
4508
|
* Each phase captures every unique initial `behavior` binding once before constructing tasks. Recovery
|
|
@@ -4520,18 +4531,17 @@ function createRecoveredWorkflow(snapshot, options) {
|
|
|
4520
4531
|
}
|
|
4521
4532
|
/**
|
|
4522
4533
|
* Creates the in-memory durable {@link WorkflowStoreInterface} — a process-lifetime
|
|
4523
|
-
* {@link MemoryWorkflowStore} persisting {@link WorkflowSnapshot}s by workflow id, the
|
|
4524
|
-
* backend behind the W-d persistence seam.
|
|
4534
|
+
* {@link MemoryWorkflowStore} persisting {@link WorkflowSnapshot}s by workflow id, the default
|
|
4535
|
+
* backend behind the W-d persistence seam. It takes no options and expires nothing: a
|
|
4536
|
+
* persisted run state lives until an explicit `delete`.
|
|
4525
4537
|
*
|
|
4526
4538
|
* @remarks
|
|
4527
4539
|
* The snapshot analogue of the server package's `createMemorySessionStore`
|
|
4528
|
-
* (and the `createMemoryQueueStore` family)
|
|
4529
|
-
*
|
|
4530
|
-
* an explicit `delete`. This is
|
|
4531
|
-
* the zero-plumbing DEFAULT (a plain `Map`); its driver-pluggable twin is
|
|
4540
|
+
* (and the `createMemoryQueueStore` family) is the zero-plumbing default (a plain `Map`); its
|
|
4541
|
+
* driver-pluggable twin is
|
|
4532
4542
|
* {@link createDatabaseWorkflowStore} (the snapshot as one opaque JSON column over a `databases`
|
|
4533
|
-
* table) — for a
|
|
4534
|
-
* driver, and it swaps in
|
|
4543
|
+
* table) — for a durable store (run-state surviving a restart) pass it a JSON / SQLite / IndexedDB
|
|
4544
|
+
* driver, and it swaps in without touching the runner or the entity tree. Restore stays a caller
|
|
4535
4545
|
* concern: read a snapshot back and rebuild the live tree with {@link createRestoredWorkflow}.
|
|
4536
4546
|
*
|
|
4537
4547
|
* @returns A memory-backed {@link WorkflowStoreInterface}
|
|
@@ -4553,22 +4563,22 @@ function createMemoryWorkflowStore() {
|
|
|
4553
4563
|
/**
|
|
4554
4564
|
* Creates a {@link DatabaseWorkflowStore} over any {@link DriverInterface} — the durable,
|
|
4555
4565
|
* driver-pluggable backing for the W-d persistence seam, the opt-in twin of
|
|
4556
|
-
* {@link createMemoryWorkflowStore}.
|
|
4566
|
+
* {@link createMemoryWorkflowStore}. It holds the snapshot as one opaque JSON column, and its
|
|
4567
|
+
* `driver` defaults to memory, so it works before any durable driver is passed.
|
|
4557
4568
|
*
|
|
4558
4569
|
* @remarks
|
|
4559
|
-
* Builds a one-table database (`snapshots`, keyed by `id`) over the supplied driver
|
|
4560
|
-
*
|
|
4570
|
+
* Builds a one-table database (`snapshots`, keyed by `id`) over the supplied driver. The column map
|
|
4571
|
+
* is `{ id; snapshot }` where `snapshot` is a
|
|
4561
4572
|
* `rawShape` (a JSON blob), exactly as `createDatabaseQueueStore` stores its `input`. The
|
|
4562
|
-
* snapshot is already a
|
|
4563
|
-
*
|
|
4573
|
+
* snapshot is already a complete, self-contained, pure-JSON payload, so storing it whole is lossless
|
|
4574
|
+
* and keeps the row type flat — a structured multi-column snapshot table would force the contract to
|
|
4564
4575
|
* `Infer` the deeply-nested snapshot shape (workflow → phases → tasks → results) and trip TS2589;
|
|
4565
4576
|
* the opaque column sidesteps it (the column reads back as `unknown`, owned and narrowed on `get` by
|
|
4566
4577
|
* {@link cloneWorkflowSnapshot}, whose semantic pass is
|
|
4567
|
-
* {@link import('./validators.js').isOwnedWorkflowSnapshot}).
|
|
4568
|
-
*
|
|
4569
|
-
* `createJSONDriver` / `createSQLiteDriver` (or a browser IndexedDB driver) for a persistent one —
|
|
4578
|
+
* {@link import('./validators.js').isOwnedWorkflowSnapshot}). Pass a server `createJSONDriver` /
|
|
4579
|
+
* `createSQLiteDriver` (or a browser IndexedDB driver) for a persistent one —
|
|
4570
4580
|
* the durability is the driver's job, the store engine is shared. It swaps in behind
|
|
4571
|
-
* {@link WorkflowStoreInterface}
|
|
4581
|
+
* {@link WorkflowStoreInterface} without touching the runner or the entity tree.
|
|
4572
4582
|
*
|
|
4573
4583
|
* @param driver - The storage backend the snapshots persist to (defaults to {@link createMemoryDriver})
|
|
4574
4584
|
* @returns A {@link WorkflowStoreInterface} over the driver
|
|
@@ -4596,22 +4606,22 @@ function createDatabaseWorkflowStore(driver = createMemoryDriver()) {
|
|
|
4596
4606
|
}).table("snapshots"));
|
|
4597
4607
|
}
|
|
4598
4608
|
/**
|
|
4599
|
-
* Creates the thin orchestrator — a {@link WorkflowRunnerInterface} — that
|
|
4600
|
-
* workflow tree by
|
|
4601
|
-
* task dispatched through its
|
|
4609
|
+
* Creates the thin orchestrator — a {@link WorkflowRunnerInterface} — that executes a live W-b
|
|
4610
|
+
* workflow tree by composing the shipped substrate: phases sequential, tasks concurrent, each
|
|
4611
|
+
* task dispatched through its own resolved handler under the workflow's `bail` policy. The
|
|
4612
|
+
* engine is pure — it carries no behavior or provider registry, and its only option is the
|
|
4613
|
+
* scheduler it paces phase boundaries with.
|
|
4602
4614
|
*
|
|
4603
4615
|
* @remarks
|
|
4604
|
-
*
|
|
4605
|
-
*
|
|
4606
|
-
* resolved its own {@link import('./types.js').WorkflowFunction} into
|
|
4607
|
-
* {@link import('./types.js').TaskInterface.handler} ONCE at construction, from the
|
|
4616
|
+
* Each live task already resolved its own {@link import('./types.js').WorkflowFunction} into
|
|
4617
|
+
* {@link import('./types.js').TaskInterface.handler} once at construction, from the
|
|
4608
4618
|
* {@link WorkflowOptions.functions} registry supplied to `execute` / {@link createWorkflow}.
|
|
4609
4619
|
* Per-phase bounded concurrency is one {@link createRunner} per phase; `bail` maps onto that
|
|
4610
4620
|
* Runner's fail-fast (`true` — the first failure aborts the in-flight siblings + skips the
|
|
4611
4621
|
* rest) vs settle-all (`false` — failures are recorded, the run finishes); the run-level abort
|
|
4612
4622
|
* / timeout / budget ({@link import('./types.js').WorkflowRunOptions}) fold through
|
|
4613
4623
|
* `AbortSignal.any` (the agent runtime's pattern); pacing is the shipped scheduler.
|
|
4614
|
-
* `execute(definition, options?)`
|
|
4624
|
+
* `execute(definition, options?)` builds the live tree from the definition itself (through
|
|
4615
4625
|
* {@link createWorkflow} — one source of truth, returned in `WorkflowResult.workflow`), drives
|
|
4616
4626
|
* the live entity (`start` → `complete` / `fail`), and resolves a
|
|
4617
4627
|
* {@link import('./types.js').WorkflowResult}.
|
|
@@ -4625,19 +4635,43 @@ function createDatabaseWorkflowStore(driver = createMemoryDriver()) {
|
|
|
4625
4635
|
* See {@link WorkflowRunnerOptions}.
|
|
4626
4636
|
* @returns A working {@link WorkflowRunnerInterface}
|
|
4627
4637
|
*
|
|
4628
|
-
* @example
|
|
4638
|
+
* @example Author a definition and run it
|
|
4629
4639
|
* ```ts
|
|
4630
4640
|
* import { createWorkflowRunner } from '@orkestrel/workflow'
|
|
4641
|
+
* import type { WorkflowDefinition } from '@orkestrel/workflow'
|
|
4642
|
+
*
|
|
4643
|
+
* const definition: WorkflowDefinition = {
|
|
4644
|
+
* id: 'release',
|
|
4645
|
+
* name: 'Release',
|
|
4646
|
+
* phases: [
|
|
4647
|
+
* {
|
|
4648
|
+
* id: 'build',
|
|
4649
|
+
* name: 'Build',
|
|
4650
|
+
* tasks: [
|
|
4651
|
+
* { id: 'compile', name: 'Compile', behavior: 'compile' },
|
|
4652
|
+
* { id: 'lint', name: 'Lint', behavior: 'lint' },
|
|
4653
|
+
* ],
|
|
4654
|
+
* },
|
|
4655
|
+
* {
|
|
4656
|
+
* id: 'ship',
|
|
4657
|
+
* name: 'Ship',
|
|
4658
|
+
* tasks: [{ id: 'publish', name: 'Publish', behavior: 'publish' }],
|
|
4659
|
+
* },
|
|
4660
|
+
* ],
|
|
4661
|
+
* }
|
|
4662
|
+
*
|
|
4663
|
+
* const runner = createWorkflowRunner() // a pure engine — no registries
|
|
4631
4664
|
*
|
|
4632
|
-
* const runner = createWorkflowRunner()
|
|
4633
|
-
* const definition = { id: 'w', name: 'W', phases: [{ id: 'p', name: 'P', tasks: [
|
|
4634
|
-
* { id: 't', name: 'T', behavior: 'compile' },
|
|
4635
|
-
* ] }] }
|
|
4636
4665
|
* const result = await runner.execute(definition, {
|
|
4637
|
-
* functions: {
|
|
4666
|
+
* functions: {
|
|
4667
|
+
* compile: async (controller) => `built ${controller.task.id}`,
|
|
4668
|
+
* lint: async () => 'clean',
|
|
4669
|
+
* publish: async () => 'published',
|
|
4670
|
+
* },
|
|
4638
4671
|
* })
|
|
4639
4672
|
* result.status // 'completed'
|
|
4640
|
-
* result.workflow.phase('
|
|
4673
|
+
* result.workflow.phase('build')?.task('compile')?.status // 'completed'
|
|
4674
|
+
* result.results // every settled task's TaskResult, in positional order
|
|
4641
4675
|
* ```
|
|
4642
4676
|
*/
|
|
4643
4677
|
function createWorkflowRunner(options) {
|
|
@@ -4646,15 +4680,17 @@ function createWorkflowRunner(options) {
|
|
|
4646
4680
|
/**
|
|
4647
4681
|
* Creates a {@link WorkflowManagerInterface} — the store-backed registry of
|
|
4648
4682
|
* {@link WorkflowInterface}s, the additive manager tier mirroring the `@orkestrel/agent`
|
|
4649
|
-
* line's `createConversationManager` / `createWorkspaceManager`.
|
|
4683
|
+
* line's `createConversationManager` / `createWorkspaceManager`. The returned registry makes
|
|
4684
|
+
* hydrated named work runnable when `options.functions` is supplied, and leaves it
|
|
4685
|
+
* inspectable when it is not.
|
|
4650
4686
|
*
|
|
4651
4687
|
* @remarks
|
|
4652
4688
|
* `options.functions` flows into every workflow the manager mints (`add`, through
|
|
4653
4689
|
* {@link createWorkflow}) or hydrates (`open`'s registry-miss path, through
|
|
4654
|
-
* {@link createRestoredWorkflow}), so a hydrated workflow is
|
|
4655
|
-
* mirror. `options.store` is the
|
|
4690
|
+
* {@link createRestoredWorkflow}), so a hydrated workflow is runnable rather than a dead snapshot
|
|
4691
|
+
* mirror. `options.store` is the exact analogue of the twins' `store` seam — omitted ⇒ the
|
|
4656
4692
|
* manager is registry-only (`open` resolves only what is registered, `save` is a no-op). This
|
|
4657
|
-
* is
|
|
4693
|
+
* is purely additive: direct {@link WorkflowStoreInterface} use and
|
|
4658
4694
|
* {@link createRestoredWorkflow} remain valid — the manager is one more caller-driven persistence
|
|
4659
4695
|
* seam, not a replacement.
|
|
4660
4696
|
*
|
|
@@ -4669,7 +4705,7 @@ function createWorkflowRunner(options) {
|
|
|
4669
4705
|
* store: createMemoryWorkflowStore(),
|
|
4670
4706
|
* functions: { compile: async (controller) => `built ${controller.task.id}` },
|
|
4671
4707
|
* })
|
|
4672
|
-
* const workflow = manager.add(definition) // minted, registered,
|
|
4708
|
+
* const workflow = manager.add(definition) // minted, registered, runnable
|
|
4673
4709
|
* await manager.save(workflow.id) // persisted to the store
|
|
4674
4710
|
* const reopened = await manager.open(workflow.id) // already registered — no store hit
|
|
4675
4711
|
* ```
|
|
@@ -4725,12 +4761,13 @@ function createScheduler() {
|
|
|
4725
4761
|
}
|
|
4726
4762
|
/**
|
|
4727
4763
|
* Creates a thin generic orchestrator that drives declared units — and any they
|
|
4728
|
-
* `spawn` — through a bounded-concurrency queue, collecting their results in order
|
|
4764
|
+
* `spawn` — through a bounded-concurrency queue, collecting their results in order and
|
|
4765
|
+
* failing the run fast on the first genuine unit failure.
|
|
4729
4766
|
*
|
|
4730
4767
|
* @remarks
|
|
4731
4768
|
* The Runner composes the workers `Queue` for backpressure, FIFO ordering, bounded
|
|
4732
4769
|
* concurrency, retries, and the per-attempt timeout — it adds only orchestration, not
|
|
4733
|
-
* a second concurrency engine. `execute(inputs)` runs the unit set
|
|
4770
|
+
* a second concurrency engine. `execute(inputs)` runs the unit set once (a second call
|
|
4734
4771
|
* throws) and resolves the units' results in order: the declared inputs first, then
|
|
4735
4772
|
* any `spawn`ed siblings in spawn order. Each unit's handler gets a `Controller` — its
|
|
4736
4773
|
* `id` / `input`, a `signal` that fires on the unit's `abort`, a runner-level `abort`,
|
|
@@ -4740,8 +4777,8 @@ function createScheduler() {
|
|
|
4740
4777
|
* typed `emitter` surfaces `start` / `unit` / `spawn` / `settle` / `fail` / `finish` / `abort`.
|
|
4741
4778
|
*
|
|
4742
4779
|
* Because `spawn` is fire-and-track (the runner awaits the whole spawn closure through an
|
|
4743
|
-
* outstanding-unit count, not a one-time snapshot), a handler need
|
|
4744
|
-
* for them to run — and on a bounded runner do
|
|
4780
|
+
* outstanding-unit count, not a one-time snapshot), a handler need not await its spawns
|
|
4781
|
+
* for them to run — and on a bounded runner do not `await` a spawn inline (a slot-holding
|
|
4745
4782
|
* handler awaiting its own spawn can deadlock); fan out and return instead.
|
|
4746
4783
|
*
|
|
4747
4784
|
* @typeParam TInput - The work input each unit carries
|