Skip to content

The agent that grows with you

fix(migration): convert Camofox homes with a missing or unstamped config.yaml

Teknium5294a6cce6e5
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index e069959754a..753503c6499 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -608,7 +608,7 @@ from hermes_cli.personality import (
# because callers and tests import these from hermes_cli.config)
from hermes_cli.config_version_stamp import (
- check_config_version, read_config_version_stamp)
+ check_config_version, note_first_stamp, read_config_version_stamp)
# ---- Config Migration System ----
@@ -2500,8 +2500,7 @@ def save_config(
from hermes_cli.config_worker_save import rebase_for_save # frozen-worker writes + merge_existing
config = rebase_for_save(config, _raw_for_paths, merge_existing)
- current_normalized = _canonicalize_config(config)
- normalized = current_normalized
+ normalized = current_normalized = _canonicalize_config(config)
if _raw_for_paths:
normalized = _preserve_env_ref_templates(
normalized, _canonicalize_config(_raw_for_paths),
@@ -2512,6 +2511,7 @@ def save_config(
effective_preserve_keys = _explicit_config_paths(_raw_for_paths) | set(preserve_keys or ())
normalized = _strip_default_values(normalized, DEFAULT_CONFIG, preserve_keys=effective_preserve_keys)
+ note_first_stamp(config_path.parent, _raw_for_paths, normalized)
atomic_config_replace(config_path, normalized, extra_content_on_create=_commented_sections_for_save(normalized))
_secure_file(config_path)
_RAW_CONFIG_CACHE.pop(str(config_path), None)
diff --git a/hermes_cli/config_version_stamp.py b/hermes_cli/config_version_stamp.py
index 51b5325e2df..46e9b569e4c 100644
--- a/hermes_cli/config_version_stamp.py
+++ b/hermes_cli/config_version_stamp.py
@@ -73,3 +73,18 @@ def check_config_version(*, raise_on_parse_error: bool = False) -> tuple[int, in
be mistaken for an up-to-date config. A file with no version key reads as 0."""
stamp, latest = read_config_version_stamp(raise_on_parse_error=raise_on_parse_error)
return (0 if stamp is None else stamp), latest
+
+
+def note_first_stamp(home, on_disk: dict, to_write: dict) -> None:
+ """``save_config`` is about to give *home*'s config.yaml (*on_disk*: missing or never stamped) its first
+ ``_config_version`` outside a migration, so the steps up to that version never see this home. Record
+ the left-core rows they would have found in use (``left_core_migration.record_core_use``) into
+ *to_write*, or the stamp would make a home that ran the core feature look newer than the split."""
+ if "_config_version" in on_disk or "_config_version" not in to_write:
+ return
+ from agent.safe_worker_policy import worker_config_snapshot
+ if worker_config_snapshot() is not None:
+ return # a frozen worker never reads the profile's files; its owner migrates the home
+ from hermes_cli.left_core_migration import LEFT_CORE, record_core_use
+ for version in sorted({feature.left_at for feature in LEFT_CORE if feature.left_at}):
+ record_core_use(home, to_write, version)
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.py
index 09ccdfd250a..ae932611f75 100644
--- a/hermes_cli/left_core_migration.py
+++ b/hermes_cli/left_core_migration.py
@@ -450,16 +450,18 @@ def record_core_use(home: Path, config: dict, version: int) -> bool:
def _predates_split(home: Path, feature: LeftCoreFeature) -> bool:
"""*home* ran *feature* in core: its config is still below ``left_at`` (this pass ran before the
- config step), or that step recorded the feature in use. A missing or unstamped config.yaml is
- neither: the config step stamps (and records) an unstamped one, a missing one is a new home."""
+ config step), that step recorded the feature in use, or config.yaml is missing or unstamped. Every
+ config.yaml Hermes writes carries a stamp, and the first save that stamps one records the rows in use
+ (``config_version_stamp.note_first_stamp``), so only a home from before the split lacks it; core ran
+ the feature there from its .env alone."""
if not feature.left_at:
return True
config = _read_config(home)
- if _marked(config, _USED_KEY, feature):
+ if _marked(config, _USED_KEY, feature) or "_config_version" not in config:
return True
try:
return int(config["_config_version"]) < feature.left_at
- except (KeyError, TypeError, ValueError):
+ except (TypeError, ValueError):
return False
diff --git a/tests/hermes_cli/test_left_core_camofox.py b/tests/hermes_cli/test_left_core_camofox.py
index 84590bd6ca5..3a160c5e58c 100644
--- a/tests/hermes_cli/test_left_core_camofox.py
+++ b/tests/hermes_cli/test_left_core_camofox.py
@@ -245,6 +245,35 @@ def test_home_from_after_the_split_keeps_browser_exec(tmp_path, monkeypatch, sta
assert (home / "config.yaml").read_bytes() == before
[email protected]("config", [None, {"platform_toolsets": _SPLIT_TOOLSETS}], ids=["no-config", "unstamped"])
+def test_an_unversioned_camofox_home_is_converted(tmp_path, monkeypatch, config):
+ """Main ran Camofox for a home with no config.yaml (CAMOFOX_URL in .env alone) or an unstamped one, and
+ Hermes always stamps a config.yaml it creates: such a home ran the core feature and is converted."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ home = _home(tmp_path, env=_SPLIT_ENV, config=config)
+ calls = []
+ assert lcm.migrate_home(home, install=_installer(home, calls), say=lambda _m: None) == ["camofox"]
+ assert _config(home)["agent"]["disabled_toolsets"] == ["browser"]
+
+
+def test_a_plain_save_stamping_an_unversioned_camofox_home_keeps_its_conversion(tmp_path, monkeypatch):
+ """Any config write before the first left-core pass (`hermes config set`, a model switch) stamps an
+ unstamped config.yaml at the current version without running the v52 step; the home still converts."""
+ from hermes_cli.config import load_config, save_config
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "launch"))
+ home = _home(tmp_path, env=_SPLIT_ENV, config={"platform_toolsets": _SPLIT_TOOLSETS})
+ token = set_hermes_home_override(home)
+ try:
+ save_config(load_config())
+ finally:
+ reset_hermes_home_override(token)
+ assert _config(home)["_config_version"] == 52
+ calls = []
+ assert lcm.migrate_home(home, install=_installer(home, calls), say=lambda _m: None) == ["camofox"]
+ assert _config(home)["platform_toolsets"]["cli"] == ["terminal", "file", "camofox"]
+
+
def test_catalog_miss_names_the_install_command(tmp_path, _fresh):
(_fresh / "camofox.yaml").unlink()
home = _home(tmp_path, env="CAMOFOX_URL=http://localhost:9377\n", config={"_config_version": 51})