Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

feat(update): tell the running build from the checkout, so a pending rebuild is visible

Rahmana06aec94ad96
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index e6af3573..e6ce3b44 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -8,6 +8,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
**Added**
+- `update` tell the running build from the checkout, so a pending rebuild is visible
- `settings,preview` update MSO from the app, and preview the formats a real disk has
**Fixed**
diff --git a/frontend/slices/os-settings/components/update-section.tsx b/frontend/slices/os-settings/components/update-section.tsx
index eb160b9d..f1b329a7 100644
--- a/frontend/slices/os-settings/components/update-section.tsx
+++ b/frontend/slices/os-settings/components/update-section.tsx
@@ -98,6 +98,7 @@ export function UpdateSection() {
if (IS_DEMO || (!info && !checking)) return null;
const behind = info?.behind ?? 0;
const running = info?.running ?? false;
+ const pending = (info?.pendingBuild ?? false) && behind === 0;
// Derived, never stored: an update we watched, that is no longer running, either
// left its marker in the log or stopped before deploying.
const finished = sawRunning && !running && info ? (info.log.includes(OK_MARKER) ? "ok" : "failed") : null;
@@ -115,10 +116,26 @@ export function UpdateSection() {
<SettingsBlock className="space-y-2">
<div className="flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-xs">
<span className="font-medium text-foreground">
- {checking ? "Checking for updates…" : behind > 0 ? `${behind} update${behind > 1 ? "s" : ""} available` : "Up to date"}
+ {checking
+ ? "Checking for updates…"
+ : behind > 0
+ ? `${behind} update${behind > 1 ? "s" : ""} available`
+ : pending
+ ? "A build is pending"
+ : "Up to date"}
+ </span>
+ {/* The RUNNING commit, not the checkout's — they differ whenever someone
+ pulled without rebuilding, and that gap is the whole point of the row. */}
+ <span className="font-mono text-[11px] text-muted-foreground">
+ running {info?.buildSha || info?.current || "—"}
</span>
- <span className="font-mono text-[11px] text-muted-foreground">running {info?.current ?? "—"}</span>
</div>
+ {pending && (
+ <p className="text-[11px] text-muted-foreground">
+ The checkout is at <span className="font-mono">{info?.current}</span>, which this build was not compiled
+ from. Rebuild to run it.
+ </p>
+ )}
{info?.currentSubject && <p className="line-clamp-2 text-[11px] text-muted-foreground">{info.currentSubject}</p>}
{info && !info.remoteChecked && !running && (
<p className="text-[11px] text-amber-500">
@@ -165,7 +182,7 @@ export function UpdateSection() {
)}
{info?.supported !== false && behind === 0 && (
<SettingsActionRow
- label="Rebuild and restart"
+ label={pending ? `Build ${info?.current} and restart` : "Rebuild and restart"}
icon={<RefreshCw />}
busy={busy || running}
disabled={running}
diff --git a/lib/host/self-update.test.ts b/lib/host/self-update.test.ts
index ba394f48..37ade5a5 100644
--- a/lib/host/self-update.test.ts
+++ b/lib/host/self-update.test.ts
@@ -14,6 +14,8 @@ const status = (over: Partial<Parameters<typeof blockingReason>[0]> = {}) => ({
reason: null,
current: "abc1234",
currentSubject: "feat: something",
+ buildSha: "abc1234",
+ pendingBuild: false,
behind: 3,
commits: [],
dirty: false,
@@ -55,6 +57,15 @@ describe("blockingReason", () => {
expect(blockingReason(status({ behind: 0 }), true)).toBeNull();
});
+ it("is NOT 'up to date' when the running build is older than the checkout", () => {
+ // Someone pulled without rebuilding: `git` says there is nothing to fetch while
+ // the process is still serving the previous commit. Saying "already up to date"
+ // there describes the checkout and leaves the operator with no way to act.
+ const pending = status({ behind: 0, buildSha: "0000000", pendingBuild: true });
+ expect(blockingReason(pending, false)).toBeNull();
+ expect(blockingReason(pending, true)).toBeNull();
+ });
+
it("refuses a dirty checkout — the fast-forward would fail anyway", () => {
expect(blockingReason(status({ dirty: true }), false)).toContain("uncommitted changes");
// Also for a rebuild: the point of refusing is that we do not know what is in
diff --git a/lib/host/self-update.ts b/lib/host/self-update.ts
index f19f7dfe..aa9d68e4 100644
--- a/lib/host/self-update.ts
+++ b/lib/host/self-update.ts
@@ -38,8 +38,14 @@ export interface UpdateStatus {
supported: boolean;
/** Why not, when `supported` is false — shown to the operator verbatim. */
reason: string | null;
+ /** HEAD of the CHECKOUT — what a rebuild would compile. */
current: string;
currentSubject: string;
+ /** The commit the RUNNING build was compiled from (baked in by next.config), or
+ * "" when the build carried no .git. Differs from `current` whenever someone
+ * pulled without rebuilding — the state the panel calls "a build is pending". */
+ buildSha: string;
+ pendingBuild: boolean;
behind: number;
commits: UpdateCommit[];
/** Uncommitted work in the checkout: a `--ff-only` merge would fail, so refuse early. */
@@ -106,7 +112,10 @@ export function blockingReason(status: UpdateStatus, rebuildOnly: boolean): stri
if (status.dirty) {
return "the checkout has uncommitted changes — commit or stash them on the host first, a fast-forward would refuse anyway";
}
- if (!rebuildOnly && status.behind === 0) return "already up to date";
+ // `pendingBuild` is a reason to run even with nothing to pull: the checkout
+ // already holds code the running process was not built from, and refusing with
+ // "already up to date" would be describing the wrong thing as up to date.
+ if (!rebuildOnly && status.behind === 0 && !status.pendingBuild) return "already up to date";
return null;
}
@@ -128,11 +137,14 @@ async function readLog(): Promise<string> {
* round trip, so the panel asks for one and the poller during an update does not.
*/
export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus> {
+ const buildSha = (process.env.NEXT_PUBLIC_COMMIT_SHA ?? "").trim();
const base: UpdateStatus = {
supported: false,
reason: null,
current: "unknown",
currentSubject: "",
+ buildSha,
+ pendingBuild: false,
behind: 0,
commits: [],
dirty: false,
@@ -166,11 +178,15 @@ export async function getUpdateStatus(fetchRemote = true): Promise<UpdateStatus>
git(["log", "--format=%h%x1f%s%x1f%cs", `-${MAX_COMMITS}`, "HEAD..origin/main"]),
]);
+ const current = head.stdout.trim() || "unknown";
return {
...base,
supported: true,
- current: head.stdout.trim() || "unknown",
+ current,
currentSubject: subject.stdout.trim(),
+ // Only when we know both: a build with no sha baked in (an archive export, a
+ // dev server) must not be reported as permanently stale.
+ pendingBuild: Boolean(buildSha) && current !== "unknown" && buildSha !== current,
behind: count.code === 0 ? Number(count.stdout.trim()) || 0 : 0,
commits: log.code === 0 ? parseCommits(log.stdout) : [],
dirty: status.stdout.trim().length > 0,
diff --git a/next.config.mjs b/next.config.mjs
index cd4efc1c..7699dc99 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -1,9 +1,27 @@
+import { execSync } from "node:child_process";
+
// Build id baked into the client bundle so a redeploy can be detected.
const BUILD_ID =
process.env.NEXT_PUBLIC_BUILD_ID ||
process.env.NEXT_DEPLOYMENT_ID ||
String(Date.now());
+// WHICH COMMIT THIS BUILD IS, baked in at build time — the only way the running app
+// can know it, since `git rev-parse HEAD` at runtime answers for the CHECKOUT, which
+// moves whenever someone pulls. Settings → About compares the two: equal means the
+// running build is current, different means a build is pending and the update panel
+// offers the rebuild. Empty is fine and expected — scripts/verify-build.sh compiles
+// a `git archive` export with no .git in it.
+const COMMIT_SHA =
+ process.env.NEXT_PUBLIC_COMMIT_SHA ||
+ (() => {
+ try {
+ return execSync("git rev-parse --short HEAD", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
+ } catch {
+ return "";
+ }
+ })();
+
/** @type {import('next').NextConfig} */
const nextConfig = {
// Don't advertise the framework/version — the shell is now public; minimize
@@ -40,7 +58,7 @@ const nextConfig = {
...(process.env.NEXT_DEPLOYMENT_ID
? { deploymentId: process.env.NEXT_DEPLOYMENT_ID }
: {}),
- env: { NEXT_PUBLIC_BUILD_ID: BUILD_ID },
+ env: { NEXT_PUBLIC_BUILD_ID: BUILD_ID, NEXT_PUBLIC_COMMIT_SHA: COMMIT_SHA },
experimental: {
// proxy.ts clones request bodies; the default clone cap is 10MB, which
// silently truncated large /api/v1/fs/upload payloads. Raise it so big