Skip to content

feat(config): warn on unrecognized brain.config keys at load time - #253

Merged
chrisjz merged 2 commits into
mainfrom
openspec/warn-unknown-brain-config-keys
Jun 23, 2026
Merged

feat(config): warn on unrecognized brain.config keys at load time#253
chrisjz merged 2 commits into
mainfrom
openspec/warn-unknown-brain-config-keys

Conversation

@chrisjz

@chrisjz chrisjz commented Jun 23, 2026

Copy link
Copy Markdown
Member

Why

Unknown keys under brain.config are silently dropped when the YAML is parsed into the brain config model (Pydantic ignores extras), so a typo'd or dead hyperparameter no-ops with no signal. This surfaced during T7: the mlpppo continuous-C3 config set entropy_coef_end / entropy_decay_episodes, but mlpppo doesn't implement an entropy schedule — so it ran flat the whole time and nobody noticed until a manual dig-in.

What changed

load_simulation_config now compares the raw YAML brain.config keys against the resolved brain config class's fields and logs a warning naming any dropped keys, before they silently no-op. (The existing _resolve_brain_config warning couldn't catch these — the keys are dropped at the first YAML→model parse, before it runs.)

Validation

  • Fires on mlpppo's entropy_coef_end/entropy_decay_episodes; silent on clean configs.
  • 3 focused tests (unknown key → warns / clean → silent / missing-or-unknown-brain → graceful), all 380 config-loading tests green; ruff + pyright clean.
  • No committed configs touched — this PR only adds the signal.

What it surfaces (follow-ups, out of scope here)

Scanning all configs through the new check finds ~71 configs with dropped keys. The notable one: normalize_advantages on 60+ mlpppo configs — and mlpppo has no advantage normalization at all (computes GAE, never normalizes), so that knob has been silently ignored project-wide. Tracked separately (see linked issue) — decide whether to implement advantage normalization or strip the dead key. The T7 mlpppo C3 config's dead entropy-schedule keys are cleaned in the T7 ranking PR.

ðŸĪ– Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Configuration loading now scans brain.config and warns about unrecognized keys, helping surface typos or unsupported settings earlier.
    • Warnings are only emitted for well-formed brain.config blocks, and are gracefully skipped when the brain name is unknown or the configuration is missing/malformed.
  • Tests

    • Added coverage to verify warning emission for unknown brain.config keys, no warnings for recognized keys, and safe behavior when the brain section is absent, incomplete, unknown, or not a dictionary.

Unknown keys under brain.config are silently dropped when the YAML is parsed
into the brain config model (Pydantic ignores extras), so a typo'd or dead
hyperparameter no-ops without any signal — e.g. the T7 mlpppo C3 config set
entropy_coef_end / entropy_decay_episodes, but mlpppo does not implement an
entropy schedule, so it ran flat the whole time and nobody noticed.

load_simulation_config now compares the raw YAML brain.config keys against the
resolved brain config class's fields and logs a warning listing any dropped
keys. Surfaces the dead param at load instead of letting it silently no-op.

(A repo scan via this check finds ~71 configs with dropped keys — notably
`normalize_advantages` on 60+ mlpppo configs, which mlpppo never implemented.
Those are pre-existing and cleaned separately; this change only adds the
signal.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

â„đïļ Recent review info
⚙ïļ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 38930c59-3820-4e4d-ab25-bc3e8709a504

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between db4d134 and 453a379.

📒 Files selected for processing (1)
  • packages/quantum-nematode/tests/quantumnematode_tests/utils/test_config_loader.py

📝 Walkthrough

Walkthrough

load_simulation_config now calls a new helper _warn_unknown_brain_config_keys before constructing SimulationConfig. The helper resolves the brain config class via BRAIN_CONFIG_MAP and emits a logger.warning when brain.config contains keys absent from model_fields. Tests cover warning, silence, and malformed-input cases.

Changes

Unknown brain config key warnings

Layer / File(s) Summary
Helper implementation and call site
packages/quantum-nematode/quantumnematode/utils/config_loader.py
Adds _warn_unknown_brain_config_keys which resolves the brain config class via BRAIN_CONFIG_MAP, computes the set difference between raw YAML keys and model_fields, and emits a logger.warning; load_simulation_config calls this helper on the parsed YAML prior to SimulationConfig(**data).
Tests
packages/quantum-nematode/tests/quantumnematode_tests/utils/test_config_loader.py
Imports _warn_unknown_brain_config_keys and adds TestUnknownBrainConfigKeyWarning covering: warning on unrecognized keys (including multiple), silence on clean configs, and graceful no-op for missing/invalid/unknown brain blocks or absent brain.config.

Estimated code review effort

ðŸŽŊ 2 (Simple) | ⏱ïļ ~10 minutes

Possibly related issues

Poem

🐇 Hippity-hop through configs so wide,
A sneaky unknown key tried to hide!
But the loader now squints with a warning bright,
"That field's not mine!" — and it calls it out right.
No silent ignoring, the rabbit insists,
Unknown keys surface — none shall be missed! ðŸŒŋ

ðŸšĨ Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(config): warn on unrecognized brain.config keys at load time' clearly and concisely summarizes the main change—adding a warning mechanism for unrecognized keys in brain configuration during loading.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏ïļ Tip: You can configure your own custom pre-merge checks in the settings.

âœĻ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧊 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch openspec/warn-unknown-brain-config-keys

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

ðŸĪ– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/quantum-nematode/quantumnematode/utils/config_loader.py`:
- Around line 2536-2542: The docstring for the function starting with "Warn
about ``brain.config`` keys..." does not follow the required NumPy-style format.
Reformat the docstring to include the required structured sections: add a
Parameters section that documents all function arguments with their types and
descriptions, and add a Returns section that documents what the function
returns. Preserve the existing summary and extended description content, but
structure them according to NumPy docstring conventions which require these
standard sections for complete documentation.
🊄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

â„đïļ Review info
⚙ïļ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 234055e8-6080-4a74-b209-0f7a511d1d3d

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between b02ed85 and db4d134.

📒 Files selected for processing (2)
  • packages/quantum-nematode/quantumnematode/utils/config_loader.py
  • packages/quantum-nematode/tests/quantumnematode_tests/utils/test_config_loader.py

Comment on lines +2536 to +2542
"""Warn about ``brain.config`` keys the brain's config class does not declare.

Unknown keys are silently dropped when the YAML is parsed into the brain config
model (Pydantic ignores extras), so a typo'd or dead hyperparameter — e.g. an
entropy-schedule key on a brain that does not implement the schedule — passes
without effect. Comparing the raw YAML keys against the resolved brain config
class's fields here surfaces them at load time, before they silently no-op.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | ðŸŸĄ Minor | ⚡ Quick win

Docstring does not follow required NumPy-style format.

The coding guidelines require NumPy-style docstrings for functions. The current docstring provides a summary and extended description but is missing the structured Parameters and Returns sections.

📝 Proposed NumPy-style docstring
-def _warn_unknown_brain_config_keys(data: object, config_path: str) -> None:
-    """Warn about ``brain.config`` keys the brain's config class does not declare.
-
-    Unknown keys are silently dropped when the YAML is parsed into the brain config
-    model (Pydantic ignores extras), so a typo'd or dead hyperparameter — e.g. an
-    entropy-schedule key on a brain that does not implement the schedule — passes
-    without effect. Comparing the raw YAML keys against the resolved brain config
-    class's fields here surfaces them at load time, before they silently no-op.
-    """
+def _warn_unknown_brain_config_keys(data: object, config_path: str) -> None:
+    """
+    Warn about ``brain.config`` keys the brain's config class does not declare.
+
+    Unknown keys are silently dropped when the YAML is parsed into the brain config
+    model (Pydantic ignores extras), so a typo'd or dead hyperparameter — e.g. an
+    entropy-schedule key on a brain that does not implement the schedule — passes
+    without effect. Comparing the raw YAML keys against the resolved brain config
+    class's fields here surfaces them at load time, before they silently no-op.
+
+    Parameters
+    ----------
+    data : object
+        Raw YAML-loaded data, expected to contain a ``brain.config`` dict.
+    config_path : str
+        Path to the configuration file, used in the warning message.
+
+    Returns
+    -------
+    None
+    """
ðŸĪ– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/quantum-nematode/quantumnematode/utils/config_loader.py` around
lines 2536 - 2542, The docstring for the function starting with "Warn about
``brain.config`` keys..." does not follow the required NumPy-style format.
Reformat the docstring to include the required structured sections: add a
Parameters section that documents all function arguments with their types and
descriptions, and add a Returns section that documents what the function
returns. Preserve the existing summary and extended description content, but
structure them according to NumPy docstring conventions which require these
standard sections for complete documentation.

Source: Coding guidelines

@chrisjz
chrisjz merged commit 3a84261 into main Jun 23, 2026
2 of 3 checks passed
@chrisjz
chrisjz deleted the openspec/warn-unknown-brain-config-keys branch June 23, 2026 09:10
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

ðŸ“Ē Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant