Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(regression): preserve metadata after failed deletion (#1883)
Atirnaed56cc4a580f
diff --git a/scripts/incus_regression.py b/scripts/incus_regression.pyindex 5b4ea00a7..cac5a0aac 100644--- a/scripts/incus_regression.py+++ b/scripts/incus_regression.py@@ -2770,19 +2770,35 @@ def cmd_delete(args: argparse.Namespace) -> int:with target_update_lock(repo_root, args.remote, lock_project, dry_run=args.dry_run, blocking=False):target = resolve_target(args, repo_root, dry_run=args.dry_run, allocate_port=False, slug=slug)runner = Runner(dry_run=args.dry_run)- runner.run(incus("delete", remote_ref(args.remote, target.instance), "--force", project=target.project), check=False)- runner.run(incus("project", "delete", remote_ref(args.remote, target.project)), check=False)+ results = (+ runner.run(incus("delete", remote_ref(args.remote, target.instance), "--force", project=target.project), check=False),+ runner.run(incus("project", "delete", remote_ref(args.remote, target.project)), check=False),+ )+ failed = [result for result in results if result.returncode != 0]+ if failed:+ statuses = ", ".join(str(result.returncode) for result in failed)+ commands = "; ".join(shlex.join(result.args) for result in failed)+ print(f"Delete commands failed for {target.slug} ({commands} exited {statuses}).", file=sys.stderr)+ # A command's exit status does not say whether its objects still exist.+ # Confirm the final inventory even after failure before deciding about the row.if target.target == WORKTREE_TARGET and not args.dry_run:metadata = WorktreeMetadata(repo_root, args.remote)- metadata.forget([target.slug])- if not metadata.owned:+ if metadata.owned:+ with metadata.locked(dry_run=False):+ if target.slug in metadata.rows():+ environment = next(env for env in worktree_environments(runner, metadata) if env.slug == target.slug)+ if environment.exists:+ print(f"Could not confirm deletion of {target.slug}; kept its metadata.", file=sys.stderr)+ return 1+ metadata.forget([target.slug])+ else:# The row describes a slug and host port on this machine, and this- # deletion happened somewhere else, so `forget` above did nothing.+ # deletion happened somewhere else, so this accessor cannot forget it.# Saying so is all that is left to the caller: a slug used on both# daemons would otherwise lose its local port reservation the moment# the remote copy was removed, and lose it silently.print(f"Kept the local metadata for {target.slug}: it describes the local Incus daemon, not remote {args.remote}.")- return 0+ return 1 if failed else 0def cmd_reconcile(args: argparse.Namespace) -> int:diff --git a/tests/test_incus_regression.py b/tests/test_incus_regression.pyindex 13c0237ec..82c80eda9 100644--- a/tests/test_incus_regression.py+++ b/tests/test_incus_regression.py@@ -2589,6 +2589,7 @@ def test_delete_round_trips_generated_worktree_slug(tmp_path: Path, monkeypatch:encoding="utf-8",)commands = []+ listings = []class RecordingRunner:def __init__(self, *, dry_run=False):@@ -2598,6 +2599,13 @@ def test_delete_round_trips_generated_worktree_slug(tmp_path: Path, monkeypatch:commands.append(command)return subprocess.CompletedProcess(command, 0)+ def records(self, command, *, what):+ listings.append((command, what))+ return []++ def names(self, command, *, what):+ return [item["name"] for item in self.records(command, what=what)]+monkeypatch.setattr(incus_regression, "current_repo_root", lambda: repo)monkeypatch.setattr(incus_regression, "git_common_root", lambda _repo_root: repo)monkeypatch.setattr(incus_regression, "load_env_file", lambda _repo_root, _env_file: None)@@ -2625,10 +2633,97 @@ def test_delete_round_trips_generated_worktree_slug(tmp_path: Path, monkeypatch:["incus", "--project", project, "delete", instance, "--force"],["incus", "project", "delete", project],]+ assert listings == [+ (["incus", "project", "list", "--format", "json"], "Incus projects"),+ (["incus", "list", "--all-projects", "--format", "json"], "Incus instances"),+ ]payload = json.loads(mapping_path.read_text(encoding="utf-8"))assert payload["worktrees"] == {}+ "delete_codes", [(0, 0), (1, 0), (0, 1), (1, 1)],+ ids=["deleted", "instance-delete-fails", "project-delete-fails", "both-deletes-fail"],+)+ "inventory",+ [+ "absent", "project", "instance", "project-and-instance",+ "project-list-fails", "instance-list-fails",+ "unreadable-project-list", "unreadable-instance-list",+ ],+)+def test_delete_keeps_worktree_metadata_until_absence_is_confirmed(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str],+ delete_codes: tuple[int, int], inventory: str,+) -> None:+ repo = tmp_path / "repo"+ runtime = repo / ".runtime" / "incus-regression"+ runtime.mkdir(parents=True)+ slug = "delete-failed"+ row = {"path": str(repo), "project": f"avr-wt-{slug}", "instance": f"avibe-wt-{slug}", "host_port": 15206}+ other_row = {"host_port": 15207, "claim": "unrelated-reservation"}+ rows = {slug: row, "another-worktree": other_row}+ mapping_path = runtime / "worktrees.json"+ mapping_path.write_text(json.dumps({"schema_version": 1, "worktrees": rows}), encoding="utf-8")+ delete_commands = [+ ["incus", "--project", row["project"], "delete", row["instance"], "--force"],+ ["incus", "project", "delete", row["project"]],+ ]+ listing_commands = [+ ["incus", "project", "list", "--format", "json"],+ ["incus", "list", "--all-projects", "--format", "json"],+ ]+ commands = []++ def run(command, **kwargs):+ assert incus_regression.target_run_in_flight(repo, None, row["project"])+ commands.append(command)+ if command in delete_commands:+ assert kwargs["check"] is False+ return subprocess.CompletedProcess(command, delete_codes[delete_commands.index(command)])+ assert command in listing_commands+ kind = "project" if command == listing_commands[0] else "instance"+ if inventory == f"{kind}-list-fails":+ return subprocess.CompletedProcess(command, 1, stderr="daemon unavailable")+ if inventory == f"unreadable-{kind}-list":+ return subprocess.CompletedProcess(command, 0, stdout=json.dumps([{"unexpected": "schema"}]))+ objects = []+ if inventory in {kind, "project-and-instance"}:+ objects.append(+ {"name": row["project"]} if kind == "project"+ else {"name": row["instance"], "project": row["project"], "status": "Running"}+ )+ return subprocess.CompletedProcess(command, 0, stdout=json.dumps(objects))++ monkeypatch.setattr(incus_regression, "current_repo_root", lambda: repo)+ monkeypatch.setattr(incus_regression, "git_common_root", lambda _repo_root: repo)+ monkeypatch.setattr(incus_regression, "load_env_file", lambda _repo_root, _env_file: None)+ monkeypatch.setattr(incus_regression, "require_incus", lambda: None)+ monkeypatch.setenv("INCUS_CMD", "incus")+ monkeypatch.setattr(incus_regression.subprocess, "run", run)++ if "list" in inventory:+ with pytest.raises(incus_regression.RegressionError):+ incus_regression.cmd_delete(_delete_args(slug))+ else:+ assert incus_regression.cmd_delete(_delete_args(slug)) == int(any(delete_codes) or inventory != "absent")++ expected_listings = (+ listing_commands[:1] if inventory in {"project-list-fails", "unreadable-project-list"}+ else listing_commands+ )+ assert commands == delete_commands + expected_listings+ assert not incus_regression.target_run_in_flight(repo, None, row["project"])+ payload = json.loads(mapping_path.read_text(encoding="utf-8"))+ assert payload["worktrees"] == ({"another-worktree": other_row} if inventory == "absent" else rows)+ err = capsys.readouterr().err+ if any(delete_codes):+ assert "exited" in err+ if inventory == "absent":+ assert "kept its metadata" not in err++def test_delete_against_a_remote_keeps_the_local_metadata(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:@@ -2777,6 +2872,12 @@ def test_delete_holds_the_slug_lock_across_the_objects_and_the_row(observed.append(("objects", held()))return subprocess.CompletedProcess(command, 0)+ def records(self, command, *, what):+ return []++ def names(self, command, *, what):+ return []+forget = incus_regression.WorktreeMetadata.forgetdef probing_forget(self, slugs):