fix(calculation): #995 change-triggered evaluations coalesce latest-wins per calc tag, so a poll cycle evaluates once against all its new inputs and the queue is bounded by the tag count

At most one evaluation is pending per calc tag; a re-trigger only moves its
timestamp forward and the dependency snapshot is taken when the pump dequeues
it. Previously every dependency arrival enqueued a separate evaluation per
dependent with a trigger-time snapshot: k inputs of one cycle ran k times
(publishing intermediates computed from mixed old/new inputs) and the queue had
no bound when triggers outpaced the pump. The out-of-process batch pump now
dequeues every pending tag once per batch.
This commit is contained in:
Joseph Doherty
2026-12-03 11:02:08 -05:00
parent a1b8312ea4
commit 2827a4c3bf
6 changed files with 250 additions and 66 deletions
+2 -2
View File
@@ -175,8 +175,8 @@ processes:
- **Batch submit (design §4.5).** `IScriptRunner.RunBatch` submits several evaluations at once: every item that is ready
to run (its key loaded in a live worker, not a suspect) goes out in ONE `EvalBatch` frame per worker, and results are
per item and streamed. The Calculation pump dequeues everything pending and submits it as one batch, publishing in
dequeue order (a tag queued twice ends the batch, so every queued evaluation still runs against the snapshot that
triggered it); the virtual-tag seam coalesces evaluations that become ready together (one actor per tag) into one
dequeue order (the queue is latest-wins per calc tag since #995, so a batch never names a tag twice and each entry's
snapshot is taken as it is dequeued); the virtual-tag seam coalesces evaluations that become ready together (one actor per tag) into one
batch, with no timer; the scripted-alarm engine submits a pass's whole dirty set. In process the pump and the engine
stay one-at-a-time, unchanged. **Per-item deadlines and blame stay exact:** an evaluation that arrives while every
evaluation thread is busy is reported back as *deferred*, the host stops its clock, and restarts T and G when the worker
+9
View File
@@ -86,6 +86,15 @@ Two deploy-time gates run over the result:
comes back after an outage usually comes back holding the reading it had before, so a value-only
dedup would swallow the recovery and leave the node Bad forever.
- **Timers are grouped by interval**, one timer per distinct interval, not one per tag.
- **Change triggers are latest-wins per tag (#995, review S-9).** A dependency change queues the calc tags that read
it, but at most **one** evaluation is ever pending per tag: a tag already queued keeps its place and only takes the
newer trigger timestamp, and its dependency snapshot is taken when the single evaluation pump *dequeues* it. So
the inputs of one poll cycle that arrive while the pump is busy evaluate **once**, against all the new values —
not once per input, where the first k−1 runs mixed new and previous-cycle values and published those
intermediates (an `A − B` spike when A had updated and B had not). The queue is bounded by the number of calc
tags, so triggers that outpace the pump (slow scripts, an out-of-process runner under load) no longer build an
unbounded backlog of stale evaluations. With an out-of-process runner the pump submits everything it dequeued as
one batch, which therefore never names a tag twice. Pinned by `CalculationDriverCoalescingTests`.
## Input quality