From 0ac154c803643953bdf246ff3d5dab053edab186 Mon Sep 17 00:00:00 2001 From: "Memoria (Noblistic)" Date: Sun, 1 Nov 2026 23:37:06 +0000 Subject: [PATCH] dashboard: drop the uptime comparison -- it could only fire on a clock step 8ee893e added `up < lastUp` beside the started_at comparison, to catch a restart landing in the same whole second as the one the page last read. It cannot catch that. uptime_s is derived, not independent: unix_now() - started_at_, both whole seconds, so started_at + uptime_s is exactly the wall clock at every poll. Two processes sharing a started_at are therefore read at increasing wall times and report INCREASING uptimes, so the comparison never fires in the case it was written for. It fires on genuine restarts, which started_at already catches, and on a backward NTP step, which is not a restart at all. Net effect: dead where it was needed, redundant elsewhere, and a false clear of the session extremes on every clock correction. The test that "proved" it worked was fed an impossible fixture: started_at 100 with uptime 40 implies the clock read 140, then started_at 100 with uptime 2 implies 102. Time running backwards is the only way to reach that pair, which is the same mistake the finding it answered was about -- reasoning from a state the instrument cannot produce. It now asserts the reachable behaviour instead: a backward uptime with an unchanged started_at is a clock step and must NOT clear the extremes, since they still belong to the running process. The collision the comparison tried to close needs a replacement process stamped in the same second as the one the page last read. The page can only learn started_at once /stats answers, startup_s after the old process began -- 69 s on this engine -- so a replacement starting after its predecessor stopped answering is stamped a later second. The bound is startup_s >= 1 s; a model that came up inside a second could collide, and would cost one stale extreme carrying a true age. That is documented where the comparison used to be. The acceptance window's use of the same signal is NOT redundant and is untouched: it has no started_at comparison, so for a tab that stopped polling while a new process drafted past the old totals, a falling uptime is the only thing that catches the restart. Verified: dashboard_test 241 checks over 8 cases, extremes.test.js 27, poll_spark.test.js 35, sched_test 62646 over 184, no failures. Mutation re-run after the revert: deleting poll()'s detection line, stamping extAtS on every sample, and deadening acceptTriple's age clause each fail the suite. Behavior is unchanged from the deployed build, which never had the comparison, so no restart is needed for this. Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI --- core/server/dashboard.cpp | 29 ++++++++++++++++------------- tests/js/extremes.test.js | 12 +++++++----- 2 files changed, 23 insertions(+), 18 deletions(-) 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 };