openclaw - ✅(Solved) Fix fix(context-overflow-diag): jinja template "No user query" errors are misclassified as context overflow [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#68868Fetched 2026-04-19 15:06:44
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

When an upstream LLM provider (in our case LM Studio + Qwen3) returns a Jinja prompt-template rendering error such as:

Error rendering prompt with jinja template: "No user query found in messages."

OpenClaw's context-overflow-diag classifies it as a context overflow and tells the user to Try /reset. Resetting and replaying the same startup prompt triggers the exact same template error again → user-visible infinite loop.

Error Message

When an upstream LLM provider (in our case LM Studio + Qwen3) returns a Jinja prompt-template rendering error such as: Error rendering prompt with jinja template: "No user query found in messages." OpenClaw's context-overflow-diag classifies it as a context overflow and tells the user to Try /reset. Resetting and replaying the same startup prompt triggers the exact same template error again → user-visible infinite loop. error_message=Error rendering prompt with jinja template: "No user query found in messages." context-overflow-diag should recognize provider responses matching Error rendering prompt with jinja template (and similar template/serialization errors) and classify them as provider-template-error (or similar). The user-facing message should be something like: The classifier seems to fall through to overflow whenever it can't compute a token count, regardless of the underlying error string. Replacing the model's Jinja chat template with a role-trusting ChatML template (does not parse message content, just emits <|im_start|>{role}\n{content}<|im_end|>\n per message) makes the error go away. But the diagnostic misclassification on OpenClaw's side is independent and should still be fixed.

Root Cause

The current behavior:

  1. Misleads the user about the root cause.
  2. Causes a reset loop because /reset re-sends the same prompt shape that the template can't render.
  3. Hides genuine provider/template bugs behind a generic overflow message.

Fix Action

Fix / Workaround

Workaround we used

PR fix notes

PR #69003: fix(pi-embedded): classify provider chat-template render failures separately from context overflow

Description (problem / solution / changelog)

Summary

  • Add a dedicated classifier for provider chat-template render errors (e.g. HuggingFace/TGI "error rendering prompt with jinja template: No user query found"), so they surface their own template-problem message instead of being misclassified as context overflow.
  • Keep both isContextOverflowError and isLikelyContextOverflowError from matching template render errors, so context-overflow auto-compaction / /reset nudges don't fire for them.

Closes #68868.

Why

When a HuggingFace-compatible backend returns a jinja template render error, the raw text contains "prompt" plus wording that is close enough to existing context-overflow heuristics to be wrongly classified. Users then see "Context overflow: prompt too large for the model. Try /reset…" even though the message is only 6 tokens and the model's chat template is the real problem.

This change adds a narrow, dedicated classifier and surfaces a specific message:

The provider failed to render the model's chat template. This is a model/provider template issue, not a context-overflow problem. Try a different model or switch providers.

It is additive: existing context-overflow and failover paths are unchanged when the new classifier doesn't match.

Test plan

  • pnpm test src/agents/pi-embedded-helpers/provider-error-patterns.test.ts (new unit coverage for isPromptTemplateRenderError, and confirms isContextOverflowError / isLikelyContextOverflowError return false for the jinja variant)
  • pnpm test src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts (confirms formatAssistantErrorText returns the template-issue message and no longer contains "Context overflow" for the jinja error)
  • pnpm check

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts (modified, +10/-0)
  • src/agents/pi-embedded-helpers.ts (modified, +1/-0)
  • src/agents/pi-embedded-helpers/errors.ts (modified, +29/-0)
  • src/agents/pi-embedded-helpers/provider-error-patterns.test.ts (modified, +27/-0)

Code Example

Error rendering prompt with jinja template: "No user query found in messages."

---

provider=lmstudio/qwen/qwen3.6-35b-a3b
error_message=Error rendering prompt with jinja template: "No user query found in messages."
context-overflow-diag: observedTokens=unknown, compactionAttempts=0
→ user message: "prompt too large… Try /reset (or /new)… use a larger-context model."
RAW_BUFFERClick to expand / collapse

Summary

When an upstream LLM provider (in our case LM Studio + Qwen3) returns a Jinja prompt-template rendering error such as:

Error rendering prompt with jinja template: "No user query found in messages."

OpenClaw's context-overflow-diag classifies it as a context overflow and tells the user to Try /reset. Resetting and replaying the same startup prompt triggers the exact same template error again → user-visible infinite loop.

Repro

  • Provider: LM Studio (http://<host>:8888) serving qwen/qwen3.6-35b-a3b
  • Agent: any OpenClaw agent (Mattermost in our case)
  • Action: send /reset (or have the runtime build any startup prompt whose first role: user message begins with System: [...])
  • Observed gateway log (representative):
provider=lmstudio/qwen/qwen3.6-35b-a3b
error_message=Error rendering prompt with jinja template: "No user query found in messages."
context-overflow-diag: observedTokens=unknown, compactionAttempts=0
→ user message: "prompt too large… Try /reset (or /new)… use a larger-context model."

Note observedTokens=unknown and compactionAttempts=0 — this is a clear signal it is not an actual overflow.

Expected behavior

context-overflow-diag should recognize provider responses matching Error rendering prompt with jinja template (and similar template/serialization errors) and classify them as provider-template-error (or similar). The user-facing message should be something like:

The model's prompt template failed to render the messages. This is usually a model/template problem on the provider side, not a context-window issue. Fix the prompt template (e.g. in LM Studio) or switch to another model.

This avoids the misleading Try /reset advice that puts the user in a reset loop.

Why it matters

The current behavior:

  1. Misleads the user about the root cause.
  2. Causes a reset loop because /reset re-sends the same prompt shape that the template can't render.
  3. Hides genuine provider/template bugs behind a generic overflow message.

Pointers (in installed dist)

grep -rE "context-overflow-diag|observedTokens|compactionAttempts" /opt/homebrew/lib/node_modules/openclaw/dist

The classifier seems to fall through to overflow whenever it can't compute a token count, regardless of the underlying error string.

Workaround we used

Replacing the model's Jinja chat template with a role-trusting ChatML template (does not parse message content, just emits <|im_start|>{role}\n{content}<|im_end|>\n per message) makes the error go away. But the diagnostic misclassification on OpenClaw's side is independent and should still be fixed.

extent analysis

TL;DR

The context-overflow-diag classifier in OpenClaw should be updated to recognize and correctly classify provider responses with Jinja template rendering errors as provider-template-error instead of context overflow.

Guidance

  • Review the context-overflow-diag classifier logic to ensure it checks for specific error messages like "Error rendering prompt with jinja template" and classifies them accordingly.
  • Update the classifier to handle cases where observedTokens is unknown and compactionAttempts is 0, to prevent misclassification as a context overflow.
  • Consider adding a new error type provider-template-error to handle such cases and provide a more informative user-facing message.
  • Verify the fix by testing with the provided repro steps and checking the gateway log for the correct error classification and user message.

Example

No code snippet is provided as the issue is more related to the logic of the classifier rather than a specific code snippet.

Notes

The current workaround of replacing the Jinja chat template with a ChatML template may resolve the error but does not address the underlying issue of misclassification by the context-overflow-diag classifier.

Recommendation

Apply a workaround by updating the context-overflow-diag classifier to correctly handle Jinja template rendering errors, as this will provide a more accurate and helpful user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

context-overflow-diag should recognize provider responses matching Error rendering prompt with jinja template (and similar template/serialization errors) and classify them as provider-template-error (or similar). The user-facing message should be something like:

The model's prompt template failed to render the messages. This is usually a model/template problem on the provider side, not a context-window issue. Fix the prompt template (e.g. in LM Studio) or switch to another model.

This avoids the misleading Try /reset advice that puts the user in a reset loop.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix fix(context-overflow-diag): jinja template "No user query" errors are misclassified as context overflow [1 pull requests, 1 participants]