diff --git a/core/server/dashboard.cpp b/core/server/dashboard.cpp index 03ad0178..a240aa4d 100644 --- a/core/server/dashboard.cpp +++ b/core/server/dashboard.cpp @@ -1697,7 +1697,7 @@ function setMetric(key, value, text) { const RECENT_S = 15; /* the `recent` window in seconds, for a figure sampled every poll */ const RECENT_PREFILL_S = 5; /* prefill's is shorter, so a several-second prefill shows up in it */ const extAt = {}, winAt = {}, extAtS = {}; /* extAtS: the poll at which each extreme was set */ -let lastActiveC = 0, lastStart = null, lastUp = -1; +let lastActiveC = 0, lastStart = null; /* A new engine process is a different discontinuity from a quiet minute: the previous run's * requests are gone and its configuration may differ, so nothing from it carries over. Every * other figure already refuses to pool across a restart -- accWindow drops its rings, histIngest @@ -3877,19 +3877,22 @@ async function poll() { const r = await api("stats"); if (!r.ok) throw new Error(r.status); const s = await r.json(); - /* A new engine process is a discontinuity, not a new measurement. started_at names it, but - * it is a whole-second clock, so a restart landing in the same second as the previous start - * leaves it unchanged -- and the previous run's extremes would then render WITH A TRUE AGE, - * which reads as honest provenance and is not. uptime_s resets to about zero on any new - * process and catches that; it is the same signal accWindow already trusts for the same - * purpose, with the same accepted risk: it is wall-clock derived, so a backward NTP step - * reads as a restart and clears the extremes. Checked before update() so the new run's - * samples land in fresh windows. */ - const up = s.uptime_s; - if (lastStart !== null && (s.started_at !== lastStart || - (typeof up === "number" && up < lastUp))) newEngineRun(); + /* A new engine process is a discontinuity, not a new measurement, and started_at names it. + * It is a whole-second clock, so two processes could share one and the clear would be + * missed. For that, the replacement would have to start within the same second as the one + * the page last read -- and the page can only read it once /stats answers, startup_s after + * the old process began (69 s here). A replacement that starts after its predecessor stopped + * answering is therefore stamped a later second. The guarantee needs startup_s >= 1 s; a + * model that came up inside a second could collide, and the cost would be one stale extreme + * carrying a true age. + * + * uptime_s is NOT a backstop for that case, because it is derived: unix_now() - started_at_, + * both whole seconds, so started_at + uptime_s is exactly the wall clock at every poll. A + * later poll always reports a larger uptime for the same started_at, so a comparison firing + * on a smaller one detects a backward NTP step and nothing else. Checked before update() so + * the new run's samples land in fresh windows. */ + if (lastStart !== null && s.started_at !== lastStart) newEngineRun(); lastStart = s.started_at; - if (typeof up === "number") lastUp = up; const now = performance.now(); update(s, prevAt ? (now - prevAt) / 1000 : 0); prev = s; prevAt = now; diff --git a/tests/js/extremes.test.js b/tests/js/extremes.test.js index fbc5edac..d2fa3830 100644 --- a/tests/js/extremes.test.js +++ b/tests/js/extremes.test.js @@ -150,16 +150,18 @@ await p.poll(); eq(p.calls.run, 0, "the first poll is a baseline, not a restart" await p.poll(); eq(p.calls.run, 0, "same started_at with a rising uptime is the same process"); await p.poll(); eq(p.calls.run, 1, "a changed started_at clears the extremes"); -console.log("== poll() catches a restart that lands in the SAME second =="); -/* started_at is a whole-second clock, so a restart inside the same second leaves it unchanged. - Without the uptime comparison the dead process's extremes render WITH A TRUE AGE, which reads - as honest provenance and is worse than not labelling it at all. */ +console.log("== uptime_s is derived, so it is not a restart signal =="); +/* uptime_s is unix_now() - started_at_, both whole seconds, so started_at + uptime_s is exactly + the wall clock at that poll. A later poll of the SAME process therefore always reports a + larger uptime; a smaller one means the wall clock moved backwards, which is an NTP adjustment + and not a new process. Clearing on it would throw away the session's extremes on a clock + correction, so nothing here treats it as a restart. */ p = makePoller([ { started_at: 100, uptime_s: 40 }, { started_at: 100, uptime_s: 2 }, /* same started_at, uptime went backwards */ ], fixed); await p.poll(); await p.poll(); -eq(p.calls.run, 1, "a same-second restart is caught by the uptime comparison"); +eq(p.calls.run, 0, "a backward uptime with an unchanged started_at is a clock step, not a restart"); console.log("== poll() takes the GAP path, not the restart path, when only the clock moved =="); const slow = { wall: 1000 };