Version badge and update check use the build's version, not the installed one
After upgrading pi-web and pi in place (npm install into the same directory, then restart),
the title badge and the footer kept showing the old versions, and /api/app-update
reported the freshly installed release as available.
Both come from NEXT_PUBLIC_APP_VERSION / NEXT_PUBLIC_PI_VERSION, which next.config.ts
fills from package.json and inlines into the bundle at build time
(components/PiWebTitle.tsx:90, components/ChatWindow.tsx:1537,
app/api/app-update/route.ts:7). Nothing rebuilds when the packages change, so the running
process keeps reporting whatever was on disk when it was compiled — a stale badge is
cosmetic, but app-update compares npm's latest against the build version, so it either
nags forever or offers an upgrade that is already installed.
Reproduce: install 0.16.0, npm run build, restart, then npm install @agegr/[email protected]
in the same directory and restart. The UI still says 0.16.0.
Fix: read the versions from disk at request time (lib/runtime-versions.ts, memoized per
process; process.cwd() is the package directory because bin/pi-web.js:127 starts next
with cwd: pkgDir), expose them on GET /api/version (force-dynamic, no-store), and
let the two badges fetch that once per page load through useRuntimeVersions, falling back
to the built-in value when the request fails. /api/app-update uses the same source for
currentVersion, so the nagging clears after the restart the upgrade already needs.
Everything keeps working without the request succeeding: the fallback is the value that is correct until someone upgrades in place, which is exactly when the fetch matters.
Tests: lib/runtime-versions.test.mjs (4 cases) covers installed-over-baked, pi resolved
from its package, the missing-file fallback, and memoization. tsc --noEmit, eslint and
next build clean; /api/version is emitted as a dynamic route.
I have a patch for this on fix/runtime-versions in my fork (srodriguezch-gh/pi-web) if the direction looks right, happy to open it as a PR instead.
Thanks for the detailed write-up. I don't think the badge is wrong, though: it reports the build that is actually running.
- The npm package ships its prebuilt
.next(seefilesinpackage.json) and no sources, so there is nonpm run buildstep for an npm install.npm install @agegr/[email protected]replaces the build with 0.17.0's, which has 0.17.0 baked in, so after the restart the badge, the footer and/api/app-updateall say 0.17.0. - In a source checkout the build is the code that runs. Installing
@agegr/[email protected]into a checkout'snode_modules, or pulling without rebuilding, leaves the server running the old compiled code, so the old version is the truthful answer. Readingpackage.jsonfrom disk at request time would report a release whose code isn't running. After updating a checkout, runnpm run buildagain. - pi's packages are pinned exactly to what a pi-web release was built and tested with (
lib/pi-packages.test.mjs). Upgrading pi inside pi-web's folder without a pi-web release isn't a supported setup, so the pi badge shows the version the build was made for.
If you see a stale badge after a plain upgrade of the published package, please share how you launch it and the /api/app-update reply; most likely an old server process was still running. Closing for now.