fix(opencode): honest context arithmetic for small and unreported model limits - #44898
Open
yanglinfang wants to merge 8 commits into
Open
fix(opencode): honest context arithmetic for small and unreported model limits#44898yanglinfang wants to merge 8 commits into
yanglinfang wants to merge 8 commits into
Conversation
…el limits Three fixes to the budget arithmetic that breaks small local models: - unset/zero limit.context disabled proactive compaction entirely; now a conservative 32k usable window applies, shrunk by a per-session cap learned from provider overflow rejections, with a one-time warning - the compaction reserve was min(20k, maxOutputTokens) — 36%% of a 56k local window; now proportional min(20k, max(2048, 15%% of the window)), with compaction.reserved config keeping absolute priority - unset limit.output was assumed to be 32k, so usable = context - 32000 reached 0 on any window under 32k and compaction re-triggered after every step; now the fallback is window-proportional (25%%, floor 1024) and each request additionally clamps its output budget to the headroom the estimated input actually leaves Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found one related PR (excluding the current PR #44898 which appears in results): Related PR:
However, this is not a duplicate but rather a parent/predecessor PR as part of the same feature split. The current PR is a focused bug fix for context arithmetic that's part of a larger effort to support small/local models. No duplicate PRs found |
6 tasks
This was referenced Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #41372
Second slice of #44242 (being split into small PRs per review feedback; first slice #44895). #41372 is the umbrella issue for the series — if this merge auto-closes it before the remaining slices land, it should be reopened.
Type of change
What does this PR do?
Fixes the context arithmetic that makes opencode unusable with small local models:
limit.contextdisabled compaction entirely. Routers and local providers frequently report 0; sessions then ran straight into provider overflow errors. Now a conservative 32k usable window applies, shrunk further by a per-session cap learned from actual provider overflow rejections (logged once per session).limit.outputwas assumed to be 32k.usable = context − 32000reaches 0 on any window under 32k, so every completed step counts as overflow and compaction re-triggers after every single step. The fallback is now window-proportional (25%, floor 1024), and each request additionally clamps its output budget to the headroom the estimated input actually leaves, so a long history can't push a request over the window.min(20k, max(2048, 15% of window)).compaction.reservedconfig keeps absolute priority and windows ≥133k keep today's 20k unchanged.How did you verify your code works?
New unit suites for the reserve formula, usable-window derivation, learned caps, and the per-request clamp; the changed upstream expectation (
context: 0→ conservative window instead of never-overflow) is updated with both directions asserted. Fullpackages/opencodesuite green on currentdev.End-to-end A/B on the same machine, model (qwen3:4b-instruct via ollama), config (
context: 16384,output: 0), and coding task:Screenshots / recordings
Evidence panels for the A/B run to be attached below (no UI change in the code itself).
before and after fix
Checklist