fix: route Kimi coding fallback via Anthropic messages - #25706
Conversation
|
Note: This PR treats |
|
Follow-up after retesting against current I verified the latest upstream behavior in a clean worktree before reducing this patch. Upstream now covers the normal provider-resolution path for Kimi, but two paths still keep Kimi Coding in
Both should route through I also reduced the patch scope after that verification:
On the Local validation on the reduced patch:
|
3e6ba7b to
5ac7a9b
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the direct-init and runtime-fallback paths; both remain unhandled on current main (agent/agent_init.py:441-454 and agent/chat_completion_helpers.py:1363-1380).
Problems
- The new
"/coding" in ...predicates and both new tests include/coding/v1, but the follow-up comment says only bare/codingshould use Anthropic Messages and/coding/v1must remainchat_completions. This needs resolution before the patch can express the intended contract. agent/agent_init.py:989-1028also activates a configured fallback without recomputingapi_mode; it is a sibling fallback path not covered by this PR.- Current main already has a competing
/coding/v1Anthropic classification inhermes_cli/runtime_provider.py:131andtests/agent/test_auxiliary_transport_autodetect.py:37, matching the open #17107 discussion conflict.
Suggested changes
- Establish and test the bare
/codingversus/coding/v1wire contract, then make all agent fallback/init paths use that same exact rule. - Include init-time fallback coverage if its desired transport behavior is the same.
Automated hermes-sweeper review.
| ): | ||
| agent = AIAgent( | ||
| api_key="sk-kimi-test", | ||
| base_url="https://api.kimi.com/coding/v1", |
There was a problem hiding this comment.
This regression encodes /coding/v1 as Anthropic, but the follow-up comment says /coding/v1 must remain chat_completions and only bare /coding should change. Please split the endpoint cases after the transport contract is confirmed.
GottZ
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Summary
Three open PRs address the Kimi fallback transport bug: #25706 covers direct initialization and runtime fallback, #33276 reuses the shared URL detector only in runtime fallback, and #41020 adds provider-wide runtime-fallback classification. All three currently over-classify at least one OpenAI-compatible Kimi or Moonshot route instead of distinguishing the bare api.kimi.com/coding endpoint from /coding/v1 and Moonshot /v1.
Related pull requests
- #25706
related— (+56/-4) — preferred consolidation target, but not merge-ready: it is the only diff covering both direct initialization and runtime fallback with regression tests, yet its substring predicate and tests classify/coding/v1as Anthropic Messages and it omits the sibling init-time fallback path. This aligns with the keep_open review on #25706: establish the exact bare/codingcontract, preserve/coding/v1as OpenAI-compatible, and apply the shared rule to every init/fallback path. - #33276
related— (+10/-0) — duplicate fallback-only approach: it delegates to the shared URL detector, but that detector currently also classifies/coding/v1as Anthropic Messages and the PR adds no regression tests. Despite the keep_open review on #33276, its diff is a narrower subset of #25706 and does not independently resolve the disputed wire contract, so its useful detector-reuse approach should be incorporated into #25706 rather than maintained separately. - #41020
related— (+4/-0) — duplicate with an over-broad fix: provider-identity routing sends allkimi-codingandkimi-coding-cnfallbacks through Anthropic Messages, incorrectly including Moonshot/v1endpoints documented by existing tests as non-Anthropic-wire. Despite the keep_open review on #41020, the diff duplicates only the fallback portion and requires replacement with URL-specific detection plus tests, making #25706 the stronger consolidation target.
Duplicates
#33276 and #41020 substantially duplicate the runtime-fallback portion of #25706; #33276 proposes shared URL-detector reuse, while #41020 uses a broader and incorrect provider-wide branch.
Suggested consolidation
Merge #25706 only after narrowing the contract to bare api.kimi.com/coding, keeping /coding/v1 and Moonshot /v1 OpenAI-compatible, centralizing that URL rule, and covering direct init, runtime fallback, and init-time fallback with positive and negative tests. Then close #33276 and #41020 as superseded duplicates; their keep_open reviews identify real fallback gaps, but their current diffs neither resolve the protocol distinction nor provide broader correct coverage than the amended #25706.
Cross-PR triage: Reviewed 3 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 7 kB of PR diffs, 4 kB of issue/PR text, 6 kB of discussion (6 comments), 1 verify verdict. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
Summary
Why
When a primary provider such as OpenAI Codex is rate-limited, fallback to the Kimi coding provider could incorrectly remain in chat_completions mode. That caused Hermes to create an OpenAI-style client against https://api.kimi.com/coding and hit a 404 instead of using the Anthropic Messages adapter.
Test Plan