Skip to content

LM Studio fails to handle context overflow gracefully after large tool response #1806

Description

@lucianommartins

Which version of LM Studio?
LM Studio 0.4.11-1

Which operating system?
Linux (but also reproducible on Windows and MacOS)

What is the bug?
LM Studio fails silently and breaks model interactions when a tool response (e.g., a full Wikipedia page) exceeds the configured Context Length of the loaded model.
Instead of warning the user that the context window has been exceeded (e.g., showing 12526/4096 tokens in the input), the app continues processing and causes the model to output either complete garbage text (e.g., Bee<|"|> extraar zerod toara/?) or generic fallbacks like "I am a large language model, trained by Google." without answering the question.

Logs
Here is an example of the garbage output received after a massive tool response was injected:

Bee<|"|> extraar zerod toara/?

To Reproduce
Steps to reproduce the behavior:

  1. Load a model with a default context length set to a low value (e.g., 4096 tokens).
  2. Enable a tool or MCP server (like the Wikipedia tool) that can return a large volume of data.
  3. Ask a question that triggers the tool to fetch a large amount of content (e.g., "Explain Capoeira" which returns ~12k tokens).
  4. Observe that the input tokens indicator in the chat box shows that the limit is exceeded (e.g., 12526/4096).
  5. See the model break and output garbage or an irrelevant generic response without any error warning from LM Studio.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions