Agent Zero AI framework
Clean uv cache during self-update
Alessandro1af5344f3c6f
diff --git a/docker/run/fs/exe/self_update_manager.py b/docker/run/fs/exe/self_update_manager.pyindex f02558885..8701c8222 100644--- a/docker/run/fs/exe/self_update_manager.py+++ b/docker/run/fs/exe/self_update_manager.py@@ -408,6 +408,24 @@ def run_command(return completed+def clean_uv_cache(logger: AttemptLogger) -> None:+ uv_path = shutil.which("uv")+ if not uv_path:+ logger.log("uv executable not found, skipping uv cache clean.")+ return++ logger.log("Cleaning uv cache before continuing self-update startup.")+ try:+ run_command(+ [uv_path, "cache", "clean"],+ cwd=None,+ logger=logger,+ error_message="Failed to clean uv cache during self-update.",+ )+ except Exception as exc:+ logger.log(f"uv cache clean skipped after error: {exc}")++def has_local_rollback_changes(repo_dir: Path) -> bool:status = git_output(repo_dir, "status", "--porcelain=v1", "--untracked-files=all")return bool(status.strip())@@ -1180,6 +1198,7 @@ def docker_run_ui() -> int:logger.reset()logger.log(f"Consumed update file at {TRIGGER_FILE}")logger.log_block("Trigger file content", raw_text)+ clean_uv_cache(logger)try:current = get_repo_version_info(REPO_DIR)diff --git a/docs/guides/self-update.md b/docs/guides/self-update.mdindex 639b54f00..d15b571b2 100644--- a/docs/guides/self-update.md+++ b/docs/guides/self-update.md@@ -21,11 +21,12 @@ Agent Zero includes a Docker-oriented self-update flow for switching to a specif1. The WebUI writes a YAML request file outside `/a0` so the request survives upgrades and downgrades.2. Agent Zero restarts.3. The durable updater in `/exe` reads the YAML request before starting the UI.-4. If requested, it creates a zip backup of `/a0/usr`.-5. It fetches the requested branch and update target from the official Agent Zero repository.-6. It updates `/a0` while preserving gitignored paths such as `/a0/usr`.-7. It starts Agent Zero again and waits for `/api/health` to become healthy.-8. If the UI does not become healthy within the allowed time, it restores the previous checkout and starts that version again.+4. It cleans the root `uv` cache when `uv` is available.+5. If requested, it creates a zip backup of `/a0/usr`.+6. It fetches the requested branch and update target from the official Agent Zero repository.+7. It updates `/a0` while preserving gitignored paths such as `/a0/usr`.+8. It starts Agent Zero again and waits for `/api/health` to become healthy.+9. If the UI does not become healthy within the allowed time, it restores the previous checkout and starts that version again.## Durable filesdiff --git a/tests/test_self_update_tag_filter.py b/tests/test_self_update_tag_filter.pyindex a0e8ef701..6a3bb8e6b 100644--- a/tests/test_self_update_tag_filter.py+++ b/tests/test_self_update_tag_filter.py@@ -781,6 +781,72 @@ 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_clean_uv_cache_uses_uv_when_available(monkeypatch):+ manager = load_self_update_manager()+ commands = []+ monkeypatch.setattr(+ manager.shutil,+ "which",+ lambda executable: "/usr/local/bin/uv" if executable == "uv" else None,+ )++ def fake_run_command(command, *, cwd, logger, error_message=None):+ commands.append((command, cwd, error_message))++ monkeypatch.setattr(manager, "run_command", fake_run_command)++ manager.clean_uv_cache(manager.NullLogger())++ assert commands == [+ (+ ["/usr/local/bin/uv", "cache", "clean"],+ None,+ "Failed to clean uv cache during self-update.",+ )+ ]+++def test_self_update_manager_clean_uv_cache_skips_when_uv_missing(monkeypatch):+ manager = load_self_update_manager()+ commands = []+ monkeypatch.setattr(manager.shutil, "which", lambda executable: None)+ monkeypatch.setattr(+ manager,+ "run_command",+ lambda command, **kwargs: commands.append(command),+ )++ manager.clean_uv_cache(manager.NullLogger())++ assert commands == []+++def test_self_update_manager_clean_uv_cache_is_best_effort(monkeypatch):+ manager = load_self_update_manager()+ messages = []+ monkeypatch.setattr(+ manager.shutil,+ "which",+ lambda executable: "/usr/local/bin/uv" if executable == "uv" else None,+ )++ class Logger:+ def log(self, message=""):+ messages.append(message)++ def log_block(self, title, content):+ return None++ def fail_run_command(command, **kwargs):+ raise RuntimeError("cache cleanup failed")++ monkeypatch.setattr(manager, "run_command", fail_run_command)++ manager.clean_uv_cache(Logger())++ assert any("uv cache clean skipped after error" in message for message in messages)++def test_self_update_manager_latest_on_main_uses_current_major_release(monkeypatch):manager = load_self_update_manager()monkeypatch.setattr(