From 92c27aed9fca881b8ed7685c706e6e9f67885769 Mon Sep 17 00:00:00 2001 From: nocode Date: Wed, 23 Sep 2026 22:32:39 +0200 Subject: [PATCH] fix(web): read the interface build date instead of freezing it at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The marker was captured once at import, while the front-end is served from disk on every request. Uploading new files therefore left it announcing the old build until the next restart — the exact confusion it was added to prevent. It is now read from disk, cached ten seconds so a health check does not walk the tree each time. Co-Authored-By: Claude Opus 5 (1M context) --- src/web/api/index.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/web/api/index.js b/src/web/api/index.js index 8380504..4447809 100644 --- a/src/web/api/index.js +++ b/src/web/api/index.js @@ -32,7 +32,20 @@ const VERSION = (() => { * Deployments that ship an archive make it easy to look at a stale copy and * wonder why a fix is missing; this gives the page something to state. */ -const BUILD_AT = (() => { +/** + * Newest file of the served interface. + * + * Read from disk rather than frozen at startup: the front-end is served from + * disk on every request, so a marker captured at boot would keep announcing an + * old build after an upload — the exact confusion it exists to prevent. Cached + * briefly so a health check does not walk the tree each time. + */ +const BUILD_TTL_MS = 10_000; +let buildCache = { at: null, readAt: 0 }; + +function buildAt() { + if (buildCache.readAt && Date.now() - buildCache.readAt < BUILD_TTL_MS) return buildCache.at; + const root = path.join(here, '../public'); let newest = 0; @@ -47,10 +60,13 @@ const BUILD_AT = (() => { try { walk(root); } catch { + buildCache = { at: null, readAt: Date.now() }; return null; } - return newest > 0 ? new Date(newest).toISOString() : null; -})(); + + buildCache = { at: newest > 0 ? new Date(newest).toISOString() : null, readAt: Date.now() }; + return buildCache.at; +} /** * Route registration order matters only for readability: the router matches on @@ -66,7 +82,7 @@ export function registerApiRoutes(router, { setupOnly = false } = {}) { setupOnly: context.setupOnly, uptimeMs: Date.now() - context.startedAt, version: VERSION, - buildAt: BUILD_AT, + buildAt: buildAt(), }), { public: true }, );