Studio: add rolling context windows for local GGUF chat - #8961
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1949328f57
ℹ️ 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".
…feat/rolling-context-window
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9388a75919
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a97e0ab589
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb4578918f
ℹ️ 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".
…feat/rolling-context-window
…window # Conflicts: # studio/backend/tests/test_gguf_completion_usage.py
for more information, see https://pre-commit.ci
|
Before/after evidence for the rolling context window, from two isolated Studio installs ( Setup, identical on both sides: BEFORE the turn dies: "Message too long: 3219 tokens exceeds the 2048-token context window. Try increasing the Context Length in Model settings, or shorten the conversation.", with a Retry button and no assistant message. AFTER it completes, with the notice and an answer that is still grounded in the kept end of the window. Numbers read back from the same servers that were photographed:
The last row is the one worth pointing at: the saved transcript is the same length on both sides, so the eviction really is request-side only and nothing is deleted or hidden from the thread. The full conversation is still scrolled through in the AFTER screenshot. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b76971675b
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 459558aa79
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90a764f5f9
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60faeefa24
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efa95e08f3
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Before/after evidence for the rolling window, from a twelve-case campaignFull results and images are on #9074, which is stacked on this branch: #9074 (comment) Three findings belong to this PR rather than to the archive, and one of them is a defect I would fix here. The window works and is invisible. In every case, this branch evicts correctly and keeps the chat answering where A boundary that creeps every turn is worse than one that jumps. Compare the two sides of the same 12-turn run: eight boundary moves here against four on the stacked branch, for the same transcript. The sticky boundary plus the headroom ratio is doing real work, and the eight-move case is the shape a user experiences as the chat quietly forgetting a little more on every reply. One real defect, in the error path. When a single message is larger than the whole window, this branch's inline red error says: Measurement notes, in case they are useful for future work: |
|
Confirmed there is no rolling context path in studio/backend/core/inference today, so long local GGUF chats still dead-end at the context limit, and this adds it with turn-aware eviction that keeps system messages and tool pairings intact. Backend CI Repo tests (CPU) is red here and has been intermittent lately, could you take a look and rerun. |
…nslothai#8686 The contract still asserted the literal `const permissionMode = loadPermissionMode();`, which unslothai#8686 removed when it put a chat-scoped override in front of that read. This branch already carries the refactored store, so Repo tests (CPU) cannot pass here or on anything stacked above it. Ported main's replacement rather than dropping the check. The read is still the contract, and it is scoped to the deep-research setter so it cannot be satisfied by the initial-state constant, which is a different property and would keep passing if the read were deleted.
# Conflicts: # tests/studio/test_deep_research_frontend_contract.py
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
pre-commit.ci run |
# Conflicts: # studio/backend/routes/inference.py
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bba75d9627
ℹ️ 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".
| for part in content: | ||
| if not isinstance(part, dict): | ||
| continue | ||
| if part.get("type") in ("image_url", "input_audio", "audio", "input_image"): |
There was a problem hiding this comment.
Recognize input_video before rolling-context preflight
When a local GGUF request includes video_base64, _inject_video_part represents it as an input_video content part, but this media predicate does not recognize that type. Both plain and tool-loop generation therefore run rolling preflight on video prompts even though /apply-template token counting does not include the sampled video tokens; the prompt may be incorrectly certified as fitting, have history unnecessarily removed, or still fail with context_length_exceeded. Include input_video in this media check so video requests retain the intended multimodal skip.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in e99cb75.
_inject_video_part (routes/inference.py:11923) writes {"type": "input_video", ...} into gguf_messages, and that is the same list the fit receives, so the predicate does see it. It listed image_url, input_audio, audio and input_image and not this one.
Added input_video to the check, with a comment saying where the part comes from so the next part type llama.cpp adds is easier to spot. Pinned by extending test_rolling_media_detection_covers_image_and_audio_parts; red before, green after. 223 passed across the overflow, video-simulation and tool-loop suites.
`_inject_video_part` writes llama.cpp's own `input_video` part into the same message list the fit is then handed, and the media predicate did not list it. Video prompts therefore ran the rolling preflight, which is skipped for media precisely because `/apply-template` token counting does not include the sampled video tokens. The prompt could be certified as fitting when it does not, or lose history it never needed to lose, and still fail with context_length_exceeded.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
CI status on this branch, checked against the same jobs on main at this PR's merge base ( Three separate main-side repairs fall out of this, and belong in their own PR rather than here:
|


Summary
truncate_oldestoverflow policy that drops complete oldest turns while preserving system instructions, the active user task, and atomic tool-call/result exchangesSafety
--no-context-shift; token-level KV rotation remains disabledVerification
1592relevant backend tests passed (1skipped)2721frontend tests passednpm run typechecknpm run buildgit diff --checkpassedCloses #7472