Skip to content

The agent that grows with you

fix(config): refuse an unknown path under a known section before writing

teknium10e63a1bc5c96
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index 03626fcd542..9d8849695dd 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -3308,7 +3308,13 @@ def _validate_config_key(key: str) -> tuple[bool, Optional[str]]:
return True, None
if seg not in node:
sibling = _suggest_closest_key(seg, set(node.keys()))
- return False, ".".join(consumed + [sibling]) if sibling is not None else None
+ if sibling is not None:
+ return False, ".".join(consumed + [sibling])
+ # ``gateway.discord.<field>``: the path minus its wrong prefix is itself a known key.
+ 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
+ return False, None
consumed.append(seg)
node = node[seg]
return True, None
@@ -3502,9 +3508,19 @@ def _print_unknown_key_notice(key: str, suggestion: Optional[str]) -> None:
"this notice.)", Colors.DIM))
+def _unknown_subkey_refusal(key: str, suggestion: Optional[str]) -> str:
+ lines = [color(f"✗ '{key}' is not a recognized config key — nothing was written.", Colors.RED)]
+ if suggestion:
+ lines.append(color(f" Did you mean: {suggestion}", Colors.YELLOW))
+ lines.append(color(
+ " (Custom top-level keys are supported; use --force to write this path anyway.)", Colors.DIM))
+ return "\n".join(lines)
+
+
def set_config_value(key: str, value: str, force: bool = False):
"""Set a configuration value at a dotted ``key``; ``value`` is auto-coerced to bool/int/float.
- ``force`` skips the unknown-key warning AND authorizes replacing a mapping section with a
+ ``force`` writes an unknown path under a known section (otherwise refused), skips the
+ unknown-top-level-key notice AND authorizes replacing a mapping section with a
scalar. Without it, scalar writes over mappings are refused and bare ``model`` is redirected
to ``model.default``."""
if is_managed():
@@ -3535,17 +3551,17 @@ def set_config_value(key: str, value: str, force: bool = False):
return
# Canonicalize per-platform display keys BEFORE validation/coercion so both see the path the
- # runtime reads. Unknown keys are still written (top-level scalars are bridged into os.environ
- # for skills/external apps) but get a post-write "did you mean" hint.
+ # runtime reads.
key, _redirect_note = _redirect_platform_display_key(key)
if _redirect_note:
- # Unknown-key notice (#34067): the key is still written (arbitrary keys are supported — top-level
- # scalars are bridged into os.environ for skills and external apps), but a plausible-but-wrong
- # dotted path like ``gateway.discord.gateway_restart_notification`` previously reported bare success
- # and left the user debugging behavior that never changed. Warn after the write so the user gets
- # immediate feedback plus a "did you mean" hint, without blocking legitimate unknown keys.
print(_redirect_note)
is_known, suggestion = _validate_config_key(key)
+ # Unknown-key handling (#34067, #112003): an unknown path UNDER a known section can only be a
+ # typo (``gateway.discord.gateway_restart_notification``), so it is refused before anything is
+ # written. Unknown TOP-LEVEL keys stay writable with a post-write notice — their scalars are
+ # bridged into os.environ for skills/external apps, so that namespace is open by design.
+ if not is_known and not force and _split_key_path(key)[0] in _known_top_level_keys():
+ _exit_invalid(_unknown_subkey_refusal(key, suggestion))
# Read the RAW user config (not merged) so defaults are never dumped back; fail-closed.
config_path = get_config_path()
diff --git a/hermes_cli/subcommands/config.py b/hermes_cli/subcommands/config.py
index b7ca790ec81..0df9d4fb8c3 100644
--- a/hermes_cli/subcommands/config.py
+++ b/hermes_cli/subcommands/config.py
@@ -30,8 +30,8 @@ def build_config_parser(subparsers, *, cmd_config: Callable) -> None:
config_set.add_argument("value", nargs="?", help="Value to set")
config_set.add_argument(
"--force", action="store_true",
- help="Skip the unknown-key notice printed after writing a key the "
- "running version doesn't recognize (the value is saved either way).")
+ help="Write a key the running version doesn't recognize: an unknown path under a known "
+ "section is otherwise refused, and an unknown top-level key is written with a notice.")
config_unset = config_subparsers.add_parser("unset", help="Remove a configuration value")
config_unset.add_argument("key", nargs="?", help="Configuration key to remove")
diff --git a/tests/hermes_cli/test_set_config_value.py b/tests/hermes_cli/test_set_config_value.py
index 1897fb7a30d..988a6d20515 100644
--- a/tests/hermes_cli/test_set_config_value.py
+++ b/tests/hermes_cli/test_set_config_value.py
@@ -450,15 +450,29 @@ class TestSecretRedactionInDisplay:
# ---------------------------------------------------------------------------
class TestSchemaValidation:
- """#34067: ``hermes config set`` must not report bare success for
- unrecognized keys. The key IS written (arbitrary keys are supported —
- top-level scalars bridge into os.environ for skills/external apps), but
- a post-write notice warns that Hermes may never read it and suggests the
- likely-intended path. Headline case: the plausible-but-wrong
- ``gateway.discord.gateway_restart_notification`` (correct path:
- ``discord.gateway_restart_notification``).
+ """#34067 / #112003: an unknown path UNDER a known section is a typo and is refused before
+ anything is written (headline case ``gateway.discord.gateway_restart_notification``, correct
+ path ``discord.gateway_restart_notification``). Unknown TOP-LEVEL keys stay writable — their
+ scalars bridge into os.environ for skills/external apps — with a post-write notice.
"""
+ def test_unknown_subkey_under_known_section_refused_before_write(self, _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")
+
+ 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
+
+ def test_unknown_top_level_key_still_written_with_notice(self, _isolated_hermes_home, capsys):
+ set_config_value("brand_new_future_key", "value")
+ assert "brand_new_future_key" in _read_config(_isolated_hermes_home)
+ assert "not a recognized config key" in capsys.readouterr().out
+
@@ -508,7 +522,7 @@ class TestValidateConfigKey:
assert is_known, f"Expected {key!r} to validate as known"
@pytest.mark.parametrize("key,expected_in_suggestion", [
- ("gateway.discord.gateway_restart_notification", None), # no close suggestion
+ ("gateway.discord.gateway_restart_notification", "discord.gateway_restart_notification"),
("disco", "discord"),
("agent.max_turn", "agent.max_turns"),
])
diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.md
index dd240ae65a5..d321a7cd717 100644
--- a/website/docs/reference/cli-commands.md
+++ b/website/docs/reference/cli-commands.md
@@ -1228,8 +1228,8 @@ Subcommands:
| `show` | Show current config values. |
| `edit` | Open `config.yaml` in your editor. |
| `get <key> [--json] [--raw]` | Print a single config value by dotted key (e.g. `hermes config get model.default`). `--json` emits machine-readable output. Credential-shaped values (`api_key`, `*_TOKEN`, `*_SECRET`, `password`, …) are masked (`sk-o...7890`) because the agent runs this from sessions whose transcripts persist; `--raw` prints the real value (or set `security.redact_secrets: false`). |
-| `set <key> <value>` | Set a config value. |
-| `unset <key>` | Remove a config key, reverting it to the built-in default. |
+| `set <key> <value> [--force]` | Set a config value. Dotted paths go to `config.yaml`; API keys and every documented environment variable (`OPENROUTER_API_KEY`, `DISCORD_HOME_CHANNEL`, `*_ALLOWED_USERS`, …) go to `.env` — the same file the platform setup flows and `/sethome` write. An unknown path under a known section (`gateway.discord.foo`) is refused with a did-you-mean and nothing is written; an unknown *top-level* key is written with a notice (top-level scalars are bridged into the environment for skills). `--force` writes either. |
+| `unset <key>` | Remove a config key, reverting it to the built-in default. For `.env`-routed names this also drops a stale top-level `config.yaml` copy. |
| `path` | Print the config file path. |
| `env-path` | Print the `.env` file path. |
| `check` | Check for missing or stale config. |
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 44ecb532e36..f6c4490efe1 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -47,7 +47,7 @@ hermes config set OPENROUTER_API_KEY sk-or-... # Saves to .env
```
:::tip
-The `hermes config set` command automatically routes values to the right file — API keys are saved to `.env`, everything else to `config.yaml`.
+The `hermes config set` command automatically routes values to the right file — API keys and every documented environment variable (`DISCORD_HOME_CHANNEL`, `TELEGRAM_ALLOWED_USERS`, …) are saved to `.env`, dotted settings to `config.yaml`. A misspelled path under a known section (`gateway.discord.foo`) is refused with a did-you-mean before anything is written; pass `--force` to write it anyway.
:::
## Configuration Precedence