Repository navigation
feat(studio): run chats in parallel in the Chat tab - #7455
Merged
Merged
Conversation
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.
Clicking New Chat used to cancel whatever the current conversation was generating. This makes the Chat tab behave like the rest of Studio: leaving a conversation lets it keep going, the sidebar shows which chats are still running, and Stop is per conversation.
unsloth runalready serves with--parallel 4, but plainunsloth studiolaunched llama-server with a single decode slot, so the admission queue serialised every chat regardless of what the UI did. Both entry points now default to the same slot count.Behaviour
Backend
studio/backend/state/active_generations.py: a registry of in-flight generations._TrackedCancelregisters into it, so every streaming path is covered without its own bookkeeping. Entries hold the samethreading.Eventas the existing per-run cancel registry, so cancelling reuses the per-request path instead of inventing a second teardown./loadand/unloadgate on it. The load path checks twice, the second time underinference_lifecycle_gate(), since a chat can start while the request queues.force_cancel_activeon the request cancels instead of raising. The frontend guard is bypassable from a second tab or curl; this one is not.GET /api/inference/active-generationsreturns the running conversations plus the slot count actually in use, so a model swap can name the chats it would interrupt, including runs the current tab cannot see._PARALLEL_DEFAULT_PLAINgoes 1 to 4 instudio/backend/run.pyandunsloth_cli/commands/studio.py, with a test pinning the two together. Loads that do not fit in VRAM still fall back to fewer slots.Frontend
cancelByThreadIdonly ever holds the visible thread'scancelRun(), which is not enough once background chats exist (deleting one, or a confirmed reload).call_0, so two chats mid tool call shared one store entry.Tool approvals
Three problems surfaced by running several chats at once, all from the approval prompt behaving as though only one chat could ever exist.
pythonandterminalnow stream their card while gated.render_htmlstays suppressed, since its card renders the payload.It also fixes a rendering bug that parallel chats surfaced: assistant-ui keys message parts by index, so switching conversations hands the same
MarkdownTextinstance a different message, and Streamdown keeps its parsed blocks in internal state and only extends them while streaming. A conversation could show the previously viewed one's answer until the page was reloaded.Streamdownis now keyed per message.Tool sandboxes were already per conversation and stay that way: the session id a chat sends is its thread id, so
_get_workdirputs each one in its own~/studio_sandbox/<thread id>at mode 0700. Chats inside a project deliberately share the project workspace instead.Tool cards
Streaming a gated call's arguments exposed three more problems in the card itself.
tool_startthat opens the approval prompt was keyed by the approval id, so it opened a second card. Only the second one ever receivedtool_end, leaving the first spinning "Running" for the rest of the conversation. The approval prompt now reuses the card already on screen.Both cells moved inside the collapsible, so one chevron now hides the code together with the output, and Copy / Download exist only while the card is open. A card parked on the prompt says so rather than counting up "Running", which the composer badge already did.
Verification
Playwright against
unsloth/gemma-4-E2B-it-GGUF:UD-Q4_K_XLon one GPU:count: 4, four sidebar spinners./api/inference/cancel. Chat 1 had 3062 characters when it was left and 16225 on return, still streaming./loadand/unloadreturn 409 naming the running thread, the chat keeps streaming through the refusal, and the forced load then ends it.terminalcall and a gatedpythoncall: one card per call rather than two, the whole command and script visible with their tail sentinel, the body reading "Waiting for approval" and never "Running", Copy and Download present while open and gone when collapsed and back on reopen, nothing left spinning at the end, and no "(truncated)" marker anywhere in the transcript. 8 of 8 checks on both tools.Tests:
studio/backend/tests/test_active_generations.py, 22 cases: registry lifecycle, overlapping runs on one conversation, JSON safety of the snapshot, per-thread against global cancel, an 8 thread concurrency stress, the 409 and force paths, and the parallel default agreement between the CLI and the backend.test_gated_python_call_still_streams_its_argumentsand two admission-queue cases covering a parked slot being freed andunparknever leaking capacity.studio/backend/tests/test_tool_sandbox_per_thread.py, 11 cases: a directory per conversation, stable across turns, private to its own chat, the project workspace exception, session ids that try to escape the sandbox root, and the 0700 mode. HOME is redirected to a tmp dir so nothing touches the real sandbox tree.main(test_studio_api.pywants a live keyed server,test_training_worker_flash_attn.pywants network installs).ubuntu-latest,windows-latestandmacos-14. Nothing added here is POSIX specific: it is a dict plus athreading.Lock, and cancelling is an HTTP connection close.