Repository navigation
Description
Problem
Kimi Code (api.kimi.com/coding) serves its flagship K3 model under the bare id k3. The live catalog correctly reports context_length = 1048576, and the provider instance's own context_window() (openrouter_provider_impl.rs) already honors it via the models cache / disk cache. But every global resolution path — the TUI context meter (update_context_limit_for_model), compaction budget derivation, model switching — goes through context_limit_for_model_with_provider → CONTEXT_LIMIT_CACHE + static classifiers, which resolve k3 to DEFAULT_CONTEXT_LIMIT (200K).
Symptom: status bar shows 41k/200k while running k3; compaction budgets are derived from a window ~5x too small.
Repro: configure default_provider = "kimi", default_model = "k3" with a valid KIMI_API_KEY, start jcode, look at the context indicator.
Root causes
- Direct OpenAI-compatible profile catalogs (
kimi_models.json, Moonshot, Z.AI, ...) never seed the globalCONTEXT_LIMIT_CACHE— only the Anthropic/OpenAI OAuth catalogs and[providers.*]config (jcode does not adhere to custom context limit #421/Configured context_window is ignored for GPT models in named providers #541) do. Thecontext_lengthvalues are read for route building and dropped. open_weight_family_context_limitonly matches ids containingkimi(K2 family, 256K), so the barek3id falls through to the 200K default even with no catalog involved.
Workaround (confirmed working)
A [providers.<anything>] config profile pinning context_window = 1048576 for k3 seeds the cache via populate_context_limits_from_config.
Proposed fix (ready patch + tests)
Branch: https://github.com/wiktorwiesek/jcode/tree/fix/kimi-k3-context-window
Compare: master...wiktorwiesek:jcode:fix/kimi-k3-context-window
jcode-base: when building routes from a direct profile's catalog disk cache, seed the global context-limit cache from each entry'scontext_lengthunder the same key shapes as config seeding (bare id +<profile>:<id>). Extracted as a pure, unit-tested helper.jcode-provider-core: add the Kimi K3 family toopen_weight_family_context_limit:k3/kimi-k3→ 1,048,576;k3-256k→ 262,144 (checked before the broader K2kimimatch; the dynamic cache still wins when populated).
Tests: new unit tests in both crates; cargo test -p jcode-base --lib provider:: -- --test-threads=1 → 159 passed, 0 failed; cargo test -p jcode-provider-core all pass; clippy clean.
(I could not open a PR — createPullRequest returns FORBIDDEN for my account on this repo, while issues work — so per CONTRIBUTING.md I'm filing this as an issue with the ready patch as reference. Happy to open the PR if access is sorted out.)
Unrelated pre-existing flake noticed while testing
provider::tests::test_available_models_display_uses_route_models_and_filters_placeholder_rows fails under parallel test execution on a machine with a populated ~/.jcode and provider API keys in the environment — on clean master too (passes with --test-threads=1). It reads env-derived global state without the test-env lock.
Activity
1jehuang commentedon Jul 24, 2026
Fixed the classifier half of this:
open_weight_family_context_limitnow mapsk3/kimi-k3to 1,048,576 andk3-256kto 262,144, checked before the broader K2kimimatch, socontext_limit_for_model("k3")resolves to 1M on the global path used by the TUI meter and compaction budget. Regression tests added (cargo test -p jcode-provider-core: 106 passed). The broader catalog-seeding half (direct OpenAI-compatible profiles seeding CONTEXT_LIMIT_CACHE fromcontext_length) is tracked with #578, which is the same recurring shape. Thanks for the thorough writeup and the ready patch.— Jcode agent (automated triage), on behalf of @1jehuang
1jehuang commentedon Jul 24, 2026
Note: the fix is committed on branch
triage/2026-07-24-batch(pushed). GitHub's pull-request creation API is currently returning 500s repo-wide, so the PR link will follow once that clears.— Jcode agent (automated triage), on behalf of @1jehuang
1jehuang commentedon Jul 24, 2026
GitHub's PR API recovered: the fix is now in #580.
— Jcode agent (automated triage), on behalf of @1jehuang
fix(models): resolve Kimi K3 (k3) to a 1M context window globally (fixes
1jehuang commentedon Jul 25, 2026
Fixed structurally in
1ce99fa35rather than by adding another prefix entry.All three instances of this bug (#450 Sonnet 5, #577 Kimi K3, #578 Opus 5) shared one shape: a hardcoded prefix list gated context resolution and failed closed at
DEFAULT_CONTEXT_LIMIT(200K), so every new model silently reported a ~5x too-small window until someone edited a list.What changed in
jcode-provider-core:anthropic_context_modenow parses family/version (same approachanthropic_reasoning_capsalready used) instead of matching prefixes, and defaults optimistically toNative1Mfor version 5+ generations.base_is_known_claude_modelaccepts any versionedclaude-*id, so the classifier is consulted rather than skipped for unrecognized ids.anthropic_context_mode_is_verifiedseparates live-probed knowledge from optimistic guesses, establishing an explicit precedence: verified pin > live catalog / user config > optimistic guess, and never the 200K default. Verified 200K-capped models likeclaude-sonnet-4-5still beat the catalog, which over-advertises 1M for them.k3id served byapi.kimi.com/codingis now recognized, and K3+ resolves to its real 1M window instead of the K2-era 256K.The regression tests assert the failure shape, not today's ids: unreleased generations (
claude-opus-6,claude-opus-7-20270101,claude-haiku-5, ...) must never fall back to the default. A future model release should no longer need a code change.fix(models): stop new models resolving to the 200K default (#577, #578)
chore(release): v0.57.0
test(context): add a context-window resolution matrix, and fix the 26…
chore: sync fork with upstream (224 behind), preserve fork commits (#2)
1 remaining item
chore(release): v0.57.0
fix(models): resolve Kimi K3 (k3) to a 1M context window globally (fixes
test(context): add a context-window resolution matrix, and fix the 26…
test(context): add a context-window resolution matrix, and fix the 26…
fix(models): stop new models resolving to the 200K default (1jehuang#577
chore(release): v0.57.0
fix(models): resolve Kimi K3 (k3) to a 1M context window globally (fixes
test(context): add a context-window resolution matrix, and fix the 26…
test(context): add a context-window resolution matrix, and fix the 26…
test(context): add a context-window resolution matrix, and fix the 26…
test(context): add a context-window resolution matrix, and fix the 26…
fix(models): stop new models resolving to the 200K default (1jehuang#577
chore(release): v0.57.0
fix(models): resolve Kimi K3 (k3) to a 1M context window globally (fixes
chore(release): v0.57.0