Skip to content

fix(auth): resolve kimi-coding-cn pool base_url for sk-kimi- keys - #69409

Open
theone139344 wants to merge 1 commit into
NousResearch:mainfrom
theone139344:fix/kimi-coding-cn-pool-base-url
Open

fix(auth): resolve kimi-coding-cn pool base_url for sk-kimi- keys#69409
theone139344 wants to merge 1 commit into
NousResearch:mainfrom
theone139344:fix/kimi-coding-cn-pool-base-url

Conversation

@theone139344

Copy link
Copy Markdown
Contributor

Summary

  • When credential pool entries use provider kimi-coding-cn with sk-kimi- keys, resolve the correct Coding API base_url so requests do not hit the wrong host.

Test plan

  • Pool entry with kimi-coding-cn + sk-kimi-… resolves api.kimi.com/coding (or configured CN endpoint)
  • Existing kimi-coding path unchanged

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/kimi Kimi / Moonshot area/auth Authentication, OAuth, credential pools sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Jul 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #5908 and #18694: this patch fixes the distinct environment-pool _env_payload path in agent/credential_pool.py; #18694 normalizes persisted entries when they are loaded.

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

Thanks for identifying the environment-pool/runtime mismatch. The implementation matches the existing runtime routing rule: current main only resolves kimi-coding in agent/credential_pool.py:2617, while hermes_cli/auth.py:6954 already resolves both Kimi provider IDs.

Problems

  • The PR has no regression coverage for the changed pool path. tests/hermes_cli/test_api_key_providers.py:916 tests _resolve_kimi_base_url() in isolation, but it does not cover _seed_from_env("kimi-coding-cn", ...), where this defect occurs.

Suggested changes

  • Add a focused test that seeds KIMI_CN_API_KEY=sk-kimi-... through _seed_from_env and asserts the created entry uses KIMI_CODE_BASE_URL; retain a legacy-key assertion for the CN default endpoint.

Automated hermes-sweeper review.

Comment thread agent/credential_pool.py
# kimi-coding-cn's ProviderConfig default is moonshot.cn; without resolve,
# pool persists the wrong base_url → Anthropic /v1/messages 404/401.
# (Carried local fix; upstream only special-cases kimi-coding.)
if provider in {"kimi-coding", "kimi-coding-cn"}:
base_url = _resolve_kimi_base_url(token, pconfig.inference_base_url, env_url)

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.

Please add a regression test for this pool-specific branch: seed KIMI_CN_API_KEY=sk-kimi-... via _seed_from_env("kimi-coding-cn", entries) and assert the entry uses KIMI_CODE_BASE_URL. Existing helper tests do not exercise pool seeding.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 30, 2026
@GottZ

GottZ commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Summary

Seven PRs address or reference the Kimi endpoint-routing complex: #5566, #5669, and #7554 target initial environment-pool seeding; #18694 targets stale persisted entries; #69409 extends environment-pool seeding to kimi-coding-cn; and #10525/#10534 cover related CN runtime resolution. The evidence shows that persisted-pool normalization and CN environment-pool seeding are distinct remaining paths, while the original kimi-coding seeding fix is already represented on main by commit 4d1b988.

Related pull requests

Duplicates

#5566 and the kimi-coding portion of #5669 are functionally identical; #7554 repeats that same routing change while adding separate token-sanitization logic. #18694 and #69409 are complementary, not duplicates: they cover persisted-entry loading and environment-pool seeding respectively; #10534 is the merged runtime-resolution subset of #10525.

Suggested consolidation

Keep #69409 open with a salvage path: add the contributor-requested _seed_from_env("kimi-coding-cn", ...) regression tests for both KIMI_CODE_BASE_URL selection and legacy CN-default preservation. Keep #18694 open separately as the recorded best fix for #5908, but require it to preserve non-default stored URLs, integrate with current profile/global fallback semantics, and add pool-to-runtime coverage; leave #5566, #5669, #7554, and #10525 closed, with #10534 retained as the merged CN runtime reference.

Cross-PR triage: Reviewed 7 pull requests and 2 issues in this complex. Diffs were read for 5 of 7 PRs (rest unavailable); Assessment working set: 12 kB of PR diffs, 15 kB of issue/PR text, 5 kB of discussion (11 comments), 10 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

_seed_from_env only called _resolve_kimi_base_url for kimi-coding, so
kimi-coding-cn pool entries stayed on moonshot.cn and sk-kimi- keys got 401.
Mirror the global+cn set used by resolve_api_key_provider_credentials.
@theone139344
theone139344 force-pushed the fix/kimi-coding-cn-pool-base-url branch from 82fe56a to c9dc828 Compare August 9, 2026 10:23
@theone139344

Copy link
Copy Markdown
Contributor Author

Rebased onto latest origin/main (3f832978d) after local re-verify 2026-08-09.

Why still needed: _seed_from_env still only special-cases kimi-coding on main; kimi-coding-cn pool entries stay on api.moonshot.cn/v1, so sk-kimi- keys get 401 and fallback looks like “all models dead”.

Local acceptance (live chat):

  • kimi-coding-cn / k3 + kimi-for-coding → HTTP 200 via https://api.kimi.com/coding (anthropic_messages)
  • Diff scope: only agent/credential_pool.py (+4/-1)

Please re-run CI.

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

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/kimi Kimi / Moonshot sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants