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
feat(regression): add a fresh-install seed mode and make the env file authoritative (#2394)
Call Whitee4575c06ae73
diff --git a/.env.regression.example b/.env.regression.exampleindex 07700ec12..5497f68d8 100644--- a/.env.regression.example+++ b/.env.regression.example@@ -1,5 +1,7 @@# Copy to .env.regression and fill in local-only secrets.# This file stays local and must never be committed.+# The runner treats this file as authoritative: a key defined here, even empty,+# replaces a value of the same name exported in your shell.# -----------------------------------------------------------------------------# Shared agent credentialsdiff --git a/docs/regression/README.md b/docs/regression/README.mdindex bd0589e16..b11558100 100644--- a/docs/regression/README.md+++ b/docs/regression/README.md@@ -93,7 +93,17 @@ an SSH daemon or host ownership metadata.When the runner is invoked from a task worktree, it looks for`.env.regression` in that current worktree first, then falls back to theprimary checkout. Keep the worktree copy intentional because it shadows the- primary checkout's configuration.+ primary checkout's configuration. `--env-file <path>` names the file+ explicitly.++ The loaded file is authoritative for every key it defines, including keys it+ leaves empty: a value exported in the operator's shell under the same name+ is replaced, so an agent session's own `ANTHROPIC_*` or `OPENAI_*` cannot+ reach the instance in place of the declared one. Keys the file does not+ mention keep their shell value. The runner prints the file it loaded and the+ names of the shell values it replaced, and `up` prints the name and source+ (env file, shell, or runner) of every key it writes into the instance. It+ never prints values.4. Fill in `.env.regression` with:@@ -184,6 +194,32 @@ python3 scripts/incus_regression.py reconcilepython3 scripts/incus_regression.py reconcile --yes```+Fresh-install worktree environment, for testing the first-run experience:++```bash+python3 scripts/incus_regression.py up --target worktree --slug <slug> --seed none+```++`--seed none` builds the environment the way a new user's machine starts: an+empty Avibe home, no agent CLI logins, no platform configuration, and an+`/etc/avibe-regression.env` that holds only the runner's own settings, never the+LLM credentials or `REGRESSION_*` values from the env file. No platform tokens+are required. The service's first start writes the default configuration with+setup not completed, so the Web UI opens the setup wizard; remote-access pairing+happens in the product.++The mode is recorded on the instance (`user.avibe-regression.seed`), so later+updates of that slug stay unseeded without repeating the flag. An environment+changes mode only together with `--reset-mode all`, which empties its Avibe home+and agent CLI homes: `--seed none --reset-mode all` turns an existing worktree+environment back into a fresh install, and `--seed regression --reset-mode all`+seeds it again. Until that reset has rebuilt the home, the instance records+`switching`; if the switch is interrupted, every later `up` refuses until the+same `--seed <mode> --reset-mode all` is run again, because the home then+matches neither mode. `--reset-mode config` on a fresh environment removes the Avibe+config and state to rerun the wizard while keeping CLI logins made in it. The+master environment is always seeded.+Delete worktree environments promptly after the worktree is merged, abandoned,or removed. The persistent `master` environment should stay running and preserveits product state across normal source updates.@@ -317,6 +353,8 @@ Useful flags:- `--slug <slug>`: set the worktree environment slug.- `--reset-mode config`: re-seed config/state/runtime.- `--reset-mode all`: wipe and re-seed the environment state.+- `--seed none`: build a worktree environment as a fresh install; see above.+- `--env-file <path>`: load this env file instead of discovering `.env.regression`.- `--clean`: compatibility flag; normal syncs already remove stale source files.- `--force-deps`: force Python dependency refresh.- `--no-build-ui`: skip UI asset build.@@ -393,4 +431,6 @@ content.- Never commit generated files under `.runtime/`.- Runtime secrets are written into the Incus instance through stdin to`/etc/avibe-regression.env`; they should not appear in command-line logs.+- A `--seed none` environment receives no secrets: neither the runtime env file+ nor the home contains credentials from the operator machine.- Share `.env.regression.example` if you only need to show the structure.diff --git a/scripts/incus_regression.py b/scripts/incus_regression.pyindex b44712995..9867ba2b4 100644--- a/scripts/incus_regression.py+++ b/scripts/incus_regression.py@@ -90,6 +90,17 @@ DEFAULT_WORKTREE_PORT_START = 15200DEFAULT_WORKTREE_PORT_END = 15399ENV_FILE_NAME = ".env.regression"ENV_PREFIX = "REGRESSION_"+LLM_ENV_KEYS = ("ANTHROPIC_API_KEY", "ANTHROPIC_BASE_URL", "OPENAI_API_KEY", "OPENAI_BASE_URL", "OPENAI_API_BASE")+# `regression` seeds platform config, agent CLI logins, and credentials into the+# environment; `none` leaves a fresh install for the first-run wizard. The mode+# is recorded on the instance, so later updates keep it without being told.+SEED_REGRESSION = "regression"+SEED_NONE = "none"+SEED_MODES = (SEED_REGRESSION, SEED_NONE)+# Recorded while `--reset-mode all` moves a home between modes: until that reset+# has rebuilt the home, it matches neither mode.+SEED_SWITCHING = "switching"+SEED_CONFIG_KEY = "user.avibe-regression.seed"SHOW_RUNTIME_BUILD_TIMEOUT_SECONDS = 300SLUG_RE = re.compile(r"^[a-z][a-z0-9-]{1,38}[a-z0-9]$")DAEMON_UNREACHABLE_HINT = (@@ -256,13 +267,21 @@ def project_exists(runner: Runner, remote: str | None, project: str) -> bool:return project in runner.names(command, what="Incus projects")-def instance_exists(runner: Runner, remote: str | None, project: str, instance: str) -> bool:+def instance_record(runner: Runner, remote: str | None, project: str, instance: str) -> dict | None:+ """The daemon's record of the instance, or None when its listing does not hold it."""# An instance cannot outlive its project, so an absent project answers the# question without asking Incus to list inside a project it does not have.if not project_exists(runner, remote, project):- return False+ return Nonecommand = incus("list", *optional_remote_ref(remote), "--format", "json", project=project)- return instance in runner.names(command, what=f"instances in project {project}")+ for record in runner.records(command, what=f"instances in project {project}"):+ if record["name"] == instance:+ return record+ return None+++def instance_exists(runner: Runner, remote: str | None, project: str, instance: str) -> bool:+ return instance_record(runner, remote, project, instance) is not Nonedef require_incus() -> None:@@ -537,7 +556,22 @@ def worktree_mapping_lock(repo_root: Path, *, dry_run: bool):fcntl.flock(fh.fileno(), fcntl.LOCK_UN)-def load_env_file(repo_root: Path, env_file: Path | None) -> Path | None:+@dataclass(frozen=True)+class EnvFile:+ """The regression env file a command loaded, and the keys it defines."""++ path: Path+ keys: frozenset[str]+++def load_env_file(repo_root: Path, env_file: Path | None) -> EnvFile | None:+ """Load the regression env file; it is authoritative for every key it defines.++ The operator's shell routinely exports keys of the same names -- an agent+ session carries its own ANTHROPIC_* and OPENAI_* -- and letting those win+ would put credentials nobody declared into the instance. A key the file+ leaves empty is still defined by it. Only names are printed, never values.+ """common_root = git_common_root(repo_root)candidates = [env_file] if env_file else [repo_root / ENV_FILE_NAME,@@ -549,6 +583,7 @@ def load_env_file(repo_root: Path, env_file: Path | None) -> Path | None:path = candidate.resolve()if not path.is_file():continue+ values: dict[str, str] = {}for raw_line in path.read_text(encoding="utf-8").splitlines():line = raw_line.strip()if not line or line.startswith("#") or "=" not in line:@@ -556,10 +591,13 @@ def load_env_file(repo_root: Path, env_file: Path | None) -> Path | None:if line.startswith("export "):line = line.removeprefix("export ").strip()key, value = line.split("=", 1)- key = key.strip()- value = value.strip().strip("'\"")- os.environ.setdefault(key, value)- return path+ values[key.strip()] = value.strip().strip("'\"")+ replaced = sorted(key for key, value in values.items() if os.environ.get(key, value) != value)+ os.environ.update(values)+ print(f"Loaded regression env file: {path}", file=sys.stderr)+ if replaced:+ print(f" It replaces values exported in the shell for: {', '.join(replaced)}", file=sys.stderr)+ return EnvFile(path, frozenset(values))return None@@ -1586,6 +1624,7 @@ def ensure_project_and_instance(memory: str,disk: str,processes: str,+ seed: str,remote: str | None,) -> None:if not project_exists(runner, remote, target.project):@@ -1607,6 +1646,8 @@ def ensure_project_and_instance("default","--config",f"cloud-init.user-data={cloud_init_user_data()}",+ "--config",+ f"{SEED_CONFIG_KEY}={seed}",project=target.project,))@@ -2057,31 +2098,57 @@ def write_metadata(runner.run(root_exec(target, command, remote=remote))-def runtime_env_payload(repo_root: Path | None = None) -> bytes:+def runtime_env(repo_root: Path | None, *, seed: str) -> tuple[dict[str, str], dict[str, str]]:+ """The instance's runtime env: what the runner sets, and what the operator supplies.++ The operator's part carries the LLM credentials and every REGRESSION_* value,+ which includes the platform tokens. A fresh install has none of them, so+ `--seed none` writes only the runner's part.+ """scm_version = "0.0.0.dev0"if repo_root is not None:sha = commit_sha(repo_root)if sha:scm_version = f"0.0.0.dev0+{sha[:12]}"- mappings = {+ runner_env = {"SETUPTOOLS_SCM_PRETEND_VERSION": scm_version,"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_AVIBE_OS": scm_version,"REGRESSION_UI_HOST": CONTAINER_UI_HOST,"AVIBE_ALLOW_DEV_STATE_MIGRATION": "1",**regression_show_runtime_env(None, SERVICE_HOME),- "ANTHROPIC_API_KEY": os.environ.get("ANTHROPIC_API_KEY", ""),- "ANTHROPIC_BASE_URL": os.environ.get("ANTHROPIC_BASE_URL", ""),- "OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", ""),- "OPENAI_BASE_URL": os.environ.get("OPENAI_BASE_URL", ""),- "OPENAI_API_BASE": os.environ.get("OPENAI_API_BASE", ""),}- for key, value in os.environ.items():- if key in {"REGRESSION_UI_HOST", "REGRESSION_VOICE_REALTIME_ENABLED"}:- continue- if key.startswith(ENV_PREFIX):- mappings[key] = value- lines = [f"{key}={shlex.quote(value)}" for key, value in mappings.items() if value]- return ("\n".join(lines) + "\n").encode("utf-8")+ operator_env: dict[str, str] = {}+ if seed == SEED_REGRESSION:+ operator_env = {key: os.environ.get(key, "") for key in LLM_ENV_KEYS}+ for key, value in os.environ.items():+ if key in {"REGRESSION_UI_HOST", "REGRESSION_VOICE_REALTIME_ENABLED"}:+ continue+ if key.startswith(ENV_PREFIX):+ operator_env[key] = value+ return (+ {key: value for key, value in runner_env.items() if value},+ {key: value for key, value in operator_env.items() if value},+ )+++def report_runtime_env_sources(+ target: RegressionTarget,+ runner_env: dict[str, str],+ operator_env: dict[str, str],+ env_file: EnvFile | None,+ *,+ seed: str,+) -> None:+ """Name the source of every key written into the instance, never its value."""+ sources: dict[str, list[str]] = {"runner": sorted(runner_env)}+ for key in sorted(operator_env):+ source = str(env_file.path) if env_file is not None and key in env_file.keys else "shell"+ sources.setdefault(source, []).append(key)+ print(f"Runtime env for {target.instance} (names only):", file=sys.stderr)+ for source, keys in sources.items():+ print(f" from {source}: {', '.join(keys)}", file=sys.stderr)+ if seed == SEED_NONE:+ print(" no credentials or REGRESSION_* values (--seed none)", file=sys.stderr)def required_platform_seed_envs() -> tuple[str, ...]:@@ -2108,7 +2175,18 @@ def require_runtime_seed_env() -> None:raise SystemExit(f"Missing required regression seed environment variables: {joined}")-def write_runtime_env(runner: Runner, target: RegressionTarget, *, repo_root: Path | None = None, remote: str | None) -> None:+def write_runtime_env(+ runner: Runner,+ target: RegressionTarget,+ *,+ repo_root: Path | None = None,+ seed: str,+ env_file: EnvFile | None,+ remote: str | None,+) -> None:+ runner_env, operator_env = runtime_env(repo_root, seed=seed)+ report_runtime_env_sources(target, runner_env, operator_env, env_file, seed=seed)+ lines = [f"{key}={shlex.quote(value)}" for key, value in {**runner_env, **operator_env}.items()]runner.run(incus("exec",@@ -2119,7 +2197,7 @@ def write_runtime_env(runner: Runner, target: RegressionTarget, *, repo_root: Paf"cat > /etc/avibe-regression.env && chown root:{SERVICE_USER} /etc/avibe-regression.env && chmod 0640 /etc/avibe-regression.env",project=target.project,),- input_bytes=b"" if runner.dry_run else runtime_env_payload(repo_root),+ input_bytes=b"" if runner.dry_run else ("\n".join(lines) + "\n").encode("utf-8"),)@@ -2138,6 +2216,56 @@ def read_existing_fingerprints(runner: Runner, target: RegressionTarget, *, remoreturn payload if isinstance(payload, dict) else {}+def recorded_seed(record: dict) -> str:+ """The seed mode an existing instance was built with, or that it is switching.++ Instances that predate the mode were all seeded, which is what an absent key means.+ """+ config = record.get("config")+ value = config.get(SEED_CONFIG_KEY) if isinstance(config, dict) else None+ if value is None:+ return SEED_REGRESSION+ if value not in (*SEED_MODES, SEED_SWITCHING):+ raise RegressionError(f"Instance {record['name']} records an unknown {SEED_CONFIG_KEY}: {value!r}")+ return value+++def resolve_seed(target: RegressionTarget, *, requested: str | None, record: dict | None, reset_mode: str) -> str:+ """The seed mode this `up` builds with: the requested one, else the one the instance records.++ A mode describes the whole home, so it changes only together with a reset+ that empties it. Otherwise `--seed none` over a seeded home would leave the+ seeded logins behind, and `--seed regression` over a fresh one would seed+ the CLI logins and credentials under whatever the first-run wizard wrote.+ """+ if requested == SEED_NONE and target.target == MASTER_TARGET:+ raise RegressionError(+ "--seed none is for worktree environments; master is the seeded four-platform environment."+ )+ if record is None:+ return requested or SEED_REGRESSION+ recorded = recorded_seed(record)+ if recorded == SEED_SWITCHING:+ if requested is not None and reset_mode == "all":+ return requested+ raise RegressionError(+ f"{target.instance} did not finish switching seed modes, so its home matches neither. "+ "Rerun the switch with --seed <regression|none> --reset-mode all."+ )+ if requested is None or requested == recorded or reset_mode == "all":+ return requested or recorded+ raise RegressionError(+ f"{target.instance} was built with --seed {recorded}. Switching it to --seed {requested} "+ "needs --reset-mode all, which empties its Avibe home and agent CLI homes."+ )+++def record_seed(runner: Runner, target: RegressionTarget, value: str, *, remote: str | None) -> None:+ runner.run(+ incus("config", "set", remote_ref(remote, target.instance), f"{SEED_CONFIG_KEY}={value}", project=target.project)+ )++def should_seed_state(runner: Runner, target: RegressionTarget, *, reset_mode: str, remote: str | None) -> bool:if runner.dry_run or reset_mode != "none":return True@@ -2247,18 +2375,7 @@ def guard_paired_master_reset()-def run_prepare_state(runner: Runner, target: RegressionTarget, *, reset_mode: str, remote: str | None) -> None:- if not should_seed_state(runner, target, reset_mode=reset_mode, remote=remote):- print("Existing Avibe state found; skipping regression state seed.")- return- runner.run(root_exec(target, f"rm -rf /home/{SERVICE_USER}/.regression-seed", remote=remote))- runner.run(- tenant_exec(- target,- f"{VENV_DIR}/bin/python scripts/prepare_regression.py --output-root /home/{SERVICE_USER}/.regression-seed --reset-mode {shlex.quote(reset_mode)}",- remote=remote,- )- )+def reset_state(runner: Runner, target: RegressionTarget, *, reset_mode: str, remote: str | None) -> None:if reset_mode == "config":runner.run(root_exec(@@ -2278,6 +2395,29 @@ def run_prepare_state(runner: Runner, target: RegressionTarget, *, reset_mode: sremote=remote,))+++def run_prepare_state(runner: Runner, target: RegressionTarget, *, reset_mode: str, seed: str, remote: str | None) -> None:+ if seed == SEED_NONE:+ # Nothing is generated: a reset only removes, and the service's first+ # start writes the default config with setup still to be completed.+ reset_state(runner, target, reset_mode=reset_mode, remote=remote)+ # The scratch seed a replaced home was built from holds that home's credentials.+ runner.run(root_exec(target, f"rm -rf /home/{SERVICE_USER}/.regression-seed", remote=remote))+ runner.run(tenant_exec(target, f"mkdir -p {AVIBE_HOME} && ln -sfn {AVIBE_HOME} {LEGACY_HOME}", remote=remote))+ return+ if not should_seed_state(runner, target, reset_mode=reset_mode, remote=remote):+ print("Existing Avibe state found; skipping regression state seed.")+ return+ runner.run(root_exec(target, f"rm -rf /home/{SERVICE_USER}/.regression-seed", remote=remote))+ runner.run(+ tenant_exec(+ target,+ f"{VENV_DIR}/bin/python scripts/prepare_regression.py --output-root /home/{SERVICE_USER}/.regression-seed --reset-mode {shlex.quote(reset_mode)}",+ remote=remote,+ )+ )+ reset_state(runner, target, reset_mode=reset_mode, remote=remote)runner.run(tenant_exec(target,@@ -2693,13 +2833,17 @@ def cmd_up(args: argparse.Namespace) -> int:with metadata.locked(dry_run=args.dry_run):target = resolve_target(args, repo_root, dry_run=args.dry_run, slug=slug)reservation = metadata.reserve(target, dry_run=args.dry_run)- target_exists = instance_exists(runner, args.remote, target.project, target.instance)+ record = instance_record(runner, args.remote, target.project, target.instance)+ target_exists = record is not None+ seed = resolve_seed(target, requested=args.seed, record=record, reset_mode=args.reset_mode)if not args.dry_run and not target_exists and args.remote is None:# Reached only once the daemon has enumerated its instances and this one# was absent, so an occupied port is a real conflict with something else# rather than this environment's own proxy device.ensure_host_port_available(target.ui_host, target.host_port)- seed_requires_env = not args.dry_run and (args.reset_mode != "none" or not target_exists)+ seed_requires_env = (+ seed == SEED_REGRESSION and not args.dry_run and (args.reset_mode != "none" or not target_exists)+ )if seed_requires_env:require_runtime_seed_env()if target_exists:@@ -2720,9 +2864,20 @@ def cmd_up(args: argparse.Namespace) -> int:memory=args.memory,disk=args.disk,processes=args.processes,+ seed=seed,remote=args.remote,)- if not args.dry_run and not seed_requires_env and should_seed_state(runner, target, reset_mode=args.reset_mode, remote=args.remote):+ # A switch records the new mode only once the reset below has rebuilt+ # the home; a run that stops before then leaves it marked as switching.+ switching_seed = target_exists and seed != recorded_seed(record)+ if switching_seed:+ record_seed(runner, target, SEED_SWITCHING, remote=args.remote)+ if (+ seed == SEED_REGRESSION+ and not args.dry_run+ and not seed_requires_env+ and should_seed_state(runner, target, reset_mode=args.reset_mode, remote=args.remote)+ ):require_runtime_seed_env()# The stop may take effect before an interrupted client returns.stopped_service_target = target@@ -2730,8 +2885,10 @@ def cmd_up(args: argparse.Namespace) -> int:# 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)+ if args.dry_run or not target_exists or args.reset_mode != "none" or loaded_env_file is not None:+ write_runtime_env(+ runner, target, repo_root=repo_root, seed=seed, env_file=loaded_env_file, remote=args.remote+ )else:print("No regression env file loaded; preserving existing runtime env file.")migrate_legacy_backend_runtimes(runner, target, remote=args.remote)@@ -2755,7 +2912,9 @@ def cmd_up(args: argparse.Namespace) -> int:# ``prepare_show_runtime`` below is unconditional, so the run either# reconciles the show runtime or fails outright.reconciled = reconciled | {"show_runtime"}- run_prepare_state(runner, target, reset_mode=args.reset_mode, remote=args.remote)+ run_prepare_state(runner, target, reset_mode=args.reset_mode, seed=seed, remote=args.remote)+ if switching_seed:+ record_seed(runner, target, seed, remote=args.remote)normalize_runtime_config(runner, target, remote=args.remote)write_metadata(runner,@@ -2788,11 +2947,11 @@ def cmd_up(args: argparse.Namespace) -> int:if reservation is not None:reservation.release(runner)raise- print_summary(target)+ print_summary(target, seed=seed)return 0-def print_summary(target: RegressionTarget) -> None:+def print_summary(target: RegressionTarget, *, seed: str) -> None:print("")print("Incus regression environment is ready:")print(f" URL: http://{target.ui_host}:{target.host_port}")@@ -2800,6 +2959,8 @@ def print_summary(target: RegressionTarget) -> None:print(f" Project: {target.project}")print(f" Instance: {target.instance}")print(f" Show Runtime source: {regression_show_runtime_source()}")+ if seed == SEED_NONE:+ print(" Seed: none (fresh install; complete setup in the Web UI)")def cmd_status(args: argparse.Namespace) -> int:@@ -3066,7 +3227,11 @@ def add_common(parser: argparse.ArgumentParser) -> None:def add_target_args(parser: argparse.ArgumentParser) -> None:parser.add_argument("--target", choices=sorted(TARGETS), default=MASTER_TARGET)parser.add_argument("--slug", help="Explicit worktree slug for --target worktree.")- parser.add_argument("--env-file", type=Path)+ parser.add_argument(+ "--env-file",+ type=Path,+ help=f"Regression env file; its values replace the shell's for the keys it defines. Defaults to {ENV_FILE_NAME} in this worktree, then in the primary checkout.",+ )parser.add_argument("--host-port", type=int, help="Host port for the Web UI proxy.")parser.add_argument("--ui-host", help="Host/interface for the Incus UI proxy. Defaults to REGRESSION_PORT_BIND_HOST or 127.0.0.1 after env loading.")parser.add_argument("--ui-port", type=int, default=DEFAULT_UI_PORT)@@ -3107,6 +3272,16 @@ def build_parser() -> argparse.ArgumentParser:up.add_argument("--disk", default="80GiB")up.add_argument("--processes", default="8192")up.add_argument("--reset-mode", choices=["none", "config", "all"], default="none")+ up.add_argument(+ "--seed",+ choices=SEED_MODES,+ help=(+ "regression (default for a new environment): seed platform config, agent CLI logins, and credentials. "+ "none: a fresh install for the first-run wizard, worktree targets only; nothing is seeded and no "+ "credentials are written. An existing environment keeps the mode it was built with; changing it "+ "needs --reset-mode all."+ ),+ )up.add_argument("--allow-reset-paired-master",action="store_true",diff --git a/scripts/run_regression.sh b/scripts/run_regression.shindex e4b9b291c..26afadf61 100755--- a/scripts/run_regression.sh+++ b/scripts/run_regression.sh@@ -81,7 +81,7 @@ while [ $# -gt 0 ]; doincus_args+=("$1")shift;;- --slug|--host-port|--ui-host|--ui-port|--worktree-port-start|--worktree-port-end|--image|--storage-pool|--network|--cpus|--memory|--disk|--processes)+ --slug|--seed|--host-port|--ui-host|--ui-port|--worktree-port-start|--worktree-port-end|--image|--storage-pool|--network|--cpus|--memory|--disk|--processes)if [ $# -lt 2 ]; thenecho "$1 requires an argument" >&2exit 1diff --git a/tests/test_core_services_settings.py b/tests/test_core_services_settings.pyindex 31ba477b6..628df94ac 100644--- a/tests/test_core_services_settings.py+++ b/tests/test_core_services_settings.py@@ -61,10 +61,6 @@ def test_default_config_is_fresh_and_needs_setup():assert config.platforms.primary == "avibe"assert {agent.mode for agent in config.model_hub.agents.values()} == {"hub"}- from vibe.runtime import default_config as runtime_default_config-- assert {agent.mode for agent in runtime_default_config().model_hub.agents.values()} == {"hub"}-def test_load_config_or_default_returns_default_without_persisting(isolated_state, tmp_path):# The read-side default backs GET /api/config on a fresh install: thediff --git a/tests/test_incus_regression.py b/tests/test_incus_regression.pyindex 0443718b1..9a8b52850 100644--- a/tests/test_incus_regression.py+++ b/tests/test_incus_regression.py@@ -26,18 +26,22 @@ SPEC.loader.exec_module(incus_regression)MASTER_NAMES = ("avr-master", "avibe-master")-def daemon_listing(*names: str):- """Build a ``Runner.names`` stand-in that answers from a fixed inventory.+def daemon_listing(*names: str, config: dict | None = None):+ """Build ``Runner.names`` and ``Runner.records`` stand-ins that answer from a fixed inventory.Stubs describe what the daemon enumerated rather than a bare yes/no, becausethe runner has to tell "absent" apart from "could not ask": a stub that canonly say True or False cannot express the difference the code now depends on.+ ``config`` is every listed object's Incus config."""def listing(self, command, *, what):return list(names)- return listing+ def records(self, command, *, what):+ return [{"name": name, "config": dict(config or {})} for name in names]++ return listing, recordsdef stub_incus_result(returncode: int, *, stdout: str = "", stderr: str = ""):@@ -665,7 +669,7 @@ def proxy_device_runner(observed: dict[str, str] | None, *, listable: bool = Trucommands = []class RecordingRunner:- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, *, check=True, capture=False, **kwargs):commands.append((command, check))@@ -803,7 +807,7 @@ def test_existing_instance_is_not_reinitialised() -> None:commands = []class RecordingRunner:- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, *, check=True, **kwargs):commands.append((command, check))@@ -829,6 +833,7 @@ def test_existing_instance_is_not_reinitialised() -> None:memory="4GiB",disk="20GiB",processes="4096",+ seed="regression",remote=None,)@@ -1725,18 +1730,18 @@ def test_runtime_env_payload_maps_show_runtime_and_llm_env(monkeypatch: pytest.Mmonkeypatch.setenv("REGRESSION_VOICE_REALTIME_ENABLED", "false")monkeypatch.setenv("OPENAI_API_KEY", "sk-test")- payload = incus_regression.runtime_env_payload().decode()+ runner_env, operator_env = incus_regression.runtime_env(None, seed="regression")+ payload = {**runner_env, **operator_env}- assert "SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0.dev0" in payload- assert "SETUPTOOLS_SCM_PRETEND_VERSION_FOR_AVIBE_OS=0.0.0.dev0" in payload- assert "AVIBE_ALLOW_DEV_STATE_MIGRATION=1" in payload- assert "VIBE_SHOW_RUNTIME_SOURCE=archive" in payload- assert "VIBE_SHOW_RUNTIME_ARCHIVE_PATH=/home/avibe/.cache/avibe-regression/vibe-show-runtime-node.tgz" in payload- assert "VIBE_SHOW_RUNTIME_ARCHIVE_PATH=/tmp/show-runtime.tgz" not in payload- assert "REGRESSION_SLACK_CHANNEL=C123" in payload+ assert payload["SETUPTOOLS_SCM_PRETEND_VERSION"] == "0.0.0.dev0"+ assert payload["SETUPTOOLS_SCM_PRETEND_VERSION_FOR_AVIBE_OS"] == "0.0.0.dev0"+ assert payload["AVIBE_ALLOW_DEV_STATE_MIGRATION"] == "1"+ assert payload["VIBE_SHOW_RUNTIME_SOURCE"] == "archive"+ assert payload["VIBE_SHOW_RUNTIME_ARCHIVE_PATH"] == "/home/avibe/.cache/avibe-regression/vibe-show-runtime-node.tgz"+ assert payload["REGRESSION_SLACK_CHANNEL"] == "C123"assert "VITE_VOICE_REALTIME_ENABLED" not in payloadassert "REGRESSION_VOICE_REALTIME_ENABLED" not in payload- assert "OPENAI_API_KEY=sk-test" in payload+ assert payload["OPENAI_API_KEY"] == "sk-test"@pytest.mark.parametrize("legacy_source", ["github", "github-source"])@@ -1746,10 +1751,9 @@ def test_runtime_env_payload_migrates_legacy_github_source() -> None:monkeypatch.setenv("REGRESSION_SHOW_RUNTIME_SOURCE", legacy_source)- payload = incus_regression.runtime_env_payload().decode()+ runner_env, _operator_env = incus_regression.runtime_env(None, seed="regression")- assert "VIBE_SHOW_RUNTIME_SOURCE=archive" in payload- assert f"VIBE_SHOW_RUNTIME_SOURCE={legacy_source}" not in payload+ assert runner_env["VIBE_SHOW_RUNTIME_SOURCE"] == "archive"def test_runtime_env_payload_ignores_legacy_regression_env(monkeypatch: pytest.MonkeyPatch) -> None:@@ -1758,10 +1762,11 @@ def test_runtime_env_payload_ignores_legacy_regression_env(monkeypatch: pytest.Mmonkeypatch.setenv("THREE_REGRESSION_SHOW_RUNTIME_ARCHIVE_PATH", "/tmp/legacy.tgz")monkeypatch.setenv("THREE_REGRESSION_SLACK_CHANNEL", "CLEGACY")- payload = incus_regression.runtime_env_payload().decode()+ runner_env, operator_env = incus_regression.runtime_env(None, seed="regression")+ payload = {**runner_env, **operator_env}- assert "VIBE_SHOW_RUNTIME_ARCHIVE_PATH=/home/avibe/.cache/avibe-regression/vibe-show-runtime-node.tgz" in payload- assert "REGRESSION_SLACK_CHANNEL=CLEGACY" not in payload+ assert payload["VIBE_SHOW_RUNTIME_ARCHIVE_PATH"] == "/home/avibe/.cache/avibe-regression/vibe-show-runtime-node.tgz"+ assert "REGRESSION_SLACK_CHANNEL" not in payloadassert "THREE_REGRESSION_SLACK_CHANNEL" not in payload@@ -1769,11 +1774,10 @@ def test_runtime_env_payload_forces_container_ui_host(monkeypatch: pytest.Monkeymonkeypatch.setenv("REGRESSION_UI_HOST", "192.168.2.3")monkeypatch.setenv("THREE_REGRESSION_UI_HOST", "10.1.2.3")- payload = incus_regression.runtime_env_payload().decode()+ runner_env, operator_env = incus_regression.runtime_env(None, seed="regression")- assert "REGRESSION_UI_HOST=127.0.0.1" in payload- assert "REGRESSION_UI_HOST=192.168.2.3" not in payload- assert "REGRESSION_UI_HOST=10.1.2.3" not in payload+ assert runner_env["REGRESSION_UI_HOST"] == "127.0.0.1"+ assert "REGRESSION_UI_HOST" not in operator_envdef test_load_env_file_accepts_export_prefix(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:@@ -1783,7 +1787,7 @@ def test_load_env_file_accepts_export_prefix(tmp_path: Path, monkeypatch: pytestloaded = incus_regression.load_env_file(tmp_path, env_file)- assert loaded == env_file+ assert loaded.path == env_fileassert incus_regression.os.environ["REGRESSION_SLACK_CHANNEL"] == "C123"@@ -1843,6 +1847,290 @@ def test_require_runtime_seed_env_rejects_legacy_platform_credentials(monkeypatcassert "REGRESSION_SLACK_BOT_TOKEN" in str(excinfo.value)+def test_env_file_replaces_shell_values_for_the_keys_it_defines(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]+) -> None:+ """The env file, not whatever the operator's shell exported, decides the keys it defines.++ An agent session exports its own ANTHROPIC_* and OPENAI_*; when those won, the+ instance received credentials nobody had declared for it. A key the file+ leaves empty is defined too, and a key it does not mention stays the shell's.+ """+ env_file = tmp_path / ".env.regression"+ env_file.write_text(+ "ANTHROPIC_API_KEY=file-key\nANTHROPIC_BASE_URL=\nOPENAI_API_KEY=sk-equal\n",+ encoding="utf-8",+ )+ monkeypatch.setenv("ANTHROPIC_API_KEY", "shell-key")+ monkeypatch.setenv("ANTHROPIC_BASE_URL", "https://shell.example")+ monkeypatch.setenv("OPENAI_API_KEY", "sk-equal")+ monkeypatch.setenv("OPENAI_BASE_URL", "https://shell-only.example")++ loaded = incus_regression.load_env_file(tmp_path, env_file)++ assert incus_regression.os.environ["ANTHROPIC_API_KEY"] == "file-key"+ assert incus_regression.os.environ["ANTHROPIC_BASE_URL"] == ""+ assert incus_regression.os.environ["OPENAI_BASE_URL"] == "https://shell-only.example"+ assert loaded.keys == {"ANTHROPIC_API_KEY", "ANTHROPIC_BASE_URL", "OPENAI_API_KEY"}+ report = capsys.readouterr().err+ assert str(env_file) in report+ assert "for: ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL\n" in report+ for value in ("file-key", "shell-key", "shell.example", "sk-equal"):+ assert value not in report+++def test_runtime_env_report_names_the_source_of_each_key_without_values(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]+) -> None:+ """Every key written into the instance is attributed to the env file, the shell, or the runner."""+ for key in incus_regression.LLM_ENV_KEYS:+ monkeypatch.delenv(key, raising=False)+ monkeypatch.setenv("ANTHROPIC_API_KEY", "file-key")+ monkeypatch.setenv("OPENAI_API_KEY", "shell-key")+ env_file = incus_regression.EnvFile(tmp_path / ".env.regression", frozenset({"ANTHROPIC_API_KEY"}))++ class RecordingRunner:+ dry_run = False++ def run(self, command, **kwargs):+ return subprocess.CompletedProcess(command, 0)++ target = incus_regression.RegressionTarget(+ target="worktree",+ slug="demo",+ project="avr-wt-demo",+ instance="avibe-wt-demo",+ host_port=15200,+ ui_host="127.0.0.1",+ ui_port=5123,+ )++ incus_regression.write_runtime_env(RecordingRunner(), target, seed="regression", env_file=env_file, remote=None)++ report = capsys.readouterr().err+ assert f"from {env_file.path}: ANTHROPIC_API_KEY\n" in report+ assert "from shell: OPENAI_API_KEY" in report+ assert "from runner: AVIBE_ALLOW_DEV_STATE_MIGRATION, REGRESSION_UI_HOST, SETUPTOOLS_SCM_PRETEND_VERSION" in report+ assert "file-key" not in report+ assert "shell-key" not in report+++ ("target_name", "requested", "recorded", "reset_mode", "expected"),+ [+ ("worktree", None, None, "none", "regression"),+ ("worktree", "none", None, "none", "none"),+ ("worktree", None, "none", "none", "none"),+ ("worktree", None, "absent", "none", "regression"),+ ("worktree", "none", "regression", "all", "none"),+ ("worktree", "regression", "none", "all", "regression"),+ ("worktree", "none", "absent", "config", "needs --reset-mode all"),+ ("worktree", "regression", "none", "none", "needs --reset-mode all"),+ ("master", "none", None, "none", "for worktree environments"),+ ("worktree", None, "switching", "none", "did not finish switching"),+ ("worktree", None, "switching", "all", "did not finish switching"),+ ("worktree", "none", "switching", "config", "did not finish switching"),+ ("worktree", "none", "switching", "all", "none"),+ ("worktree", "regression", "switching", "all", "regression"),+ ],+)+def test_seed_mode_belongs_to_the_environment(+ target_name: str, requested: str | None, recorded: str | None, reset_mode: str, expected: str+) -> None:+ """An environment keeps the seed mode it was built with until a full reset replaces its home.++ An update that forgot `--seed none` would otherwise seed CLI logins and+ credentials under the first-run wizard's state, and `--seed none` over a+ seeded home would leave that home's logins behind while claiming a fresh one.+ """+ target = incus_regression.RegressionTarget(+ target=target_name,+ slug="demo",+ project="avr-wt-demo",+ instance="avibe-wt-demo",+ host_port=15200,+ ui_host="127.0.0.1",+ ui_port=5123,+ )+ record = None+ if recorded == "absent":+ record = {"name": target.instance, "config": {}}+ elif recorded is not None:+ record = {"name": target.instance, "config": {incus_regression.SEED_CONFIG_KEY: recorded}}++ if expected in incus_regression.SEED_MODES:+ assert incus_regression.resolve_seed(target, requested=requested, record=record, reset_mode=reset_mode) == expected+ else:+ with pytest.raises(incus_regression.RegressionError, match=expected):+ incus_regression.resolve_seed(target, requested=requested, record=record, reset_mode=reset_mode)+++def run_fresh_up(+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+ commands: list[str],+ inputs: dict[str, str],+ *,+ requested: str | None,+ recorded: str | None,+ reset_mode: str,+ fail_on: str | None = None,+) -> int:+ """Run `up` for worktree slug `fresh` against a daemon whose instance records `recorded`.++ The operator's credentials are loaded and the platform tokens are absent.+ Every command `up` issues lands in `commands`, and the stdin it writes in+ `inputs` keyed by that command. A command containing `fail_on` fails.+ """+ write_ui_builder_stage(tmp_path)+ inventory = () if recorded is None else ("avr-wt-fresh", "avibe-wt-fresh")+ config = {} if recorded in (None, "regression") else {incus_regression.SEED_CONFIG_KEY: recorded}++ class RecordingRunner:+ def __init__(self, *, dry_run=False):+ self.dry_run = dry_run++ names, records = daemon_listing(*inventory, config=config)++ def run(self, command, *, input_bytes=None, **kwargs):+ commands.append(" ".join(command))+ if input_bytes is not None:+ inputs[commands[-1]] = input_bytes.decode()+ if fail_on is not None and fail_on in commands[-1]:+ raise subprocess.CalledProcessError(1, command)+ return subprocess.CompletedProcess(command, 0, stdout="")++ for key in incus_regression.required_platform_seed_envs():+ monkeypatch.delenv(key, raising=False)+ monkeypatch.setenv("ANTHROPIC_API_KEY", "sk-ant-operator")+ monkeypatch.setenv("OPENAI_API_KEY", "sk-openai-operator")+ monkeypatch.setenv("REGRESSION_SLACK_BOT_TOKEN", "xoxb-operator")+ env_file = incus_regression.EnvFile(+ tmp_path / ".env.regression",+ frozenset({"ANTHROPIC_API_KEY", "OPENAI_API_KEY", "REGRESSION_SLACK_BOT_TOKEN"}),+ )+ monkeypatch.setattr(incus_regression, "git_common_root", lambda repo_root: repo_root)+ monkeypatch.setattr(incus_regression, "current_repo_root", lambda: tmp_path)+ monkeypatch.setattr(incus_regression, "load_env_file", lambda repo_root, env_file_arg: env_file)+ monkeypatch.setattr(incus_regression, "require_incus", lambda: None)+ monkeypatch.setattr(incus_regression, "Runner", RecordingRunner)+ monkeypatch.setattr(incus_regression, "ensure_host_port_available", lambda host, port: None)+ monkeypatch.setattr(incus_regression, "sync_source", lambda *args, **kwargs: None)+ monkeypatch.setattr(incus_regression, "compute_fingerprints", lambda repo_root: {})+ monkeypatch.setattr(incus_regression, "update_dependencies_and_build", lambda *args, **kwargs: set())+ monkeypatch.setattr(incus_regression, "prepare_show_runtime", lambda *args, **kwargs: None)+ monkeypatch.setattr(incus_regression, "restart_and_verify", lambda *args, **kwargs: None)++ args = argparse.Namespace(+ target="worktree",+ slug="fresh",+ host_port=15210,+ 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=reset_mode,+ seed=requested,+ )+ return incus_regression.cmd_up(args)+++FRESH_SEED_SET = "config set avibe-wt-fresh user.avibe-regression.seed="+FRESH_HOME_WIPE = "rm -rf /home/avibe/.avibe /home/avibe/.vibe_remote /home/avibe/.claude"+++ ("case", "requested", "recorded", "reset_mode"),+ [+ ("create", "none", None, "none"),+ ("update", None, "none", "none"),+ ("switch", "none", "regression", "all"),+ ("rerun an unfinished switch", "none", "switching", "all"),+ ],+)+def test_fresh_install_environment_gets_no_seed_and_no_credentials(+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+ case: str,+ requested: str | None,+ recorded: str | None,+ reset_mode: str,+) -> None:+ """`--seed none` builds a home the first-run wizard has never seen.++ No platform tokens are asked for, `prepare_regression.py` never runs, and the+ instance's runtime env carries none of the operator's credentials although+ the loaded env file has them -- on creation, on a later update that does not+ repeat the flag, and when an environment is switched by a full reset.+ """+ commands: list[str] = []+ inputs: dict[str, str] = {}++ assert run_fresh_up(+ tmp_path, monkeypatch, commands, inputs, requested=requested, recorded=recorded, reset_mode=reset_mode+ ) == 0++ joined = "\n".join(commands)+ assert "prepare_regression.py --output-root" not in joined+ (runtime_env,) = [payload for command, payload in inputs.items() if "/etc/avibe-regression.env" in command]+ assert "VIBE_SHOW_RUNTIME_SOURCE=archive" in runtime_env+ for name in ("ANTHROPIC_API_KEY", "OPENAI_API_KEY", "REGRESSION_SLACK_BOT_TOKEN"):+ assert name not in runtime_env+ if case == "create":+ assert "--config user.avibe-regression.seed=none" in joined+ marks = [(i, command.rsplit("=", 1)[1]) for i, command in enumerate(commands) if FRESH_SEED_SET in command]+ if reset_mode == "all":+ wipe = next(i for i, command in enumerate(commands) if FRESH_HOME_WIPE in command)+ # The new mode is recorded only once the reset has rebuilt the home.+ assert [mode for _, mode in marks] == ["switching", "none"]+ assert marks[0][0] < wipe < marks[1][0]+ assert "rm -rf /home/avibe/.regression-seed" in joined+ else:+ assert marks == []+ assert FRESH_HOME_WIPE not in joined+++def test_an_interrupted_seed_switch_is_never_read_as_finished(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """A switch that stops before its reset rebuilt the home leaves no mode for the next `up` to trust.++ Recording the new mode up front let a later plain `up` skip the reset it+ still owed: seeded logins kept under a fresh-install mode, or a fresh home+ under a seeded one. The instance stays marked as switching instead, and+ only the switch itself may run on it.+ """+ commands: list[str] = []++ with pytest.raises(subprocess.CalledProcessError):+ run_fresh_up(+ tmp_path,+ monkeypatch,+ commands,+ {},+ requested="none",+ recorded="regression",+ reset_mode="all",+ fail_on=FRESH_HOME_WIPE,+ )++ assert [command.rsplit("=", 1)[1] for command in commands if FRESH_SEED_SET in command] == ["switching"]++def test_prepare_state_skips_existing_state_without_reset() -> None:commands = []@@ -1863,7 +2151,7 @@ def test_prepare_state_skips_existing_state_without_reset() -> None:ui_port=5123,)- incus_regression.run_prepare_state(RecordingRunner(), target, reset_mode="none", remote=None)+ incus_regression.run_prepare_state(RecordingRunner(), target, reset_mode="none", seed="regression", remote=None)joined = "\n".join(" ".join(command) for command in commands)assert "test -f /home/avibe/.avibe/config/config.json" in joined@@ -1892,7 +2180,7 @@ def test_prepare_state_reseeds_when_reset_requested(monkeypatch: pytest.MonkeyPaui_port=5123,)- incus_regression.run_prepare_state(RecordingRunner(), target, reset_mode="config", remote=None)+ incus_regression.run_prepare_state(RecordingRunner(), target, reset_mode="config", seed="regression", remote=None)joined = "\n".join(" ".join(command) for command in commands)assert "rm -rf /home/avibe/.avibe/config /home/avibe/.avibe/state /home/avibe/.avibe/runtime" in joined@@ -1926,7 +2214,7 @@ def test_prepare_state_reset_all_deletes_target_home_before_copy(monkeypatch: pyui_port=5123,)- incus_regression.run_prepare_state(RecordingRunner(), target, reset_mode="all", remote=None)+ incus_regression.run_prepare_state(RecordingRunner(), target, reset_mode="all", seed="regression", remote=None)joined = "\n".join(" ".join(command) for command in commands)assert "rm -rf /home/avibe/.avibe /home/avibe/.vibe_remote" in joined@@ -2208,7 +2496,7 @@ def test_write_runtime_env_uses_stdin_not_command_line() -> None:ui_port=5123,)- incus_regression.write_runtime_env(RecordingRunner(), target, remote="lab")+ incus_regression.write_runtime_env(RecordingRunner(), target, seed="regression", env_file=None, remote="lab")joined_command = " ".join(commands[0])assert commands[0][:5] == ["incus", "--project", "avr-master", "exec", "lab:avibe-master"]@@ -3374,7 +3662,7 @@ def test_up_skips_host_port_preflight_for_existing_instance(tmp_path: Path, monkdef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -3419,6 +3707,7 @@ def test_up_skips_host_port_preflight_for_existing_instance(tmp_path: Path, monkno_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -3433,7 +3722,7 @@ def test_up_defers_master_port_preflight_until_after_instance_exists(def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -3488,6 +3777,7 @@ def test_up_defers_master_port_preflight_until_after_instance_exists(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -3498,7 +3788,7 @@ def test_up_checks_host_port_preflight_for_new_local_instance(tmp_path: Path, modef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -3547,6 +3837,7 @@ def test_up_checks_host_port_preflight_for_new_local_instance(tmp_path: Path, mono_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -3608,6 +3899,7 @@ def test_up_stops_when_the_daemon_cannot_say_whether_the_target_exists(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)with pytest.raises(incus_regression.RegressionError, match="context deadline exceeded"):@@ -3623,7 +3915,7 @@ def test_up_checks_seed_env_before_target_mutation(tmp_path: Path, monkeypatch:def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 1, stdout="")@@ -3672,6 +3964,7 @@ def test_up_checks_seed_env_before_target_mutation(tmp_path: Path, monkeypatch:no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)with pytest.raises(SystemExit):@@ -3687,7 +3980,7 @@ def test_up_checks_platform_seed_env_before_existing_reset_mutation(tmp_path: Padef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="")@@ -3733,6 +4026,7 @@ def test_up_checks_platform_seed_env_before_existing_reset_mutation(tmp_path: Pano_build_ui=True,force_ui=False,reset_mode="config",+ seed=None,)with pytest.raises(SystemExit):@@ -3748,7 +4042,7 @@ def test_up_rejects_paired_master_reset_before_instance_mutation(tmp_path: Path,def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout='{"state": "paired"}')@@ -3792,6 +4086,7 @@ def test_up_rejects_paired_master_reset_before_instance_mutation(tmp_path: Path,no_build_ui=True,force_ui=False,reset_mode="config",+ seed=None,allow_reset_paired_master=False,)@@ -3808,7 +4103,7 @@ def test_up_dry_run_does_not_require_seed_env(tmp_path: Path, monkeypatch: pytesdef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -3864,6 +4159,7 @@ def test_up_dry_run_does_not_require_seed_env(tmp_path: Path, monkeypatch: pytesno_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -3890,7 +4186,7 @@ def test_up_stops_old_service_before_mutating_runtime(tmp_path: Path, monkeypatcdef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -3945,6 +4241,7 @@ def test_up_stops_old_service_before_mutating_runtime(tmp_path: Path, monkeypatcno_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -3970,7 +4267,7 @@ def test_up_preserves_runtime_env_when_existing_target_has_no_env_file(tmp_path:def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -4025,6 +4322,7 @@ def test_up_preserves_runtime_env_when_existing_target_has_no_env_file(tmp_path:no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -4041,7 +4339,7 @@ def test_up_rewrites_runtime_env_when_env_file_is_loaded(tmp_path: Path, monkeypdef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -4095,6 +4393,7 @@ def test_up_rewrites_runtime_env_when_env_file_is_loaded(tmp_path: Path, monkeypno_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -4122,7 +4421,7 @@ def test_up_reserves_worktree_port_under_both_locks_that_protect_it(tmp_path: Padef __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing("avr-wt-demo-branch", "avibe-wt-demo-branch")+ names, records = daemon_listing("avr-wt-demo-branch", "avibe-wt-demo-branch")def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -4225,6 +4524,7 @@ def test_up_reserves_worktree_port_under_both_locks_that_protect_it(tmp_path: Pano_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)assert incus_regression.cmd_up(args) == 0@@ -4310,7 +4610,7 @@ def test_up_gives_its_row_back_only_when_the_daemon_says_nothing_came_of_it(inventory = ("avr-wt-demo-branch",) if holds_project else ()class NewRunner(incus_regression.Runner):- names = daemon_listing(*inventory)+ names, records = daemon_listing(*inventory)host_run = subprocess.run@@ -4423,6 +4723,7 @@ def test_up_gives_its_row_back_only_when_the_daemon_says_nothing_came_of_it(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)with pytest.raises(failure_type) as raised:@@ -4471,7 +4772,7 @@ def test_up_leaves_behind_a_row_another_run_has_taken_over(def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -4512,6 +4813,7 @@ def test_up_leaves_behind_a_row_another_run_has_taken_over(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)with pytest.raises(RuntimeError):@@ -4559,7 +4861,7 @@ def test_no_end_of_a_reservation_writes_over_a_row_another_run_took(def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()mine = incus_regression.WorktreeMetadata(tmp_path, None).reserve(target_on(15200))theirs = incus_regression.WorktreeMetadata(tmp_path, None).reserve(target_on(15201))@@ -4672,7 +4974,7 @@ def test_an_update_records_the_revision_its_sync_copied(def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()def run(self, command, **kwargs):commands.append(command)@@ -4739,6 +5041,7 @@ def test_an_update_records_the_revision_its_sync_copied(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)def served_builds() -> list[dict]:@@ -4811,7 +5114,7 @@ def test_up_releases_its_reservation_when_the_run_is_interrupted(def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing()+ names, records = daemon_listing()def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -4850,6 +5153,7 @@ def test_up_releases_its_reservation_when_the_run_is_interrupted(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)with pytest.raises(KeyboardInterrupt):@@ -5346,7 +5650,7 @@ def test_a_run_that_dies_mid_build_leaves_nothing_licensing_a_skip(def __init__(self, *, dry_run=False):self.dry_run = dry_run- names = daemon_listing(*MASTER_NAMES)+ names, records = daemon_listing(*MASTER_NAMES)def run(self, command, **kwargs):return subprocess.CompletedProcess(command, 0, stdout="{}")@@ -5399,6 +5703,7 @@ def test_a_run_that_dies_mid_build_leaves_nothing_licensing_a_skip(no_build_ui=True,force_ui=False,reset_mode="none",+ seed=None,)with pytest.raises(RuntimeError):diff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex ff1c7e981..b79376cf3 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -605,6 +605,11 @@ def test_default_config_written(tmp_path, monkeypatch):config = runtime.ensure_config()assert config.mode == "self_host"assert (tmp_path / ".vibe_remote" / "config" / "config.json").exists()+ # A service or UI that starts before the CLI seeds the first-run config the+ # CLI would: no setup done and no IM platform enabled, not a phantom Slack.+ assert config.setup_completed is False+ assert config.platforms.enabled == []+ assert config.platforms.primary == "avibe"def test_status_written(tmp_path, monkeypatch):diff --git a/vibe/runtime.py b/vibe/runtime.pyindex c97e76cfc..480909520 100644--- a/vibe/runtime.py+++ b/vibe/runtime.py@@ -26,15 +26,7 @@ import psutilfrom config import pathsfrom config.atomic_io import write_atomic-from config.v2_config import (- AgentsConfig,- ClaudeConfig,- CodexConfig,- OpenCodeConfig,- RuntimeConfig,- SlackConfig,- V2Config,-)+from config.v2_config import V2Configfrom core.process_isolation import fingerprint_process_marker, isolated_subprocess_kwargs, processes_carrying_markerfrom vibe.log_sink import RUNTIME_LOG_MAX_BYTES, RUNTIME_LOG_RETAIN_BYTES@@ -188,31 +180,13 @@ def ensure_dirs():paths.ensure_data_dirs()-def default_config():- from config.v2_config import ModelHubConfig-- work_dir = Path.home() / "work"- work_dir.mkdir(parents=True, exist_ok=True)- return V2Config(- mode="self_host",- version="v2",- slack=SlackConfig(bot_token="", app_token=""),- runtime=RuntimeConfig(default_cwd=str(work_dir)),- agents=AgentsConfig(- opencode=OpenCodeConfig(enabled=True, cli_path="opencode"),- claude=ClaudeConfig(enabled=True, cli_path="claude"),- codex=CodexConfig(enabled=False, cli_path="codex"),- ),- model_hub=ModelHubConfig(),- )--def ensure_config():from storage.migrations import guard_source_checkout_default_state_bootstrapguard_source_checkout_default_state_bootstrap()config_path = paths.get_config_path()from config.v2_config import config_file_lock+ from core.services import settings as settings_service# Create-if-absent under the cross-process file lock (#1458 stage# ③): the existence check and the seeding save are one atomic step,@@ -221,8 +195,8 @@ def ensure_config():# and the write.with config_file_lock(config_path):if not config_path.exists():- default = default_config()- default.save(config_path)+ # The same first-run shape the CLI seeds, whichever process starts first.+ settings_service.default_config().save(config_path)return V2Config.load(config_path)