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 round 4): force-clean stale workspaces on reconcile (sh + ps1)

[._.]/ Adam Eivy81aaa4df964f
diff --git a/server/routes/update.js b/server/routes/update.js
index 808b022fa7..b96bbd37c2 100644
--- a/server/routes/update.js
+++ b/server/routes/update.js
@@ -180,11 +180,16 @@ router.post('/execute', asyncHandler(async (req, res) => {
// landed after the release. The script writes the true version to
// data/update-complete.json, which the server reads on boot.
//
- // 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 => {
+ // For a reconcile, hand the updater the workspaces whose installed deps are
+ // stale (per installState's receipt check) so it force-reinstalls exactly
+ // those — a bare `git pull` (possibly already restarted) leaves the scripts'
+ // commit-diff dependency detection empty. 'root' maps to update.sh's '.' token.
+ const forceCleanWorkspaces = reconcile
+ ? (status.installState.staleDeps?.workspaces || [])
+ .filter(w => w.stale)
+ .map(w => (w.name === 'root' ? '.' : w.name))
+ : undefined;
+ executeUpdate(tag, emit, { forceCleanWorkspaces }).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 06dc1cc239..4d20fe615b 100644
--- a/server/routes/update.test.js
+++ b/server/routes/update.test.js
@@ -65,15 +65,31 @@ 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 and threading the boot commit', async () => {
- updateChecker.getUpdateStatus.mockResolvedValue(
- baseStatus({ installState: { outOfSync: true, bootCommit: 'abc1234def' } })
- );
+ it('runs the reconcile when out of sync, targeting the current version and forcing clean of stale workspaces', async () => {
+ updateChecker.getUpdateStatus.mockResolvedValue(baseStatus({
+ installState: {
+ outOfSync: true,
+ staleDeps: { stale: true, workspaces: [
+ { name: 'root', stale: true },
+ { name: 'client', stale: false },
+ { name: 'server', stale: true }
+ ] }
+ }
+ }));
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' });
- // 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' });
+ // Only the stale workspaces, with 'root' mapped to update.sh's '.' token.
+ expect(executeUpdate).toHaveBeenCalledWith('v1.26.0', expect.any(Function), { forceCleanWorkspaces: ['.', 'server'] });
+ });
+
+ it('reconcile with no stale deps (build/migration staleness) forces no clean', async () => {
+ updateChecker.getUpdateStatus.mockResolvedValue(baseStatus({
+ installState: { outOfSync: true, staleDeps: { stale: false, workspaces: [] }, staleBuild: true }
+ }));
+ const res = await request(makeApp()).post('/api/update/execute').send({ reconcile: true });
+ expect(res.status).toBe(200);
+ expect(executeUpdate).toHaveBeenCalledWith('v1.26.0', expect.any(Function), { forceCleanWorkspaces: [] });
});
it('reconcile runs even with NO cached release (out of sync)', async () => {
@@ -104,11 +120,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 and passes no fromSha', async () => {
+ it('a normal update uses the cached release tag and forces no clean', 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), { fromSha: undefined });
+ expect(executeUpdate).toHaveBeenCalledWith('v1.27.0', expect.any(Function), { forceCleanWorkspaces: undefined });
});
});
diff --git a/server/services/updateExecutor.js b/server/services/updateExecutor.js
index f389579378..fc1ae1b854 100644
--- a/server/services/updateExecutor.js
+++ b/server/services/updateExecutor.js
@@ -21,7 +21,11 @@ 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, { fromSha } = {}) {
+// Workspaces update.sh / update.ps1 know how to clean-reinstall — the env
+// passthrough is allowlisted to these so nothing arbitrary reaches the scripts.
+const CLEANABLE_WORKSPACES = new Set(['.', 'client', 'server', 'autofixer']);
+
+export async function executeUpdate(tag, emit, { forceCleanWorkspaces } = {}) {
const isWindows = process.platform === 'win32';
const cmd = isWindows ? 'powershell' : 'bash';
const args = isWindows
@@ -30,13 +34,16 @@ export async function executeUpdate(tag, emit, { fromSha } = {}) {
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 }
+ // For a reconcile (issue #1779), a bare `git pull` left stale node_modules
+ // even though HEAD already advanced — so the scripts' commit-diff dependency
+ // detection finds nothing to reinstall. Pass the workspaces whose deps are
+ // actually stale (per installState's receipt check) so update.sh/update.ps1
+ // force a from-scratch reinstall of exactly those, regardless of the diff.
+ const cleanList = Array.isArray(forceCleanWorkspaces)
+ ? forceCleanWorkspaces.filter(w => CLEANABLE_WORKSPACES.has(w))
+ : [];
+ const childEnv = cleanList.length
+ ? { ...process.env, PORTOS_FORCE_CLEAN_WORKSPACES: cleanList.join(',') }
: process.env;
return new Promise((resolve) => {
diff --git a/server/services/updateExecutor.test.js b/server/services/updateExecutor.test.js
index c621fb1ee9..c195319956 100644
--- a/server/services/updateExecutor.test.js
+++ b/server/services/updateExecutor.test.js
@@ -163,35 +163,45 @@ describe('executeUpdate', () => {
);
});
- // 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 () => {
+ // Reconcile (issue #1779) passes the stale workspaces so update.sh force-
+ // reinstalls exactly those, regardless of the commit diff.
+ it('passes allowlisted forceCleanWorkspaces as PORTOS_FORCE_CLEAN_WORKSPACES', async () => {
const child = createMockChild();
spawn.mockReturnValue(child);
- const promise = executeUpdate('v1.0.0', () => {}, { fromSha: 'abc1234def5678' });
+ const promise = executeUpdate('v1.0.0', () => {}, { forceCleanWorkspaces: ['.', 'client'] });
child.emit('close', 0);
await promise;
const env = spawn.mock.calls[0][2].env;
- expect(env.PORTOS_UPDATE_FROM_SHA).toBe('abc1234def5678');
+ expect(env.PORTOS_FORCE_CLEAN_WORKSPACES).toBe('.,client');
});
- it('does NOT set PORTOS_UPDATE_FROM_SHA when no fromSha is given', async () => {
+ it('does NOT set PORTOS_FORCE_CLEAN_WORKSPACES when none are 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();
+ expect(env.PORTOS_FORCE_CLEAN_WORKSPACES).toBeUndefined();
});
- it('rejects a non-sha fromSha (no env injection)', async () => {
+ it('filters out non-allowlisted workspace names (no injection)', async () => {
const child = createMockChild();
spawn.mockReturnValue(child);
- const promise = executeUpdate('v1.0.0', () => {}, { fromSha: 'main; rm -rf /' });
+ const promise = executeUpdate('v1.0.0', () => {}, { forceCleanWorkspaces: ['client', '../../etc', 'rm -rf /'] });
child.emit('close', 0);
await promise;
const env = spawn.mock.calls[0][2].env;
- expect(env.PORTOS_UPDATE_FROM_SHA).toBeUndefined();
+ expect(env.PORTOS_FORCE_CLEAN_WORKSPACES).toBe('client');
+ });
+
+ it('does NOT set the env when every workspace name is rejected', async () => {
+ const child = createMockChild();
+ spawn.mockReturnValue(child);
+ const promise = executeUpdate('v1.0.0', () => {}, { forceCleanWorkspaces: ['bogus'] });
+ child.emit('close', 0);
+ await promise;
+ const env = spawn.mock.calls[0][2].env;
+ expect(env.PORTOS_FORCE_CLEAN_WORKSPACES).toBeUndefined();
});
});
diff --git a/update.ps1 b/update.ps1
index 8961ad53fe..e050f46cb3 100644
--- a/update.ps1
+++ b/update.ps1
@@ -83,6 +83,14 @@ $script:DepsChangedUnknown = $false
function Test-WorkspaceDepsChanged {
param([string]$Dir)
if ($script:DepsChangedUnknown) { return $true }
+ # RECONCILE (issue #1779): PortOS passes the workspaces whose installed deps
+ # are stale (per npm's install receipt) in PORTOS_FORCE_CLEAN_WORKSPACES, so
+ # they get a from-scratch reinstall even when the commit diff is empty (a
+ # bare `git pull`, possibly already restarted). Mirrors update.sh.
+ if ($env:PORTOS_FORCE_CLEAN_WORKSPACES) {
+ $forced = $env:PORTOS_FORCE_CLEAN_WORKSPACES -split ','
+ if ($forced -contains $Dir) { return $true }
+ }
$rel = if ($Dir -eq ".") { "package.json" } else { ($Dir -replace '^\./', '') + "/package.json" }
return $script:DepsChangedFiles -contains $rel
}
diff --git a/update.sh b/update.sh
index c99786351d..c6aaa32808 100755
--- a/update.sh
+++ b/update.sh
@@ -61,6 +61,17 @@ DEPS_CHANGED_UNKNOWN=0
workspace_deps_changed() {
local dir="$1"
[ "$DEPS_CHANGED_UNKNOWN" = "1" ] && return 0
+ # RECONCILE (issue #1779): a bare `git pull` (no update.sh) leaves stale
+ # node_modules even though HEAD already advanced — so the commit diff above is
+ # empty (especially if the user also restarted). PortOS passes the workspaces
+ # whose installed deps are stale (detected via npm's install receipt) in
+ # PORTOS_FORCE_CLEAN_WORKSPACES so they get the from-scratch reinstall here
+ # regardless of the diff. Tokens are dir names (".","client","server","autofixer").
+ if [ -n "${PORTOS_FORCE_CLEAN_WORKSPACES:-}" ]; then
+ case ",${PORTOS_FORCE_CLEAN_WORKSPACES}," in
+ *",${dir},"*) return 0 ;;
+ esac
+ fi
local rel="package.json"
[ "$dir" != "." ] && rel="${dir#./}/package.json"
printf '%s\n' "$DEPS_CHANGED_FILES" | grep -qx "$rel"
@@ -135,14 +146,7 @@ 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.
-#
-# 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 "")}"
+pre_pull_sha=$(git rev-parse HEAD 2>/dev/null || echo "")
run git pull --rebase --autostash
step "git-pull" "done" "Latest changes pulled"