Skip to content

Studio: stop the KV starvation message reading as a context limit on the client - #9417

Merged
danielhanchen merged 1 commit into
mainfrom
studio/starvation-not-context-limit
Aug 23, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio/starvation-not-context-limit

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #9390, which made a mid-stream llama-server failure reach the user with its real cause instead of a generic message. One of the two curated messages it added is worded in a way the chat client re-labels, so on the KV starvation path the user is now shown a confident and specific piece of wrong advice.

What happens

KV_STARVATION_MESSAGE explains that several generations share one pool of KV, and said so with the phrase "because they share one context window".

chat-adapter.ts::isContextLimitError matches on substrings, and "context window" is one of them:

m.includes("context size") ||
m.includes("context shift") ||
m.includes("exceeds the available context") ||
m.includes("message too long") ||
m.includes("context window") ||
(m.includes("n_ctx") && (m.includes("exceed") || m.includes("full")))

So the message matches, and the client toasts "Context limit reached" with, in the no-truncation case that starvation always is, "The conversation has filled the model's context window. Increase Context Length ..., or start a new chat."

Starting a new chat is precisely the wrong move: nothing about the conversation was too long, and a new chat fails the same way for as long as the other generation is running. This is the failure #9390 exists to prevent, reintroduced one layer further out.

The error code cannot rescue it. _classify_llama_generation_error correctly returns None for starvation, so the chunk carries no code, and chat-api.ts rethrows an in-band stream error as new Error(parsed.error.message). The text is all the client ever sees.

The change

Reword the message so it stops colliding with the client heuristic while saying the same thing:

because they all draw on one shared pool of context

"Context Length" is kept, because it names the actual UI control and is not one of the client's markers.

The LlamaStreamError docstring is corrected in the same commit: it cited the removed "context window" phrasing as the reason kv_starvation needs to opt out of _classify_llama_generation_error. The backend heuristic still matches on "context" beside "length", so the opt-out is still required, but the rationale as written no longer described the text.

Tests

TestTheStarvationTextDoesNotReadAsAContextLimitOnTheClient in tests/test_stream_errors.py mirrors the client predicate's substring list and asserts the curated message hits none of it. It also asserts that the raw llama-server wording would have matched, so the test cannot pass vacuously if someone later empties the marker list. Fails before this commit, passes after.

test_stream_errors, test_research_runs_hardening: 193 passed.

Backend-only, matching #9390's scope. The client predicate is left alone deliberately: it is doing its job for the cases it was written for, and loosening it would blunt the genuine oversize path.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 93e932c179

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the starvation text in studio/backend/core/inference/stream_errors.py still trips the "context window" branch of isContextLimitError in chat-adapter.ts, so the user gets the start-a-new-chat advice for a conversation that was never too long. Will get this reviewed.

@danielhanchen
danielhanchen force-pushed the studio/starvation-not-context-limit branch from 93e932c to ed2894c Compare August 23, 2026 01:13
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: ed2894c80e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 1c6a9e0 into main Aug 23, 2026
36 checks passed
@danielhanchen
danielhanchen deleted the studio/starvation-not-context-limit branch August 23, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant