@bian-womp/spark-graph 0.2.77 → 0.2.79

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
@@ -487,6 +487,7 @@ class GraphRuntime {
487
487
  logLevel: desc.logLevel,
488
488
  runSeq: 0,
489
489
  activeControllers: new Set(),
490
+ controllerRunIds: new Map(),
490
491
  queue: [],
491
492
  stats: {
492
493
  runs: 0,
@@ -731,6 +732,7 @@ class GraphRuntime {
731
732
  node.stats.lastStartAt = now;
732
733
  node.stats.progress = 0;
733
734
  node.activeControllers.add(controller);
735
+ node.controllerRunIds.set(controller, runId);
734
736
  const mode = policy.asyncConcurrency ?? "switch";
735
737
  if (mode === "switch") {
736
738
  for (const c of Array.from(node.activeControllers)) {
@@ -745,6 +747,10 @@ class GraphRuntime {
745
747
  const ctx = this.createExecutionContext(nodeId, node, capturedInputs, runId, controller.signal, {
746
748
  emitHandler: (handle, value) => {
747
749
  const m = policy.asyncConcurrency ?? "switch";
750
+ // Drop emits from runs that were explicitly cancelled due to a
751
+ // snapshot/undo/redo operation, regardless of asyncConcurrency.
752
+ if (node.snapshotCancelledRunIds?.has(runId))
753
+ return;
748
754
  if (m !== "merge" && runId !== node.latestRunId)
749
755
  return;
750
756
  this.propagate(nodeId, handle, value);
@@ -792,6 +798,7 @@ class GraphRuntime {
792
798
  if (timeoutId)
793
799
  clearTimeout(timeoutId);
794
800
  node.activeControllers.delete(controller);
801
+ node.controllerRunIds.delete(controller);
795
802
  node.stats.active = Math.max(0, node.activeControllers.size);
796
803
  node.stats.lastEndAt = Date.now();
797
804
  node.stats.lastDurationMs =
@@ -1370,7 +1377,14 @@ class GraphRuntime {
1370
1377
  const node = this.nodes.get(nodeId);
1371
1378
  if (!node)
1372
1379
  continue;
1380
+ if (!node.snapshotCancelledRunIds) {
1381
+ node.snapshotCancelledRunIds = new Set();
1382
+ }
1373
1383
  for (const controller of Array.from(node.activeControllers)) {
1384
+ const rid = node.controllerRunIds.get(controller);
1385
+ if (rid) {
1386
+ node.snapshotCancelledRunIds.add(rid);
1387
+ }
1374
1388
  try {
1375
1389
  controller.abort("snapshot");
1376
1390
  }
@@ -1379,6 +1393,7 @@ class GraphRuntime {
1379
1393
  }
1380
1394
  }
1381
1395
  node.activeControllers.clear();
1396
+ node.controllerRunIds.clear();
1382
1397
  node.stats.active = 0;
1383
1398
  node.queue = [];
1384
1399
  node.runSeq += 1;
@@ -1487,6 +1502,7 @@ class GraphRuntime {
1487
1502
  },
1488
1503
  runSeq: 0,
1489
1504
  activeControllers: new Set(),
1505
+ controllerRunIds: new Map(),
1490
1506
  queue: [],
1491
1507
  stats: {
1492
1508
  runs: 0,