@rotorsoft/act 1.23.22 → 1.23.24

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.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  ExitCodes,
5
5
  InMemoryCache,
6
6
  InMemoryStore,
7
- LruSet,
7
+ LruMap,
8
8
  PackageSchema,
9
9
  SNAP_EVENT,
10
10
  TOMBSTONE_EVENT,
@@ -20,7 +20,7 @@ import {
20
20
  sleep,
21
21
  store,
22
22
  validate
23
- } from "./chunk-T722JHPU.js";
23
+ } from "./chunk-ORKHOSH2.js";
24
24
  import {
25
25
  ActorSchema,
26
26
  CausationEventSchema,
@@ -1512,6 +1512,11 @@ var CorrelateCycle = class {
1512
1512
  _checkpoint = -1;
1513
1513
  _initialized = false;
1514
1514
  _timer = void 0;
1515
+ // target → the priority it was last subscribed at. A dynamic target is
1516
+ // re-subscribed (so the store's `GREATEST` upsert runs) only when a later
1517
+ // scan resolves a *higher* priority for it — the runtime `max()` invariant
1518
+ // (#1363). Static targets are recorded at +Infinity so a dynamic resolution
1519
+ // never re-opens them (their priority is owned by the build-time subscribe).
1515
1520
  _subscribed;
1516
1521
  _registry;
1517
1522
  _static_targets;
@@ -1553,7 +1558,7 @@ var CorrelateCycle = class {
1553
1558
  on_init_async,
1554
1559
  cold_start_back_scan = DEFAULT_COLD_START_BACK_SCAN
1555
1560
  }) {
1556
- this._subscribed = new LruSet(max_subscribed_streams);
1561
+ this._subscribed = new LruMap(max_subscribed_streams);
1557
1562
  this._registry = registry;
1558
1563
  this._static_targets = static_targets;
1559
1564
  this._has_dynamic_resolvers = has_dynamic_resolvers;
@@ -1593,7 +1598,7 @@ var CorrelateCycle = class {
1593
1598
  this._checkpoint = this._has_dynamic_resolvers ? Math.max(-1, watermark - this._cold_start_back_scan) : watermark;
1594
1599
  this._on_init?.();
1595
1600
  for (const { stream } of this._static_targets) {
1596
- this._subscribed.add(stream);
1601
+ this._subscribed.set(stream, Number.POSITIVE_INFINITY);
1597
1602
  }
1598
1603
  await this._on_init_async?.();
1599
1604
  }
@@ -1617,7 +1622,7 @@ var CorrelateCycle = class {
1617
1622
  for (const reaction of register.reactions.values()) {
1618
1623
  if (typeof reaction.resolver !== "function") continue;
1619
1624
  const resolved = reaction.resolver(event);
1620
- if (resolved && !this._subscribed.has(resolved.target)) {
1625
+ if (resolved && (resolved.priority ?? 0) > (this._subscribed.get(resolved.target) ?? Number.NEGATIVE_INFINITY)) {
1621
1626
  const incoming_priority = resolved.priority ?? 0;
1622
1627
  const entry = correlated.get(resolved.target) || {
1623
1628
  source: resolved.source,
@@ -1653,8 +1658,8 @@ var CorrelateCycle = class {
1653
1658
  const { subscribed } = await this._cd.subscribe(streams);
1654
1659
  this._checkpoint = last_id;
1655
1660
  if (subscribed) {
1656
- for (const { stream } of streams) {
1657
- this._subscribed.add(stream);
1661
+ for (const { stream, priority } of streams) {
1662
+ this._subscribed.set(stream, priority);
1658
1663
  }
1659
1664
  }
1660
1665
  return { subscribed, last_id };