Skip to content

The agent that grows with you

fix(config): a transient read error is no longer remembered as a corrupt config.yaml

teknium1061da070d2f3
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index f9b4b965947..a4ba470ed05 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -94,6 +94,9 @@ def format_config_parse_failure(config_path: Path, exc: Exception, *, fallback:
where = _yaml_error_location(exc)
at = f" at {where}" if where else ""
fallback_msg = _PARSE_FAILURE_FALLBACK_MSG.get(fallback, _PARSE_FAILURE_DEFAULTS_MSG)
+ if isinstance(exc, OSError): # the file is intact; EMFILE/EIO/sharing violation, not a YAML problem
+ return (f"Your settings file ({config_path}) could not be read. {fallback_msg} "
+ "Try again; run `hermes config check` if it keeps failing.")
repair = _PARSE_FAILURE_REPAIR_MSG.format(where=where or "the problem")
return f"Your settings file ({config_path}) has a formatting error{at}. {fallback_msg} {repair}"
@@ -118,7 +121,8 @@ def _warn_config_parse_failure(
return
_CONFIG_PARSE_WARNED.add(key)
from hermes_cli.config_backups import backup_config
- backup_path = backup_config(config_path, "corrupt")
+ # A read error leaves an intact file behind: no "corrupt" copy of a good file.
+ backup_path = None if isinstance(exc, OSError) else backup_config(config_path, "corrupt")
msg = format_config_parse_failure(config_path, exc, fallback=fallback)
if backup_path is not None:
msg += f" A copy of the broken file was saved to {backup_path}."
@@ -2013,6 +2017,7 @@ def _read_raw_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:
if not isinstance(data, dict):
return FailedConfigRead(error=TypeError(f"top-level YAML must be a mapping, got {type(data).__name__}"))
+ _CONFIG_PARSE_FAILURES.pop(path_key, None) # the file reads now (a transient error left the record)
# The cache stores its own deepcopy. The readonly path returns THAT object (identity
# invariant: later cache hits return the same dict); the mutable path returns the parse.
cached_copy = copy.deepcopy(data)
@@ -2384,6 +2389,7 @@ def _load_config_impl(*, want_deepcopy: bool) -> Dict[str, Any]:
try:
with open(config_path, encoding="utf-8") as f:
user_config = fast_safe_load(f) or {}
+ _CONFIG_PARSE_FAILURES.pop(path_key, None) # the file reads now (a transient error left the record)
if "max_turns" in user_config:
agent_user_config = dict(user_config.get("agent") or {})
diff --git a/tests/hermes_cli/test_config_save_integrity.py b/tests/hermes_cli/test_config_save_integrity.py
index 27363e87889..0266e6a7ce5 100644
--- a/tests/hermes_cli/test_config_save_integrity.py
+++ b/tests/hermes_cli/test_config_save_integrity.py
@@ -129,6 +129,29 @@ def test_no_single_transient_read_error_reaches_the_file(write, last_known_good,
assert path.read_bytes() == good_after, f"read {k}/{reads} failed, the saved file differs"
[email protected]("read", [load_config, read_raw_config], ids=["load_config", "read_raw_config"])
+def test_transient_read_error_is_not_recorded_as_a_corrupt_config(read, home, monkeypatch, capsys):
+ """One EMFILE on an intact file must not leave the process treating config.yaml as corrupt: the
+ provider auto-resolution refusal (`corrupt_config`) keyed on the file signature would otherwise
+ fire until the file is next edited, and the good file would be copied away as `.corrupt`."""
+ from hermes_cli.auth import _refuse_env_adoption_if_config_corrupt
+ from hermes_cli.config import get_active_config_parse_failure
+ path = home / "config.yaml"
+ _fresh_process(home, _CONFIG)
+ config_mod._CONFIG_PARSE_WARNED.clear()
+ faults = _ReadFaults(monkeypatch, path)
+ faults.arm(1)
+
+ read()
+ assert get_active_config_parse_failure() is not None # unreadable right now: the refusal holds
+ assert read()["display"]["skin"] == "mono"
+
+ assert get_active_config_parse_failure() is None
+ _refuse_env_adoption_if_config_corrupt()
+ assert not list((home / "backups").glob("**/*.corrupt.*"))
+ assert "could not be read" in capsys.readouterr().err
+
+
@pytest.mark.parametrize("operation", ["save", "partial_save", "migrate"])
def test_authored_nulls_survive_config_writes(tmp_path, monkeypatch, operation):
from hermes_cli.resource_limits import configured_nofile_soft_limit