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): record the source identity the sync copied (#2296)
Call Whiteb0d37274b4ee
diff --git a/docs/regression/README.md b/docs/regression/README.mdindex 1d3f3a9bf..fa16d97fa 100644--- a/docs/regression/README.md+++ b/docs/regression/README.md@@ -367,6 +367,9 @@ The Incus runner separates slow-changing dependencies from fast-changing source:- **Build identity**: the version badge and `/api/version` report the commitrecorded by the latest source sync separately from install-time packagemetadata. Source targets do not use that package metadata for update prompts.+ The recorded branch, commit, and dirty flag are read before the sync and+ checked again after it; a checkout that moves in between fails the update+ rather than attributing the synced tree to either revision.- **Show Runtime**: every successful update runs `vibe runtime prepare --strict`and then verifies `vibe runtime status --json`.diff --git a/scripts/incus_regression.py b/scripts/incus_regression.pyindex 4c9ba5bdb..a3b6c3921 100644--- a/scripts/incus_regression.py+++ b/scripts/incus_regression.py@@ -569,6 +569,39 @@ def is_dirty(repo_root: Path) -> bool:return bool(result.stdout.strip())+@dataclass(frozen=True)+class SourceIdentity:+ """The checkout revision a source sync copied.++ The checkout is a live tree that other sessions may move while an update is+ building, so the identity recorded for an environment is read around its sync+ rather than whenever a record is written: a record written from a later read+ names a revision whose code was never deployed.+ """++ branch: str+ commit: str+ dirty: bool++ @classmethod+ def read(cls, repo_root: Path) -> SourceIdentity:+ return cls(branch=branch_name(repo_root), commit=commit_sha(repo_root), dirty=is_dirty(repo_root))++ def describe(self) -> str:+ return f"{self.branch or 'detached'}@{self.commit[:12] or 'unknown'}{' (dirty)' if self.dirty else ''}"+++def require_unchanged_source(repo_root: Path, synced: SourceIdentity) -> None:+ """Fail when the checkout moved while its source was being synced."""+ current = SourceIdentity.read(repo_root)+ if current != synced:+ raise RegressionError(+ f"The checkout changed from {synced.describe()} to {current.describe()} while its source was being "+ "synced, so the synced source cannot be attributed to either revision. Rerun the update once the "+ "checkout is stable."+ )++def slugify(value: str) -> str:slug = re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-")slug = re.sub(r"-+", "-", slug)@@ -817,7 +850,7 @@ class WorktreeMetadata:self.mutate(guarded)- def complete(self, target: RegressionTarget, claim: str) -> None:+ def complete(self, target: RegressionTarget, claim: str, identity: SourceIdentity) -> None:"""Stamp the environment as built, replacing the row, its claim and its `reserved_at`."""self.apply_claimed(target,@@ -828,8 +861,8 @@ class WorktreeMetadata:"instance": target.instance,"host_port": target.host_port,"updated_at": datetime.now(timezone.utc).isoformat(),- "branch": branch_name(self.repo_root),- "commit": commit_sha(self.repo_root),+ "branch": identity.branch,+ "commit": identity.commit,},)@@ -892,11 +925,11 @@ class WorktreeReservation:dry_run: bool = Falseclaim: str | None = None- def complete(self) -> None:- """Stamp the environment as built, ending the reservation."""+ def complete(self, identity: SourceIdentity) -> None:+ """Stamp the environment as built from `identity`, ending the reservation."""if self.claim is None:return- self.metadata.complete(self.target, self.claim)+ self.metadata.complete(self.target, self.claim, identity)def release(self, runner: Runner) -> None:"""Give the row back if nothing came of it and nobody else has taken it."""@@ -1968,7 +2001,15 @@ def invalidate_fingerprints(runner: Runner, target: RegressionTarget, *, remote:)-def write_metadata(runner: Runner, target: RegressionTarget, repo_root: Path, fingerprints: dict, *, remote: str | None) -> None:+def write_metadata(+ runner: Runner,+ target: RegressionTarget,+ repo_root: Path,+ identity: SourceIdentity,+ fingerprints: dict,+ *,+ remote: str | None,+) -> None:payload = {"schema_version": 1,"updated_at": datetime.now(timezone.utc).isoformat(),@@ -1977,9 +2018,9 @@ def write_metadata(runner: Runner, target: RegressionTarget, repo_root: Path, fi"project": target.project,"instance": target.instance,"repo_root": str(repo_root),- "branch": branch_name(repo_root),- "commit": commit_sha(repo_root),- "dirty": is_dirty(repo_root),+ "branch": identity.branch,+ "commit": identity.commit,+ "dirty": identity.dirty,"fingerprints": fingerprints,}encoded = json.dumps(payload, indent=2)@@ -2650,6 +2691,9 @@ def cmd_up(args: argparse.Namespace) -> int:# The stop may take effect before an interrupted client returns.stopped_service_target = targetstop_service_for_update(runner, target, remote=args.remote)+ # Everything from here to the fingerprints reads the checkout, and the+ # records written at the end name the revision read here.+ identity = SourceIdentity.read(repo_root)if seed_requires_env or loaded_env_file is not None or args.dry_run:write_runtime_env(runner, target, repo_root=repo_root, remote=args.remote)else:@@ -2657,6 +2701,9 @@ def cmd_up(args: argparse.Namespace) -> int:migrate_legacy_backend_runtimes(runner, target, remote=args.remote)sync_source(runner, target, repo_root, remote=args.remote, clean=args.clean, include_ui_dist=args.no_build_ui)fingerprints = compute_fingerprints(repo_root)+ # Before the previous fingerprints are invalidated, so a moved checkout+ # leaves the next run's dependency decisions as they were.+ require_unchanged_source(repo_root, identity)previous_fingerprints = read_existing_fingerprints(runner, target, remote=args.remote)invalidate_fingerprints(runner, target, remote=args.remote)reconciled = update_dependencies_and_build(@@ -2678,6 +2725,7 @@ def cmd_up(args: argparse.Namespace) -> int:runner,target,repo_root,+ identity,reconciled_fingerprints(previous_fingerprints, fingerprints, reconciled),remote=args.remote,)@@ -2686,7 +2734,7 @@ def cmd_up(args: argparse.Namespace) -> int:prepare_show_runtime(runner, target, remote=args.remote)restart_and_verify(runner, target, remote=args.remote)stopped_service_target = None- reservation.complete()+ reservation.complete(identity)except BaseException:# Recovery still owns the update lock: another up must not stop and# sync this environment while this failed run is starting it again.diff --git a/tests/test_incus_regression.py b/tests/test_incus_regression.pyindex 287be7ec5..166f02cd8 100644--- a/tests/test_incus_regression.py+++ b/tests/test_incus_regression.py@@ -3221,7 +3221,7 @@ def test_metadata_about_another_daemon_neither_reads_nor_writes_the_local_file(# land if authority were ignored -- the file is unchanged because of who the# accessor is bound to, not because the writes had nothing to match.metadata.reserve(target)- metadata.complete(target, "seeded")+ metadata.complete(target, "seeded", incus_regression.SourceIdentity(branch="demo", commit="a" * 40, dirty=False))metadata.release(target, "seeded")metadata.forget(["demo"])metadata.mutate(lambda worktrees: worktrees.clear())@@ -4241,7 +4241,12 @@ def test_up_gives_its_row_back_only_when_the_daemon_says_nothing_came_of_it(class NewRunner(incus_regression.Runner):names = daemon_listing(*inventory)+ host_run = subprocess.run+def run_command(command, **kwargs):+ if command[0] == "git":+ # The checkout's revision is read on the host, not through the daemon.+ return host_run(command, **kwargs)script = command[-1]service_commands.append(script)if "/health" in script:@@ -4498,9 +4503,13 @@ def test_no_end_of_a_reservation_writes_over_a_row_another_run_took(for name in writes:method = getattr(mine, name)parameters = set(inspect.signature(method).parameters)- unknown = parameters - {"runner"}+ supplied = {+ "runner": NewRunner(),+ "identity": incus_regression.SourceIdentity(branch="demo", commit="a" * 40, dirty=False),+ }+ unknown = parameters - set(supplied)assert not unknown, f"{name} takes {sorted(unknown)}: teach this test how to call it"- method(**({"runner": NewRunner()} if "runner" in parameters else {}))+ method(**{parameter: supplied[parameter] for parameter in parameters})rows = json.loads(mapping_path.read_text(encoding="utf-8"))["worktrees"]assert rows["demo"]["claim"] == theirs.claim@@ -4520,8 +4529,6 @@ def test_a_reserved_row_still_reports_the_environment_that_is_installed(operator reads before deciding whether the environment is still wanted."""monkeypatch.setattr(incus_regression, "git_common_root", lambda repo_root: repo_root)- monkeypatch.setattr(incus_regression, "branch_name", lambda repo_root: "fix/installed")- monkeypatch.setattr(incus_regression, "commit_sha", lambda repo_root: "aaaaaaaaaaaa")(tmp_path / ".runtime" / "incus-regression").mkdir(parents=True)target = incus_regression.RegressionTarget(target="worktree",@@ -4535,9 +4542,12 @@ def test_a_reserved_row_still_reports_the_environment_that_is_installed(metadata = incus_regression.WorktreeMetadata(tmp_path, None)built = metadata.reserve(target)- metadata.complete(target, built.claim)+ metadata.complete(+ target, built.claim, incus_regression.SourceIdentity(branch="fix/installed", commit="aaaaaaaaaaaa", dirty=False)+ )monkeypatch.setattr(incus_regression, "branch_name", lambda repo_root: "fix/arriving")+ monkeypatch.setattr(incus_regression, "commit_sha", lambda repo_root: "bbbbbbbbbbbb")taking_over = metadata.reserve(target)row = metadata.rows()["demo"]@@ -4548,6 +4558,148 @@ def test_a_reserved_row_still_reports_the_environment_that_is_installed(assert "fix/arriving" not in described[email protected]("moved_during", ["build", "sync"])+def test_an_update_records_the_revision_its_sync_copied(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, moved_during: str+) -> None:+ """The revision an environment is recorded as is the one its sync copied.++ The checkout is shared with other sessions, which move it while an update is+ building. Both records -- the build identity the environment serves and the+ row the report reads -- were read from the checkout when they were written, so+ a fast-forward during the build stamped the environment with a revision whose+ code was never synced. A move after the sync still leaves the synced revision+ to record; a move during it leaves the synced tree attributable to neither+ revision, so the update stops before recording anything.+ """+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", os.devnull)+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")++ def git(*command: str) -> str:+ return subprocess.run(+ ["git", "-C", str(tmp_path), "-c", "user.name=t", "-c", "[email protected]", *command],+ capture_output=True,+ text=True,+ check=True,+ ).stdout.strip()++ git("init", "--initial-branch=fix/synced")+ (tmp_path / ".gitignore").write_text(".runtime/\n", encoding="utf-8")+ git("add", ".gitignore")+ git("commit", "-m", "synced")+ synced = git("rev-parse", "HEAD")++ def move_checkout(*args, **kwargs):+ (tmp_path / "moved.txt").write_text("moved\n", encoding="utf-8")+ git("add", "moved.txt")+ git("commit", "-m", "moved")+ return set()++ commands: list[list[str]] = []++ class NewRunner:+ def __init__(self, *, dry_run=False):+ self.dry_run = dry_run++ names = daemon_listing()++ def run(self, command, **kwargs):+ commands.append(command)+ return subprocess.CompletedProcess(command, 0, stdout="{}")++ calls: list[str] = []++ def record(name):+ def wrapper(*args, **kwargs):+ calls.append(name)+ if name == moved_during:+ return move_checkout()+ return set()++ return wrapper++ monkeypatch.setattr(incus_regression, "current_repo_root", lambda: tmp_path)+ monkeypatch.setattr(incus_regression, "git_common_root", lambda repo_root: repo_root)+ monkeypatch.setattr(incus_regression, "load_env_file", lambda repo_root, env_file: None)+ monkeypatch.setattr(incus_regression, "require_incus", lambda: None)+ monkeypatch.setattr(incus_regression, "require_source_sync", lambda: None)+ monkeypatch.setattr(incus_regression, "ensure_host_port_available", lambda host, port: None)+ monkeypatch.setattr(incus_regression, "Runner", NewRunner)+ monkeypatch.setattr(incus_regression, "should_seed_state", lambda *args, **kwargs: False)+ monkeypatch.setattr(incus_regression, "compute_fingerprints", lambda repo_root: {})+ monkeypatch.setattr(incus_regression, "read_existing_fingerprints", lambda *args, **kwargs: {})+ monkeypatch.setattr(incus_regression, "sync_source", record("sync"))+ monkeypatch.setattr(incus_regression, "update_dependencies_and_build", record("build"))+ for name in (+ "require_runtime_seed_env",+ "ensure_project_and_instance",+ "stop_service_for_update",+ "write_runtime_env",+ "migrate_legacy_backend_runtimes",+ "invalidate_fingerprints",+ "run_prepare_state",+ "normalize_runtime_config",+ "prepare_show_runtime",+ "restart_and_verify",+ "restart_service_after_failed_update",+ ):+ monkeypatch.setattr(incus_regression, name, record(name))++ args = argparse.Namespace(+ target="worktree",+ slug="demo",+ host_port=None,+ ui_host="127.0.0.1",+ ui_port=5123,+ worktree_port_start=15200,+ worktree_port_end=15399,+ env_file=None,+ dry_run=False,+ image="avibe-regression-base-current",+ storage_pool="default",+ network="incusbr0",+ cpus="2",+ memory="4GiB",+ disk="20GiB",+ processes="4096",+ remote=None,+ clean=False,+ force_deps=False,+ no_build_ui=True,+ force_ui=False,+ reset_mode="none",+ )++ def served_builds() -> list[dict]:+ marker = f"cat > {incus_regression.METADATA_PATH} <<'EOF'\n"+ return [+ json.loads(part.split(marker, 1)[1].split("\nEOF", 1)[0])+ for command in commands+ for part in command+ if marker in part+ ]++ mapping_path = tmp_path / ".runtime" / "incus-regression" / "worktrees.json"++ if moved_during == "sync":+ with pytest.raises(incus_regression.RegressionError, match="while its source was being synced"):+ incus_regression.cmd_up(args)+ assert served_builds() == []+ # The previous fingerprints still describe what the instance holds.+ assert "invalidate_fingerprints" not in calls+ assert "restart_service_after_failed_update" in calls+ assert "commit" not in json.loads(mapping_path.read_text(encoding="utf-8"))["worktrees"].get("demo", {})+ return++ assert incus_regression.cmd_up(args) == 0+ assert git("rev-parse", "HEAD") != synced+ assert [(build["branch"], build["commit"], build["dirty"]) for build in served_builds()] == [+ ("fix/synced", synced, False)+ ]+ row = json.loads(mapping_path.read_text(encoding="utf-8"))["worktrees"]["demo"]+ assert (row["branch"], row["commit"]) == ("fix/synced", synced)++def test_an_empty_remote_names_the_local_daemon_for_every_command() -> None:"""`--remote ""` is this machine's daemon everywhere, not two authorities at once.