@rotorsoft/act 1.25.3 → 1.27.0

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.
@@ -479,6 +479,10 @@ var InMemoryStream = class {
479
479
  // re-claimed (and `retry` is never bumped) until its due-time passes. Unlike
480
480
  // in-process backoff, this is durable store state shared across workers.
481
481
  _deferred_at = void 0;
482
+ // Work mark (#1485): highest event id observed to resolve to this target.
483
+ // `undefined` means UNKNOWN — the row predates the mark, so `claim` falls
484
+ // back to the legacy has-work probe rather than treating it as "no work".
485
+ _correlated_at = void 0;
482
486
  constructor(stream, source, priority = 0, lane = DEFAULT_LANE) {
483
487
  this.stream = stream;
484
488
  this.source = source;
@@ -502,6 +506,17 @@ var InMemoryStream = class {
502
506
  bump_priority(priority) {
503
507
  if (priority > this._priority) this._priority = priority;
504
508
  }
509
+ get correlated_at() {
510
+ return this._correlated_at;
511
+ }
512
+ /**
513
+ * Raise the work mark via {@link subscribe}: keeps the maximum, for every
514
+ * value including zero and negatives, so a mark never regresses.
515
+ */
516
+ mark(correlated_at) {
517
+ if (this._correlated_at === void 0 || correlated_at > this._correlated_at)
518
+ this._correlated_at = correlated_at;
519
+ }
505
520
  /**
506
521
  * Set the priority outright via {@link prioritize}: operator
507
522
  * runtime override that ignores the build-time `max()` invariant.
@@ -657,6 +672,8 @@ var InMemoryStore = class {
657
672
  _next_id = 0;
658
673
  // stored stream positions and other metadata
659
674
  _streams = /* @__PURE__ */ new Map();
675
+ /** Correlate checkpoint (#1484): how far the log has been READ. */
676
+ _correlated_at = -1;
660
677
  // last committed version per stream — O(1) replacement for filter-on-commit
661
678
  _stream_versions = /* @__PURE__ */ new Map();
662
679
  // max non-snapshot event id per stream — drives the has-work probe in
@@ -674,6 +691,7 @@ var InMemoryStore = class {
674
691
  _reset_indexes() {
675
692
  this._events.length = 0;
676
693
  this._next_id = 0;
694
+ this._correlated_at = -1;
677
695
  this._stream_versions.clear();
678
696
  this._max_event_id_by_stream.clear();
679
697
  this._max_non_snap_event_id = -1;
@@ -853,6 +871,7 @@ var InMemoryStore = class {
853
871
  async claim(lagging, leading, by, millis, lane) {
854
872
  await sleep();
855
873
  const has_work = (s) => {
874
+ if (s.correlated_at !== void 0) return s.at < s.correlated_at;
856
875
  if (!s.source) return s.at < this._max_non_snap_event_id;
857
876
  if (is_literal_source(s.source)) {
858
877
  const max_id = this._max_event_id_by_stream.get(s.source);
@@ -905,24 +924,27 @@ var InMemoryStore = class {
905
924
  * @param streams - Streams to register with optional source + priority.
906
925
  * @returns subscribed count and current max watermark.
907
926
  */
908
- async subscribe(streams) {
927
+ async subscribe(streams, correlated_at) {
928
+ if (correlated_at !== void 0 && correlated_at > this._correlated_at)
929
+ this._correlated_at = correlated_at;
909
930
  await sleep();
910
931
  let subscribed = 0;
911
932
  for (const {
912
933
  stream,
913
934
  source,
914
935
  priority = 0,
915
- lane = DEFAULT_LANE
936
+ lane = DEFAULT_LANE,
937
+ correlated_at: correlated_at2
916
938
  } of streams) {
917
939
  const existing = this._streams.get(stream);
918
940
  if (existing) {
919
941
  existing.bump_priority(priority);
920
942
  existing.lane = lane;
943
+ if (correlated_at2 !== void 0) existing.mark(correlated_at2);
921
944
  } else {
922
- this._streams.set(
923
- stream,
924
- new InMemoryStream(stream, source, priority, lane)
925
- );
945
+ const created = new InMemoryStream(stream, source, priority, lane);
946
+ if (correlated_at2 !== void 0) created.mark(correlated_at2);
947
+ this._streams.set(stream, created);
926
948
  subscribed++;
927
949
  }
928
950
  }
@@ -930,7 +952,7 @@ var InMemoryStore = class {
930
952
  for (const s of this._streams.values()) {
931
953
  if (s.at > watermark) watermark = s.at;
932
954
  }
933
- return { subscribed, watermark };
955
+ return { subscribed, watermark, correlated_at: this._correlated_at };
934
956
  }
935
957
  /**
936
958
  * Acknowledge completion of processing for leased streams.