feat: add contextTokens config for custom model context window (#2075, #2074)#2085
Conversation
esengine
left a comment
There was a problem hiding this comment.
Solid feature — contextTokens config closes a real gap (#2074 / #2075), the resolver priority is clean (user → built-in → 131K), all six ctxMax call sites get migrated to resolveContextTokens(), desktop settings UI + i18n × 4 are complete, and the validation tests (negative / zero / Infinity / non-number / fractional flooring) are exactly the right ones.
Two things blocking merge:
-
CI red — typecheck fails on
maxIterPerTurn. Your branch importsloadMaxIterPerTurnand passesmaxIterPerTurn: loadMaxIterPerTurn()in twoCacheFirstLoopOptionsconstructions, butCacheFirstLoopOptionsdoesn't have that field onmain(it's in #2046, which I just requested changes on). Result:desktop.ts(1050,5)andApp.tsx(1026,7)fail TS2353. Please drop allmaxIterPerTurnchanges from this PR — config.ts loader, App.tsx import + call site, desktop.ts import + call site, and the JSDoc on themaxIterPerTurnconfig field. Those belong to #2046 only. -
Scope cleanup. Once the maxIter pieces are out, this PR is a clean contextTokens feature with no scope creep. Make sure the rebase leaves only contextTokens + the StatusRow / ctx-breakdown / observability / context-manager / desktop-settings hunks.
Minor (optional): resolveContextTokens(model) runs through decideAfterUsage once per turn and re-reads the config file every time via loadContextTokens → readConfig. Same pattern as other load* helpers so not strictly worse than existing behavior, but if you want to optimize: memoize on configPath with a one-shot invalidation when the desktop settings handler writes a new value. Not required for merge.
CI will go green once the maxIter pieces come out. Rebase, retest, ping me.
e2aac68 to
976c587
Compare
…ine#2075, esengine#2074) Add a user-configurable per-model context-window override so third-party models (e.g. mimo, qwen) no longer fall back to the 131 K default that triggers premature auto-compact. - config: new contextTokens field (Record<string, number>) - stats: new resolveContextTokens(model) — user config > built-in > 131K - context-manager / observability / ctx-breakdown / StatusRow: use it - desktop settings: context-window size input below custom model ID - desktop protocol: contextTokens in SettingsPatch - i18n: en / zh-CN / ja / de strings - tests: 4 new loadContextTokens round-trip + validation cases
976c587 to
6d884cf
Compare
Problem
Third-party models (mimo, qwen, etc.) fall back to DEFAULT_CONTEXT_TOKENS = 131_072 because DEEPSEEK_CONTEXT_TOKENS only hardcodes 4 DeepSeek models. This causes premature auto-compact at ~98K tokens on models with 1M+ windows.
Solution
Add a user-configurable contextTokens field to ~/.reasonix/config.json:
json { "contextTokens": { "mimo": 1000000, "qwen-72b": 131072 } }Resolution priority: user config → built-in table → 131K default.
Changes