Repository navigation
Description
Bug Description
A named OpenAI-compatible provider with an explicit per-model context_window can still over-budget context and send a request larger than the provider's actual runtime context.
This appears related to #352 and #366, but still occurs on v0.31.2 when the runtime request model is provider-qualified.
Environment
- jcode:
v0.31.2 (446be1d3) - build time:
2026-06-25 01:41:13 +0000 - OS: Linux x86_64
- Provider type: named
openai-compatible - Backend: llama.cpp OpenAI-compatible server
Config
~/.jcode/config.toml:
[provider]
default_provider = "cachyai-a2000"
default_model = "qwen3.6-35b-a2000-128k"
[providers.cachyai-a2000]
type = "openai-compatible"
base_url = "http://10.15.15.53:8080/v1"
auth = "none"
default_model = "qwen3.6-35b-a2000-128k"
requires_api_key = false
model_catalog = true
[[providers.cachyai-a2000.models]]
id = "qwen3.6-35b-a2000-128k"
context_window = 131072Evidence
Startup logs show the configured context is recognized under the bare model id:
Context limit cache: qwen3.6-35b-a2000-128k = 131k
jcode provider current --provider-profile cachyai-a2000 reports:
requested_provider openai-compatible
resolved_provider cachyai-a2000
selected_model qwen3.6-35b-a2000-128k
However, the failing chat request reports the model as provider-qualified:
Model: cachyai-a2000:qwen3.6-35b-a2000-128k
The request exceeded the actual served context and was rejected by llama.cpp:
OpenAI-compatible chat request failed
Endpoint: http://10.15.15.53:8080/v1/chat/completions
Model: cachyai-a2000:qwen3.6-35b-a2000-128k
Auth: local endpoint (no auth)
Status: 400 Bad Request
Response: {"error":{"code":400,"message":"request (137486 tokens) exceeds available context size (131072 tokens), try increasing it","type":"exceed_context_size_error","n_prompt_tokens":137486,"n_ctx":131072}}
The llama.cpp /v1/models response exposes both runtime and training context:
{
"id": "qwen3.6-35b-a2000-128k",
"meta": {
"n_ctx": 131072,
"n_ctx_train": 262144
}
}Expected Behavior
jcode should not send a prompt larger than the configured/runtime context.
For named OpenAI-compatible profiles, the explicit model config should apply to both:
qwen3.6-35b-a2000-128k
and the provider-qualified runtime id:
cachyai-a2000:qwen3.6-35b-a2000-128k
Also, when reading llama.cpp-compatible catalog metadata, context budgeting should prefer the runtime context:
meta.n_ctx
over the training/architecture context:
meta.n_ctx_train
Actual Behavior
jcode recognizes/cache-logs the configured context under the bare id:
qwen3.6-35b-a2000-128k = 131k
but later sends a request using the provider-qualified id:
cachyai-a2000:qwen3.6-35b-a2000-128k
and allows a prompt of 137486 tokens against a backend with n_ctx=131072.
Suspected Root Cause
The context-limit lookup path appears to miss the configured context_window when the runtime model id is provider-qualified.
Likely mismatch:
cache/config key: qwen3.6-35b-a2000-128k
runtime lookup key: cachyai-a2000:qwen3.6-35b-a2000-128k
This may cause fallback to catalog/default context metadata. With llama.cpp, meta.n_ctx_train can be larger than the actually served meta.n_ctx, so using n_ctx_train for request budgeting can overrun the server.
Suggested Fix
Normalize provider-qualified model ids during context lookup, or try both full and bare ids:
context_limit_for("cachyai-a2000:qwen3.6-35b-a2000-128k")
.or_else(|| context_limit_for("qwen3.6-35b-a2000-128k"))For llama.cpp/OpenAI-compatible model catalogs, prefer runtime context:
configured context_window
> meta.n_ctx
> context_length
> meta.n_ctx_train
n_ctx_train should not be treated as the active served context.
Activity
WarlockSyno commentedon Jun 27, 2026
Fix available on my fork:
WarlockSyno:jcode:fix/issue-403-named-provider-context-window(commit92b778e9).I traced the over-budgeting to two causes:
fork()dropped the per-model config.MultiProvider::fork()runs on every client/session-recovery/compaction/tool/ambient cycle and rebuilt the OpenRouter arm vianew(), which leavesstatic_context_limitsempty — so the configuredcontext_windowwas lost and budgeting fell back to the catalog/heuristic. Fixed withfork_typed(), which clones the configured provider and preservesstatic_context_limits(and all config-derived fields).The catalog parser ignored llama.cpp's
meta. llama.cpp nests context undermeta: { n_ctx, n_ctx_train }, but the parser only read flatcontext_lengthkeys (which llama.cpp omits), so it resolved toNoneand budgeting hit the qwen3 family heuristic (262144) instead of the served runtime context (131072). The parser now prefersmeta.n_ctx> flat keys >meta.n_ctx_train.(The provider-qualified id (
<profile>:<model>) turned out not to be the cause — it's a routing token thatstrip_session_profile_prefixreduces to the bare id before any context lookup.)Couldn't open a PR directly here (permission-restricted on this repo), but the branch is reviewable/compareable at: master...WarlockSyno:jcode:fix/issue-403-named-provider-context-window
fix(provider): preserve named OpenAI-compatible profile across auth r…
1jehuang commentedon Jun 28, 2026
Released in v0.32.0. Run
jcode updateto get it.PwrBank commentedon Jun 29, 2026
Having this issue as well on v0.32.0
Here is my config.toml
Shows a context window of 200K even though I've set it to 131K everywhere. Seems to be pulling it out of the training context value from the model itself.
PwrBank commentedon Jun 29, 2026
Also hitting the over available context size issue...
It hit that around 90K context.
test(context): add a context-window resolution matrix, and fix the 26…
chore: sync fork with upstream (224 behind), preserve fork commits (#2)
fix(provider): preserve named OpenAI-compatible profile across auth r…
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(provider): preserve named OpenAI-compatible profile across auth r…
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…
Match a pinned @Provider variant against the catalog by its base id
fix(kcode): isolate updates and storage; restore configured models (#98)