#[OpenClaw] Local Model works in TUI/WebUI, but fails ONLY via WhatsApp with "Context window too smal

1 messages · Page 1 of 1 (latest)

twilit magnetBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

umbral lionBOT
#

That error is coming from the embedded runner (subsystem=agent/embedded). WhatsApp replies go through that path, and it enforces a hard minimum context window of 16k tokens (CONTEXT_WINDOW_HARD_MIN_TOKENS = 16000). If the runner thinks your model is 4096, it will block before it even tries to generate.

Why it can look “inconsistent” vs WebUI/TUI:

  • WebUI/TUI can still “work” even if the model metadata is wrong, because they don’t necessarily hit this “minimum context window” guard the same way.
  • WhatsApp auto-reply does hit it, so mis-detected context is fatal there.

Where the “4096” is coming from (in OpenClaw)

The embedded runner resolves “context window” in this order (docs match the code):

  1. models.providers.<provider>.models[].contextWindow override
  2. model registry contextWindow (from the per-agent models.json)
  3. default (200000)

And then it applies a cap if you set agents.defaults.contextTokens.

Docs: https://docs.openclaw.ai/concepts/session-pruning (see “Context window estimation”)

So the 4096 is almost always one of these:

#
  1. Your config override isn’t being matched (provider id or model id mismatch).
    • The match is strict: it must be the exact provider key and exact modelId.
    • Your log shows the provider id is literally custom-127-0-0-1-5001 (that’s the “auto-generated” custom provider id when you don’t choose one explicitly).
  2. Your per-agent model registry has 4096 in it (this file, not the workspace one):
    • ~/.openclaw/agents/<agentId>/agent/models.json
  3. You’re capping it with agents.defaults.contextTokens: 4096 (or a per-agent override), which will force it down even if the model supports more.

The 1-line thing that will immediately tell us which case it is

Can you paste the full log line including the tail that OpenClaw prints, especially:

  • source=...

It will say source=modelsConfig or source=model or source=agentContextTokens, which directly identifies which layer produced the 4096.

What I’d check/fix next (no guesswork)

  1. Version + config mismatch check
    • openclaw --version
    • openclaw gateway status (make sure you’re editing the same config the daemon is running)