@workflow/core 5.0.0-beta.40 → 5.0.0-beta.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/events-consumer.d.ts +224 -6
  2. package/dist/events-consumer.d.ts.map +1 -1
  3. package/dist/events-consumer.js +497 -50
  4. package/dist/private.d.ts +87 -18
  5. package/dist/private.d.ts.map +1 -1
  6. package/dist/private.js +118 -47
  7. package/dist/runtime/constants.d.ts +50 -1
  8. package/dist/runtime/constants.d.ts.map +1 -1
  9. package/dist/runtime/constants.js +59 -3
  10. package/dist/runtime/helpers.d.ts +212 -70
  11. package/dist/runtime/helpers.d.ts.map +1 -1
  12. package/dist/runtime/helpers.js +275 -86
  13. package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -1
  14. package/dist/runtime/quickjs-assets.generated.js +2 -2
  15. package/dist/runtime/quickjs-entrypoint.d.ts +8 -9
  16. package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -1
  17. package/dist/runtime/quickjs-entrypoint.js +172 -41
  18. package/dist/runtime/quickjs-runtime.d.ts +36 -1
  19. package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
  20. package/dist/runtime/quickjs-runtime.js +613 -185
  21. package/dist/runtime/quickjs-serde.d.ts +107 -0
  22. package/dist/runtime/quickjs-serde.d.ts.map +1 -0
  23. package/dist/runtime/quickjs-serde.js +2098 -0
  24. package/dist/runtime/replay-budget.d.ts +13 -14
  25. package/dist/runtime/replay-budget.d.ts.map +1 -1
  26. package/dist/runtime/replay-budget.js +20 -73
  27. package/dist/runtime/resume-hook.d.ts.map +1 -1
  28. package/dist/runtime/resume-hook.js +57 -13
  29. package/dist/runtime/resume-latency.d.ts +143 -0
  30. package/dist/runtime/resume-latency.d.ts.map +1 -0
  31. package/dist/runtime/resume-latency.js +153 -0
  32. package/dist/runtime/runs.d.ts.map +1 -1
  33. package/dist/runtime/runs.js +3 -4
  34. package/dist/runtime/start.js +2 -7
  35. package/dist/runtime/step-executor.d.ts +27 -12
  36. package/dist/runtime/step-executor.d.ts.map +1 -1
  37. package/dist/runtime/step-executor.js +105 -15
  38. package/dist/runtime/suspension-handler.d.ts +46 -8
  39. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  40. package/dist/runtime/suspension-handler.js +173 -15
  41. package/dist/runtime/world-compatibility.d.ts +16 -0
  42. package/dist/runtime/world-compatibility.d.ts.map +1 -1
  43. package/dist/runtime/world-compatibility.js +26 -5
  44. package/dist/runtime.d.ts.map +1 -1
  45. package/dist/runtime.js +911 -524
  46. package/dist/serialization/codec-devalue-vm.d.ts +7 -0
  47. package/dist/serialization/codec-devalue-vm.d.ts.map +1 -1
  48. package/dist/serialization/codec-devalue-vm.js +12 -1
  49. package/dist/serialization/codec-devalue.d.ts.map +1 -1
  50. package/dist/serialization/codec-devalue.js +15 -4
  51. package/dist/serialization/workflow-vm.d.ts +8 -3
  52. package/dist/serialization/workflow-vm.d.ts.map +1 -1
  53. package/dist/serialization/workflow-vm.js +9 -4
  54. package/dist/serialization.d.ts.map +1 -1
  55. package/dist/serialization.js +8 -3
  56. package/dist/step.js +2 -2
  57. package/dist/telemetry/semantic-conventions.d.ts +104 -0
  58. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  59. package/dist/telemetry/semantic-conventions.js +84 -1
  60. package/dist/test-support/orchestrator-context.d.ts +25 -0
  61. package/dist/test-support/orchestrator-context.d.ts.map +1 -0
  62. package/dist/test-support/orchestrator-context.js +91 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +2 -2
  65. package/dist/vm/index.d.ts.map +1 -1
  66. package/dist/vm/index.js +9 -6
  67. package/dist/workflow/abort-controller.d.ts.map +1 -1
  68. package/dist/workflow/abort-controller.js +4 -6
  69. package/dist/workflow/attribute-dispatcher.js +2 -2
  70. package/dist/workflow/hook.js +2 -2
  71. package/dist/workflow/sleep.js +2 -2
  72. package/dist/workflow.d.ts +10 -0
  73. package/dist/workflow.d.ts.map +1 -1
  74. package/dist/workflow.js +94 -20
  75. package/docs/how-it-works/event-sourcing.mdx +11 -3
  76. package/package.json +7 -7
  77. package/dist/correlation-id.d.ts +0 -109
  78. package/dist/correlation-id.d.ts.map +0 -1
  79. package/dist/correlation-id.js +0 -139
  80. package/dist/serialization/vm-bundle-entry.d.ts +0 -12
  81. package/dist/serialization/vm-bundle-entry.d.ts.map +0 -1
  82. package/dist/serialization/vm-bundle-entry.js +0 -58
@@ -1,5 +1,5 @@
1
1
  import type { Span } from '@opentelemetry/api';
2
- import { type SerializedData, type WorkflowRun, type World } from '@workflow/world';
2
+ import { type SerializedData, type TraceCarrier, type ValidQueueName, type WorkflowRun, type World } from '@workflow/world';
3
3
  import type { StepInvocationQueueItem, WorkflowSuspension } from '../global.js';
4
4
  import { type LoadedEventLog } from './helpers.js';
5
5
  import { ReplayRecoveryReporter } from './replay-recovery-reporter.js';
@@ -11,12 +11,13 @@ export interface SuspensionHandlerParams {
11
11
  requestId?: string;
12
12
  /**
13
13
  * The runtime's loaded event log. Every event creation this suspension makes
14
- * is sent with the precondition snapshot derived from it, so a backend that
15
- * has recorded an event the replay did not see rejects the write with a 412
16
- * instead of accepting a divergent event. The rejection is not retried here:
17
- * the event's correlation id was minted by *this* replay's seeded sequence,
18
- * so re-committing it against a corrected log would persist an event no
19
- * correct replay produces. The caller restarts the replay instead.
14
+ * names the position it was derived from, so a backend that has recorded
15
+ * events the replay did not see can report them back on the write or, if
16
+ * it would rather refuse than report, reject it with a 412. A rejection is
17
+ * not retried here: the event's correlation id was minted by *this* replay's
18
+ * seeded sequence, so re-committing it against a corrected log would persist
19
+ * an event no correct replay produces. The caller restarts the replay
20
+ * instead.
20
21
  */
21
22
  eventLog?: LoadedEventLog;
22
23
  /**
@@ -31,6 +32,26 @@ export interface SuspensionHandlerParams {
31
32
  runReadyBarrier?: Promise<unknown>;
32
33
  /** One-shot telemetry reporter, activated only after replay has recovered. */
33
34
  replayRecoveryReporter?: ReplayRecoveryReporter;
35
+ /**
36
+ * Resilient step dispatch: when provided (and the per-step eligibility gates
37
+ * pass — see the step ops below), each newly created non-inline step's
38
+ * `step_created` write is parallelized with its step-execution queue
39
+ * publish, and the queue message carries the serialized step input
40
+ * (`stepInput`) so the consumer can idempotently re-ensure the event if the
41
+ * direct write failed transiently. Steps queued this way are reported in
42
+ * {@link SuspensionHandlerResult.queuedStepCorrelationIds} so the caller
43
+ * skips them in its own dispatch pass. Omitted by callers that must not
44
+ * queue (terminal drain, tests) — creates then behave exactly as before.
45
+ */
46
+ stepDispatch?: {
47
+ /** The unified workflow queue this run's step messages are published to. */
48
+ queueName: ValidQueueName;
49
+ /**
50
+ * Lazily resolves the trace carrier to stamp on the step messages.
51
+ * Called at most once per suspension (memoized here).
52
+ */
53
+ getTraceCarrier: () => Promise<TraceCarrier>;
54
+ };
34
55
  }
35
56
  /**
36
57
  * Result of handling a suspension. Returns pending step items so the caller
@@ -48,6 +69,23 @@ export interface SuspensionHandlerResult {
48
69
  * into the same batch boundary.
49
70
  */
50
71
  createdStepCorrelationIds: Set<string>;
72
+ /**
73
+ * Correlation IDs of steps this suspension call already published
74
+ * step-execution queue messages for, via resilient step dispatch (the
75
+ * `step_created` write parallelized with a `stepInput`-carrying queue
76
+ * publish). The caller MUST NOT dispatch these again — the message is
77
+ * already out (a duplicate would be deduped by its idempotency key, but
78
+ * costs a wasted round-trip). Empty when {@link SuspensionHandlerParams.stepDispatch}
79
+ * was not provided or no step was eligible.
80
+ */
81
+ queuedStepCorrelationIds: Set<string>;
82
+ /**
83
+ * How many events this phase's writes reported back as occupying slots they
84
+ * skipped over, already merged into the caller's `eventLog.events`. Nonzero
85
+ * means the array was reordered to restore slot order, so any index the
86
+ * caller cached into it (payload prewarm scan position) is stale.
87
+ */
88
+ reportedEventCount: number;
51
89
  /**
52
90
  * The steps whose `step_created` writes were intentionally deferred so the
53
91
  * caller can run them inline via lazy `step_started` events (which create
@@ -115,5 +153,5 @@ export interface SuspensionHandlerResult {
115
153
  * 1. Hooks are processed first to prevent race conditions with webhook receivers
116
154
  * 2. Step events and wait events are created in parallel
117
155
  */
118
- export declare function handleSuspension({ suspension, world, run, span, requestId, eventLog, runReadyBarrier, replayRecoveryReporter, }: SuspensionHandlerParams): Promise<SuspensionHandlerResult>;
156
+ export declare function handleSuspension({ suspension, world, run, span, requestId, eventLog, runReadyBarrier, replayRecoveryReporter, stepDispatch, }: SuspensionHandlerParams): Promise<SuspensionHandlerResult>;
119
157
  //# sourceMappingURL=suspension-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"suspension-handler.d.ts","sourceRoot":"","sources":["../../src/runtime/suspension-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAS/C,OAAO,EAGL,KAAK,cAAc,EAGnB,KAAK,WAAW,EAChB,KAAK,KAAK,EACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAGV,uBAAuB,EAEvB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,WAAW,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,8EAA8E;IAC9E,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,4DAA4D;IAC5D,YAAY,EAAE,uBAAuB,EAAE,CAAC;IACxC;;;;;;;OAOG;IACH,yBAAyB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC;;;;;;;;;;;;OAYG;IACH,eAAe,EAAE,KAAK,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,eAAe,EAAE,cAAc,CAAC;KACjC,CAAC,CAAC;IACH;;;;;;OAMG;IACH,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,0EAA0E;IAC1E,eAAe,EAAE,OAAO,CAAC;IACzB,wFAAwF;IACxF,sBAAsB,EAAE,OAAO,CAAC;IAChC,wEAAwE;IACxE,kBAAkB,EAAE,OAAO,CAAC;IAC5B;;;;;;OAMG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;;;;OAKG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAgED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,UAAU,EACV,KAAK,EACL,GAAG,EACH,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,eAAe,EACf,sBAAsB,GACvB,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAwkB5D"}
1
+ {"version":3,"file":"suspension-handler.d.ts","sourceRoot":"","sources":["../../src/runtime/suspension-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAS/C,OAAO,EAKL,KAAK,cAAc,EAInB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,KAAK,EACX,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAGV,uBAAuB,EAEvB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAWtB,OAAO,EAGL,KAAK,cAAc,EAIpB,MAAM,cAAc,CA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