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 + claude round 3): reconcile dep-diff base + null-health guard

[._.]/ Adam Eivy27c6b871a7d1
diff --git a/client/src/components/apps/tabs/UpdateTab.jsx b/client/src/components/apps/tabs/UpdateTab.jsx
index 35a40a2410..5fa50528ee 100644
--- a/client/src/components/apps/tabs/UpdateTab.jsx
+++ b/client/src/components/apps/tabs/UpdateTab.jsx
@@ -157,8 +157,11 @@ export default function UpdateTab() {
setTimeout(() => window.location.reload(), 1000);
return;
}
- // Track the running peak so a later uptime drop is detectable.
- if (typeof ok.uptime === 'number' && ok.uptime > maxUptimeRef.current) {
+ // Track the running peak so a later uptime drop is detectable. Guard on
+ // `ok` — the !ok (server-down) branch falls through to here, and a null
+ // deref would throw before the attempts>=30 timeout check below, hanging the
+ // UI on a restart that never recovers.
+ if (ok && typeof ok.uptime === 'number' && ok.uptime > maxUptimeRef.current) {
maxUptimeRef.current = ok.uptime;
}
if (attemptsRef.current >= 30) {
diff --git a/server/routes/update.js b/server/routes/update.js
index ffe5873545..808b022fa7 100644
--- a/server/routes/update.js
+++ b/server/routes/update.js
@@ -179,7 +179,12 @@ router.post('/execute', asyncHandler(async (req, res) => {
// so the actual post-update version may differ from `tag` if new commits
// landed after the release. The script writes the true version to
// data/update-complete.json, which the server reads on boot.
- executeUpdate(tag, emit).then(result => {
+ //
+ // For a reconcile, hand update.sh the commit the running process was built at
+ // (installState.bootCommit) so its dependency-change diff spans install→now —
+ // a bare `git pull` already advanced HEAD, so HEAD-vs-HEAD would miss it.
+ const fromSha = reconcile ? status.installState.bootCommit : undefined;
+ executeUpdate(tag, emit, { fromSha }).then(result => {
// Note: this .then() may never fire if the update script's PM2 restart
// kills this server process first. The client handles this by polling
// /api/system/health after receiving the 'restart' step.
diff --git a/server/routes/update.test.js b/server/routes/update.test.js
index f332ae8560..06dc1cc239 100644
--- a/server/routes/update.test.js
+++ b/server/routes/update.test.js
@@ -65,12 +65,15 @@ describe('POST /api/update/execute — reconcile gating (issue #1779)', () => {
expect(executeUpdate).not.toHaveBeenCalled();
});
- it('runs the reconcile when out of sync, targeting the current version', async () => {
- updateChecker.getUpdateStatus.mockResolvedValue(baseStatus({ installState: { outOfSync: true } }));
+ it('runs the reconcile when out of sync, targeting the current version and threading the boot commit', async () => {
+ updateChecker.getUpdateStatus.mockResolvedValue(
+ baseStatus({ installState: { outOfSync: true, bootCommit: 'abc1234def' } })
+ );
const res = await request(makeApp()).post('/api/update/execute').send({ reconcile: true });
expect(res.status).toBe(200);
expect(res.body).toEqual({ started: true, tag: 'v1.26.0' });
- expect(executeUpdate).toHaveBeenCalledWith('v1.26.0', expect.any(Function));
+ // update.sh needs the install→now diff base, so the boot commit is threaded.
+ expect(executeUpdate).toHaveBeenCalledWith('v1.26.0', expect.any(Function), { fromSha: 'abc1234def' });
});
it('reconcile runs even with NO cached release (out of sync)', async () => {
@@ -101,11 +104,11 @@ describe('POST /api/update/execute — reconcile gating (issue #1779)', () => {
expect(res.body.code).toBe('NO_RELEASE');
});
- it('a normal update uses the cached release tag', async () => {
+ it('a normal update uses the cached release tag and passes no fromSha', async () => {
updateChecker.getUpdateStatus.mockResolvedValue(baseStatus());
const res = await request(makeApp()).post('/api/update/execute').send({});
expect(res.status).toBe(200);
expect(res.body.tag).toBe('v1.27.0');
- expect(executeUpdate).toHaveBeenCalledWith('v1.27.0', expect.any(Function));
+ expect(executeUpdate).toHaveBeenCalledWith('v1.27.0', expect.any(Function), { fromSha: undefined });
});
});
diff --git a/server/services/updateExecutor.js b/server/services/updateExecutor.js
index 187b9a3a1c..f389579378 100644
--- a/server/services/updateExecutor.js
+++ b/server/services/updateExecutor.js
@@ -21,7 +21,7 @@ const UPDATE_PS1 = join(PATHS.root, 'update.ps1');
* @param {function} emit - Callback (step, status, message) for progress
* @returns {Promise<{success: boolean, version?: string, failedStep?: string, errorMessage?: string}>}
*/
-export async function executeUpdate(tag, emit) {
+export async function executeUpdate(tag, emit, { fromSha } = {}) {
const isWindows = process.platform === 'win32';
const cmd = isWindows ? 'powershell' : 'bash';
const args = isWindows
@@ -30,11 +30,21 @@ export async function executeUpdate(tag, emit) {
emit('starting', 'running', `Starting update (target: ${tag})...`);
+ // For a reconcile (issue #1779) the checkout is already at the new HEAD, so
+ // update.sh's HEAD-based dependency-change diff would be empty and miss the
+ // clean reinstall stale node_modules needs. Pass the commit the running
+ // process was built at as the diff base so update.sh detects the real delta.
+ // Validate as a hex sha to keep arbitrary input out of the child env.
+ const childEnv = (typeof fromSha === 'string' && /^[0-9a-f]{7,40}$/i.test(fromSha))
+ ? { ...process.env, PORTOS_UPDATE_FROM_SHA: fromSha }
+ : process.env;
+
return new Promise((resolve) => {
const child = spawn(cmd, args, {
detached: true,
stdio: ['ignore', 'pipe', 'pipe'],
- cwd: PATHS.root
+ cwd: PATHS.root,
+ env: childEnv
});
let lastStep = 'starting';
diff --git a/server/services/updateExecutor.test.js b/server/services/updateExecutor.test.js
index 16d9ecf00a..c621fb1ee9 100644
--- a/server/services/updateExecutor.test.js
+++ b/server/services/updateExecutor.test.js
@@ -162,4 +162,36 @@ describe('executeUpdate', () => {
expect.objectContaining({ success: false, log: 'spawn failed' })
);
});
+
+ // Reconcile (issue #1779) passes the boot commit so update.sh diffs
+ // install→now for its dependency-change detection.
+ it('passes a valid fromSha to the child as PORTOS_UPDATE_FROM_SHA', async () => {
+ const child = createMockChild();
+ spawn.mockReturnValue(child);
+ const promise = executeUpdate('v1.0.0', () => {}, { fromSha: 'abc1234def5678' });
+ child.emit('close', 0);
+ await promise;
+ const env = spawn.mock.calls[0][2].env;
+ expect(env.PORTOS_UPDATE_FROM_SHA).toBe('abc1234def5678');
+ });
+
+ it('does NOT set PORTOS_UPDATE_FROM_SHA when no fromSha is given', async () => {
+ const child = createMockChild();
+ spawn.mockReturnValue(child);
+ const promise = executeUpdate('v1.0.0', () => {});
+ child.emit('close', 0);
+ await promise;
+ const env = spawn.mock.calls[0][2].env;
+ expect(env.PORTOS_UPDATE_FROM_SHA).toBeUndefined();
+ });
+
+ it('rejects a non-sha fromSha (no env injection)', async () => {
+ const child = createMockChild();
+ spawn.mockReturnValue(child);
+ const promise = executeUpdate('v1.0.0', () => {}, { fromSha: 'main; rm -rf /' });
+ child.emit('close', 0);
+ await promise;
+ const env = spawn.mock.calls[0][2].env;
+ expect(env.PORTOS_UPDATE_FROM_SHA).toBeUndefined();
+ });
});
diff --git a/update.sh b/update.sh
index 877160cc91..c99786351d 100755
--- a/update.sh
+++ b/update.sh
@@ -135,7 +135,14 @@ fi
# installs/builds), not a feature branch we just left. Diffing this against
# post-pull HEAD yields exactly the pull's delta on main, so a manifest change
# the update brings is detected even when launched from another branch.
-pre_pull_sha=$(git rev-parse HEAD 2>/dev/null || echo "")
+#
+# RECONCILE (issue #1779): when PortOS triggers this to finish a bare `git pull`
+# the user already did, the checkout is ALREADY at the new HEAD, so capturing
+# HEAD here would diff against itself (empty) and skip the clean reinstall the
+# stale node_modules needs. PortOS passes PORTOS_UPDATE_FROM_SHA = the commit the
+# running process was built at, so the manifest diff spans the install→now delta
+# and the clean reinstall fires for workspaces whose deps actually changed.
+pre_pull_sha="${PORTOS_UPDATE_FROM_SHA:-$(git rev-parse HEAD 2>/dev/null || echo "")}"
run git pull --rebase --autostash
step "git-pull" "done" "Latest changes pulled"