Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(temporal): start from new when the pinned server did not create the database
trohitg7caa49e4d5e7
diff --git a/server/config/temporal_cli.json b/server/config/temporal_cli.jsonindex a6bde978..70815b53 100644--- a/server/config/temporal_cli.json+++ b/server/config/temporal_cli.json@@ -1,5 +1,5 @@{- "_comment": "The release pin for new Temporal installations (services/temporal/_install.py). Asset keys are <os>_<arch> in the CLI release's spellings. Bump the version, server_version and all checksums together from the official checksums.txt. Existing installations retain their installed server/database pair until an explicit migration; older binaries and database files are never automatically deleted.",+ "_comment": "The Temporal CLI pin (services/temporal/_install.py). Asset keys are <os>_<arch> in the CLI release's spellings. Bump the version, server_version and all checksums together from the official checksums.txt. A new server minor starts every install from an empty Temporal database: at the next start, a database the pinned server minor did not create is deleted with every older CLI file (RFC-0005 E16). A patch bump of the same minor keeps the database.","version": "1.9.1","server_version": "1.32.0","base": "https://github.com/temporalio/cli/releases/download/v{version}/",diff --git a/server/services/temporal/_install.py b/server/services/temporal/_install.pyindex 32dd15c2..f49e7a16 100644--- a/server/services/temporal/_install.py+++ b/server/services/temporal/_install.py@@ -7,13 +7,16 @@ same root that holds the Stripe and agent-browser binaries (see:func:`core.paths.package_dir`). pooch verifies the archive against thepinned hash before extracting it (zip on Windows, tar.gz elsewhere), soa re-run is a cache hit and a tampered or truncated download fails.-Older binaries remain available beside the pin so existing databases keep-using the server that created them. Upgrading the application never migrates-or deletes Temporal state; a server minor change requires an explicit move.-A marker beside each database records the selected CLI/server and binary.-Unmarked pre-pin databases are adopted only with the existing legacy binary;-missing/ambiguous provenance refuses startup instead of guessing.+A new Temporal server minor starts from an empty database (RFC-0005 E16).+``temporal.db.server.json`` beside the database names the server that+created it, and :func:`prepare_database` runs before every spawn. A+database with no marker, or with one naming another server minor than the+pin, is deleted together with its ``-wal`` and ``-shm`` files, and every+CLI file that is not the pin's goes with it. Nothing is migrated:+generations whose controller lived in the old database fail with+``controller_execution_missing``, and owners Reset and Start them. A patch+release of the same minor keeps the database.The downloaded ``temporal`` CLI powers ``temporal server start-dev``(the SQLite dev server) and ad-hoc workflow / operator commands.@@ -25,15 +28,14 @@ import asyncioimport jsonimport platformimport re-import subprocess-from datetime import datetime, timezone+import shutilimport stat+from datetime import datetime, timezonefrom pathlib import Pathfrom typing import Anyimport pooch-from core.config import Settingsfrom core.logging import get_loggerlogger = get_logger(__name__)@@ -86,26 +88,15 @@ _cached: dict[str, Path] | None = None_lock = asyncio.Lock()-async def ensure_temporal_binaries(- settings: Settings | None = None,-) -> dict[str, Path]:+async def ensure_temporal_binaries() -> dict[str, Path]:"""Return ``{"temporal": Path}`` — the pinned ``temporal`` CLI binary.Idempotent — first call downloads, subsequent calls hit the poochcache under ``<DATA_DIR>/packages/temporal/<version>/``.Async-locked so concurrent callers don't double-download.-- Runtime callers pass settings so an existing database selects its own- installed server. Build callers omit it and materialize the release pin- alongside older versions, without touching their databases."""global _cachedasync with _lock:- if settings is not None:- db = Path(settings._resolve_under_data(settings.temporal_sqlite_path))- selected = await asyncio.to_thread(_existing_database_cli, db)- if selected is not None:- return {"temporal": selected}if _cached is not None and _cached["temporal"].is_file() and _cached["temporal"].resolve().is_relative_to(_cache_dir().resolve()):return _cachedcli_path = await asyncio.to_thread(_fetch_cli_sync)@@ -159,101 +150,56 @@ def _fetch_cli_sync() -> Path:def marker_path(db_path: Path) -> Path:- """The file beside the database that names its server and CLI."""+ """The file beside the database that names the server that created it."""return db_path.with_name(db_path.name + ".server.json")-def _read_marker(db_path: Path) -> dict | None:- marker = marker_path(db_path)- if not marker.exists():- return None- try:- value = json.loads(marker.read_text(encoding="utf-8"))- if not isinstance(value, dict) or _server_minor(value.get("server_version")) is None:- raise ValueError("server version is missing")- return value- except (OSError, ValueError, TypeError) as exc:- raise RuntimeError(f"Cannot verify Temporal server marker {marker}; existing database was preserved") from exc---def _binary_versions(binary: Path) -> dict[str, str]:- result = subprocess.run([str(binary), "--version"], capture_output=True, text=True, check=True, timeout=15)- match = re.search(r"(?:temporal CLI|temporal version)\s+(\d+\.\d+\.\d+)\s+\(Server\s+(\d+\.\d+\.\d+)", result.stdout, re.I)- if match is None:- raise RuntimeError(f"Cannot verify Temporal CLI/server version: {binary}")- return {"cli_version": match[1], "server_version": match[2]}+def prepare_database(db_path: Path) -> None:+ """Start from an empty database unless the pin's server minor created it.+ Runs before every spawn. A database whose marker names the pin's server+ minor is kept. Otherwise the database, its ``-wal`` and ``-shm`` files and+ every CLI file that is not the pin's are deleted, and the pin's marker is+ written, so ``start-dev`` creates an empty database for the pinned server.+ A database that cannot be deleted stops the start: the pinned server must+ never open another minor's schema.+ """+ pin = cli_pin()+ marker = marker_path(db_path)+ if _server_minor(_recorded_server(marker)) == _server_minor(pin["server_version"]):+ return+ stale = [path for path in (db_path, Path(f"{db_path}-wal"), Path(f"{db_path}-shm")) if path.exists()]+ for path in stale:+ path.unlink()+ if stale:+ logger.warning(+ "[Temporal install] Deleted a Temporal database the pinned server %s did not create (RFC-0005 E16); "+ "employees whose controller lived in it need Reset and Start: %s",+ pin["server_version"],+ db_path,+ )+ _remove_unpinned_clis(pin["version"])+ db_path.parent.mkdir(parents=True, exist_ok=True)+ record = {"cli_version": pin["version"], "server_version": pin["server_version"], "created_at": datetime.now(timezone.utc).isoformat()}+ marker.write_text(json.dumps(record), encoding="utf-8")-def _find_binary(directory: Path) -> Path | None:- candidates = sorted(directory.rglob(_binary_name())) if directory.is_dir() else []- candidates = [path for path in candidates if path.is_file()]- if len(candidates) > 1:- raise RuntimeError(f"Ambiguous Temporal binaries in {directory}; database was preserved")- return candidates[0] if candidates else None+def _remove_unpinned_clis(version: str) -> None:+ """Delete every CLI file in the package root except the pinned version's folder.-def _existing_database_cli(db_path: Path) -> Path | None:- """Keep the installed server/database pair; never download a replacement."""- if not db_path.exists():- return None- marker = _read_marker(db_path)- root = _cache_dir()- if marker is None:- os_, arch = _CLI_PLATFORM_MAP[(platform.system(), platform.machine())]- archive = f"temporal_cli_latest_{os_}_{arch}." + ("zip.unzip" if os_ == "windows" else "tar.gz.untar")- binary = _find_binary(root / archive)- if binary is None:- raise RuntimeError(f"No original Temporal binary is available for unmarked database {db_path}; "- "restore its binary or explicitly migrate the installation. Database was preserved")- _binary_versions(binary) # Prove it can identify the server before adoption.- return binary- version = marker.get("cli_version")- if not isinstance(version, str) or re.fullmatch(r"\d+\.\d+\.\d+", version) is None:- raise RuntimeError(f"Cannot identify the original Temporal CLI for {db_path}; database was preserved")- if version == cli_pin()["version"] and _server_minor(marker["server_version"]) == _server_minor(cli_pin()["server_version"]):- return None # Safe to install/reuse the same server minor's pinned binary.- relative = marker.get("binary")- binary = (root / relative).resolve() if isinstance(relative, str) else None- if binary is not None and not binary.is_relative_to(root.resolve()):- raise RuntimeError("Temporal binary marker escapes package directory; database was preserved")- if binary is None or not binary.is_file():- binary = _find_binary(root / str(version)) if version else None- if binary is None:- raise RuntimeError(f"The original Temporal {version} binary for {db_path} is missing; database was preserved")- actual = _binary_versions(binary)- if _server_minor(actual["server_version"]) != _server_minor(marker["server_version"]):- raise RuntimeError("Temporal binary/server marker mismatch; database was preserved")- return binary---def prepare_database(db_path: Path, binary: Path | None = None) -> None:- """Validate before spawn; no database or WAL file is ever removed here."""- pin = cli_pin()- actual = _binary_versions(binary) if binary is not None else {- "cli_version": pin["version"], "server_version": pin["server_version"],- }- marker = _read_marker(db_path) if db_path.exists() else None- if db_path.exists() and marker is None and binary is None:- raise RuntimeError(f"Unmarked Temporal database {db_path} requires its original binary; database was preserved")- if marker is not None:- if _server_minor(marker["server_version"]) != _server_minor(actual["server_version"]):- raise RuntimeError(f"Temporal server minor mismatch for {db_path}; explicit migration required. Database was preserved")- return- record = {**actual, "created_at": datetime.now(timezone.utc).isoformat()}- if binary is not None:+ These are unused once the database is reset, so a file that cannot be+ deleted is logged and left for the next reset rather than stopping the start.+ """+ for entry in _cache_dir().iterdir():+ if entry.name == version:+ continuetry:- record["binary"] = str(binary.resolve().relative_to(_cache_dir().resolve()))- except ValueError:- raise RuntimeError("Temporal binary must be inside its package directory; database was preserved") from None- db_path.parent.mkdir(parents=True, exist_ok=True)- # Exclusive creation avoids two startup attempts overwriting provenance.- try:- with marker_path(db_path).open("x", encoding="utf-8") as stream:- json.dump(record, stream)- except FileExistsError:- existing = _read_marker(db_path)- if existing is None or _server_minor(existing["server_version"]) != _server_minor(actual["server_version"]):- raise RuntimeError("Concurrent Temporal database marker mismatch; database was preserved") from None+ if entry.is_dir():+ shutil.rmtree(entry)+ else:+ entry.unlink()+ except OSError as exc:+ logger.warning("[Temporal install] Could not delete an old Temporal CLI file %s: %s", entry, exc)def _recorded_server(marker: Path) -> object:diff --git a/server/services/temporal/_runtime.py b/server/services/temporal/_runtime.pyindex 006e84a3..ee0832d2 100644--- a/server/services/temporal/_runtime.py+++ b/server/services/temporal/_runtime.py@@ -93,12 +93,13 @@ class TemporalServerRuntime(BaseProcessSupervisor):async def _pre_spawn(self) -> None:from services.temporal._install import ensure_temporal_binaries, prepare_database- self._binaries = await ensure_temporal_binaries(self.settings)+ self._binaries = await ensure_temporal_binaries()# Ensure the parent dir for the SQLite file exists before# ``temporal server start-dev`` opens it.self._sqlite_path.parent.mkdir(parents=True, exist_ok=True)- # Validate the selected existing pair before opening any SQLite file.- await asyncio.to_thread(prepare_database, self._sqlite_path, self._binaries["temporal"])+ # A database the pinned server minor did not create is deleted+ # before the server opens it (RFC-0005 E16).+ await asyncio.to_thread(prepare_database, self._sqlite_path)def binary_path(self) -> Path:# ``_pre_spawn`` (called by ``BaseProcessSupervisor._do_start``diff --git a/server/tests/temporal/test_cli_pin.py b/server/tests/temporal/test_cli_pin.pyindex 7ed7edda..5c8ba594 100644--- a/server/tests/temporal/test_cli_pin.py+++ b/server/tests/temporal/test_cli_pin.py@@ -1,7 +1,8 @@"""The pinned Temporal CLI and the database its dev server may open.-RFC-0004 D1/Q3: new installs use the checksum pin; an upgrade preserves-the existing server/database pair until an explicit migration.+RFC-0004 D1 and RFC-0005 E16: the CLI is a checksum pin, and a database+the pinned server minor did not create is deleted with every older CLI+file, so the pinned server starts from an empty database."""from __future__ import annotations@@ -12,8 +13,6 @@ import refrom pathlib import Pathfrom types import SimpleNamespace-import pytest-from services.temporal import _install, _runtime@@ -30,6 +29,10 @@ def _write_marker(db: Path, server_version: str) -> None:_install.marker_path(db).write_text(json.dumps({"server_version": server_version}), encoding="utf-8")+def _read_marker(db: Path) -> dict:+ return json.loads(_install.marker_path(db).read_text(encoding="utf-8"))++def _same_minor_other_patch() -> str:major, minor, _patch = _install.cli_pin()["server_version"].split(".")return f"{major}.{minor}.99"@@ -40,6 +43,22 @@ def _other_minor() -> str:return f"{major}.{int(minor) - 1}.0"+def _old_clis(root: Path) -> list[Path]:+ """Lay out the CLI files an install may hold from before the pin, plus the pinned folder."""+ archive = root / "temporal_cli_latest_windows_amd64.zip"+ archive.write_bytes(b"unpinned archive")+ extracted = root / "temporal_cli_latest_windows_amd64.zip.unzip"+ extracted.mkdir()+ (extracted / "temporal.exe").write_bytes(b"unpinned")+ older = root / "1.8.0" / "archive.untar"+ older.mkdir(parents=True)+ (older / "temporal").write_bytes(b"older")+ pinned = root / _install.cli_pin()["version"] / "archive.untar"+ pinned.mkdir(parents=True)+ (pinned / "temporal").write_bytes(b"pinned")+ return [archive, extracted, root / "1.8.0"]++def test_pin_names_one_exact_release_with_a_hash_for_every_platform():pin = _install.cli_pin()@@ -54,14 +73,10 @@ def test_pin_names_one_exact_release_with_a_hash_for_every_platform():assert re.fullmatch(r"[0-9a-f]{64}", asset["sha256"])-def test_fetch_verifies_the_pinned_archive_and_preserves_older_clis(tmp_path, monkeypatch):+def test_fetch_verifies_the_pinned_archive_into_its_versioned_folder(tmp_path, monkeypatch):monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path)monkeypatch.setattr(_install.platform, "system", lambda: "Linux")monkeypatch.setattr(_install.platform, "machine", lambda: "x86_64")- (tmp_path / "temporal_cli_latest_linux_amd64.tar.gz").write_bytes(b"unpinned archive")- (tmp_path / "temporal_cli_latest_linux_amd64.tar.gz.untar").mkdir()- (tmp_path / "temporal_cli_latest_linux_amd64.tar.gz.untar" / "temporal").write_bytes(b"unpinned")- (tmp_path / "1.0.0").mkdir()calls = []def fake_retrieve(**kwargs):@@ -85,9 +100,6 @@ def test_fetch_verifies_the_pinned_archive_and_preserves_older_clis(tmp_path, moassert Path(calls[0]["path"]) == tmp_path / pin["version"]assert calls[0]["fname"] == asset["file"]assert binary == tmp_path / pin["version"] / f"{asset['file']}.untar" / "temporal"- assert (tmp_path / "1.0.0").is_dir()- assert (tmp_path / "temporal_cli_latest_linux_amd64.tar.gz").read_bytes() == b"unpinned archive"- assert (tmp_path / pin["version"]).is_dir()def test_only_the_pinned_cli_counts_as_installed(tmp_path, monkeypatch):@@ -105,57 +117,99 @@ def test_only_the_pinned_cli_counts_as_installed(tmp_path, monkeypatch):assert _install.binary_installed() is True-def test_a_new_install_records_the_pinned_server_beside_its_database(tmp_path):+def test_a_new_install_records_the_pinned_server_beside_its_database(tmp_path, monkeypatch):+ monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path / "packages")+ (tmp_path / "packages").mkdir()db = tmp_path / "temporal.db"_install.prepare_database(db)pin = _install.cli_pin()assert not db.exists()- marker = json.loads(_install.marker_path(db).read_text(encoding="utf-8"))+ marker = _read_marker(db)assert marker["cli_version"] == pin["version"]assert marker["server_version"] == pin["server_version"]assert marker["created_at"]-def test_unmarked_database_is_never_deleted_or_guessed(tmp_path):+def test_an_unmarked_database_starts_from_new_with_the_old_clis_deleted(tmp_path, monkeypatch):+ root = tmp_path / "packages"+ root.mkdir()+ monkeypatch.setattr(_install, "_cache_dir", lambda: root)+ old = _old_clis(root)db = tmp_path / "temporal.db"_write_db(db)- with pytest.raises(RuntimeError, match="original binary"):- _install.prepare_database(db)- assert all(path.read_bytes() == b"temporal state" for path in _db_files(db))- assert not _install.marker_path(db).exists()+ _install.prepare_database(db)++ assert not any(path.exists() for path in _db_files(db))+ assert not any(path.exists() for path in old)+ assert (root / _install.cli_pin()["version"] / "archive.untar" / "temporal").read_bytes() == b"pinned"+ assert _read_marker(db)["server_version"] == _install.cli_pin()["server_version"]-def test_another_server_minor_requires_explicit_migration(tmp_path):++def test_another_server_minor_starts_from_new(tmp_path, monkeypatch):+ root = tmp_path / "packages"+ root.mkdir()+ monkeypatch.setattr(_install, "_cache_dir", lambda: root)db = tmp_path / "temporal.db"_write_db(db)_write_marker(db, _other_minor())- before = _install.marker_path(db).read_bytes()- with pytest.raises(RuntimeError, match="explicit migration"):- _install.prepare_database(db)- assert all(path.read_bytes() == b"temporal state" for path in _db_files(db))- assert _install.marker_path(db).read_bytes() == before+ _install.prepare_database(db)-def test_a_patch_release_of_the_same_minor_keeps_the_database(tmp_path):+ assert not any(path.exists() for path in _db_files(db))+ assert _read_marker(db)["server_version"] == _install.cli_pin()["server_version"]+++def test_an_unreadable_marker_starts_from_new(tmp_path, monkeypatch):+ root = tmp_path / "packages"+ root.mkdir()+ monkeypatch.setattr(_install, "_cache_dir", lambda: root)+ db = tmp_path / "temporal.db"+ _write_db(db)+ _install.marker_path(db).write_text("not json", encoding="utf-8")++ _install.prepare_database(db)++ assert not any(path.exists() for path in _db_files(db))+ assert _read_marker(db)["server_version"] == _install.cli_pin()["server_version"]+++def test_a_patch_release_of_the_same_minor_keeps_the_database(tmp_path, monkeypatch):+ root = tmp_path / "packages"+ root.mkdir()+ monkeypatch.setattr(_install, "_cache_dir", lambda: root)+ old = _old_clis(root)db = tmp_path / "temporal.db"_write_db(db)_write_marker(db, _same_minor_other_patch())+ before = _install.marker_path(db).read_bytes()_install.prepare_database(db)assert all(path.read_bytes() == b"temporal state" for path in _db_files(db))+ assert _install.marker_path(db).read_bytes() == before+ assert all(path.exists() for path in old)-def test_unreadable_marker_refuses_startup_and_preserves_database(tmp_path):+def test_an_old_cli_that_cannot_be_deleted_does_not_stop_the_start(tmp_path, monkeypatch):+ root = tmp_path / "packages"+ root.mkdir()+ monkeypatch.setattr(_install, "_cache_dir", lambda: root)+ _old_clis(root)db = tmp_path / "temporal.db"_write_db(db)- _install.marker_path(db).write_text("not json", encoding="utf-8")- with pytest.raises(RuntimeError, match="Cannot verify"):- _install.prepare_database(db)- assert all(path.exists() for path in _db_files(db))+ def refuse(path, *args, **kwargs):+ raise PermissionError(f"in use: {path}")++ monkeypatch.setattr(_install.shutil, "rmtree", refuse)++ _install.prepare_database(db)++ assert not any(path.exists() for path in _db_files(db))+ assert _read_marker(db)["server_version"] == _install.cli_pin()["server_version"]def test_the_dev_server_prepares_its_database_before_it_spawns(tmp_path, monkeypatch):@@ -167,79 +221,14 @@ def test_the_dev_server_prepares_its_database_before_it_spawns(tmp_path, monkeypruntime = _runtime.TemporalServerRuntime(settings=settings)prepared = []- async def fake_binaries(_settings):+ async def fake_binaries():return {"temporal": tmp_path / "temporal"}monkeypatch.setattr(_install, "ensure_temporal_binaries", fake_binaries)- monkeypatch.setattr(_install, "prepare_database", lambda db, binary: prepared.append((db, binary)))+ monkeypatch.setattr(_install, "prepare_database", prepared.append)asyncio.run(runtime._pre_spawn())- assert prepared == [(tmp_path / "data" / "temporal.db", tmp_path / "temporal")]+ assert prepared == [tmp_path / "data" / "temporal.db"]+ assert runtime.binary_path() == tmp_path / "temporal"assert (tmp_path / "data").is_dir()---def test_runtime_adopts_the_existing_legacy_cli_for_an_unmarked_database(tmp_path, monkeypatch):- monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path / "packages")- monkeypatch.setattr(_install.platform, "system", lambda: "Windows")- monkeypatch.setattr(_install.platform, "machine", lambda: "AMD64")- binary = tmp_path / "packages" / "temporal_cli_latest_windows_amd64.zip.unzip" / "temporal.exe"- binary.parent.mkdir(parents=True)- binary.write_bytes(b"original")- monkeypatch.setattr(_install, "_binary_versions", lambda path: {"cli_version": "1.8.0", "server_version": "1.31.2"})- db = tmp_path / "temporal.db"- _write_db(db)- assert _install._existing_database_cli(db) == binary- _install.prepare_database(db, binary)- marker = json.loads(_install.marker_path(db).read_text(encoding="utf-8"))- assert marker["server_version"] == "1.31.2"- assert marker["cli_version"] == "1.8.0"- assert _install._existing_database_cli(db) == binary.resolve()- assert all(path.read_bytes() == b"temporal state" for path in _db_files(db))---def test_missing_original_binary_refuses_startup_without_downloading(tmp_path, monkeypatch):- monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path / "packages")- db = tmp_path / "temporal.db"- _write_db(db)- with pytest.raises(RuntimeError, match="original Temporal binary"):- _install._existing_database_cli(db)- assert all(path.exists() for path in _db_files(db))---def test_original_marker_retains_older_versioned_binary(tmp_path, monkeypatch):- monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path / "packages")- monkeypatch.setattr(_install, "_binary_name", lambda: "temporal")- monkeypatch.setattr(_install, "_binary_versions", lambda path: {"cli_version": "1.8.0", "server_version": "1.31.2"})- binary = tmp_path / "packages" / "1.8.0" / "archive.untar" / "temporal"- binary.parent.mkdir(parents=True)- binary.write_bytes(b"original")- db = tmp_path / "temporal.db"- _write_db(db)- _install.marker_path(db).write_text(json.dumps({"cli_version": "1.8.0", "server_version": "1.31.2"}), encoding="utf-8")- assert _install._existing_database_cli(db) == binary---def test_tampered_server_identity_cannot_open_a_database(tmp_path, monkeypatch):- monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path / "packages")- monkeypatch.setattr(_install, "_binary_name", lambda: "temporal")- monkeypatch.setattr(_install, "_binary_versions", lambda path: {"cli_version": "1.8.0", "server_version": "1.32.0"})- binary = tmp_path / "packages" / "1.8.0" / "temporal"- binary.parent.mkdir(parents=True)- binary.write_bytes(b"wrong")- db = tmp_path / "temporal.db"- _write_db(db)- _install.marker_path(db).write_text(json.dumps({"cli_version": "1.8.0", "server_version": "1.31.2"}), encoding="utf-8")- with pytest.raises(RuntimeError, match="mismatch"):- _install._existing_database_cli(db)- assert all(path.exists() for path in _db_files(db))---def test_marker_version_cannot_escape_the_package_directory(tmp_path, monkeypatch):- monkeypatch.setattr(_install, "_cache_dir", lambda: tmp_path / "packages")- db = tmp_path / "temporal.db"- _write_db(db)- _install.marker_path(db).write_text(json.dumps({"cli_version": "../other", "server_version": "1.31.2"}), encoding="utf-8")- with pytest.raises(RuntimeError, match="Cannot identify the original Temporal CLI"):- _install._existing_database_cli(db)- assert all(path.exists() for path in _db_files(db))