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: keep self-updates stash-free

[._.]/ Adam Eivyf0003340e14e
diff --git a/scripts/update-headless-recovery.test.js b/scripts/update-headless-recovery.test.js
index e8dfdd69fc..660ddbb025 100644
--- a/scripts/update-headless-recovery.test.js
+++ b/scripts/update-headless-recovery.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
-import { spawn } from 'child_process';
+import { spawn, execFileSync } from 'child_process';
import { mkdirSync, writeFileSync, copyFileSync, readFileSync, existsSync, chmodSync, rmSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
@@ -51,6 +51,9 @@ async function makeSandbox({
chmodSync(join(repo, 'update.sh'), 0o755);
writeFileSync(join(repo, 'package.json'), JSON.stringify({ name: 'sandbox', version: '0.0.0' }));
writeFileSync(join(repo, 'ecosystem.config.cjs'), 'module.exports = { apps: [] };\n');
+ // Mirror the production ignore rule so update.sh's own runtime log does not
+ // turn an otherwise clean synthetic checkout into a dirty one.
+ writeFileSync(join(repo, '.gitignore'), 'data/*\n');
// Records every pm2 invocation the script makes, in order. When stallDelete is
// set the `delete` call logs and then BLOCKS until the test deletes the release
@@ -106,6 +109,12 @@ if (${stallDelete} && args.startsWith('delete')) {
chmodSync(join(bin, 'pm2'), 0o755);
}
+ // The updater now refuses dirty checkouts instead of stashing them. Commit
+ // the synthetic fixture so this test still exercises the headless recovery
+ // window rather than the dirty-checkout guard.
+ execFileSync('git', ['add', '.'], { cwd: repo });
+ execFileSync('git', ['commit', '-m', 'fixture'], { cwd: repo, stdio: 'ignore' });
+
return { scratch, repo, bin, calls, forceClean, releaseFile };
}
diff --git a/scripts/update-submodules.test.js b/scripts/update-submodules.test.js
index 1c944f60c6..c8e4b8861e 100644
--- a/scripts/update-submodules.test.js
+++ b/scripts/update-submodules.test.js
@@ -13,13 +13,13 @@ const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const SCRIPT_COMMANDS = [
{
path: 'update.sh',
- pull: 'run git pull --rebase --autostash',
+ pull: 'run git pull --rebase',
sync: 'run git submodule sync --recursive',
update: 'run git submodule update --init --recursive',
},
{
path: 'update.ps1',
- pull: 'Invoke-Logged git pull --rebase --autostash',
+ pull: 'Invoke-Logged git pull --rebase',
sync: 'Invoke-Logged git submodule sync --recursive',
update: 'Invoke-Logged git submodule update --init --recursive',
},
@@ -42,6 +42,11 @@ describe.each(SCRIPT_COMMANDS)('$path submodule update contract', ({ path, pull,
expect(source).not.toMatch(/git submodule update[^\n]*--remote/);
});
+ it('never uses stash as an implicit update transport', () => {
+ expect(source).not.toMatch(/git\s+stash|--autostash/);
+ expect(source).toContain('Checkout is dirty; no stash was created');
+ });
+
// This script is the most likely producer of an abandoned lock (PM2 tree-kills
// it mid-run), and without the sweep every later self-update fails identically
// on a file under `.git/` only a human would find. Both platforms call the one
diff --git a/update.ps1 b/update.ps1
index d4a06632a1..7dce74b80c 100644
--- a/update.ps1
+++ b/update.ps1
@@ -247,11 +247,8 @@ function Safe-Install {
# Pull latest — always switch to main (detached HEAD or feature branch both
# need to land on main before pulling, or the version won't advance). The
# rest of the script (install, build, restart) runs on main so the app
-# starts on the freshly-pulled revision. Local edits on the original branch
-# are stashed first so checkout doesn't abort, and we leave them in the
-# stash list afterward — the user can restore with `git stash pop` after
-# the update completes (we don't auto-pop because the rest of the script
-# needs to keep running with main's contents).
+# starts on the freshly-pulled revision. A dirty checkout is refused rather
+# than stashed, so agent or user work cannot be duplicated by a later rebase.
Step "git-pull" "running" "Pulling latest changes..."
$originUrl = git remote get-url origin 2>$null
if ($originUrl) {
@@ -265,31 +262,23 @@ if ($originUrl) {
}
$headRef = git symbolic-ref -q HEAD 2>$null
$currentBranch = if ($headRef) { $headRef -replace "refs/heads/", "" } else { "" }
-$stashedForBranch = ""
-$stashedForCommit = ""
-if ($currentBranch -ne "main") {
- $hasChanges = $false
- git diff --quiet 2>$null
+$hasChanges = $false
+git diff --quiet 2>$null
+if ($LASTEXITCODE -ne 0) { $hasChanges = $true }
+if (-not $hasChanges) {
+ git diff --cached --quiet 2>$null
if ($LASTEXITCODE -ne 0) { $hasChanges = $true }
- if (-not $hasChanges) {
- git diff --cached --quiet 2>$null
- if ($LASTEXITCODE -ne 0) { $hasChanges = $true }
- }
- if (-not $hasChanges) {
- $untracked = git ls-files --others --exclude-standard
- if ($untracked) { $hasChanges = $true }
- }
- if ($hasChanges) {
- $branchLabel = if ($currentBranch) { $currentBranch } else { "detached HEAD" }
- Write-SafeHost "⚠️ Stashing local changes from '$branchLabel' so checkout can proceed" -ForegroundColor Yellow
- Invoke-Logged git stash push -u -m "portos-update-$([int][double]::Parse((Get-Date -UFormat %s)))"
- if ($LASTEXITCODE -eq 0) {
- $stashedForBranch = $branchLabel
- # Capture the original commit SHA so detached-HEAD users can return
- # to the exact tree their stash was taken from.
- $stashedForCommit = git rev-parse HEAD
- }
- }
+}
+if (-not $hasChanges) {
+ $untracked = git ls-files --others --exclude-standard
+ if ($untracked) { $hasChanges = $true }
+}
+if ($hasChanges) {
+ Write-SafeHost "❌ Refusing update: checkout has uncommitted changes; commit or restore them first" -ForegroundColor Red
+ Step "git-pull" "failed" "Checkout is dirty; no stash was created"
+ Stop-UpdateScript 1
+}
+if ($currentBranch -ne "main") {
if (-not $currentBranch) {
$detachedCommit = git rev-parse --short HEAD
Write-SafeHost "⚠️ On detached HEAD (commit $detachedCommit) — switching to main for update" -ForegroundColor Yellow
@@ -311,7 +300,7 @@ $prePullSha = git rev-parse HEAD 2>$null
# of it. Never fatal: a failed sweep must not block the update.
node -e "import('./server/lib/gitStaleLock.js').then(m => m.clearStaleGitLocksIn('.git')).catch(() => {})" 2>$null
$global:LASTEXITCODE = 0
-Invoke-Logged git pull --rebase --autostash
+Invoke-Logged git pull --rebase
if ($LASTEXITCODE -ne 0) { Stop-UpdateScript $LASTEXITCODE }
Step "git-pull" "done" "Latest changes pulled"
@@ -571,15 +560,6 @@ if ($setupGuide) {
Write-SafeHost ""
}
-if ($stashedForBranch) {
- Write-SafeHost "ℹ️ Your local changes from '$stashedForBranch' were stashed for the update." -ForegroundColor Cyan
- if ($stashedForBranch -eq "detached HEAD") {
- Write-SafeHost " To restore them: git checkout $stashedForCommit; git stash pop" -ForegroundColor Cyan
- } else {
- Write-SafeHost " To restore them: git checkout '$stashedForBranch'; git stash pop" -ForegroundColor Cyan
- }
- Write-SafeHost " The stash entry is at the top of 'git stash list'." -ForegroundColor Cyan
-}
# Exit non-zero when the install did not come back. This script outlives the
# server it restarts, so its status is the only signal a caller still has.
diff --git a/update.sh b/update.sh
index d5f0ab20ca..5c9b68a655 100755
--- a/update.sh
+++ b/update.sh
@@ -110,11 +110,8 @@ safe_install() {
# Pull latest — always switch to main (detached HEAD or feature branch both
# need to land on main before pulling, or the version won't advance). The
# rest of the script (install, build, restart) runs on main so the app
-# starts on the freshly-pulled revision. Local edits on the original branch
-# are stashed first so checkout doesn't abort, and we leave them in the
-# stash list afterward — the user can restore with `git stash pop` after
-# the update completes (we don't auto-pop because the rest of the script
-# needs to keep running with main's contents).
+# starts on the freshly-pulled revision. A dirty checkout is refused rather
+# than stashed, so agent or user work cannot be duplicated by a later rebase.
step "git-pull" "running" "Pulling latest changes..."
origin_url=$(git remote get-url origin 2>/dev/null || echo "")
if [ -n "$origin_url" ]; then
@@ -127,18 +124,15 @@ if [ -n "$origin_url" ]; then
echo "🌐 Pulling from origin: $origin_url_safe" >> "$UPDATE_LOG"
fi
current_branch=$(git symbolic-ref -q --short HEAD 2>/dev/null || echo "")
-stashed_for_branch=""
-stashed_for_commit=""
+has_local_changes() {
+ ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]
+}
+if has_local_changes; then
+ log "❌ Refusing update: checkout has uncommitted changes; commit or restore them first"
+ step "git-pull" "failed" "Checkout is dirty; no stash was created"
+ exit 1
+fi
if [ "$current_branch" != "main" ]; then
- if ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
- log "⚠️ Stashing local changes from '${current_branch:-detached HEAD}' so checkout can proceed"
- if run git stash push -u -m "portos-update-$(date +%s)"; then
- stashed_for_branch="${current_branch:-detached HEAD}"
- # Capture the original commit SHA so detached-HEAD users can return
- # to the exact tree their stash was taken from.
- stashed_for_commit=$(git rev-parse HEAD)
- fi
- fi
log "⚠️ On branch '${current_branch:-detached HEAD}' — switching to main for update"
run git checkout main
fi
@@ -157,7 +151,7 @@ pre_pull_sha=$(git rev-parse HEAD 2>/dev/null || echo "")
# it; it refuses any lock young enough to still belong to a running command.
# Builtins-only, so it runs before `npm install` — and never fatal.
node -e "import('./server/lib/gitStaleLock.js').then(m => m.clearStaleGitLocksIn('.git')).catch(() => {})" 2>/dev/null || true
-run git pull --rebase --autostash
+run git pull --rebase
step "git-pull" "done" "Latest changes pulled"
# Determine which workspaces' package.json this update touched, so safe_install
@@ -513,15 +507,6 @@ if [ -n "$setup_guide" ]; then
log ""
fi
-if [ -n "$stashed_for_branch" ]; then
- log "ℹ️ Your local changes from '$stashed_for_branch' were stashed for the update."
- if [ "$stashed_for_branch" = "detached HEAD" ]; then
- log " To restore them: git checkout $stashed_for_commit && git stash pop"
- else
- log " To restore them: git checkout '$stashed_for_branch' && git stash pop"
- fi
- log " The stash entry is at the top of 'git stash list'."
-fi
# Exit non-zero when the install did not come back. This script outlives the
# server it restarts, so its status is the only signal a caller still has.