fix: persist moonshot cn endpoint selection (closes #33637)#33651
fix: persist moonshot cn endpoint selection (closes #33637)#33651stakeswky wants to merge 1 commit into
Conversation
Greptile SummaryThis PR attempts to fix Moonshot CN endpoint selection not being persisted in auth profiles, so that provider config reconstruction correctly routes to However, the non-interactive path contains a critical inversion:
The fix is to swap the two Confidence Score: 1/5
Last reviewed commit: e71515a |
| if (resolved.source !== "profile") { | ||
| await setMoonshotApiKey(resolved.key); | ||
| await setMoonshotApiKey(resolved.key, undefined, "cn"); |
There was a problem hiding this comment.
Endpoint metadata swapped with moonshot-api-key-cn branch
This branch handles the non-CN (moonshot-api-key) path — i.e. https://api.moonshot.ai/v1 — but the PR changed it to persist endpoint: "cn". That means users who pick the .ai endpoint will have their profile metadata set to "cn", causing resolveMoonshotFromProfiles to resolve MOONSHOT_CN_BASE_URL (api.moonshot.cn) at runtime — exactly the wrong URL.
Conversely, line 445 (moonshot-api-key-cn branch) still calls setMoonshotApiKey(resolved.key) with no endpoint argument, so the .cn users end up with no metadata and fall back to MOONSHOT_BASE_URL (api.moonshot.ai).
The two endpoint tags are inverted. The fix should be:
| if (resolved.source !== "profile") { | |
| await setMoonshotApiKey(resolved.key); | |
| await setMoonshotApiKey(resolved.key, undefined, "cn"); | |
| if (resolved.source !== "profile") { | |
| await setMoonshotApiKey(resolved.key); | |
| } |
And the moonshot-api-key-cn branch at line 444–445 should be updated to:
if (resolved.source !== "profile") {
await setMoonshotApiKey(resolved.key, undefined, "cn");
}Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/onboard-non-interactive/local/auth-choice.ts
Line: 421-422
Comment:
**Endpoint metadata swapped with `moonshot-api-key-cn` branch**
This branch handles the non-CN (`moonshot-api-key`) path — i.e. `https://api.moonshot.ai/v1` — but the PR changed it to persist `endpoint: "cn"`. That means users who pick the `.ai` endpoint will have their profile metadata set to `"cn"`, causing `resolveMoonshotFromProfiles` to resolve `MOONSHOT_CN_BASE_URL` (`api.moonshot.cn`) at runtime — exactly the wrong URL.
Conversely, line 445 (`moonshot-api-key-cn` branch) still calls `setMoonshotApiKey(resolved.key)` with no `endpoint` argument, so the `.cn` users end up with no metadata and fall back to `MOONSHOT_BASE_URL` (`api.moonshot.ai`).
The two endpoint tags are inverted. The fix should be:
```suggestion
if (resolved.source !== "profile") {
await setMoonshotApiKey(resolved.key);
}
```
And the `moonshot-api-key-cn` branch at line 444–445 should be updated to:
```ts
if (resolved.source !== "profile") {
await setMoonshotApiKey(resolved.key, undefined, "cn");
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e71515aa28
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| if (resolved.source !== "profile") { | ||
| await setMoonshotApiKey(resolved.key); | ||
| await setMoonshotApiKey(resolved.key, undefined, "cn"); |
There was a problem hiding this comment.
Keep moonshot-api-key mapped to .ai endpoint in non-interactive flow
In applyNonInteractiveAuthChoice, the moonshot-api-key branch now calls setMoonshotApiKey(resolved.key, undefined, "cn"), which persists CN endpoint metadata for the .ai auth choice. When provider config is later rebuilt in resolveImplicitProviders, that metadata switches Moonshot to https://api.moonshot.cn/v1, so non-interactive setups that selected .ai can be routed to the wrong endpoint and fail authentication.
Useful? React with 👍 / 👎.
Closes #33637
Problem
Moonshot .cn onboarding could still resolve to the default Moonshot .ai endpoint at runtime when provider config was reconstructed from auth profiles, causing valid platform.moonshot.cn keys to fail with HTTP 401.
Fix
Persist the Moonshot endpoint selection (cn) in auth profile metadata during onboarding, and use that metadata when resolving implicit Moonshot provider config so .cn selections map to https://api.moonshot.cn/v1 consistently.