Skip to content

[Bug]: Ollama context overflow shows cryptic error instead of graceful handling #34005

@joemcurry

Description

@joemcurry

Description

When an Ollama model (specifically ollama/glm-5:cloud in my case) hits its internal context limit, OpenClaw shows a cryptic error message in the TUI instead of handling it gracefully:

run error: Ollama API error 400: {"StatusCode":400,"Status":"400 Bad Request","error":"prompt too long; exceeded max context length by 4 tokens"}
connected | error

Expected Behavior

  1. Proactive prevention: Auto-compact should trigger before hitting the limit (currently waits for idle + 60% threshold, but Ollama's internal limit can be hit before OpenClaw's tracking indicates it's time)
  2. Graceful degradation: If overflow occurs, show a helpful message like "Context limit reached. Starting fresh conversation..." and auto-compact/reset
  3. Recovery: Don't leave the session in an "error" state - either auto-compact and retry, or guide the user to start fresh

Current Behavior

  • Shows cryptic error message
  • Session appears "broken" until user manually starts new conversation
  • Auto-compact doesn't trigger because it waits for idle state

Environment

  • OpenClaw: latest
  • Model: ollama/glm-5:cloud (Ollama Cloud)
  • Surface: openclaw-tui (gateway-client)

Root Cause

  1. OpenClaw's token tracking may not match Ollama's actual context usage
  2. Auto-compact is reactive (waits for idle) rather than proactive
  3. No graceful handling when the 400 error occurs - just surfaces the raw API error

Related Issues

Suggested Fix

  1. Add preflight check before sending to Ollama API
  2. If context would exceed limit, auto-trigger /compact and retry
  3. If still over limit, show helpful message and suggest /new
  4. Improve error message in TUI to be user-friendly

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions