Skip to content

feat(doctor): deeper config validation — walk-up, overlays, unknown keys#237

Merged
emal-avala merged 1 commit intomainfrom
feat/doctor-extended-config-checks
Apr 24, 2026
Merged

feat(doctor): deeper config validation — walk-up, overlays, unknown keys#237
emal-avala merged 1 commit intomainfrom
feat/doctor-extended-config-checks

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Extends /doctor with deeper config validation. Catches the class of "my config silently did nothing" problems that #[serde(default)] tolerance otherwise hides.

New checks

Check Category Fires when
config:project_file via walk-up Pass/Warn/Fail Project settings found via ancestor walk, reports parse failures
config:project_local_file Pass/Warn/Fail .agent/settings.local.toml overlay detected, reports parse failures
Unknown key detection (all three config files) Warn Top-level section not in the known allow-list — catches typos like [permisions]
env:api_key_precedence Warn Multiple provider API-key env vars set; tells user which ones are being ignored

Known allow-list: api, ui, permissions, features, security, sandbox, mcp_servers, hooks, subagents, allowed_project_dirs.

Example session

Before: user has a sub-crate cwd in a monorepo and a typo'd [permisions] section in the repo-root config — /doctor either misses the file entirely or silently passes.

After:

  ✓ Project config: /repo/.agent/settings.toml
  ! Project config /repo/.agent/settings.toml has unknown key(s): permisions
  ✓ Project local overrides: /repo/.agent/settings.local.toml
  ! Multiple API-key env vars set: OPENAI_API_KEY, ANTHROPIC_API_KEY. Resolver uses the first — others ignored.

Why this matters

#[serde(default)] on the root config struct silently drops unknown fields — the right call at load time (forwards-compat with newer tools writing a shared file) but it converts config typos into total-silent no-ops. The allow-list guard test fails the moment the loader grows a new section without an accompanying /doctor entry, so this stays in sync.

Tests (5 new)

  • Known sections produce an empty unknown-key list
  • Typo section flagged correctly
  • Unknowns sorted for stable output
  • Allow-list completeness guard: fails the moment the loader grows a section that isn't taught here
  • Non-table TOML root is a no-op

Full services::diagnostics suite: 21 pass, 0 fail. Clippy clean.

Test plan

  • cargo test -p agent-code-lib --lib services::diagnostics
  • cargo clippy --workspace --tests --no-deps -- -D warnings
  • cargo fmt --all --check

Extends `/doctor` with checks that catch the class of "my config
silently did nothing" problems:

- **Project-config walk-up**: uses the same ancestor walk the loader
  uses, so a sub-crate session in a monorepo reports the repo-root
  `settings.toml` instead of silently finding nothing. Also reports
  `.agent/settings.local.toml` when present as its own row.

- **Per-file syntax dry-run**: each of user / project / local files
  is parsed separately. A broken file is surfaced as a fail row
  with the parse error, instead of only showing up at the next
  `/reload`.

- **Unknown top-level section detection**: `#[serde(default)]` on
  the root config makes typos silent (`[permisions]` quietly becomes
  a nop). Diagnostics now lists any unknown top-level key against
  an explicit allow-list so those typos get flagged.

- **Env-var precedence warning**: when more than one provider API
  key env var is set, warns which ones are being ignored. The
  resolver is deterministic but the user may not realize the
  others have no effect.

Tests:
- Known sections produce an empty unknown-key list
- Typo section (`permisions`) is flagged
- Unknowns are returned sorted for stable output
- Allow-list guard fails the moment the loader grows a new section
  that isn't taught here
- Non-table TOML root is a no-op (robustness)

Full diagnostics suite: 21 pass, 0 fail. Clippy clean.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit 0ae92ec into main Apr 24, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/doctor-extended-config-checks branch April 24, 2026 04:33
@emal-avala emal-avala mentioned this pull request Apr 24, 2026
4 tasks
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