Skip to content

fix(config): fix bad config for providers or keys that cotains dots (self-defined) - #1661

Merged
lizhengfeng101 merged 4 commits into
alibaba:mainfrom
wu21-web:fix-config
Oct 16, 2026
Merged

lizhengfeng101 merged 4 commits into
alibaba:mainfrom
wu21-web:fix-config

Conversation

@wu21-web

@wu21-web wu21-web commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Description

#1660

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)

No other tests applicable.

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
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Codex + ChatGPT 6.1 Sol high effort wrote tests.

Related Issues

Closes #1660

@wu21-web wu21-web changed the title fix(config): Fix config setters for provider names containing dot fix(config): fix bad config for providers or keys that cotains dots Oct 6, 2026
@wu21-web wu21-web changed the title fix(config): fix bad config for providers or keys that cotains dots fix(config): fix bad config for providers or keys that cotains dots (self-defined) Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@6639835 6639835 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.

Reviewed complete two-file diff plus config dispatch/setter at 70caa625. Suffix parsing preserves dotted provider names while callers constrain the prefix; incomplete paths are rejected and preset routing remains. Tests cover both prefixes, field preservation and invalid paths. No actionable issue found. Static review only; Go tests were not run.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Overall: The direction is right — field names never contain dots, so splitting providers.<name>.<field> on the last dot is unambiguous for any name. Two concerns: the rewritten guard is weaker than what it replaced, and the same logic in both IDE extensions wasn't updated.

1. cmd/opencodereview/config_cmd.go:998 (medium) — weakened validation lets degenerate names through

dot <= len("providers.") only proves one character sits between the prefix and the last dot; it no longer rejects what parts[1] == "" used to catch. Verified on the patched build:

$ ocr config set providers.anthropic..url https://x
Set providers.anthropic..url = https://x     # creates custom_providers["anthropic."]
# before this PR: unknown provider field ".url"

One mistyped dot now silently writes a junk provider instead of configuring the anthropic preset. Same for providers..a.url (name ".a") and providers. .url (name " "). Suggest rejecting a name that is empty after strings.TrimSpace, or that starts/ends with ..

2. cmd/opencodereview/config_cmd.go:1017 (medium) — same gap, plus the preset-conflict guard is bypassed

custom_providers.anthropic..url yields name "anthropic.", which llm.LookupProvider does not recognize, so the "conflicts with a preset provider" error never fires and a near-miss duplicate of a preset name gets stored.

3. cmd/opencodereview/config_cmd_test.go:424 (low) — tests miss exactly the regressed shapes

TestSetConfigValueProviderEntryInvalidPath covers providers., providers.anthropic, providers..url and the trailing-dot forms, but none of providers.anthropic..url, providers..a.url, providers. .url — so the suite passes on the cases the new guard stopped catching.

4. extensions/vscode/src/extension/services/configDraft.ts:67 (medium) — CLI and VS Code now diverge

Still key.split('.') with if (parts.length !== 3) return;. Since ConfigService.testWithEntries builds the temp-HOME config from applyConfigEntries, naming a gateway mimo-v2.6-flash in the webview drops every custom_providers.mimo-v2.6-flash.{protocol,url,model,api_key} entry from the draft: "Test connection" fails with an unconfigured provider while the subsequent save now succeeds. extensions/frontend/src/shared/configUtils.ts:123 interpolates the raw name with no dot restriction, so this is reachable from the UI.

5. extensions/idea/src/main/kotlin/com/alibaba/opencodereview/idea/services/ConfigDraft.kt:121 (medium) — same defect in the IDEA port

setProviderValue uses key.split('.') with if (parts.size != 3) return, and line 152 does the same for custom_providers., feeding the draft at ConfigService.kt:156. Dotted names are dropped with no error.

6. cmd/opencodereview/config_cmd.go:1052 (low) — setMCPServerValue left inconsistent

It keeps strings.SplitN(key, ".", 3), so ocr config set mcp_servers.github.v2.type stdio still fails with unknown MCP server field "v2.type" — even though runConfigUnset already handles dotted server names via SplitN(key, ".", 2). Same bug class as this PR fixes, one function below.

Minor: for a mistyped nested path like providers.anthropic.extra_body.temperature, the error degrades from unknown provider field "extra_body.temperature" to "temperature", hiding what the user actually typed.


On the AI/LLM disclosure: the PR description checks "I did not use AI/LLM to create this PR" while the disclosure section also says Codex + ChatGPT wrote tests. Please make this consistent — per AGENTS.md, state the tools/models you used and confirm you reviewed the generated code yourself, rather than checking the "did not use" box.

@wu21-web

wu21-web commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@lizhengfeng101 To be exact, the option is

I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

It has a "or I disclosed the tool/model below and ...". I did that.

@NanaseInori NanaseInori 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.

Splitting at the final dot correctly preserves dots within provider names for both configuration prefixes. The regression exercises all supported provider fields and checks that values land under the intended custom-provider key. No blocking issue found in this CLI fix.

This does not by itself establish dotted-name support in the IDE draft/connection-test builders; that can be followed up separately rather than expanding this setter fix.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@wu21-web Thanks for the fix and the regression tests! Splitting at the last dot makes sense, but it also turns some previously invalid paths into successful writes. For example:

ocr config set providers.openai.extra_body.model some-model

Previously, this failed with an unknown-field error. With this change, it silently creates a custom provider named openai.extra_body, rather than modifying OpenAI’s configuration. An accidental extra dot, such as providers.openai..url, can similarly create a provider named openai..

Would you be open to the following approach?

  • Require dotted provider names to exist before setting their fields, for both providers.* and custom_providers.*. Users could explicitly create/select one through ocr config set provider <name> first. Keep implicit creation unchanged for dot-free names.
  • Reject leading, trailing, and consecutive dots in provider names, consistently at creation and field-setting entry points.
  • Add regression tests confirming that rejected writes leave the configuration unchanged and return a non-zero CLI exit status, while explicitly created dotted names remain configurable.

This would retain support for names like mimo-v2.6-flash and foo.api_key, while preserving fail-fast behavior for unintended new entries.

The trade-off is that configuring a new dotted name becomes a two-step operation, and config set provider also changes the active provider. An already configured openai.extra_body would still be addressable intentionally.

Does this direction seem reasonable to you, or do you see a better way to distinguish intentional dotted names from malformed paths?

@wu21-web

Copy link
Copy Markdown
Contributor Author

Thanks! I saw your response but I don't have enough time to address. Might do this this week.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

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 8eb8334 into alibaba:main Oct 16, 2026
18 checks passed
@wu21-web
wu21-web deleted the fix-config branch October 16, 2026 09:37
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.

Nested config set cannot address provider names containing dots, yet provider still creates them

4 participants