#13940: fix: suppress low context window warning for explicitly configured models
agents
stale
Cluster:
Context Window Fixes
## Problem
When a model's `contextWindow` is explicitly set in `openclaw.json` (e.g., `2048` for a cheap heartbeat model), OpenClaw still logs:
```
warn agent/embedded low context window: ollama/qwen2.5:7b-2k ctx=2048 (warn<32000) source=modelsConfig
```
This is noise — the user deliberately chose that value.
## Fix
Skip the warning when `source === "modelsConfig"` (user explicitly configured it). The warning still fires for auto-detected (`model` metadata) and `default` sources where the value might be wrong.
`shouldBlock` is **unaffected** — the hard minimum is still enforced regardless of source, so genuinely broken configs are still caught.
## Changes
- `src/agents/context-window-guard.ts`: Added `source !== "modelsConfig"` condition to `shouldWarn`
- `src/agents/context-window-guard.test.ts`: Added test case for explicit modelsConfig with small context window
Closes #13933
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Suppresses low context window warnings when `contextWindow` is explicitly configured in `openclaw.json` via `models.providers.<provider>.models[].contextWindow`. The warning still fires for auto-detected (`model` metadata) and `default` sources where the value might be incorrect.
- Modified `shouldWarn` logic to skip warnings when `source === "modelsConfig"`
- Added test case validating the new behavior
- `shouldBlock` remains unchanged, preserving hard minimum enforcement
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is focused and well-tested with a new test case that validates the fix. The logic correctly suppresses warnings only for explicitly configured models while preserving the hard minimum blocking behavior and warnings for other sources.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23279: fix: show correct context limit in status when runtime model differs
by Imccccc · 2026-02-22
77.3%
#21614: fix: warn when thinking level xhigh falls back for unsupported models
by lbo728 · 2026-02-20
75.6%
#6053: fix: use 400K context window instead of 200K if the model allows (g...
by icedac · 2026-02-01
75.1%
#12220: fix: forward-compat models now respect user-configured contextWindow
by Batuhan4 · 2026-02-09
75.0%
#17604: fix(context): use getAvailable() to prevent cross-provider model ID...
by aldoeliacim · 2026-02-16
74.1%
#16988: fix: always regenerate models.json from gateway config
by MisterGuy420 · 2026-02-15
73.9%
#17647: fix: Display error messages instead of (no output) for non-Claude m...
by MisterGuy420 · 2026-02-16
73.7%
#9739: #9291 fix(models): preserve existing models in models.json when mer...
by ximzzzzz · 2026-02-05
73.4%
#12191: fix: guard against undefined model.input in display and scan layers
by mcaxtr · 2026-02-09
73.3%
#15632: fix: use provider-qualified key in MODEL_CACHE for context window l...
by linwebs · 2026-02-13
73.3%