Skip to content

refactor: centralize model input token limit resolution - #2071

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

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

Conversation

@NarwhalChen

@NarwhalChen NarwhalChen commented Jul 22, 2026

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.

This PR is independent of #2150: it only centralizes input-limit consumption and does not change capability sourcing or catalog fallback behavior.

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.

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

  • Full agent-core suite: 3,999 passed; existing 3 expected failures, 30 skips, and 1 todo unchanged.
  • Full agent-core-v2 suite: 4,084 passed.
  • Full kap-server suite: 797 passed.
  • Combined kosong and SDK suites: 1,567 passed, 1 existing todo.
  • Typechecks passed for kosong, agent-core, agent-core-v2, the SDK, and kap-server.
  • agent-core-v2 domain-layer lint passed for 938 files.
  • Type-aware lint on all touched TypeScript files completed with 0 errors; remaining warnings are on unchanged main lines.
  • git diff origin/main --check passed.

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; no changeset is needed because this is not user-perceivable and does not change behavior.
  • No documentation update is needed because this centralizes existing internal behavior.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: baf1ece

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

…obe/user-shell-command-command-git-p-emz4q4
…obe/user-shell-command-command-git-p-emz4q4
…nd-command-git-p-emz4q4

# Conflicts:
#	packages/agent-core-v2/test/kosong/provider/composition.test.ts
@NarwhalChen

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: baf1ece6b9

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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