Skip to content

fix(provider): widen Kimi anthropic-SDK thinking match to K2.x#739

Merged
Astro-Han merged 1 commit into
devfrom
claude/kimi-anthropic-sdk-k2x
May 18, 2026
Merged

fix(provider): widen Kimi anthropic-SDK thinking match to K2.x#739
Astro-Han merged 1 commit into
devfrom
claude/kimi-anthropic-sdk-k2x

Conversation

@Astro-Han

@Astro-Han Astro-Han commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Widen the transform.ts substring match that enables thinking on Kimi models served over the Anthropic SDK path, so Kimi K2.6 (k2p6) is covered the same way K2.5 already is. Cherry-pick from upstream anomalyco/opencode commit 58232d896 (PR #23696, 2026-04-21).

Why

Upstream widened the Anthropic-SDK Kimi match from K2.5-only to all k2.x ids a month ago. PawWork missed that sync, so on the Anthropic-SDK Kimi path (kimi-for-coding provider), K2.6 requests went out without the thinking block that Moonshot's coding endpoint expects on reasoning models. This is a latent protocol-level gap on a paid Kimi tier.

Note on scope: a user-reported "death loop on Kimi for Coding K2.6" arrived at the same time, and this PR was initially expected to fix it. End-to-end testing on a real Kimi for Coding plan account showed that the death-loop symptom is actually HTTP 429 + rate_limit_error from Moonshot side (a quota / rate-limit issue, not a protocol issue). Builds on this branch send the correct thinking block but still hit 429 when the account is rate-limited. So this PR fixes a real protocol gap but is not the fix for the rate-limit report; that needs separate work on retry behavior and error messaging.

Related Issue

No GitHub issue. The rate-limit UX follow-up will be tracked separately.

Human Review Status

Pending. A human should make the final merge decision after reviewing the final diff and verification evidence.

Review Focus

  • The widened substring matches mirror upstream 58232d896 exactly (k2p5 -> k2p, kimi-k2.5 -> kimi-k2.). The intent is to stay sync-friendly, not to micro-optimize the match shape.
  • The updated negative-case fixtures (kimi-k2-preview, kimi-k2, kimi-k2-thinking) are the only K2-family ids in our snapshot that should still be excluded.

Risk Notes

  • Behavior change only affects models on the Anthropic SDK code path. Today that is kimi-for-coding per models-snapshot.js. OpenAI-compatible Kimi paths (volcengine plan, moonshot.cn, moonshot.ai) are untouched.
  • kimi-k2-thinking returns reasoning content by design and intentionally stays out of this branch; covered by the negative test.

How To Verify

Targeted local checks from the worktree:

bun --cwd packages/opencode test test/provider/transform.test.ts:
  201 pass, 0 fail, 385 expect() calls
bun --cwd packages/opencode test test/provider/provider.test.ts:
  95 pass, 0 fail, 252 expect() calls
bun turbo typecheck:
  5/5 successful (opencode + 4 cached)

Manual desktop verification on a real Kimi for Coding K2.6 account confirmed the request body now includes thinking: { type: enabled, budget_tokens: 16000 } on this branch. Server-side rate-limit behavior is out of scope for this PR.

Screenshots or Recordings

Not applicable; provider-layer change with no UI surface.

Checklist

  • Human review status is stated above as pending, approved, or not required
  • I linked the related issue, or stated why there is no issue
  • This PR has exactly one type label (bug, enhancement, task, or documentation), at least one primary routing label (app, ui, platform, harness, or ci), and exactly one priority label (P0 to P3), or I requested maintainer labeling
  • I described the review focus and any meaningful risks
  • I listed the relevant verification steps and the key result for each
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant
  • I reviewed the final diff for unrelated changes and suspicious dependency changes
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

Cherry-pick from upstream anomalyco/opencode #23696 (commit 58232d896,
2026-04-21). Without this, Kimi for Coding K2.6 (k2p6) on the Anthropic
SDK path never gets `thinking` enabled, the request is rejected by
Moonshot's coding endpoint, and the user is stuck in a 10-attempt retry
loop showing "The engine is currently overloaded, please try again later".

Root cause:
- `kimi-for-coding` uses `@ai-sdk/anthropic` but Kimi is not an Anthropic
  model. Moonshot's coding endpoint requires `thinking: enabled` on K2.x
  reasoning models or it returns a misleading overload-style error.
- The existing transform only matched K2.5 ids (`k2p5`, `kimi-k2.5`,
  `kimi-k2p5`). K2.6 (`k2p6`) had no transform and went out unmodified.

Change boundary:
- transform.ts: substring match widened from `k2p5` -> `k2p` and from
  `kimi-k2.5` -> `kimi-k2.` in two places (variants() and options()).
  Now covers K2.5, K2.6, and future K2.x without further edits.
- transform.test.ts: update the existing "Kimi anthropic thinking" block
  to assert K2.5 and K2.6 both get thinking enabled, while
  `kimi-k2-preview`, `kimi-k2`, and `kimi-k2-thinking` still don't.

Out of scope:
- This PR does not touch the OpenAI-compatible Kimi paths (volcengine
  plan, moonshot.cn, moonshot.ai). Those already have their own
  reasoning_content handling.
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Astro-Han has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f083c27-6013-4756-b3e1-a52f50716b6f

📥 Commits

Reviewing files that changed from the base of the PR and between 18b9429 and 0bd0af3.

📒 Files selected for processing (2)
  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/provider/transform.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/kimi-anthropic-sdk-k2x

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added harness Model harness, prompts, tool descriptions, and session mechanics P2 Medium priority labels May 18, 2026

@github-actions github-actions Bot 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.

Suggested priority: P2 (includes non-doc, non-test paths outside the low-risk bucket).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@Astro-Han Astro-Han added the bug Something isn't working label May 18, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request generalizes the matching logic for Kimi K2 models by replacing specific version strings like 'k2p5' with broader patterns such as 'k2p' and 'kimi-k2.', and updates the test suite to include additional K2.x variants. The reviewer recommends using explicit regular expressions instead of broad string inclusion checks to ensure more robust model identification and avoid unintended matches.

Comment thread packages/opencode/src/provider/transform.ts
Comment thread packages/opencode/src/provider/transform.ts
@Astro-Han

Copy link
Copy Markdown
Owner Author

Re Gemini review on transform.ts:686 and transform.ts:1161:

These two hunks are an intentional verbatim cherry-pick of upstream anomalyco/opencode commit 58232d896 (PR #23696, 2026-04-21). Keeping the same includes(...) substring style — not a regex — is the deliberate trade-off: PawWork is already 4269 commits behind upstream on this layer, and any local micro-optimization here just adds another conflict point on the next sync.

The false-positive surface Gemini is worried about is bounded by what models-snapshot.js actually exposes: the only k2p* ids today are k2p5 and k2p6 under kimi-for-coding, both of which we want matched. If a future model id legitimately contains k2p but should NOT get this branch, that's a model-registry fix at that time, not a precondition for this backport.

Not actioning the suggestion. Resolving the threads.

@Astro-Han Astro-Han merged commit d2cf1c8 into dev May 18, 2026
28 of 29 checks passed
@Astro-Han Astro-Han deleted the claude/kimi-anthropic-sdk-k2x branch May 18, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working harness Model harness, prompts, tool descriptions, and session mechanics P2 Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant