Repository navigation
Studio: keep chat context when switching models - #16493
Conversation
|
@codex review |
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e7a79bf22
ℹ️ 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".
| while len(_unload_kv) > 1 and sum(map(_resume_bytes, _unload_kv)) > _SLOT_SAVE_MAX_BYTES: | ||
| stale.append(_unload_kv.pop(0)) |
There was a problem hiding this comment.
Include idle and swap saves in the retained-cache disk budget
With keep-context and idle unloading enabled, manually unloading model A and then idle-unloading model B leaves saves in both _unload_kv and _kv_resume. This eviction loop only counts _unload_kv, while idle_unload_loop retains B's independently capped save through _set_kv_resume. Two 6 GiB saves therefore remain on disk despite the advertised 10 GB limit, and retained storage can approach twice the configured cap. Enforce a shared budget whenever either cache changes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this one. Each save already has its own 10 GB cap and a free space check before writing, and leftovers are swept on startup, so the worst case is extra disk use, not a failed or wrong restore.
There was a problem hiding this comment.
Changed my mind on this one, fixed in e093bbd. Idle and media swap saves now share the same 10 GB budget with the unload saves, oldest goes first.
| abort.set() | ||
| future.cancel() |
There was a problem hiding this comment.
Delete completed save results before cancelling the future
When a save completes at the timeout boundary, _deliver can set the shielded future's result before wait_for raises TimeoutError. Cancelling that already-completed future does not delete its manifest, and the worker no longer owns cleanup, leaving the cache files untracked on disk. These files evade both budget eviction and purge_kv_resume() when the setting is disabled. Check and delete a completed successful result before cancelling, as the existing save_chat_kv_before_swap handler does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this as is. It needs the save to land in the same loop iteration as the 45s timeout, and the only cost is one orphaned slot file that the startup sweep deletes.
There was a problem hiding this comment.
Fixed in e093bbd. A result that lands at the timeout or a cancel is deleted before cancelling, same as the swap save.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1912d720f8
ℹ️ 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".
| if _chat_account() != _account_id() or _chat_busy(): | ||
| return |
There was a problem hiding this comment.
Check resident ownership for CPU-only unload saves
For a primary GGUF loaded in Manual mode with gpu_layers=0 and no other kept chat model, _load_model_impl deliberately releases its CHAT claim through _release_chat_for_zero_vram_primary (routes/inference.py:19544-19546). _chat_account() then returns None, whereas _account_id() is still an account ID such as "owner", so this guard skips saving even for the caller's idle model with keep-context enabled. These CPU-only chats therefore still reprocess their whole history after every manual switch. Check chat-resident ownership, or provide a safe zero-VRAM ownership fallback, rather than requiring a GPU claim.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping the ownership guard. A gpu_layers=0 primary just falls back to what main does today and reprocesses the history, nothing breaks, and the media swap save uses the same check. CPU-only loads can be a follow-up.
There was a problem hiding this comment.
Fixed in e093bbd. When no CHAT claim is held, a zero VRAM primary is checked against the account that loaded it, so CPU-only chats get saved too.
|
I cancelled the CI runs on this PR for now, since Codex hasn't converged at the current head yet: Codex still has open findings on the head commit. CI here runs on the team's shared runner pool, and it's backed up right now (380+ runs queued), so runs on code that's still changing push everyone else's back. Once Codex says "Didn't find any major issues" on the head commit, one push or a re-run brings CI back. A small ask going forward: hold the push until Codex is clean, and batch follow-up fixes into a single push. Thanks! |
|
@codex review |
1 similar comment
|
@codex review |
|
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". |
Switching to another chat model and back threw away everything the first model had already read, so the next message in a long chat reprocessed the whole history. A 23,000 token chat took 20 seconds before the first word on a T4, and a 100,000 token chat on slower hardware takes around 11 minutes. The cache was only saved on idle unloads and when an image or video model took the GPU.
Unloading a GGUF model from the model picker now saves its chat cache first, under the existing "Keep chat context across unloads" setting and the same 10 GB limit. Loading that model again restores the cache, so the next message only reads what is new. The restore keeps the existing checks, so a changed file, context length or other load setting starts fresh. The save adds a few seconds to the switch, holds other model loads while it runs, and stops after 45 seconds. It is skipped while another request is running or when the chat belongs to another account.
Turning the setting off deletes these saves. Restarting Studio still starts with an empty cache. MLX models, the /v1 auto-switch, a forced /load without an unload and a switch while a reply is generating are not covered by this change, so those still reprocess the history.
Refs #9037