Skip to content

The agent that grows with you

fix: an active config write failure still migrates siblings and restores snapshots

Teknium3cb93ce516b9
diff --git a/hermes_cli/update_cmd_config.py b/hermes_cli/update_cmd_config.py
index 5e91cc1c726..554165d9f1f 100644
--- a/hermes_cli/update_cmd_config.py
+++ b/hermes_cli/update_cmd_config.py
@@ -182,6 +182,7 @@ def _check_and_apply_config_migration(
print(" Run 'hermes config migrate' to check manually.")
return
+ owed_error = None
has_new_options = bool(missing_env or missing_config)
version_bump_only = not has_new_options and current_ver < latest_ver
needs_migration = has_new_options or current_ver < latest_ver
@@ -205,10 +206,11 @@ def _check_and_apply_config_migration(
except Exception as _mig_err:
print(f" ⚠️ Config format update failed: {_mig_err}")
print(" Run 'hermes config migrate' to retry.")
- # Not a silent success: the caller's owed-step guard records ``config_migration`` as
- # a receipt follow-up and keeps the source-update tail pending, so it is retried.
- raise RuntimeError(
- f"config format v{current_ver} → v{latest_ver} was not written: {_mig_err}") from _mig_err
+ # Not a silent success: raised after the sibling migration and snapshot safety nets
+ # below (independent of the active write, and the snapshot id is only in hand now), so
+ # the caller's owed-step guard records ``config_migration`` and keeps the tail pending.
+ owed_error = RuntimeError(f"config format v{current_ver} → v{latest_ver} was not written: {_mig_err}")
+ owed_error.__cause__ = _mig_err
elif needs_migration:
print()
# Show WHAT changed, not just a count, for an informed yes/no.
@@ -245,6 +247,8 @@ def _check_and_apply_config_migration(
print(f" ✓ Profile '{_name}': config format updated (v{_from_ver} → v{_to_ver})")
_restore_snapshot_safety_nets(pre_update_snapshot_id)
+ if owed_error is not None:
+ raise owed_error
# {profile: snapshot_id} from this run's pre-update backup, consumed by the per-profile
diff --git a/tests/hermes_cli/test_update_config_migration_on_current.py b/tests/hermes_cli/test_update_config_migration_on_current.py
index 700f9f5bb40..d7bf507967c 100644
--- a/tests/hermes_cli/test_update_config_migration_on_current.py
+++ b/tests/hermes_cli/test_update_config_migration_on_current.py
@@ -95,3 +95,43 @@ def test_update_copies_bundled_skill_bytes_to_default_active_and_sibling(tmp_pat
witness = next(bundled.rglob('SKILL.md'))
for profile in homes:
assert (profile / 'skills' / witness.relative_to(bundled)).read_bytes() == witness.read_bytes()
+
+
+def test_active_config_write_failure_still_migrates_siblings_and_restores_snapshots(tmp_path, monkeypatch):
+ """A failed ACTIVE config write is owed debt, but the independent sibling migration and the
+ pre-update snapshot safety nets (the only holders of this run's snapshot ids) still run."""
+ import json
+ from pathlib import Path
+
+ from hermes_cli import backup, update_cmd_config
+
+ root = tmp_path / '.hermes'
+ sibling = root / 'profiles' / 'sibling'
+ jobs = {'jobs': [{'id': 'nightly', 'name': 'nightly', 'schedule': '0 3 * * *', 'prompt': 'report'}]}
+ for home in (root, sibling):
+ (home / 'cron').mkdir(parents=True)
+ (home / 'config.yaml').write_text('_config_version: 48\n', encoding='utf-8')
+ (home / 'cron' / 'jobs.json').write_text(json.dumps(jobs), encoding='utf-8')
+ monkeypatch.setattr(Path, 'home', lambda: tmp_path)
+ monkeypatch.setenv('HERMES_HOME', str(root))
+ active_snapshot = backup.create_quick_snapshot(label='pre-update', hermes_home=root)
+ monkeypatch.setattr(update_cmd_config, '_LAST_SIBLING_SNAPSHOTS',
+ backup.create_pre_update_snapshots_all_profiles(root))
+ for home in (root, sibling): # the documented mutation-window loss the safety nets repair
+ (home / 'cron' / 'jobs.json').write_text('{"jobs": []}', encoding='utf-8')
+ real_replace = config.atomic_config_replace
+
+ def replace(path, *args, **kwargs):
+ if Path(path) == root / 'config.yaml':
+ raise OSError('disk full')
+ return real_replace(path, *args, **kwargs)
+
+ monkeypatch.setattr(config, 'atomic_config_replace', replace)
+ with pytest.raises(RuntimeError, match='was not written: disk full'):
+ update_cmd_config._check_and_apply_config_migration(pre_update_snapshot_id=active_snapshot)
+ for home in (root, sibling):
+ assert json.loads((home / 'cron' / 'jobs.json').read_text(encoding='utf-8')) == jobs
+ assert config.check_config_version()[0] == 48 # the active write stays owed
+ monkeypatch.setenv('HERMES_HOME', str(sibling))
+ sibling_version, latest = config.check_config_version()
+ assert sibling_version == latest > 48