Skip to content

fix(ollama): preserve configured context window#26475

Closed
jimmielightner wants to merge 1 commit intoopenclaw:mainfrom
jimmielightner:fix/ollama-context-window
Closed

fix(ollama): preserve configured context window#26475
jimmielightner wants to merge 1 commit intoopenclaw:mainfrom
jimmielightner:fix/ollama-context-window

Conversation

@jimmielightner
Copy link

@jimmielightner jimmielightner commented Feb 25, 2026

Summary

  • keep user-configured contextWindow/maxTokens when merging explicit and implicit provider entries
  • ensures direct Ollama provider can request >128k contexts if configured (e.g., glm-4.7-flash:203k)

Testing

  • patched local install, restarted gateway
  • sent local-model turn and confirmed ollama ps now reports context_length: 202752

Greptile Summary

This PR fixes mergeProviderModels so that user-configured contextWindow and maxTokens values are preserved when merging explicit (user) and implicit (built-in catalog) provider model entries. Previously, the implicit catalog values always won for these fields, which meant users couldn't override the default 128k context window for Ollama models even when the model supported larger contexts.

  • contextWindow and maxTokens now use explicitModel.value ?? implicitModel.value, consistent with the existing reasoning override pattern
  • input field also changed from always-implicit to prefer-explicit, allowing users to override input modality capabilities
  • ...implicitModel spread added as a base layer before ...explicitModel, ensuring new catalog fields propagate automatically while user overrides still take priority
  • No new tests were added for the contextWindow/maxTokens preservation behavior

Confidence Score: 4/5

  • This PR is safe to merge — the change is small, well-scoped, and follows established patterns in the codebase.
  • The logic change is straightforward and consistent with the existing reasoning field override pattern. The ?? operator correctly handles the fallback behavior. The addition of ...implicitModel as a base spread is a sensible improvement. No new tests were added, but the change is low-risk and the existing reasoning override tests still pass. The only minor gap is test coverage for the new contextWindow/maxTokens preservation behavior.
  • No files require special attention — the single changed file has a clear, well-understood merge function.

Last reviewed commit: f8d6b16

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Feb 25, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 54 to 61
return {
...implicitModel,
...explicitModel,
input: implicitModel.input,
input: explicitModel.input ?? implicitModel.input,
reasoning: "reasoning" in explicitModel ? explicitModel.reasoning : implicitModel.reasoning,
contextWindow: implicitModel.contextWindow,
maxTokens: implicitModel.maxTokens,
contextWindow: explicitModel.contextWindow ?? implicitModel.contextWindow,
maxTokens: explicitModel.maxTokens ?? implicitModel.maxTokens,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing test coverage for new merge behavior

The contextWindow/maxTokens override behavior is the core fix of this PR, but no test validates it. The existing preserves-explicit-reasoning-override.test.ts already sets contextWindow: 1000000 in its explicit model config — it would be straightforward to add an assertion there (e.g., expect(m25?.contextWindow).toBe(1000000)) to ensure the explicit context window isn't overwritten by the catalog default (200000). Same for maxTokens and input.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/models-config.ts
Line: 54-61

Comment:
**Missing test coverage for new merge behavior**

The `contextWindow`/`maxTokens` override behavior is the core fix of this PR, but no test validates it. The existing `preserves-explicit-reasoning-override.test.ts` already sets `contextWindow: 1000000` in its explicit model config — it would be straightforward to add an assertion there (e.g., `expect(m25?.contextWindow).toBe(1000000)`) to ensure the explicit context window isn't overwritten by the catalog default (200000). Same for `maxTokens` and `input`.

How can I resolve this? If you propose a fix, please make it concise.

@vincentkoc
Copy link
Member

Superseded by #29205, which includes a scoped preservation strategy for higher explicit token limits while keeping stale-low capability refresh behavior intact.

Credit: @jimmielightner for raising and implementing the configured context-window preservation need in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants