fix(config): guard xai migration writer + drop gratuitous annotation

Phase-2 review follow-ups on the unreadable-config chokepoint work:

- hermes_cli/xai_retirement.py apply_migration() is a full-file config.yaml
  rewriter (ruamel round-trip + plain open("w")) that lives outside the
  atomic_yaml_write path, so the chokepoint didn't cover it. It reads the
  file first (which already fails closed on an unreadable file), but add
  require_readable_config_before_write() right before the write as a
  backstop for the read-then-write window, and a regression test asserting
  the original bytes survive an unreadable config.
- Drop the unnecessary "Path" string quotes on atomic_config_write's
  annotation — Path is imported eagerly at module top, no forward ref needed.

auth.py _update_config_for_provider / _reset_config_provider intentionally
keep their standalone require_readable_config_before_write guard + bare
atomic_yaml_write: the guard must fire BEFORE the read (fail-fast) at those
read-then-write sites, and a test pins the atomic_yaml_write call. Both are
already fully guarded against the bug; routing them through the wrapper
would move the check to write time for no benefit.
This commit is contained in:
kshitijk4poor 2026-07-05 22:53:25 +05:30 committed by kshitij
parent 123c6f3a23
commit beaa1a08e6
3 changed files with 31 additions and 1 deletions

View file

@ -6523,7 +6523,7 @@ def require_readable_config_before_write(config_path: Optional[Path] = None) ->
) from exc
def atomic_config_write(config_path: "Path", data: Any, **kwargs: Any) -> None:
def atomic_config_write(config_path: Path, data: Any, **kwargs: Any) -> None:
"""Fail-closed atomic write for ``config.yaml``.
The single chokepoint every config-update path should use instead of

View file

@ -242,6 +242,9 @@ def apply_migration(
)
shutil.copy2(config_path, backup_path)
from hermes_cli.config import require_readable_config_before_write
require_readable_config_before_write(config_path)
with config_path.open("w", encoding="utf-8") as fh:
yaml.dump(doc, fh)