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: align update semantics with git-pull flow, fix PS BOM

Adam Eivy12d4950c5e5c
diff --git a/server/routes/update.js b/server/routes/update.js
index bfdafdd7dd..2f09ed5841 100644
--- a/server/routes/update.js
+++ b/server/routes/update.js
@@ -68,8 +68,10 @@ router.post('/execute', asyncHandler(async (req, res) => {
};
// 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.
+ // The update script runs `git pull --rebase` to get the latest code,
+ // 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 => {
// Note: this .then() may never fire if the update script's PM2 restart
// kills this server process first. The client handles this by polling
diff --git a/server/services/updateExecutor.js b/server/services/updateExecutor.js
index 965b522b5a..1360fd7dbc 100644
--- a/server/services/updateExecutor.js
+++ b/server/services/updateExecutor.js
@@ -7,11 +7,16 @@ const UPDATE_SH = join(PATHS.root, 'update.sh');
const UPDATE_PS1 = join(PATHS.root, 'update.ps1');
/**
- * Execute the PortOS update script for a given release tag.
+ * Execute the PortOS update script (git pull to latest).
* Spawns update.sh (or update.ps1 on Windows) detached so it survives
* the Node process dying during the PM2 restart phase.
*
- * @param {string} tag - The git tag to update to (e.g. "v1.27.0")
+ * The scripts pull the latest code via `git pull --rebase --autostash` and
+ * write the actual resulting version to `data/update-complete.json`.
+ * The `tag` parameter is used only for logging and the initial API response;
+ * the true post-update version is determined by the script from package.json.
+ *
+ * @param {string} tag - The release tag that triggered the update (for logging)
* @param {function} emit - Callback (step, status, message) for progress
* @returns {Promise<{success: boolean, failedStep?: string, errorMessage?: string}>}
*/
@@ -20,7 +25,7 @@ export async function executeUpdate(tag, emit) {
const cmd = isWindows ? 'powershell' : 'bash';
const args = isWindows ? ['-ExecutionPolicy', 'Bypass', '-File', UPDATE_PS1] : [UPDATE_SH];
- emit('starting', 'running', `Starting update to ${tag}...`);
+ emit('starting', 'running', `Starting update (target: ${tag})...`);
return new Promise((resolve) => {
const child = spawn(cmd, args, {
@@ -64,14 +69,19 @@ export async function executeUpdate(tag, emit) {
child.on('close', async (code, signal) => {
const success = code === 0;
const exitDetail = signal ? `killed by ${signal}` : `exit code ${code}`;
- await recordUpdateResult({
- version: tag.replace(/^v/, ''),
- success,
- completedAt: new Date().toISOString(),
- log: success ? '' : `Process ${exitDetail}`
- }).catch(e => console.error(`❌ Failed to record update result: ${e.message}`));
+ // On success the update script writes data/update-complete.json with
+ // the actual post-pull version; the server reads it on boot to record
+ // the result. We only record here on failure (when the marker won't exist).
+ if (!success) {
+ await recordUpdateResult({
+ version: tag.replace(/^v/, ''),
+ success: false,
+ completedAt: new Date().toISOString(),
+ log: `Process ${exitDetail}`
+ }).catch(e => console.error(`❌ Failed to record update result: ${e.message}`));
+ }
if (success) {
- emit('complete', 'done', `Update to ${tag} complete`);
+ emit('complete', 'done', 'Update complete — restarting');
} else {
emit(lastStep, 'error', `Update failed at step "${lastStep}" (${exitDetail})`);
}
diff --git a/server/services/updateExecutor.test.js b/server/services/updateExecutor.test.js
index 99c613af35..a0ace4958b 100644
--- a/server/services/updateExecutor.test.js
+++ b/server/services/updateExecutor.test.js
@@ -73,17 +73,16 @@ describe('executeUpdate', () => {
expect(emits.some(e => e[0] === 'git-pull' && e[1] === 'done')).toBe(true);
});
- it('records update result on close', async () => {
+ it('does not record update result on success (marker file handles it)', async () => {
const child = createMockChild();
spawn.mockReturnValue(child);
const promise = executeUpdate('v1.0.0', () => {});
child.emit('close', 0);
- await promise;
+ const result = await promise;
- expect(recordUpdateResult).toHaveBeenCalledWith(
- expect.objectContaining({ version: '1.0.0', success: true })
- );
+ expect(result.success).toBe(true);
+ expect(recordUpdateResult).not.toHaveBeenCalled();
});
it('records failure on non-zero exit code', async () => {
diff --git a/update.ps1 b/update.ps1
index 4ddd0ca5ba..c5b24e5247 100644
--- a/update.ps1
+++ b/update.ps1
@@ -118,7 +118,8 @@ Write-Host ""
$Tag = (Get-Content package.json | ConvertFrom-Json).version
$completedAt = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$marker = "{`"version`":`"$Tag`",`"completedAt`":`"$completedAt`"}"
-$marker | Out-File -Encoding utf8 -FilePath "$RootDir\data\update-complete.json.tmp"
+$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
+[System.IO.File]::WriteAllText("$RootDir\data\update-complete.json.tmp", $marker, $utf8NoBom)
Move-Item -Force "$RootDir\data\update-complete.json.tmp" "$RootDir\data\update-complete.json"
# Restart PM2 apps