Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): cache-bust the build-id probe so a historical SW cache entry can't spoof it offline

[._.]/ Adam Eivy4902b5c82f94
diff --git a/client/src/utils/staleChunkReload.js b/client/src/utils/staleChunkReload.js
index cd6506bd14..fe6ef186ad 100644
--- a/client/src/utils/staleChunkReload.js
+++ b/client/src/utils/staleChunkReload.js
@@ -78,11 +78,14 @@ const withTimeout = (promise, ms) =>
// index.html (`server/lib/buildId.js`): only a confirmed different build
// justifies dropping the caches. Returns the server's build id, or null when
// offline/unreachable/unstamped (all "do not purge" signals). `cache:
-// 'no-store'` bypasses the HTTP cache, and the service worker routes this
-// non-navigation GET network-first, so a cached shell can't spoof the probe.
+// 'no-store'` bypasses the HTTP cache, and the unique query param guarantees a
+// Cache Storage miss inside the service worker — its fallback for this
+// non-navigation GET is `caches.match(request)`, which `no-store` does NOT
+// bypass, so without the param a historical cache entry keyed `/` could answer
+// the probe with old HTML and fake a "different build" while offline.
export const fetchServerBuildId = async () => {
if (typeof navigator !== 'undefined' && navigator.onLine === false) return null;
- const res = await fetch('/', { cache: 'no-store' }).catch(() => null);
+ const res = await fetch(`/?portos-build-probe=${Date.now()}`, { cache: 'no-store' }).catch(() => null);
if (!res || !res.ok) return null;
const html = await res.text().catch(() => '');
const doc = new DOMParser().parseFromString(html, 'text/html');
diff --git a/client/src/utils/staleChunkReload.test.js b/client/src/utils/staleChunkReload.test.js
index 8f88390c76..1c1355d396 100644
--- a/client/src/utils/staleChunkReload.test.js
+++ b/client/src/utils/staleChunkReload.test.js
@@ -109,7 +109,13 @@ describe('fetchServerBuildId', () => {
it('reads the build id stamped into the served shell', async () => {
const fetch = stubFetch();
await expect(fetchServerBuildId()).resolves.toBe('build-new');
- expect(fetch).toHaveBeenCalledWith('/', { cache: 'no-store' });
+ // Cache-busting query param: the SW's offline fallback is
+ // caches.match(request), which `no-store` does not bypass — a unique URL
+ // guarantees a miss so a historical cached shell can't spoof the probe.
+ expect(fetch).toHaveBeenCalledWith(
+ expect.stringMatching(/^\/\?portos-build-probe=\d+$/),
+ { cache: 'no-store' }
+ );
});
it('is null when the probe rejects (offline)', async () => {