Agent Zero AI framework
Make self-update backups skip runtime sockets
Alessandro7ba1d61e3419
diff --git a/docker/run/fs/exe/self_update_manager.py b/docker/run/fs/exe/self_update_manager.pyindex 8701c8222..63f751b07 100644--- a/docker/run/fs/exe/self_update_manager.py+++ b/docker/run/fs/exe/self_update_manager.py@@ -8,6 +8,7 @@ import osimport reimport shutilimport signal+import statimport subprocessimport sysimport tempfile@@ -366,11 +367,15 @@ def create_usr_backup(root_path = Path(root)for filename in files:source_file = root_path / filename- if source_file.is_symlink() and not source_file.exists():- logger.log(f"Skipping broken symlink during usr backup: {source_file}")+ if not should_include_usr_backup_entry(source_file, logger):continuearchive_name = Path("usr") / source_file.relative_to(usr_dir)- archive.write(source_file, archive_name.as_posix())+ try:+ archive.write(source_file, archive_name.as_posix())+ except FileNotFoundError:+ logger.log(f"Skipping vanished usr backup entry: {source_file}")+ except OSError as exc:+ logger.log(f"Skipping usr backup entry after read error: {source_file}: {exc}")destination.parent.mkdir(parents=True, exist_ok=True)shutil.move(str(temporary_backup), str(destination))@@ -381,6 +386,41 @@ def create_usr_backup(temporary_backup.unlink(missing_ok=True)+def should_include_usr_backup_entry(source_file: Path, logger: AttemptLogger) -> bool:+ try:+ source_stat = source_file.lstat()+ except FileNotFoundError:+ logger.log(f"Skipping vanished usr backup entry: {source_file}")+ return False+ except OSError as exc:+ logger.log(f"Skipping unreadable usr backup entry: {source_file}: {exc}")+ return False++ if stat.S_ISLNK(source_stat.st_mode):+ try:+ target_stat = source_file.stat()+ except FileNotFoundError:+ logger.log(f"Skipping broken symlink during usr backup: {source_file}")+ return False+ except OSError as exc:+ logger.log(+ f"Skipping unreadable symlink target during usr backup: {source_file}: {exc}"+ )+ return False+ if not stat.S_ISREG(target_stat.st_mode):+ logger.log(+ f"Skipping non-regular symlink target during usr backup: {source_file}"+ )+ return False+ return True++ if not stat.S_ISREG(source_stat.st_mode):+ logger.log(f"Skipping non-regular usr backup entry: {source_file}")+ return False++ return True++def run_command(command: list[str],*,diff --git a/tests/test_self_update_tag_filter.py b/tests/test_self_update_tag_filter.pyindex 6a3bb8e6b..346217929 100644--- a/tests/test_self_update_tag_filter.py+++ b/tests/test_self_update_tag_filter.py@@ -1,5 +1,7 @@import importlib.util+import socketimport sys+import tempfileimport typesimport zipfilefrom pathlib import Path@@ -781,6 +783,52 @@ def test_self_update_manager_usr_backup_skips_broken_symlinks(tmp_path):assert "usr/workdir/reachy-mini-mcp/.venv/bin/python" not in names+def test_self_update_manager_usr_backup_skips_runtime_sockets():+ manager = load_self_update_manager()+ with tempfile.TemporaryDirectory(prefix="a0su-", dir="/tmp") as temp_root:+ repo_dir = Path(temp_root) / "repo"+ usr_dir = repo_dir / "usr"+ gnupg_dir = (+ usr_dir+ / "plugins"+ / "_desktop"+ / "profiles"+ / "agent-zero-desktop"+ / ".gnupg"+ )+ gnupg_dir.mkdir(parents=True)+ (usr_dir / "settings.json").write_text('{"ok": true}\n', encoding="utf-8")+ socket_path = gnupg_dir / "S.gpg-agent"+ messages = []++ class ListLogger:+ def log(self, message=""):+ messages.append(message)++ with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as runtime_socket:+ runtime_socket.bind(str(socket_path))+ backup_path = manager.create_usr_backup(+ repo_dir=repo_dir,+ backup_path=str(Path(temp_root) / "backups"),+ backup_name="usr-backup.zip",+ conflict_policy="rename",+ logger=ListLogger(),+ )++ with zipfile.ZipFile(backup_path) as archive:+ names = set(archive.namelist())++ assert "usr/settings.json" in names+ assert (+ "usr/plugins/_desktop/profiles/agent-zero-desktop/.gnupg/S.gpg-agent"+ not in names+ )+ assert any(+ "Skipping non-regular usr backup entry" in message+ for message in messages+ )++def test_self_update_manager_clean_uv_cache_uses_uv_when_available(monkeypatch):manager = load_self_update_manager()commands = []