Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(update): user state must survive every update path — salvage the wiki vault, never fail silently, snapshot before reset

Personal Jarvis Maintainerb67190fa09e6
diff --git a/install/install.ps1 b/install/install.ps1
index d5c990217a..c45f4c12ac 100644
--- a/install/install.ps1
+++ b/install/install.ps1
@@ -656,14 +656,20 @@ function Invoke-SalvageReclone {
}
Write-Note "moved the old directory to $StaleBackup (nothing was deleted)"
if (-not (Invoke-FetchPayload)) { exit 1 }
- foreach ($Item in @('data', $ConfigFileName, '.env')) {
+ # Everything a user can lose: config, credentials file-fallback + DBs
+ # (inside data/), the dotenv, AND the wiki vault (its absence from this
+ # list is what destroyed a user's wiki pages on 2026-07-20). A failed
+ # copy is a loud warning pointing at the backup dir - never silent.
+ foreach ($Item in @('data', $ConfigFileName, '.env', 'wiki')) {
$Old = Join-Path $StaleBackup $Item
$New = Join-Path $InstallDir $Item
if ((Test-Path $Old) -and -not (Test-Path $New)) {
try {
Copy-Item -LiteralPath $Old -Destination $New -Recurse -ErrorAction Stop
Write-Note "kept your $Item from the previous install"
- } catch {}
+ } catch {
+ Write-Err "could NOT carry over $Item - it is still safe in $Old; copy it back manually."
+ }
}
}
Write-Ok 'reinstalled fresh (previous state preserved in the backup dir)'
diff --git a/install/install.sh b/install/install.sh
index 4228b1f83f..45208eccf9 100755
--- a/install/install.sh
+++ b/install/install.sh
@@ -1042,11 +1042,17 @@ salvage_reclone() {
fi
note "moved the old directory to $stale_backup (nothing was deleted)"
fetch_payload || exit 1
+ # Everything a user can lose: config, credentials file-fallback + DBs
+ # (inside data/), the dotenv, AND the wiki vault (its absence from this
+ # list is what destroyed a user's wiki pages on 2026-07-20). A failed
+ # copy is a loud warning pointing at the backup dir — never silent.
local item
- for item in data "$CONFIG_FILE_NAME" .env; do
+ for item in data "$CONFIG_FILE_NAME" .env wiki; do
if [ -e "$stale_backup/$item" ] && [ ! -e "$INSTALL_DIR/$item" ]; then
- if cp -R "$stale_backup/$item" "$INSTALL_DIR/$item" 2>/dev/null; then
+ if cp -R "$stale_backup/$item" "$INSTALL_DIR/$item"; then
note "kept your $item from the previous install"
+ else
+ err "could NOT carry over $item - it is still safe in $stale_backup/$item; copy it back manually."
fi
fi
done
diff --git a/jarvis/ui/relauncher.py b/jarvis/ui/relauncher.py
index 4007b811d4..d74c71f9c5 100644
--- a/jarvis/ui/relauncher.py
+++ b/jarvis/ui/relauncher.py
@@ -410,6 +410,62 @@ def _write_update_result(
pass
+#: Precious, small user state that must survive ANY update outcome. Copied to
+#: a sibling directory OUTSIDE the checkout before the first ``git reset`` so
+#: even a catastrophic tree replacement (the 2026-07-20 wipe lost API keys,
+#: config, and wiki pages) can be recovered by hand. Large data/ databases are
+#: deliberately excluded: git never touches untracked files, and a full copy
+#: of a multi-hundred-MB data dir per update is not "best-effort" territory.
+_STATE_SNAPSHOT_ITEMS = (
+ "jarvis.toml",
+ ".env",
+ Path("data") / "credentials.json",
+ Path("wiki") / "obsidian-vault",
+)
+_STATE_SNAPSHOT_KEEP = 3
+
+
+def snapshot_user_state(root: Path) -> Path | None:
+ """Copy precious user state to ``<root>.pre-update-state/<timestamp>/``.
+
+ Best-effort belt-and-suspenders: an update must proceed even when the
+ snapshot fails, and a snapshot failure must never raise. Returns the
+ snapshot directory when at least one item was saved, else ``None``.
+ Old snapshots beyond the newest ``_STATE_SNAPSHOT_KEEP`` are pruned.
+ """
+ import shutil
+
+ base = root.parent / (root.name + ".pre-update-state")
+ stamp = time.strftime("%Y%m%d-%H%M%S")
+ target = base / stamp
+ saved = False
+ for item in _STATE_SNAPSHOT_ITEMS:
+ src = root / item
+ try:
+ if not src.exists():
+ continue
+ dst = target / item
+ dst.parent.mkdir(parents=True, exist_ok=True)
+ if src.is_dir():
+ shutil.copytree(src, dst, dirs_exist_ok=True)
+ else:
+ shutil.copy2(src, dst)
+ saved = True
+ except OSError:
+ logging.getLogger(__name__).warning(
+ "pre-update snapshot could not save %s", src, exc_info=True
+ )
+ if not saved:
+ return None
+ try:
+ stamps = sorted((p for p in base.iterdir() if p.is_dir()), reverse=True)
+ for old in stamps[_STATE_SNAPSHOT_KEEP:]:
+ shutil.rmtree(old, ignore_errors=True)
+ except OSError:
+ pass
+ return target
+
+
def finalize_pending_update(cwd: str | Path) -> bool:
"""Apply a fetched update while the old app is fully stopped.
@@ -428,6 +484,8 @@ def finalize_pending_update(cwd: str | Path) -> bool:
pending_path.unlink(missing_ok=True)
return False
+ snapshot_user_state(root)
+
previous = str(payload["previous_revision"])
target = str(payload["target_revision"])
profile = str(payload["profile"])
diff --git a/tests/unit/ui/test_relauncher_update_transaction.py b/tests/unit/ui/test_relauncher_update_transaction.py
index 189c710f22..3d02767dc7 100644
--- a/tests/unit/ui/test_relauncher_update_transaction.py
+++ b/tests/unit/ui/test_relauncher_update_transaction.py
@@ -175,3 +175,89 @@ def test_relauncher_finalizes_before_spawning_new_app(tmp_path: Path) -> None:
assert rc == 0
assert order == ["finalize", "spawn"]
+
+
+# ---------------------------------------------------------------------------
+# Pre-update user-state snapshot (belt-and-suspenders against tree wipes).
+# ---------------------------------------------------------------------------
+
+
+def _seed_user_state(root: Path) -> None:
+ (root / "jarvis.toml").write_text("[brain]\n", encoding="utf-8")
+ (root / ".env").write_text("GROQ_API_KEY=gsk-x\n", encoding="utf-8")
+ (root / "data").mkdir()
+ (root / "data" / "credentials.json").write_text("{}", encoding="utf-8")
+ vault = root / "wiki" / "obsidian-vault"
+ vault.mkdir(parents=True)
+ (vault / "Home.md").write_text("# Home\n", encoding="utf-8")
+
+
+def test_snapshot_user_state_saves_precious_items_outside_the_checkout(
+ tmp_path: Path,
+) -> None:
+ root = tmp_path / "install"
+ root.mkdir()
+ _seed_user_state(root)
+
+ target = relauncher.snapshot_user_state(root)
+
+ assert target is not None
+ assert not target.is_relative_to(root), (
+ "the snapshot must live OUTSIDE the checkout so a tree wipe cannot "
+ "take it down too"
+ )
+ assert (target / "jarvis.toml").is_file()
+ assert (target / ".env").is_file()
+ assert (target / "data" / "credentials.json").is_file()
+ assert (target / "wiki" / "obsidian-vault" / "Home.md").is_file()
+
+
+def test_snapshot_user_state_returns_none_when_nothing_to_save(
+ tmp_path: Path,
+) -> None:
+ root = tmp_path / "install"
+ root.mkdir()
+ assert relauncher.snapshot_user_state(root) is None
+
+
+def test_snapshot_user_state_prunes_to_the_newest_snapshots(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ root = tmp_path / "install"
+ root.mkdir()
+ _seed_user_state(root)
+
+ stamps = iter(["20260101-000001", "20260101-000002", "20260101-000003",
+ "20260101-000004", "20260101-000005"])
+ monkeypatch.setattr(relauncher.time, "strftime", lambda _fmt: next(stamps))
+ for _ in range(5):
+ assert relauncher.snapshot_user_state(root) is not None
+
+ base = root.parent / (root.name + ".pre-update-state")
+ kept = sorted(p.name for p in base.iterdir())
+ assert kept == ["20260101-000003", "20260101-000004", "20260101-000005"]
+
+
+def test_finalize_pending_update_snapshots_before_touching_git(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ _managed_root(tmp_path)
+ _seed_user_state(tmp_path)
+ order: list[str] = []
+
+ def _fake_snapshot(root: Path) -> None:
+ order.append("snapshot")
+
+ def _fake_run(cmd: list[str], **_kw: object) -> int:
+ order.append(" ".join(cmd[:3]))
+ return 1 # first git command fails -> update aborts after snapshot
+
+ monkeypatch.setattr(relauncher, "snapshot_user_state", _fake_snapshot)
+ monkeypatch.setattr(relauncher, "_run_update_command", _fake_run)
+
+ relauncher.finalize_pending_update(tmp_path)
+
+ assert order, "the update must have attempted at least one step"
+ assert order[0] == "snapshot", (
+ "the user-state snapshot must run before the first git command"
+ )