@workflow/core 5.0.0-beta.35 → 5.0.0-beta.36

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 (68) hide show
  1. package/dist/classify-error.d.ts.map +1 -1
  2. package/dist/classify-error.js +5 -2
  3. package/dist/create-hook.d.ts +41 -22
  4. package/dist/create-hook.d.ts.map +1 -1
  5. package/dist/create-hook.js +1 -1
  6. package/dist/describe-error.d.ts.map +1 -1
  7. package/dist/describe-error.js +12 -1
  8. package/dist/flushable-stream.d.ts +29 -0
  9. package/dist/flushable-stream.d.ts.map +1 -1
  10. package/dist/flushable-stream.js +228 -2
  11. package/dist/global.d.ts +2 -0
  12. package/dist/global.d.ts.map +1 -1
  13. package/dist/global.js +1 -1
  14. package/dist/private.d.ts +6 -17
  15. package/dist/private.d.ts.map +1 -1
  16. package/dist/private.js +1 -1
  17. package/dist/replay-payload-cache.d.ts +56 -0
  18. package/dist/replay-payload-cache.d.ts.map +1 -0
  19. package/dist/replay-payload-cache.js +137 -0
  20. package/dist/runtime/constants.d.ts +11 -0
  21. package/dist/runtime/constants.d.ts.map +1 -1
  22. package/dist/runtime/constants.js +26 -1
  23. package/dist/runtime/get-port-lazy.js +4 -4
  24. package/dist/runtime/helpers.d.ts +6 -4
  25. package/dist/runtime/helpers.d.ts.map +1 -1
  26. package/dist/runtime/helpers.js +23 -7
  27. package/dist/runtime/resume-hook.d.ts +4 -1
  28. package/dist/runtime/resume-hook.d.ts.map +1 -1
  29. package/dist/runtime/resume-hook.js +23 -20
  30. package/dist/runtime/step-executor.d.ts +39 -0
  31. package/dist/runtime/step-executor.d.ts.map +1 -1
  32. package/dist/runtime/step-executor.js +74 -4
  33. package/dist/runtime/step-handler.js +3 -3
  34. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  35. package/dist/runtime/suspension-handler.js +2 -1
  36. package/dist/runtime.d.ts.map +1 -1
  37. package/dist/runtime.js +372 -110
  38. package/dist/serialization.d.ts +44 -4
  39. package/dist/serialization.d.ts.map +1 -1
  40. package/dist/serialization.js +88 -54
  41. package/dist/step.d.ts.map +1 -1
  42. package/dist/step.js +10 -16
  43. package/dist/symbols.d.ts +13 -0
  44. package/dist/symbols.d.ts.map +1 -1
  45. package/dist/symbols.js +14 -1
  46. package/dist/version.d.ts +1 -1
  47. package/dist/version.js +2 -2
  48. package/dist/workflow/abort-controller.d.ts.map +1 -1
  49. package/dist/workflow/abort-controller.js +3 -2
  50. package/dist/workflow/hook.d.ts.map +1 -1
  51. package/dist/workflow/hook.js +22 -7
  52. package/dist/workflow.d.ts +12 -9
  53. package/dist/workflow.d.ts.map +1 -1
  54. package/dist/workflow.js +16 -10
  55. package/docs/api-reference/create-hook.mdx +43 -2
  56. package/docs/api-reference/define-hook.mdx +26 -24
  57. package/docs/api-reference/fatal-error.mdx +29 -7
  58. package/docs/api-reference/fetch.mdx +3 -4
  59. package/docs/api-reference/sleep.mdx +1 -1
  60. package/docs/foundations/hooks.mdx +1 -1
  61. package/docs/foundations/idempotency.mdx +16 -9
  62. package/docs/how-it-works/encryption.mdx +3 -3
  63. package/docs/how-it-works/event-sourcing.mdx +6 -6
  64. package/docs/how-it-works/framework-integrations.mdx +2 -2
  65. package/package.json +5 -5
  66. package/dist/step-hydration-cache.d.ts +0 -148
  67. package/dist/step-hydration-cache.d.ts.map +0 -1
  68. package/dist/step-hydration-cache.js +0 -171
@@ -1,6 +1,7 @@
1
1
  import type { Event, SerializedData, World } from '@workflow/world';
2
2
  import type { CryptoKey } from '../encryption.js';
3
3
  import { type StepLatencyTracking } from './step-latency.js';
4
+ export declare const DEFAULT_STEP_MAX_RETRIES = 3;
4
5
  export interface StepExecutorParams {
5
6
  world: World;
6
7
  workflowRunId: string;
@@ -54,6 +55,33 @@ export interface StepExecutorParams {
54
55
  * handler is the sole inline writer for the run on this iteration.
55
56
  */
56
57
  inlineDeltaSinceCursor?: string;
58
+ /**
59
+ * Precondition-guard snapshot (epoch ms of the latest event the caller's
60
+ * replay loaded) to attach to this step's `step_started` claim. On the lazy
61
+ * inline path the claim is the step's FIRST durable write (its
62
+ * `step_created` is deferred), so without this the claim would bypass the
63
+ * optimistic-concurrency guard entirely: a replay working from a stale view
64
+ * could claim — and then commit — a step scheduled without observing an
65
+ * out-of-band event. A guard-enforcing World rejects a stale claim with
66
+ * `PreconditionFailedError` (412); executeStep does NOT translate that
67
+ * rejection (re-claiming in place would still commit the stale schedule),
68
+ * so it propagates for the caller to abandon the batch and force a fresh
69
+ * replay. Undefined when the guard is disabled or the caller has no
70
+ * snapshot; Worlds that don't enforce the guard ignore it.
71
+ */
72
+ stateUpdatedAt?: number;
73
+ /**
74
+ * Suppress optimistic inline start for this step regardless of
75
+ * `WORKFLOW_OPTIMISTIC_INLINE_START` / `forceOptimisticStart`: take the
76
+ * await-then-run path so the body only runs after the `step_started` claim
77
+ * succeeds. Set by the runtime for guard-enforced batches that are
78
+ * stale-sensitive (an open hook means an out-of-band event can make the
79
+ * scheduling view stale): the guard's 412 fence can reject a stale claim's
80
+ * durable writes, but it cannot un-run a body that optimistic start began
81
+ * before the claim settled — awaiting the claim extends the fence to user
82
+ * code. Wins over `forceOptimisticStart` and the env flag.
83
+ */
84
+ suppressOptimisticStart?: boolean;
57
85
  /**
58
86
  * Force optimistic inline start regardless of
59
87
  * `WORKFLOW_OPTIMISTIC_INLINE_START`. Set by turbo mode on the first delivery
@@ -80,6 +108,17 @@ export interface StepExecutorParams {
80
108
  * runtime/step-latency.ts.
81
109
  */
82
110
  latencyTracking?: StepLatencyTracking;
111
+ /**
112
+ * Authoritative attempt number for this execution, used to bound retries
113
+ * against `maxRetries` BEFORE the body runs. In order to also catch
114
+ * step timeouts (which we can't have catch handlers for), we determine
115
+ * the attempt count based as follows:
116
+ * - Inline (combined handler): the number of `step_started` events already
117
+ * in the event log for this step, plus one for the attempt about to run.
118
+ * - Background (queue-dispatched): the queue delivery count
119
+ * (`metadata.attempt`), which increments on every redelivery.
120
+ */
121
+ authoritativeAttempt?: number;
83
122
  }
84
123
  /**
85
124
  * Inline-delta returned by a step-terminal write when the caller passed
@@ -1 +1 @@
1
- {"version":3,"file":"step-executor.d.ts","sourceRoot":"","sources":["../../src/runtime/step-executor.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAQ,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA0BlD,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AA0B3B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,mBAAmB,CAAC;CACvC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,GA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