fix: honor model-specific context limits for non-Anthropic models#2366
Merged
code-yeongyu merged 4 commits intodevfrom Mar 11, 2026
Merged
fix: honor model-specific context limits for non-Anthropic models#2366code-yeongyu merged 4 commits intodevfrom
code-yeongyu merged 4 commits intodevfrom
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <[email protected]>
There was a problem hiding this comment.
2 issues found across 6 files
Confidence score: 3/5
- There is concrete regression risk:
src/hooks/context-window-monitor.tsstill hardcodes Anthropic-specific limits/messages, which can produce incorrect warning stats (including negative percentages) and misleading guidance for non-Anthropic models. src/hooks/context-window-monitor.model-context-limits.test.tsuses a boolean forAssistantMessage.finishwhere Opencode compatibility expects a string (for example, "stop"), indicating a likely contract mismatch that could surface beyond tests.- Given two medium-severity, high-confidence findings with user-visible impact, this looks like some risk rather than a safe-to-merge change.
- Pay close attention to
src/hooks/context-window-monitor.tsandsrc/hooks/context-window-monitor.model-context-limits.test.ts- model-specific messaging math and message-shape compatibility need correction.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/hooks/context-window-monitor.ts">
<violation number="1" location="src/hooks/context-window-monitor.ts:74">
P2: The warning message output still hardcodes `ANTHROPIC_DISPLAY_LIMIT` (1M) and `CONTEXT_REMINDER`, which will send incorrect stats (e.g., negative percentages) and Anthropic-specific instructions to non-Anthropic models.</violation>
</file>
<file name="src/hooks/context-window-monitor.model-context-limits.test.ts">
<violation number="1" location="src/hooks/context-window-monitor.model-context-limits.test.ts:31">
P1: Custom agent: **Opencode Compatibility**
The `finish` property on `AssistantMessage` should be a string (e.g. `"stop"`), not a boolean.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| sessionID, | ||
| providerID: "opencode", | ||
| modelID: "kimi-k2.5-free", | ||
| finish: true, |
There was a problem hiding this comment.
P1: Custom agent: Opencode Compatibility
The finish property on AssistantMessage should be a string (e.g. "stop"), not a boolean.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/hooks/context-window-monitor.model-context-limits.test.ts, line 31:
<comment>The `finish` property on `AssistantMessage` should be a string (e.g. `"stop"`), not a boolean.</comment>
<file context>
@@ -0,0 +1,90 @@
+ sessionID,
+ providerID: "opencode",
+ modelID: "kimi-k2.5-free",
+ finish: true,
+ tokens: {
+ input: 150000,
</file context>
This was referenced Mar 11, 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.
Summary
context-window-monitorinstead of skipping non-Anthropic modelsdynamic-truncatorresolve provider-aware context limits before falling back to Anthropic-specific limitstool-output-truncatorto passmodelContextLimitsCachethrough and cover the fix with regression testsTesting
bun test src/hooks/preemptive-compaction.test.ts src/hooks/context-window-monitor.test.ts src/hooks/context-window-monitor.model-context-limits.test.ts src/shared/dynamic-truncator.test.ts src/hooks/tool-output-truncator.test.tsbun testbun run typecheckbun run buildSummary by cubic
Honors model-specific context window limits for non-Anthropic providers in warnings, reminder text, and truncation. Fixes missing warnings and incorrect truncation by using cached per-model limits, with tests. Fixes issue 2338.
modelContextLimitsCachewithproviderID/modelID; warns only when a known limit is exceeded.modelContextLimitsCache.Written for commit 7de80e6. Summary will update on new commits.