Skip to content

fix(config): default context limits to a share of the model window - #671

Open
Jonakss wants to merge 1 commit into
Tarquinen:masterfrom
Jonakss:fix/context-limit-defaults
Open

Jonakss wants to merge 1 commit into
Tarquinen:masterfrom
Jonakss:fix/context-limit-defaults

Conversation

@Jonakss

@Jonakss Jonakss commented Nov 5, 2026 •

Copy link
Copy Markdown

What happens

maxContextLimit / minContextLimit default to absolute token counts
(100000 / 50000), while both already accept a percentage of the model window.

On a 1M-token model at 250k tokens that is 2.5x the default maximum, so
isContextOverLimits() returns overMaxLimit: true on every turn and DCP keeps
injecting:

CRITICAL WARNING: MAX CONTEXT LIMIT REACHED — you MUST use the compress tool now.

…while three quarters of the window are still free.

Reproduced on OpenCode 2.2.5 with a 1M-window model at 250k tokens: the nudge
fires every turn.

Fix

Only the default changes. resolveContextTokenLimit() already resolves "X%"
against state.modelContextLimit, so the plumbing stays untouched.

File Change
lib/config.ts 100000 → "70%", 50000 → "35%"
dcp.schema.json the two property defaults + the compress.default block
README.md config example, with a note on why it is percentage-based
tests/context-limit-defaults.test.ts new regression test

A 128k window resolves to ~90k / ~45k, so small-window behaviour is preserved.
When the window is unknown the percentage resolves to undefined and the nudge
fails open instead of nagging on a guessed budget.

Untouched: nudgeFrequency, iterationNudgeThreshold, nudgeForce, and the
per-model modelMaxLimits / modelMinLimits overrides.

Verification

Case Result
250k tokens, 1M window overMaxLimit: false — was true, this is the bug
750k tokens, 1M window true
80k tokens, 128k window min only
95k tokens, 128k window max
unknown window false — fails open

npm test 119 → 123 pass; typecheck, build and prettier clean.

The regression test asserts the shipped defaults against dcp.schema.json and the
lib/config.ts source rather than the runtime object, because lib/config cannot
be imported under tsx (its jsonc-parser subpath exposes no named exports).
That is pre-existing and stated at the top of the test so the indirection does not
look accidental.

maxContextLimit/minContextLimit defaulted to 100000/50000 tokens: absolute
numbers that only made sense for 128k windows. On models with larger windows
the plugin compares the live token count against those fixed numbers, so a
1M-token model sitting at 250k tokens is reported as 250% of the limit. Every
turn then injects "CRITICAL WARNING: MAX CONTEXT LIMIT REACHED" and pushes
hard compression while three quarters of the window are still free.

The percent form of both knobs already existed and is resolved against
state.modelContextLimit, so only the default had to change: 70% / 35%. A 128k
window resolves to ~90k / ~45k, keeping the behaviour the old numbers were
written for, while large windows now scale instead of tripping early. When the
model window is unknown the percent form resolves to undefined and the nudge
fails open instead of nagging on a guessed budget.

Schema, README and a regression test are updated to match. Per-model
maxContextLimit/minContextLimit overrides, nudgeFrequency and
iterationNudgeThreshold are untouched.

Co-authored-by: Sinder <sinder@kss.local>
@Jonakss

Jonakss commented Nov 5, 2026 •

Copy link
Copy Markdown
Author

Heads-up: CI sequence run locally

Before opening I ran the .github/workflows/pr-checks.yml steps in the checkout:

npm ci --legacy-peer-deps    # ok
npm run format:check         # ok
npm run typecheck            # ok
npm run build                # ok
npm test                     # 123 pass
npm audit --audit-level=high # exit 1

The last one fails with the current lock: 49 vulnerabilities — 13 high, 3 critical
(@opentui/solid, seroval, solid-js).

It is pre-existing. package-lock.json is untouched in this PR:

$ git diff master...HEAD -- package-lock.json package.json
# empty

so master reports exactly the same. Not fixed here because it is a TUI dependency
bump, out of scope for this change.

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.

1 participant