Skip to content

[Bug] Cannot attach image when historical token count exceeds limit, even though post-compaction context has room #10155

Closed

Description

@Dhrhciebcy

Environment

Where are you using Unsloth?

  • Unsloth desktop application
  • Unsloth web UI (unsloth studio)
  • Unsloth CLI
  • Python package or notebook
  • Colab or Kaggle

Operating system and version:

Windows 11

GPU model(s) and accelerator backend:

NVIDIA CUDA

Versions:

  • Unsloth: v0.1.804-beta
  • Package: 2026.8.22
  • Desktop: 0.1.804-beta
  • llama.cpp: custom build (TheTom), commit 30d6881

What happened?

When I attach an image to a chat whose cumulative token count exceeds my configured context window limit, Studio rejects it — even though automatic compaction has already shrunk the active prompt down to a tiny fraction of that limit. The pre-flight check compares the total conversation length since the start against the configured context window, instead of the currently occupied (post-compaction) token count.

Setup that triggers it:

  • Model native max context: 262K tokens
  • Context window I configured for the model: 70K tokens
  • Total chat length (all messages since conversation start): ~288K tokens (i.e. even above the model's own 262K max)

The chat itself is working perfectly: Studio auto-compacts it, so the prompt actually sent to the model is small and well under 70K. The model answers with no trouble at all.

Steps to reproduce:

  1. Start a long-running chat and let it grow past the configured context window limit (e.g. > 70K cumulative tokens). Compaction keeps trimming the active prompt, so the model keeps responding fine.
  2. Attach an image to the next message (or send any new multimodal input).

Expected behavior:

The pre-flight validation should compare against the currently occupied context window — i.e. the size of the prompt after compaction — not the cumulative token count accumulated since the start of the conversation. After compaction my active window is nearly empty, so there is plenty of room for the image and it should be accepted.

Actual behavior:

Studio reports that the context window is exceeded (e.g. 288K > 70K) and blocks the image / the turn, even though the post-compaction active prompt is only a few thousand tokens.

Model and operation involved:

Inference — multimodal image attachment in the Studio chat tab. GGUF model via llama.cpp backend.

Diagnostics and logs

Desktop application

# From the server llama.cpp log:

71.52.897.611 I srv  params_from_: Chat format: peg-native
71.53.138.224 I srv  prompt_get_n: message_spans: last user message: byte_pos=867453, media=0, n_before_user=288033
71.53.139.399 I slot update_slots: id  0 | task 17205 | new prompt, n_ctx_slot = 70144, n_keep = 0, task.n_tokens = 288882
71.53.139.402 E srv    send_error: task id = 17205, error: request (288882 tokens) exceeds the available context size (70144 tokens), try increasing it

Additional context

This is independent of the model's own max context (262K) — it's specifically about the user-configured context window limit being compared against the wrong token count.

The whole point of auto-compaction is that a long-lived chat never "dies": old turns are evicted from the active window while the full transcript stays in the background archive. But because the pre-flight validation measures the cumulative conversation length, any chat that has outlived its configured window becomes permanently unable to accept images (and presumably other multimodal content), regardless of how much free space the active window actually has. This will eventually happen to every long chat using compaction — it's a matter of time before it trips for anyone.

Suggested direction: In the image/multimodal pre-flight check (and any other place that guards on context size), use the effective post-compaction prompt token count rather than the monotonic total-conversation counter, so the guard reflects what will actually be sent to the model

Activity

  1. added
    feature request
    on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfeature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions