@dudousxd/nestjs-durable-core 0.106.0 → 0.106.2

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
@@ -7700,6 +7707,13 @@ interface WorkflowDecision {
7700
7707
  */
7701
7708
  interface WorkflowStepEvent {
7702
7709
  runId: string;
7710
+ /**
7711
+ * The dispatched turn ({@link WorkflowTask.taskId}) whose replay ran the step. The engine keeps an
7712
+ * event only while the run still awaits that turn, so a turn that went quiet, was dispatched again
7713
+ * and kept running on its first worker cannot write over the live turn's checkpoints. Absent (a
7714
+ * worker from before this field): the event is kept, unchecked.
7715
+ */
7716
+ taskId?: string | undefined;
7703
7717
  seq: number;
7704
7718
  name: string;
7705
7719
  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
@@ -7700,6 +7707,13 @@ interface WorkflowDecision {
7700
7707
  */
7701
7708
  interface WorkflowStepEvent {
7702
7709
  runId: string;
7710
+ /**
7711
+ * The dispatched turn ({@link WorkflowTask.taskId}) whose replay ran the step. The engine keeps an
7712
+ * event only while the run still awaits that turn, so a turn that went quiet, was dispatched again
7713
+ * and kept running on its first worker cannot write over the live turn's checkpoints. Absent (a
7714
+ * worker from before this field): the event is kept, unchecked.
7715
+ */
7716
+ taskId?: string | undefined;
7703
7717
  seq: number;
7704
7718
  name: string;
7705
7719
  phase: 'running' | 'completed' | 'failed';
package/dist/index.js CHANGED
@@ -7007,6 +7007,10 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
7007
7007
  __name(createWorkflowCtx, "createWorkflowCtx");
7008
7008
 
7009
7009
  // src/engine.ts
7010
+ function isRequeuedStepFailure(cp) {
7011
+ return cp.status === "failed" && cp.attempts === 0 && cp.seq >= 0 && (cp.kind === "local" || cp.kind === "remote");
7012
+ }
7013
+ __name(isRequeuedStepFailure, "isRequeuedStepFailure");
7010
7014
  function mergeTags(staticTags, runTags) {
7011
7015
  if (!staticTags?.length && !runTags?.length) return void 0;
7012
7016
  return [
@@ -12873,6 +12877,20 @@ var WorkflowEngine = class _WorkflowEngine {
12873
12877
  ];
12874
12878
  }
12875
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
+ /**
12876
12894
  * Persist a streamed local-step lifecycle event from a remote workflow worker (see
12877
12895
  * {@link WorkflowStepEvent}). A Python `@workflow` runs its `ctx.step`s inline over one turn that
12878
12896
  * can last minutes; the worker streams each step's start/finish so the engine checkpoints it LIVE —
@@ -12882,6 +12900,7 @@ var WorkflowEngine = class _WorkflowEngine {
12882
12900
  * idempotently, so this is purely additive observability and never changes the run's outcome.
12883
12901
  */
12884
12902
  async persistStepEvent(event) {
12903
+ if (!await this.stepEventFromAwaitedTurn(event)) return;
12885
12904
  const startedAt = new Date(event.startedAt);
12886
12905
  if (event.phase === "running") {
12887
12906
  await this.store.saveCheckpoint(stepCheckpoint({
@@ -14196,6 +14215,7 @@ ${run.workflowVersion}`;
14196
14215
  };
14197
14216
  const events = [];
14198
14217
  for (const cp of checkpoints) {
14218
+ if (isRequeuedStepFailure(cp)) continue;
14199
14219
  if (cp.status === "completed" || cp.status === "failed") {
14200
14220
  if (cp.seq >= HANDOFF_SEQ_BASE) continue;
14201
14221
  if (isAnyCheckpoint(cp)) {
@@ -14280,7 +14300,7 @@ ${run.workflowVersion}`;
14280
14300
  });
14281
14301
  } else if (cmd.kind === "call") {
14282
14302
  const existing = await this.store.getCheckpoint(run.id, cmd.seq);
14283
- if (existing) {
14303
+ if (existing && !isRequeuedStepFailure(existing)) {
14284
14304
  const policed = redriveLost && cmd.policy !== void 0 ? await this.applyCallPolicy(run, cmd, existing) : null;
14285
14305
  const leaseAt = policed !== null ? policed : redriveLost ? await this.redriveLostCall(run, existing) : void 0;
14286
14306
  if (leaseAt != null) wakeAt = wakeAt == null ? leaseAt : Math.min(wakeAt, leaseAt);