Repository navigation
feat(studio): show estimated context usage before model load - #9475
Merged
danielhanchen merged 10 commits intoOct 5, 2026
Merged
danielhanchen merged 10 commits into
danielhanchen merged 10 commits into
Conversation
Show estimated token usage (~char length / 4) when browsing chat histories prior to model load or when exact tokenizer counts are not yet produced. Formats with a leading ~ (e.g. ~900 tokens) to give immediate feedback on context size before loading a model. Fixes unslothai#9330
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…Adapter imports The merge of main into this branch resolved a conflict in runtime-provider.tsx's import block by keeping only the incoming imports from main and this branch's new estimateMessagesTokenCount import, silently dropping two imports still used later in the file (VideoAttachmentAdapter for the video attachment adapter, sanitizeThreadScopedSettings for per-thread settings restore). Reviewed per PR unslothai#9475 feedback.
This comment has been minimized.
This comment has been minimized.
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 5, 2026
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 5, 2026
Member
|
Review record for #9475, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#446. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
danielhanchen
added a commit
that referenced
this pull request
Oct 5, 2026
…ates from (#12747) * Recount harness: bind the loader's msgs that the history restore now estimates from #9475 made the history restore fall back to estimateContextUsage(msgs) when no saved usage is usable. The harness replays that block inside hydrateThreadUsage, which never declared msgs, so every history-hydration case threw 'msgs is not defined' on main. Bind msgs from props, pin the estimate-then-recount behaviour, and guard that every loader local the sliced block reads is declared by the harness. * Recount harness guard: read destructured loader locals too The binding guard only collected 'const name' declarations, so a destructured loader local such as remoteId was never checked. Collect object and array destructuring names as well, and require the guard to see remoteId.
This was referenced Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shows an estimated context usage in the chat header for a stored chat that no model has counted yet, for example when browsing chats before loading a model, so you can see roughly how much context to load it with. The estimate is the selected branch's text length divided by 4 and is shown with a leading
~(~900 tokens,~4.1k tokens, or~900 / 32.8kwhen a window is known).Fixes #9330
Changes
utils/estimate-chat-tokens.ts:estimateContextUsage(records)walks the selected branch with the existingorderBySelectedBranchfrommessage-order.tsand returns a usage snapshot flaggedestimated: true.runtime-provider.tsxhistory loader and the compare-exit restore inchat-page.tsx: when no saved usage matches the active model, the estimate fills the bar instead of leaving it empty.ThreadContextUsageRecount, the status hydrate inuse-chat-model-runtime.ts) treat an estimated bar as blank, so a loaded model still replaces it with the exact count.context-usage-bar-state.ts/context-usage-bar.tsx: estimated faces get the~prefix, no per-turn rows and no limit advice, and the tooltip notes that the number is an estimate without attachments.Before / after
Same stored chat, no model loaded, merge base vs this branch:
Tooltip on hover:
Testing
node --experimental-strip-types --test tests/estimate-chat-tokens.test.ts tests/context-window-visible.test.ts: 21/21 pass. Two of the new bar-state tests fail with the previouscontext-usage-bar-state.ts.npm run typecheckclean. Fullnpm test: 10477/10480 pass. The 3 failures are in unrelated files (reasoning-source-render,tauri-backend-transport-failure), hit timeouts under load, and pass when re-run alone.