Repository navigation
Studio: simplify the inference orchestrator and worker - #6439
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the inference orchestrator and worker to reduce code duplication and improve maintainability. Key changes include consolidating generation command building and token stream consumption into shared helper methods (_build_generate_cmd and _consume_token_stream), simplifying response handling by automatically stamping timestamps in _send_response, and leveraging a shared watchdog utility for heartbeats. Additionally, unused imports, fields, and redundant inline imports were cleaned up. One review comment suggests checking the cancellation event at the beginning of the token stream consumption loop to ensure immediate responsiveness during timeouts or status updates.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Refactor only, no behavior change. Removes about 190 lines of duplicated code and dead state from the two inference backend files,
orchestrator.py(parent process) andworker.py(model subprocess).Rebased on #6391, so its Nemotron trust check and the malware/consent security gates work exactly as before.
Details
orchestrator.py:_consume_token_stream, that takes aread_onecallback so each path can keep reading its own queue (sharedresp_queueunder_gen_lock, or the per-request mailbox on the dispatcher path).generatecommand dict was built in two places. It is now built once in_build_generate_cmd, and_generate_lockedfolds back into its caller._lock,loaded_local_models,_current_transformers_major) and the unusedstructlogimport.worker.py:_get_hf_download_stateand_start_heartbeat, about 130 lines) and calledstart_watchdogfromutils.hf_xet_fallbackinstead, which already does the same thing.tstimestamp was stamped on every outgoing message by hand._send_responsenow stamps it once viasetdefault._clean_token,_needs_nemotron_trust,_resolve_lora_4bit,_ensure_backend_on_path).