Files
loki/scripts
ca646cc9bf fix(control): an age read from a stale cache is not an age (#278)
#275 gave "builder online" an expiry, then handed it timestamps that could be
minutes old. /api/control's slow cache has a 20s TTL but SERVES STALE while it
refreshes in the background, so the first request after an idle spell gets a
cache built long before "now". Measured against the real clock, a live runner's
heartbeat had already aged past RUNNER_OFFLINE_THRESHOLD_MS — and Control
reported a builder that was heartbeating fine as offline.

Caught on prod: two probes 12s apart returned runnerVersion "dev" then
"box-0.8.9" from the same cache field, proving the cache was serving data built
minutes earlier; builderPresence read {cloud:false, local:false} while the DB
had connected=t/t/t with snapshots 2.5min and 3.6min old.

The fix is to delete the optimisation, not to tune it. getBuilderPresence now
does both reads itself, at request time, and no longer accepts caller-supplied
heartbeats — an age is only meaningful against the clock it is compared to.
Two indexed reads on two-row tables are cheaper than a false liveness claim.

Pinned by a regression check so the pass-through cannot come back as a
performance tweak.

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 15:02:53 +00:00
..