Skip to content

fix(config): warn when active provider shadows llm settings - #588

Merged
lizhengfeng101 merged 4 commits into
alibaba:mainfrom
amh1k:fix/config-warn-shadowed-llm-settings
Jul 30, 2026
Merged

fix(config): warn when active provider shadows llm settings#588
lizhengfeng101 merged 4 commits into
alibaba:mainfrom
amh1k:fix/config-warn-shadowed-llm-settings

Conversation

@amh1k

@amh1k amh1k commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Warns users when they configure llm.* settings while an active provider takes precedence over them.

Adds ocr config unset provider, which clears the active provider and top-level model so OCR can fall back to legacy llm.* configuration. Saved provider entries and credentials remain intact for later reuse.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally

  • Manual testing (describe below)

  • Ran focused configuration and resolver tests:

    go test ./cmd/opencodereview ./internal/llm
  • Ran the full race-enabled suite:

    make test
  • Ran formatting, dependency, and vet checks:

    make check
  • Added test coverage for warnings on shadowed llm.* settings and for ocr config unset provider.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

Closes #583

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)
  • 📝 In summary (no line info): 1 comment(s)

[bug · medium]

📄 cmd/opencodereview/flags.go

⚠️ GitHub could not post this as an inline comment: No line information provided

Bug: The warning always suggests providers.<name>.<field> even when the active provider is a custom provider. For custom providers, the correct config path is custom_providers.<name>.<field>. You should use llm.LookupProvider(provider) (already used elsewhere in this file) to determine whether the provider is built-in or custom, and adjust the suggested prefix accordingly.

💡 Suggested Change

Before:

	return fmt.Sprintf("[ocr] WARNING: provider %q is active and takes precedence over llm.* settings.\n"+
		"[ocr] Use 'ocr config set providers.%s.<field> <value>' to configure the active provider,\n"+
		"[ocr] or run 'ocr config unset provider' to disable provider-based config.\n", provider, provider)

After:

	prefix := "providers"
	if _, isPreset := llm.LookupProvider(provider); !isPreset {
		prefix = "custom_providers"
	}
	return fmt.Sprintf("[ocr] WARNING: provider %q is active and takes precedence over llm.* settings.\n"+
		"[ocr] Use 'ocr config set %s.%s.<field> <value>' to configure the active provider,\n"+
		"[ocr] or run 'ocr config unset provider' to disable provider-based config.\n", provider, prefix, provider)

Comment thread cmd/opencodereview/config_cmd.go Outdated

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice PR — two small issues:

  1. legacyLLMShadowWarning: the strings.ToLower on the key causes false-positive warnings

    The config system is case-sensitive, so LLM.url or Llm.model won't actually set a valid config field. But strings.HasPrefix(strings.ToLower(key), "llm.") still matches them and emits the shadow warning, which is misleading. Should just be strings.HasPrefix(key, "llm.") without the ToLower.

  2. flags.go:282: the unset usage error message lost helpful examples

    The original error text listed examples for both custom_providers.<name> and mcp_servers.<name>. The new version only shows ocr config unset provider as an example, making it harder for users to discover the other unset targets. Consider keeping at least one example per supported key type.

@amh1k

amh1k commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Nice PR — two small issues:

1. **`legacyLLMShadowWarning`: the `strings.ToLower` on the key causes false-positive warnings**
   The config system is case-sensitive, so `LLM.url` or `Llm.model` won't actually set a valid config field. But `strings.HasPrefix(strings.ToLower(key), "llm.")` still matches them and emits the shadow warning, which is misleading. Should just be `strings.HasPrefix(key, "llm.")` without the ToLower.

2. **`flags.go:282`: the unset usage error message lost helpful examples**
   The original error text listed examples for both `custom_providers.<name>` and `mcp_servers.<name>`. The new version only shows `ocr config unset provider` as an example, making it harder for users to discover the other unset targets. Consider keeping at least one example per supported key type.

Done

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 5a7a25d into alibaba:main Jul 30, 2026
7 checks passed
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.

fix(config): warn when llm.* settings are silently ignored due to active provider

3 participants