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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: address round 3 review — race guard, version fallback, scheduler dedup, target version pre-set
Adam Eivy4a380a065180
diff --git a/client/src/components/apps/tabs/UpdateTab.jsx b/client/src/components/apps/tabs/UpdateTab.jsxindex 86cc0ba789..d35b503be4 100644--- a/client/src/components/apps/tabs/UpdateTab.jsx+++ b/client/src/components/apps/tabs/UpdateTab.jsx@@ -134,6 +134,11 @@ export default function UpdateTab() {};const handleUpdate = async () => {+ // Set target version BEFORE executing so it's available when the+ // restarting step arrives via socket (which may beat the HTTP response)+ if (status?.latestRelease?.version) {+ targetVersionRef.current = status.latestRelease.version;+ }setUpdating(true);setSteps([]);setUpdateError(null);@@ -142,6 +147,7 @@ export default function UpdateTab() {setUpdating(false);return null;});+ // Update from response if available (should match, but server is authoritative)if (result?.tag) {targetVersionRef.current = result.tag.replace(/^v/, '');}diff --git a/server/routes/update.js b/server/routes/update.jsindex ebe9644793..6a4c87ae28 100644--- a/server/routes/update.js+++ b/server/routes/update.js@@ -55,6 +55,11 @@ router.post('/execute', asyncHandler(async (req, res) => {throw new ServerError('Invalid release tag format', { status: 400, code: 'INVALID_TAG' });}+ // Lock out duplicate requests synchronously BEFORE spawning the update,+ // preventing the race where a second request slips in before executeUpdate's+ // first await persists the flag+ await updateChecker.setUpdateInProgress(true);+const io = req.app.get('io');// Start update in background, stream progress via socket@@ -64,11 +69,13 @@ router.post('/execute', asyncHandler(async (req, res) => {}};- // Don't await — respond immediately, progress streams via socket+ // Don't await — respond immediately, progress streams via socket.+ // The update script emits STEP:restart:running when it reaches the PM2+ // restart phase, which triggers the client's health polling.executeUpdate(tag, emit).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 'restarting' step (see below).+ // /api/system/health after receiving the 'restart' step.if (io) {if (result.success) {io.emit('portos:update:complete', { success: true, newVersion: tag.replace(/^v/, '') });@@ -82,10 +89,6 @@ router.post('/execute', asyncHandler(async (req, res) => {}});- // Emit a restarting step immediately so the client knows to start- // health polling now, before the PM2 restart kills this process- emit('restarting', 'running', 'Server will restart momentarily...');-res.json({ started: true, tag });}));diff --git a/server/services/updateChecker.js b/server/services/updateChecker.jsindex affadd4fa7..b9fec9ed69 100644--- a/server/services/updateChecker.js+++ b/server/services/updateChecker.js@@ -31,7 +31,8 @@ const defaultState = () => ({export async function getCurrentVersion() {const pkgPath = join(PATHS.root, 'package.json');const pkg = await readJSONFile(pkgPath, { version: '0.0.0' });- return pkg.version;+ const version = (typeof pkg.version === 'string' && pkg.version) ? pkg.version : '0.0.0';+ return version;}/**@@ -182,6 +183,8 @@ export async function recordUpdateResult(result) {* Start the periodic update checker.*/export function startUpdateScheduler() {+ if (startupTimeout || schedulerInterval) return;+// Initial check after startup delaystartupTimeout = setTimeout(() => {startupTimeout = null;diff --git a/server/services/updateExecutor.js b/server/services/updateExecutor.jsindex f96e6f8679..fefcf3830c 100644--- a/server/services/updateExecutor.js+++ b/server/services/updateExecutor.js@@ -1,7 +1,7 @@import { spawn } from 'child_process';import { join } from 'path';import { PATHS } from '../lib/fileUtils.js';-import { setUpdateInProgress, recordUpdateResult } from './updateChecker.js';+import { recordUpdateResult } from './updateChecker.js';const SCRIPT_PATH = join(PATHS.root, 'scripts', 'portos-update.sh');@@ -20,7 +20,8 @@ export async function executeUpdate(tag, emit) {return { success: false, error: msg };}- await setUpdateInProgress(true);+ // The route sets updateInProgress synchronously before calling us,+ // so skip the redundant write here (it's already true)emit('starting', 'running', `Starting update to ${tag}...`);return new Promise((resolve) => {