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

fix: tell the truth when a tree was dirty, and retry a timed-out probe (#4694)

[._.]/ Adam Eivy0213aca0e399
diff --git a/client/src/components/system-resources/BuildStampPanel.jsx b/client/src/components/system-resources/BuildStampPanel.jsx
index 6335248916..be10bb6ddb 100644
--- a/client/src/components/system-resources/BuildStampPanel.jsx
+++ b/client/src/components/system-resources/BuildStampPanel.jsx
@@ -48,7 +48,8 @@ export default function BuildStampPanel({ uptimeFormatted }) {
});
const bundleLabel = describeBuild({
commit: TRUSTED_BUNDLE_STAMP?.commit,
- branch: TRUSTED_BUNDLE_STAMP?.branch
+ branch: TRUSTED_BUNDLE_STAMP?.branch,
+ dirty: TRUSTED_BUNDLE_STAMP?.dirty
});
return (
@@ -103,13 +104,26 @@ function footnote(state, build) {
? 'Running from the Vite dev server, so there is no built bundle to compare against the server.'
: 'Commit unknown on at least one side (no git metadata), so bundle/server drift cannot be checked here.';
}
- // Matching commits are not the whole story: the comparison is commit-only, and
- // the server tree can carry uncommitted edits that no commit id reflects.
- // Claiming "this is the code that is running" there would be a false assurance
- // in exactly the debugging session this panel exists to end.
- return build?.dirty === false
+
+ // Matching commits are not the whole story. The comparison is commit-only, and
+ // EITHER tree can carry uncommitted edits that no commit id reflects: the
+ // server booted from a dirty checkout, or the dist was built from one (which
+ // stamps its parent's clean commit). Claiming "this is the code that is
+ // running" in either case would be a false assurance in exactly the debugging
+ // session this panel exists to end.
+ const unclean = [
+ build?.dirty === true && 'the server tree',
+ TRUSTED_BUNDLE_STAMP?.dirty === true && 'this bundle'
+ ].filter(Boolean);
+ if (unclean.length > 0) {
+ return `Same commit on both sides, but ${unclean.join(' and ')} had uncommitted changes that commit does not include.`;
+ }
+
+ // Only claim full agreement once both sides confirmed clean — `null` means the
+ // check did not run, which is not the same as clean.
+ return build?.dirty === false && TRUSTED_BUNDLE_STAMP?.dirty === false
? 'Bundle and server agree — what you are looking at is the code that is running.'
- : 'Bundle and server are on the same commit, but the server tree has changes that commit does not include.';
+ : 'Bundle and server are on the same commit. Whether either tree had uncommitted changes could not be checked.';
}
function StampRow({ label, value, hint }) {
diff --git a/client/src/components/system-resources/BuildStampPanel.test.jsx b/client/src/components/system-resources/BuildStampPanel.test.jsx
index 7f43d5b8b3..367ae78182 100644
--- a/client/src/components/system-resources/BuildStampPanel.test.jsx
+++ b/client/src/components/system-resources/BuildStampPanel.test.jsx
@@ -51,8 +51,8 @@ describe('BuildStampPanel', () => {
expect(screen.getByText('abc1234')).toBeInTheDocument();
});
- it('confirms agreement only when the server tree is also clean', async () => {
- await renderPanel({ stamp: { commit: 'abc1234', branch: 'main' } });
+ it('confirms agreement only when BOTH trees are confirmed clean', async () => {
+ await renderPanel({ stamp: { commit: 'abc1234', branch: 'main', dirty: false } });
await waitFor(() => expect(screen.getByText(/what you are looking at is the code that is running/i)).toBeInTheDocument());
});
@@ -61,11 +61,43 @@ describe('BuildStampPanel', () => {
// Commit-only comparison cannot see working-tree edits — asserting a match
// here would be a false assurance in the exact session this panel ends.
await renderPanel({
- stamp: { commit: 'abc1234', branch: 'main' },
+ stamp: { commit: 'abc1234', branch: 'main', dirty: false },
build: serverBuild({ dirty: true }),
});
- await waitFor(() => expect(screen.getByText(/changes that commit does not include/i)).toBeInTheDocument());
+ await waitFor(() => expect(screen.getByText(/the server tree had uncommitted changes/i)).toBeInTheDocument());
+ expect(screen.queryByText(/what you are looking at is the code that is running/i)).not.toBeInTheDocument();
+ });
+
+ it('does not claim agreement when the BUNDLE was built from a dirty tree', async () => {
+ // A dist built from edited sources carries its parent's clean commit, so the
+ // commit ids match while the bundle contains code that was never committed.
+ await renderPanel({
+ stamp: { commit: 'abc1234', branch: 'main', dirty: true },
+ build: serverBuild({ dirty: false }),
+ });
+
+ await waitFor(() => expect(screen.getByText(/this bundle had uncommitted changes/i)).toBeInTheDocument());
+ expect(screen.queryByText(/what you are looking at is the code that is running/i)).not.toBeInTheDocument();
+ });
+
+ it('names both trees when both were dirty', async () => {
+ await renderPanel({
+ stamp: { commit: 'abc1234', branch: 'main', dirty: true },
+ build: serverBuild({ dirty: true }),
+ });
+
+ await waitFor(() => expect(screen.getByText(/the server tree and this bundle had uncommitted changes/i)).toBeInTheDocument());
+ });
+
+ it('says the cleanliness check did not run rather than claiming agreement', async () => {
+ // `null` is "we could not tell" — never rendered as clean.
+ await renderPanel({
+ stamp: { commit: 'abc1234', branch: 'main', dirty: null },
+ build: serverBuild({ dirty: null }),
+ });
+
+ await waitFor(() => expect(screen.getByText(/could not be checked/i)).toBeInTheDocument());
expect(screen.queryByText(/what you are looking at is the code that is running/i)).not.toBeInTheDocument();
});
diff --git a/client/src/services/staleBuildToast.jsx b/client/src/services/staleBuildToast.jsx
index 6cd3ae6aef..e529a35665 100644
--- a/client/src/services/staleBuildToast.jsx
+++ b/client/src/services/staleBuildToast.jsx
@@ -24,16 +24,20 @@ export function showStaleBuildToast() {
/**
* Sticky toast for the OTHER staleness: this tab matches the bundle on disk,
* but that bundle was built from a different git commit than the server process
- * is running (#4694). Deliberately offers no Reload button — reloading re-serves
- * the same stale dist and changes nothing. The remedy is a rebuild or a restart,
- * so the toast names it instead of offering an action that would not work.
+ * is running (#4694).
+ *
+ * No Reload button, because reloading ON ITS OWN re-serves the same stale dist
+ * and changes nothing — but the copy must not say reloading never helps either:
+ * after the rebuild it names first, a reload is exactly what puts this tab on
+ * the new bundle. Restarting the server instead drops the socket, and the
+ * reconnect frame clears this toast (see services/socket.js).
*/
export function showBuildDriftToast() {
toast(
<div className="flex flex-col gap-0.5">
<span>UI and server were built from different commits.</span>
<span className="text-xs opacity-80">
- Rebuild the client or restart the server — reloading will not help.
+ Rebuild the client and reload, or restart the server from the checkout you are editing.
</span>
</div>,
{ id: 'portos-build-drift', duration: Infinity, label: 'UI and server built from different commits' },
diff --git a/client/vite.config.js b/client/vite.config.js
index dcc4a241e1..b8e9f26585 100644
--- a/client/vite.config.js
+++ b/client/vite.config.js
@@ -37,13 +37,28 @@ function gitStamp(args) {
function buildStamp() {
const head = gitStamp(['rev-parse', '--abbrev-ref', 'HEAD']);
+ // Were the CLIENT sources uncommitted when this bundle was built? Scoped to
+ // this directory (`-- .`) on purpose: a dirty server file says nothing about
+ // what went into the bundle, and repo-wide would mark every dist dirty during
+ // ordinary server work. Without this the commit id alone is not enough — a
+ // dist built from an edited tree carries its parent's clean commit, and the
+ // panel would assert full agreement for code that was never committed.
+ //
+ // `--porcelain` prints nothing for a clean tree, so `gitStamp` returns null
+ // there — which is indistinguishable from a failed probe. Re-probe with a
+ // marker instead: `--porcelain` plus `rev-parse --is-inside-work-tree` tells
+ // us the command CAN run, so a null status means clean rather than unknown.
+ const inRepo = gitStamp(['rev-parse', '--is-inside-work-tree']) === 'true';
return {
commit: gitStamp(['rev-parse', '--short=7', 'HEAD']),
// `rev-parse --abbrev-ref` prints the literal string `HEAD` on a detached
- // checkout, which is not a branch name.
+ // checkout, which is not a branch name. (git refuses to CREATE a branch
+ // named HEAD, so this is never a real branch.)
branch: head === 'HEAD' ? null : head,
- // Commit / branch / timestamp only. No paths (they embed the OS username),
- // no hostname — this string ships to every browser that loads the app.
+ // null = we could not check, distinct from false = checked and clean.
+ dirty: inRepo ? gitStamp(['status', '--porcelain', '--', '.']) !== null : null,
+ // Commit / branch / dirty / timestamp only. No paths (they embed the OS
+ // username), no hostname — this ships to every browser that loads the app.
builtAt: new Date().toISOString()
};
}
diff --git a/server/lib/buildIdentity.js b/server/lib/buildIdentity.js
index 1c47f6eda3..66764215ac 100644
--- a/server/lib/buildIdentity.js
+++ b/server/lib/buildIdentity.js
@@ -95,6 +95,11 @@ export function parsePorcelainV2(stdout) {
// must stay distinguishable from "we checked and the tree is clean".
const UNKNOWN_IDENTITY = { commit: null, shortCommit: null, branch: null, dirty: null };
+/**
+ * @returns {Promise<{identity: object, definitive: boolean}>} `definitive` is
+ * false only when the probe itself failed (timeout, spawn error) — a state
+ * that can clear on its own and so must not be cached forever.
+ */
async function probe() {
// `ignoreExitCode` so a non-repo resolves to a readable non-zero exit rather
// than rejecting — the house convention for probe-shaped git calls, see
@@ -104,10 +109,19 @@ async function probe() {
timeout: GIT_TIMEOUT_MS
}).catch(() => null);
- // No `.git`, a broken checkout, or a timeout — report not-known, never a
- // fabricated value.
- if (!result || result.exitCode !== 0) return UNKNOWN_IDENTITY;
- return parsePorcelainV2(result.stdout);
+ // A REJECTION is transient: git timed out or could not be spawned. That can
+ // genuinely happen once at boot — the 5s bound elapsing while migrations and
+ // the DB hammer the disk, or a cold/dataless tree git has to materialize —
+ // and caching it would pin every field to null for the process lifetime,
+ // silently disabling the whole feature on a perfectly good checkout.
+ if (!result) return { identity: UNKNOWN_IDENTITY, definitive: false };
+
+ // A non-zero EXIT is definitive: git ran and told us this is not a checkout
+ // (a tarball install). Cache it, or every health request would re-spawn git
+ // to re-learn the same answer.
+ if (result.exitCode !== 0) return { identity: UNKNOWN_IDENTITY, definitive: true };
+
+ return { identity: parsePorcelainV2(result.stdout), definitive: true };
}
let cached = null;
@@ -125,13 +139,19 @@ let resolved = null;
* the UI labels it as an at-start fact.
*
* Non-throwing. Every field is independently nullable: a tarball install with
- * no `.git`, a detached checkout, or a git timeout reports `commit: null`.
+ * no `.git`, a detached checkout, or a git timeout reports `commit: null`. A
+ * timeout is retried on the next call; a definitive "not a repo" is not.
*
* @returns {Promise<{commit: string|null, shortCommit: string|null, branch: string|null, dirty: boolean|null}>}
*/
export function getBuildIdentity() {
- cached ??= probe().then((identity) => {
+ cached ??= probe().then(({ identity, definitive }) => {
resolved = identity;
+ // Release the cache when the probe merely FAILED, so the next caller retries
+ // instead of inheriting a transient null forever. A definitive answer —
+ // including "not a git checkout" — is kept, preserving the one-spawn
+ // property for real repos and tarball installs alike.
+ if (!definitive) cached = null;
return identity;
});
return cached;
diff --git a/server/lib/buildIdentity.test.js b/server/lib/buildIdentity.test.js
index 86c4927b6d..ceb79b13f1 100644
--- a/server/lib/buildIdentity.test.js
+++ b/server/lib/buildIdentity.test.js
@@ -120,6 +120,31 @@ describe('getBuildIdentity', () => {
expect(identity.dirty).toBeNull();
});
+ it('retries after a TRANSIENT probe failure instead of caching null forever', async () => {
+ // A 5s timeout can elapse once at boot while migrations hammer the disk.
+ // Caching that would disable the whole feature for the process lifetime on
+ // a checkout that is perfectly fine.
+ mocks.execGit.mockRejectedValueOnce(new Error('git command timed out after 5s'));
+ mocks.execGit.mockResolvedValue(ok(CLEAN));
+ const { getBuildIdentity } = await loadModule();
+
+ expect((await getBuildIdentity()).commit).toBeNull();
+ expect((await getBuildIdentity()).commit).toBe('1234567890abcdef1234567890abcdef12345678');
+ });
+
+ it('caches a DEFINITIVE not-a-repo answer rather than re-spawning git per request', async () => {
+ // git ran and told us there is no checkout (a tarball install). That cannot
+ // change under a running process, so one spawn is enough.
+ mocks.execGit.mockResolvedValue(fail());
+ const { getBuildIdentity } = await loadModule();
+
+ await getBuildIdentity();
+ await getBuildIdentity();
+ await getBuildIdentity();
+
+ expect(mocks.execGit).toHaveBeenCalledTimes(1);
+ });
+
it('shares one spawn across concurrent first callers', async () => {
// The boot log and an early health request can both land before the first
// probe resolves; caching the PROMISE (not the value) keeps that to one spawn.