Skip to content

feat: add contextTokens config for custom model context window (#2075, #2074)#2085

Merged
esengine merged 1 commit into
esengine:mainfrom
zhangyapu1:feat/context-tokens-config
May 28, 2026
Merged

feat: add contextTokens config for custom model context window (#2075, #2074)#2085
esengine merged 1 commit into
esengine:mainfrom
zhangyapu1:feat/context-tokens-config

Conversation

@zhangyapu1

Copy link
Copy Markdown

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

Layer File Change
Config config.ts New contextTokens field + loadContextTokens()
Resolver elemetry/stats.ts New
esolveContextTokens(model) — user config > built-in > 131K
Context mgr context-manager.ts 3 ctxMax lookups →
esolveContextTokens()
CLI status StatusRow.tsx ctxMax lookup updated
CLI observability observability.ts 2 ctxMax lookups updated
CLI ctx card ctx-breakdown.tsx ctxMax lookup updated
CLI App App.tsx 3 ctxMax lookups updated
Desktop protocol protocol.ts contextTokens in SettingsPatch
Desktop App App.tsx contextTokens in Settings type
Desktop settings settings.tsx Context-window size input below custom model ID
Desktop backend desktop.ts Handle contextTokens in settings_save + �mitSettings
i18n �n.ts zh-CN.ts ja.ts de.ts 3 new translation keys each
Tests config.test.ts 4 new loadContextTokens round-trip + validation cases

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. CI red — typecheck fails on maxIterPerTurn. Your branch imports loadMaxIterPerTurn and passes maxIterPerTurn: loadMaxIterPerTurn() in two CacheFirstLoopOptions constructions, but CacheFirstLoopOptions doesn't have that field on main (it's in #2046, which I just requested changes on). Result: desktop.ts(1050,5) and App.tsx(1026,7) fail TS2353. Please drop all maxIterPerTurn changes from this PR — config.ts loader, App.tsx import + call site, desktop.ts import + call site, and the JSDoc on the maxIterPerTurn config field. Those belong to #2046 only.

  2. 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.

…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
@zhangyapu1 zhangyapu1 force-pushed the feat/context-tokens-config branch from 976c587 to 6d884cf Compare May 28, 2026 03:32
@esengine esengine merged commit 0b64723 into esengine:main May 28, 2026
4 checks passed
@zhangyapu1 zhangyapu1 deleted the feat/context-tokens-config branch May 29, 2026 07:44
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.

关于最大上下文的定义 mimo模型上下文不能自动总结

2 participants