Skip to content

The agent that grows with you

fix(config): a structural wrong-prefix match beats a fuzzy sibling suggestion

kshitijk4poorc10711465236
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index cdb2ad6644e..2ca30e5ae5e 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -3296,13 +3296,16 @@ def _validate_config_key(key: str) -> tuple[bool, Optional[str]]:
if seg in _PLATFORM_CONTAINER_KEYS or not isinstance(node, dict) or not node:
return True, None
if seg not in node:
- sibling = _suggest_closest_key(seg, set(node.keys()))
- if sibling is not None:
- return False, ".".join(consumed + [sibling])
# ``gateway.discord.<field>``: the path minus its wrong prefix is itself a known key.
+ # Checked BEFORE the fuzzy sibling: a structural match is proof, a fuzzy match is a
+ # guess, and ``agent.gateway.strict`` must be refused as ``gateway.strict`` rather
+ # than written with a misleading ``agent.gateway_timeout`` did-you-mean.
rest = ".".join(segments[len(consumed):])
if _split_key_path(rest)[0] in _known_top_level_keys() and _validate_config_key(rest)[0]:
return False, rest
+ sibling = _suggest_closest_key(seg, set(node.keys()))
+ if sibling is not None:
+ return False, ".".join(consumed + [sibling])
return False, None
consumed.append(seg)
node = node[seg]
diff --git a/tests/hermes_cli/test_set_config_value.py b/tests/hermes_cli/test_set_config_value.py
index 1aaa3c4a568..0252a59132a 100644
--- a/tests/hermes_cli/test_set_config_value.py
+++ b/tests/hermes_cli/test_set_config_value.py
@@ -513,17 +513,26 @@ class TestSchemaValidation:
DEFAULT_CONFIG is not a complete registry of what the runtime reads.
"""
- def test_unknown_subkey_under_known_section_refused_before_write(self, _isolated_hermes_home, capsys):
+ @pytest.mark.parametrize("key,suggestion", [
+ ("gateway.discord.gateway_restart_notification", "discord.gateway_restart_notification"),
+ # The stray middle segment ``gateway`` fuzzy-matches the sibling ``agent.gateway_timeout``;
+ # the structural wrong-prefix match must win so the path is refused, not written with
+ # a misleading did-you-mean.
+ ("agent.gateway.strict", "gateway.strict"),
+ ])
+ def test_unknown_subkey_under_known_section_refused_before_write(
+ self, key, suggestion, _isolated_hermes_home, capsys
+ ):
config_path = _isolated_hermes_home / "config.yaml"
config_path.write_text("model: gpt-4o\n", encoding="utf-8")
with pytest.raises(SystemExit):
- set_config_value("gateway.discord.gateway_restart_notification", "true")
+ set_config_value(key, "true")
assert config_path.read_text(encoding="utf-8") == "model: gpt-4o\n"
err = capsys.readouterr().err
assert "nothing was written" in err
- assert "discord.gateway_restart_notification" in err
+ assert f"Did you mean: {suggestion}" in err
@pytest.mark.parametrize("key,value,expected,suggestion", [
# ``stt.provider`` is read at runtime (tools/transcription_tools.py) but has no seeded