Skip to content

refactor: centralize model input token limit resolution#2071

Open
NarwhalChen wants to merge 1 commit into
MoonshotAI:mainfrom
NarwhalChen:refactor/model-input-token-limit
Open

refactor: centralize model input token limit resolution#2071
NarwhalChen wants to merge 1 commit into
MoonshotAI:mainfrom
NarwhalChen:refactor/model-input-token-limit

Conversation

@NarwhalChen

Copy link
Copy Markdown

Related Issue

Follow-up to #2036. @RealKai42 identified the duplicated input-limit fallback as a deliberate out-of-scope cleanup.

Problem

Compaction, context validation, session status, and SDK/server projections independently repeated the rule that a model's prompt ceiling prefers max_input_tokens, falls back to max_context_tokens, and uses zero when capability data is unavailable. Keeping that semantic decision at each consumer risks the engine and its status surfaces drifting apart.

What changed

  • Add getModelInputTokenLimit at the model-capability boundary in legacy kosong and in the self-contained v2 contract.
  • Migrate the duplicated v1, v2, SDK, and kap-server consumers while preserving the existing v1/v2 dependency boundary.
  • Cover input-cap precedence, context-window fallback, and unavailable capability data in both contract test suites.
  • Add patch changesets for the bundled CLI and SDK artifacts.

Completion-budget code intentionally continues to use the total context window because it answers a different question: how much output can fit after the prompt.

Verification

  • pnpm --filter @moonshot-ai/agent-core test — 3,978 passed
  • pnpm --filter @moonshot-ai/agent-core-v2 test — 3,951 passed
  • Relevant SDK and kap-server suites — 538 passed when run serially
  • Typechecks passed for kosong, agent-core, agent-core-v2, kimi-code-sdk, and kap-server
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain
  • oxlint --type-aware on all touched TypeScript files — 0 errors
  • git diff --check

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the prior maintainer request and explained the problem above.
  • I have added tests that prove the behavior works.
  • Ran gen-changesets skill and added a changeset.
  • No documentation update is needed because this centralizes existing internal behavior.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1cf8f8c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/kimi-code-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant