@dudousxd/nestjs-durable-core 0.106.1 → 0.106.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -4632,6 +4632,13 @@ declare class WorkflowEngine {
4632
4632
  * step yet) and deduped to distinct groups.
4633
4633
  */
4634
4634
  private inflightStepGroups;
4635
+ /**
4636
+ * Whether a streamed step event comes from the turn its run awaits. A dispatched turn that went
4637
+ * quiet past the silence window is dispatched again, but its first worker may still be replaying it
4638
+ * and streaming its steps; written unchecked, those would put a stale turn's output under the live
4639
+ * turn's checkpoint. An event without a `taskId` (a worker from before the field) is kept.
4640
+ */
4641
+ private stepEventFromAwaitedTurn;
4635
4642
  /**
4636
4643
  * Persist a streamed local-step lifecycle event from a remote workflow worker (see
4637
4644
  * {@link WorkflowStepEvent}). A Python `@workflow` runs its `ctx.step`s inline over one turn that
@@ -6338,7 +6345,9 @@ interface StateStore {
6338
6345
  /**
6339
6346
  * Settle steps from their results: per entry and in input order, while the row at `(runId, seq)`
6340
6347
  * is still `pending`, write the entry's `status`, `output`, `error`, `events`, `startedAt` and
6341
- * `finishedAt` (an absent one is stored empty) and leave every other column as it is stored;
6348
+ * `finishedAt` (an absent one is stored empty), clear `wakeAt` (a settled step has no dispatch
6349
+ * lease left, and a failed one's `wakeAt` is later its retry's backoff deadline), and leave every
6350
+ * other column as it is stored;
6342
6351
  * resolves whether each entry wrote. Claims like {@link saveCheckpointsIfPending}: a later entry for
6343
6352
  * a row an earlier one settled loses, and a rejection writes nothing. The engine settles a batch of
6344
6353
  * one run's step results through it, so a step's `input` (an LLM prompt, say) is not written again
@@ -6353,7 +6362,8 @@ interface StateStore {
6353
6362
  * `cancelled` or `completed` (a late result for a finished run settles nothing), write the result
6354
6363
  * (see {@link StepResultSettlement} for what keeps its stored value) and resolve the row as it now
6355
6364
  * reads, without its `input` (as {@link getCheckpointsForSettle} reads it); `null` for an entry
6356
- * that wrote nothing (the row is absent or already settled, or the run finished). Claims like
6365
+ * that wrote nothing (the row is absent or already settled, or the run finished). Clears `wakeAt`
6366
+ * as {@link settleCheckpointsIfPending} does. Claims like
6357
6367
  * {@link settleCheckpointsIfPending}: a later entry for a row an earlier one settled loses, and a
6358
6368
  * rejection writes nothing. The engine settles a batch of one run's step results through it
6359
6369
  * without reading the rows first.
@@ -7700,6 +7710,13 @@ interface WorkflowDecision {
7700
7710
  */
7701
7711
  interface WorkflowStepEvent {
7702
7712
  runId: string;
7713
+ /**
7714
+ * The dispatched turn ({@link WorkflowTask.taskId}) whose replay ran the step. The engine keeps an
7715
+ * event only while the run still awaits that turn, so a turn that went quiet, was dispatched again
7716
+ * and kept running on its first worker cannot write over the live turn's checkpoints. Absent (a
7717
+ * worker from before this field): the event is kept, unchecked.
7718
+ */
7719
+ taskId?: string | undefined;
7703
7720
  seq: number;
7704
7721
  name: string;
7705
7722
  phase: 'running' | 'completed' | 'failed';
package/dist/index.d.ts CHANGED
@@ -4632,6 +4632,13 @@ declare class WorkflowEngine {
4632
4632
  * step yet) and deduped to distinct groups.
4633
4633
  */
4634
4634
  private inflightStepGroups;
4635
+ /**
4636
+ * Whether a streamed step event comes from the turn its run awaits. A dispatched turn that went
4637
+ * quiet past the silence window is dispatched again, but its first worker may still be replaying it
4638
+ * and streaming its steps; written unchecked, those would put a stale turn's output under the live
4639
+ * turn's checkpoint. An event without a `taskId` (a worker from before the field) is kept.
4640
+ */
4641
+ private stepEventFromAwaitedTurn;
4635
4642
  /**
4636
4643
  * Persist a streamed local-step lifecycle event from a remote workflow worker (see
4637
4644
  * {@link WorkflowStepEvent}). A Python `@workflow` runs its `ctx.step`s inline over one turn that
@@ -6338,7 +6345,9 @@ interface StateStore {
6338
6345
  /**
6339
6346
  * Settle steps from their results: per entry and in input order, while the row at `(runId, seq)`
6340
6347
  * is still `pending`, write the entry's `status`, `output`, `error`, `events`, `startedAt` and
6341
- * `finishedAt` (an absent one is stored empty) and leave every other column as it is stored;
6348
+ * `finishedAt` (an absent one is stored empty), clear `wakeAt` (a settled step has no dispatch
6349
+ * lease left, and a failed one's `wakeAt` is later its retry's backoff deadline), and leave every
6350
+ * other column as it is stored;
6342
6351
  * resolves whether each entry wrote. Claims like {@link saveCheckpointsIfPending}: a later entry for
6343
6352
  * a row an earlier one settled loses, and a rejection writes nothing. The engine settles a batch of
6344
6353
  * one run's step results through it, so a step's `input` (an LLM prompt, say) is not written again
@@ -6353,7 +6362,8 @@ interface StateStore {
6353
6362
  * `cancelled` or `completed` (a late result for a finished run settles nothing), write the result
6354
6363
  * (see {@link StepResultSettlement} for what keeps its stored value) and resolve the row as it now
6355
6364
  * reads, without its `input` (as {@link getCheckpointsForSettle} reads it); `null` for an entry
6356
- * that wrote nothing (the row is absent or already settled, or the run finished). Claims like
6365
+ * that wrote nothing (the row is absent or already settled, or the run finished). Clears `wakeAt`
6366
+ * as {@link settleCheckpointsIfPending} does. Claims like
6357
6367
  * {@link settleCheckpointsIfPending}: a later entry for a row an earlier one settled loses, and a
6358
6368
  * rejection writes nothing. The engine settles a batch of one run's step results through it
6359
6369
  * without reading the rows first.
@@ -7700,6 +7710,13 @@ interface WorkflowDecision {
7700
7710
  */
7701
7711
  interface WorkflowStepEvent {
7702
7712
  runId: string;
7713
+ /**
7714
+ * The dispatched turn ({@link WorkflowTask.taskId}) whose replay ran the step. The engine keeps an
7715
+ * event only while the run still awaits that turn, so a turn that went quiet, was dispatched again
7716
+ * and kept running on its first worker cannot write over the live turn's checkpoints. Absent (a
7717
+ * worker from before this field): the event is kept, unchecked.
7718
+ */
7719
+ taskId?: string | undefined;
7703
7720
  seq: number;
7704
7721
  name: string;
7705
7722
  phase: 'running' | 'completed' | 'failed';
package/dist/index.js CHANGED
@@ -12877,6 +12877,20 @@ var WorkflowEngine = class _WorkflowEngine {
12877
12877
  ];
12878
12878
  }
12879
12879
  /**
12880
+ * Whether a streamed step event comes from the turn its run awaits. A dispatched turn that went
12881
+ * quiet past the silence window is dispatched again, but its first worker may still be replaying it
12882
+ * and streaming its steps; written unchecked, those would put a stale turn's output under the live
12883
+ * turn's checkpoint. An event without a `taskId` (a worker from before the field) is kept.
12884
+ */
12885
+ async stepEventFromAwaitedTurn(event) {
12886
+ if (event.taskId === void 0) return true;
12887
+ const run = await this.store.getRun(event.runId);
12888
+ if (!run) return false;
12889
+ return awaitsDecision(run, {
12890
+ taskId: event.taskId
12891
+ });
12892
+ }
12893
+ /**
12880
12894
  * Persist a streamed local-step lifecycle event from a remote workflow worker (see
12881
12895
  * {@link WorkflowStepEvent}). A Python `@workflow` runs its `ctx.step`s inline over one turn that
12882
12896
  * can last minutes; the worker streams each step's start/finish so the engine checkpoints it LIVE —
@@ -12886,6 +12900,7 @@ var WorkflowEngine = class _WorkflowEngine {
12886
12900
  * idempotently, so this is purely additive observability and never changes the run's outcome.
12887
12901
  */
12888
12902
  async persistStepEvent(event) {
12903
+ if (!await this.stepEventFromAwaitedTurn(event)) return;
12889
12904
  const startedAt = new Date(event.startedAt);
12890
12905
  if (event.phase === "running") {
12891
12906
  await this.store.saveCheckpoint(stepCheckpoint({
@@ -16067,7 +16082,8 @@ ${run.workflowVersion}`;
16067
16082
  if (!settle2) {
16068
16083
  return this.savePendingCheckpoints(settlements.map((s, i) => ({
16069
16084
  ...settled[i],
16070
- ...s
16085
+ ...s,
16086
+ wakeAt: void 0
16071
16087
  })));
16072
16088
  }
16073
16089
  if (settlements.length > 1) {
@@ -18391,7 +18407,8 @@ var InMemoryStateStore = class {
18391
18407
  if (cp?.status !== "pending") return false;
18392
18408
  this.checkpoints.set(key, {
18393
18409
  ...cp,
18394
- ...settlement
18410
+ ...settlement,
18411
+ wakeAt: void 0
18395
18412
  });
18396
18413
  return true;
18397
18414
  });
@@ -18463,7 +18480,8 @@ var InMemoryStateStore = class {
18463
18480
  const cp = before.get(this.key(settlement.runId, settlement.seq));
18464
18481
  out[at[k]] = {
18465
18482
  ...cp,
18466
- ...settlement
18483
+ ...settlement,
18484
+ wakeAt: void 0
18467
18485
  };
18468
18486
  });
18469
18487
  return out;