Repository navigation
Studio: add /context to show what fills the context window - #13929
Conversation
/context shows, under the last message, how many tokens go to the system prompt, the tools and the messages, and how much is free. Nothing is sent to the model. count_tokens gains a breakdown option for it. API models, which have no local tokenizer, show the last reply's total against the model's catalogued window. The GGUF count now includes what the completion adds after a compaction (the note that older turns were removed, and search_conversation with tools off) and follows the launcher tool default, so it no longer reads low on compacted chats. Fixes unslothai#13921
|
nice feature, and keeping P1
P2
P3
nits: the "System prompt" row also holds template markup, and the bar stays grey while the header ring turns amber and red. fixes for the P1 test and both P2s, with tests, are on the mirror below. Full results, screenshots and a branch to pull from: LeoBorcherding#625 |
# Conflicts: # studio/backend/core/inference/llama_cpp.py # studio/backend/routes/inference.py # studio/backend/tests/test_openai_auto_switch.py # studio/frontend/src/features/chat/api/chat-adapter.ts # studio/frontend/src/features/chat/api/chat-api.ts # studio/frontend/tests/auto-compaction-settings.test.ts
…recheck branch before ring write The usage bar's fixed bg-foreground alphas broke contrast-slider.test.ts. The API report showed a text-length estimate as provider usage. The ring write now checks the branch's message ids, since an edit or rewind mid-count passed every other guard.
… the ring - The nudge is in the prompt only because tools are, so the breakdown's tool-free render leaves it out. Plain counts are unchanged. - The "System prompt" row is now "System": it also holds the template's markup. - The usage bar takes the header ring's severity colors. - Drop the MLX count's checkpoint-recall reopen. It skipped gates the completion applies, and it is outside /context. - The API-model hint says models report token usage, not "their size".
|
Thanks for the careful test pass and the fixes, @LeoBorcherding.
The merge dropped what has since landed on |
|
Pushed
Retested at |
…ty chat The report was bare text under the reply, so it read as part of the assistant message. On a new chat with no messages it floated below the welcome screen, far from anything; it now asks for a message first.
cs, es-419, fa, id, nl, pl, th, tr, uk, vi and zh-TW had none of the 19 context.* keys, so i18n:check:strict failed.
# Conflicts: # studio/frontend/src/features/chat/external-providers.ts
main's llama-server count memo returns before /apply-template runs, so after a header recount /context showed the system-only prefix as the prompt, and a second /context showed none. A caller that passes on_prompt now bypasses the memo, like admission counts do.
With audio or video the count left the media out, and a compacted chat on a non-GGUF model was priced as if never compacted; the ring took either number. Images are now refused before the request instead of by the backend. A clip still in the composer is not refused.
2e2c868 to
ac086f5
Compare
|
Merged
The one conflict was @LeoBorcherding heads-up: I force-pushed to clean up the history. Your three commits keep you as author, and before the merge the tree is identical to The backend count tests, typecheck, ESLint, strict i18n and the repo's Python formatter pass. The frontend suite's 6 failures also fail on |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 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". |
# Conflicts: # studio/frontend/src/features/chat/chat-page.tsx # studio/frontend/src/features/chat/external-providers.ts
…tal), the unreachable total-only state and unused strings; trim comments
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9fd640dc2c
ℹ️ 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".
| now.params.checkpoint !== checkpoint || | ||
| branchSignature(readBranch()) !== signature |
There was a problem hiding this comment.
Reject counts when prompt settings change in flight
If the system prompt or tool settings change while /context is awaiting its count, these checks still accept the old result: those setters advance queuedSettingsEpoch without changing the checkpoint, message signature, or contextUsage reference. Consequently, the old breakdown is displayed and its total can overwrite the header ring through recountedTokens, even though it prices different prompt settings. The existing refreshContextUsage guards against this with a captured settings epoch; apply equivalent invalidation here before returning or publishing the count.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5084f678a: countContext now captures queuedSettingsEpoch and drops the count if it moved, as refreshContextUsage does; test added.
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
) Fixes unslothai#16716 The Skills dialog opens only from "Manage skills" in the Skills pill's menu, and the pill is hidden while Skills is off, which is the default until a skill is enabled. Typing `/skills` and pressing Enter now opens the same dialog, with Skills on or off. Like `/rewind`, it is handled in the composer before the model and queue gates, so it is never sent and works with no model loaded. Only the bare command matches: `/skills list`, or `/skills` with an attachment or staged audio, is sent as usual. It reuses `ChatSkillsDialog` and adds no new strings. ## Testing - **`chat-skills-command.test.ts`:** only the bare `/skills` matches, ignoring case and surrounding whitespace. It also checks that `handleSubmit` intercepts it ahead of `shouldBlockSend` and `interceptSend`, clears the composer and opens the dialog. - **Live, in Studio with no model loaded, with Skills on and with Skills off:** `/skills` opened the dialog and cleared the composer. No message was sent and no `/chat/completions` request was made. - Typecheck is clean. ESLint reports nothing new. This touches the same command block in `handleSubmit` as unslothai#13929 (`/context`). I'll rebase whichever lands second. ## Before / after `/skills` typed into a fresh chat with no model loaded, then Enter. Before (merge base `3221ed08b`): it is sent as a prompt, a user message appears and Studio starts loading a model. After (`0fcc25b1f`): the Skills dialog opens, nothing is sent, and the composer stays empty after a reload.  --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: imagineer99 <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
Fixes #13921
/contextType
/contextand press Enter. A report appears on its own card under the last message. It shows how many tokens go to the system turn, the tools and the messages, how many are free, and where automatic compaction starts. "Tools (n)" expands to the tool names, and "Show prompt" shows the exact text the model receives.The report is not a chat message. It is never saved or sent to the model, so the prompt cache is unaffected. The header ring updates to the same total. The report disappears on the next message or
/compact./contextis refused while a reply is running, on an empty chat, and where the header ring's own recount declines: images, audio, video, or a compacted chat on a non-GGUF model. API models have no local tokenizer, so/contextshows a toast saying there is no breakdown; the header ring already shows the provider's total against the catalogued window.How the split works.
/chat/count_tokenstakes a newbreakdown: true. The backend then prices the full prompt, plus the system turn with and without the tools, so the parts always add up to the total. The tool nudge counts under Tools, because it is only there for the tools. After compaction, the split is of the fitted promptmainalready counts. Withoutbreakdown, the count is unchanged.Count fix. The GGUF count now follows the launcher's tools-on default, as the completion and the MLX count already do. Without it, the count priced a tool catalog the model never got.
Live run
unsloth/gemma-4-E2B-it-GGUFUD-Q4_K_XL, Thinking on, on an M-series Mac. MLX is covered by tests, not run live./contextRunning
/contextbetween two turns does not change the next turn. With tools off, it was 65 prompt tokens and 36 cached both with and without/context. With tools on, it was 1,470 and 1,446.Known limitation, not changed here. With tools on, the count includes the model's previous thinking, which the completion drops. Here it counted 1,667, while the next turn sent 1,470 including the new question. The header recount on
mainbuilds the same payload, so I'll look at it separately.Tests
test_openai_auto_switch.py(+5): the parts add up, including the clamp case, and the nudge goes under Tools with or without a system prompt. A plain count still renders once, the shown prompt is the full one, and the launcher-default test fails onmain.test_llama_count_memo.py(+1): a count that asks for the prompt renders it instead of returningmain's memoised count without one.test_mlx_inference_backend.py(+2): the MLX split adds up, puts the nudge under Tools, and returns no prompt. A plain count keeps the nudge when a forced tool narrows the catalog to none.chat-context-command.test.ts(23):/contexttriggers, and it never reaches the send path. An empty chat asks for a message first./compact.Before / after
Same Studio build pair from this PR's merge base and head,
unsloth/gemma-3-270m-it-GGUFUD-Q4_K_XL on CPU, one turn then/context. Before,/contextis sent as a chat message; after, it shows the report card and nothing is sent, and the header ring reads the same 34 tokens.