@bian-womp/spark-graph 0.1.10 → 0.1.11

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/lib/cjs/index.cjs CHANGED
@@ -561,6 +561,7 @@ class GraphRuntime {
561
561
  },
562
562
  };
563
563
  const exec = async (attempt) => {
564
+ let hadError = false;
564
565
  try {
565
566
  await node.runtime.onInputsChanged?.(capturedInputs, ctx);
566
567
  }
@@ -572,6 +573,9 @@ class GraphRuntime {
572
573
  return; // ignore switched runs
573
574
  }
574
575
  }
576
+ hadError = true;
577
+ // Record last error for node
578
+ node.stats.lastError = err;
575
579
  const retry = policy.retry;
576
580
  if (retry && attempt < (retry.attempts ?? 0)) {
577
581
  const delay = retry.backoffMs ? retry.backoffMs(attempt) : 0;
@@ -590,6 +594,9 @@ class GraphRuntime {
590
594
  node.stats.lastStartAt && node.stats.lastEndAt
591
595
  ? node.stats.lastEndAt - node.stats.lastStartAt
592
596
  : undefined;
597
+ // Clear lastError upon successful completion
598
+ if (!hadError)
599
+ node.stats.lastError = undefined;
593
600
  this.emit("stats", {
594
601
  kind: "node-done",
595
602
  nodeId,
@@ -651,7 +658,8 @@ class GraphRuntime {
651
658
  // fan-out along all edges from this output
652
659
  const outEdges = this.edges.filter((e) => e.source.nodeId === srcNodeId && e.source.handle === srcHandle);
653
660
  for (const e of outEdges) {
654
- let nextVal = value;
661
+ // Clone per edge to isolate conversions from mutating the shared source value
662
+ let nextVal = structuredClone(value);
655
663
  const applyToTarget = (v) => {
656
664
  const dstNode = this.nodes.get(e.target.nodeId);
657
665
  if (!dstNode)
@@ -688,6 +696,8 @@ class GraphRuntime {
688
696
  e.stats.inFlight = false;
689
697
  e.stats.lastEndAt = Date.now();
690
698
  e.stats.lastDurationMs = e.stats.lastEndAt - startAt;
699
+ // Clear lastError on successful conversion
700
+ e.stats.lastError = undefined;
691
701
  this.emit("stats", {
692
702
  kind: "edge-done",
693
703
  edgeId: e.id,