Problem
When running NCode in BYOK mode against an OpenAI-compatible endpoint whose model has a 1M context window (e.g. OPENAI_BASE_URL=https://api.kimi.com/coding/v1, OPENAI_MODEL=k3 — the endpoint self-reports context_length: 1048576 via /models), auto-compaction triggers at roughly 167k–179k tokens, compacting ~5x earlier than the model requires.
Root cause
getContextWindowForModel() falls back to MODEL_CONTEXT_WINDOW_DEFAULT = 200_000 for any model string that is not Noumena-managed, has no [1m] suffix, and has no capability entry (src/utils/context.ts:12,54-112). The auto-compact threshold derives entirely from this local assumption:
- effective window = window − min(maxOutputTokens, 20_000) summary reserve (src/services/compact/autoCompact.ts:51-56)
- threshold = effective − 13_000 buffer (autoCompact.ts:70,84)
The server-advertised context length is never consulted.
What users can do today
OPENAI_MODEL="k3[1m]" works as a client-side opt-in (context.ts:84-86) and the suffix is stripped before the API call (openAICompatInferenceClient.ts:240) — but this is undocumented for BYOK users and abuses a suffix meant for Anthropic 1M opt-in.
CLAUDE_CODE_MAX_CONTEXT_TOKENS would be the natural knob, but it is gated behind isInternalBuild() (context.ts:62-70), so external builds ignore it.
CLAUDE_CODE_AUTO_COMPACT_WINDOW is a min() cap only — it can lower, never raise (autoCompact.ts:39-45).
Suggested fixes (any of)
- Ungate
CLAUDE_CODE_MAX_CONTEXT_TOKENS for external builds, or
- Read
context_length from the OpenAI-compat /models response and use it as the window for BYOK models, or
- Document
[1m] as the supported way to declare large-context BYOK models.
Environment
- external build, BYOK via
OPENAI_API_KEY + OPENAI_BASE_URL
- model
k3, server-reported context 1,048,576; locally assumed 200,000
Problem
When running NCode in BYOK mode against an OpenAI-compatible endpoint whose model has a 1M context window (e.g.
OPENAI_BASE_URL=https://api.kimi.com/coding/v1,OPENAI_MODEL=k3— the endpoint self-reportscontext_length: 1048576via/models), auto-compaction triggers at roughly 167k–179k tokens, compacting ~5x earlier than the model requires.Root cause
getContextWindowForModel()falls back toMODEL_CONTEXT_WINDOW_DEFAULT = 200_000for any model string that is not Noumena-managed, has no[1m]suffix, and has no capability entry (src/utils/context.ts:12,54-112). The auto-compact threshold derives entirely from this local assumption:The server-advertised context length is never consulted.
What users can do today
OPENAI_MODEL="k3[1m]"works as a client-side opt-in (context.ts:84-86) and the suffix is stripped before the API call (openAICompatInferenceClient.ts:240) — but this is undocumented for BYOK users and abuses a suffix meant for Anthropic 1M opt-in.CLAUDE_CODE_MAX_CONTEXT_TOKENSwould be the natural knob, but it is gated behindisInternalBuild()(context.ts:62-70), so external builds ignore it.CLAUDE_CODE_AUTO_COMPACT_WINDOWis amin()cap only — it can lower, never raise (autoCompact.ts:39-45).Suggested fixes (any of)
CLAUDE_CODE_MAX_CONTEXT_TOKENSfor external builds, orcontext_lengthfrom the OpenAI-compat/modelsresponse and use it as the window for BYOK models, or[1m]as the supported way to declare large-context BYOK models.Environment
OPENAI_API_KEY+OPENAI_BASE_URLk3, server-reported context 1,048,576; locally assumed 200,000