Skip to content

Studio: keep SSM kernel installs alive and reap the worker on load timeout - #9419

Merged
oobabooga merged 9 commits into
unslothai:mainfrom
indrajeetapache:studio/ssm-kernel-install-heartbeat-reap
Aug 25, 2026
Merged

oobabooga merged 9 commits into
unslothai:mainfrom
indrajeetapache:studio/ssm-kernel-install-heartbeat-reap

Conversation

@indrajeetapache

Copy link
Copy Markdown
Contributor

Problem

Loading a local Qwen3.5 Safetensors model that needs causal-conv1d can leave Studio looking ready while chat is broken. On Linux aarch64 the prebuilt wheel install emits one status (Installing causal-conv1d (prebuilt kernel)...) and then goes quiet while pip/uv downloads and unpacks. The parent treats that silence as a dead load:

Timeout waiting for 'loaded' response (no activity for 300.0s)
Model load failed with 500 after the response committed
POST /api/inference/load -> HTTP 200

Because /load already committed HTTP 200 after 15s (tunnel padding), the UI can still show the model as loaded. Chat then gets HTTP 400 (No model loaded). Worse, the failed load used to leave the inference subprocess alive, so pip/nvcc kept running and held GPU memory for a long time after Studio had already reported failure. Reported in #9398.

Fix

  • Heartbeat during the prebuilt-wheel install the same way we already do for source builds, so a slow aarch64 / cold-cache install keeps resetting the inactivity deadline.
  • On any failed load after the worker was spawned (including that inactivity timeout), shut the subprocess down so an in-flight kernel install cannot outlive the failed load.

Verification

  • tests/test_ssm_runtime.py: a quiet prebuilt wheel install emits Still installing … (prebuilt kernel) heartbeats while install_wheel runs.
  • tests/test_orchestrator_unload_cancel.py: an inactivity timeout waiting for loaded reaps the worker.

Fixes #9398

…meout

Quiet prebuilt causal-conv1d wheel installs were tripping the 300s inactivity
deadline and leaving pip/nvcc holding the GPU after Studio already reported
the load failed (unslothai#9398).
@NilayYadav

NilayYadav commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

One bug worth fixing first.

If someone hits Stop while a load is failing, cancel_load and load_model both end up in _shutdown_subprocess at once. cancel_load doesn't hold the lifecycle gate and it nulls _cmd_queue at the very end of its teardown, so the load thread can get there after it's gone:

core/inference/orchestrator.py:1494: in load_model
    self._shutdown_subprocess(timeout = 5)
>           self._cmd_queue.put({"type": "shutdown"})
E           AttributeError: 'NoneType' object has no attribute 'put'

The AttributeError then replaces the real error, so instead of "load timed out" the user gets that. Two small changes:

        except Exception as exc:
            # cancel_load drops this marker before tearing the worker down,
            # so if it's already gone the cancel owns the worker.
            cancelled = model_name not in self.loading_models
            self.loading_models.discard(model_name)
            ...
            self.active_model_name = None
            self.models.clear()
            if not cancelled:
                try:
                    self._shutdown_subprocess(timeout = 5)
                except Exception as teardown_exc:
                    logger.warning("Could not shut the failed load's worker down: %s", teardown_exc)
            raise

unload_model already wraps its own teardown the same way, for the same reason. I have a test that reproduces this deterministically.

Two minor things: the heartbeat with block closes before the for installer, result in attempts: loop, so _is_importable (the first real torch import) runs outside it. And a thread.join(timeout = 1) after done.set() would stop a stray status landing after the block.

cancel_load already owns the worker once it drops the loading marker, and a
second _shutdown_subprocess after it nulled _cmd_queue was replacing the
real load error with AttributeError. Keep the prebuilt-kernel heartbeat
open through the first torch import and join the beat thread so a stray
status cannot land after the block.
@indrajeetapache

Copy link
Copy Markdown
Contributor Author

@NilayYadav took your review — thanks.

Stop during a failing load no longer sends both threads into _shutdown_subprocess. cancel_load still owns the worker once it drops the loading marker, and a teardown that raises stays a warning so the caller keeps the real timeout instead of AttributeError: 'NoneType' object has no attribute 'put'. Same wrap unload_model already uses.

Also moved the prebuilt-wheel heartbeat with around the for installer, result in install_wheel(...) loop so _is_importable (the first real torch import) stays inside it, and thread.join(timeout = 1) after done.set() so a stray status cannot land after the block.

Tests:

  • test_failed_load_skips_reap_when_cancel_already_owns_worker — the deterministic Stop-during-timeout race
  • test_failed_load_keeps_the_timeout_when_teardown_raises
  • test_install_kernel_heartbeats_through_the_import_check
  • test_heartbeat_does_not_emit_after_the_block

Mind another look?

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the prebuilt-wheel path in studio/backend/utils/ssm_runtime.py still runs without a heartbeat on main and the failed load leaves the worker alive, and the cancel-owns-teardown guard NilayYadav asked for is in. Will get this reviewed.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d17d83e43

ℹ️ 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".

Comment on lines +326 to 329
with _heartbeat(
status_cb,
f"Still installing {display_name} (prebuilt kernel)...",
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Put a hard deadline around prebuilt installs

If uv or pip becomes permanently stuck rather than merely slow, this heartbeat continues emitting every 60 seconds while install_wheel blocks. Those statuses continually reset _wait_response's only timeout, while the underlying subprocess.run calls in wheel_utils.py have no timeout, so a model load that previously failed after 300 seconds can now remain stuck indefinitely until the user explicitly cancels it. Retain a separate overall installer deadline that heartbeat messages cannot extend.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this unchanged: the heartbeat protects legitimate slow installs, Stop remains available, and source builds already use the same cancellable inactivity semantics. An overall deadline would reintroduce the failure reported in #9398.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 385f679d4b

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 385f679d4b

ℹ️ 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".

@oobabooga

Copy link
Copy Markdown
Member

I traced model-load status from the worker through the orchestrator and confirmed the issue and layer are correct: a quiet prebuilt causal-conv1d installation can exhaust Studio's 300-second inactivity deadline, while the new 60-second status uses the existing response path to reset it. I also checked the failed-load, Stop, and concurrent teardown paths; the original load error is preserved and the worker process tree is reaped.

A clean Linux ARM64 CI run installed the real published wheel after a forced 65-second quiet period, observed the heartbeat at 60.1 seconds, and confirmed that concurrent timeout and cancellation cleanup terminated both the worker and its descendant while preserving the timeout (CI run). The hosted runner has no NVIDIA GPU, so this was not a full model load, but it exercised the architecture-specific wheel path. Looks good to merge.

@oobabooga
oobabooga merged commit 5205a38 into unslothai:main Aug 25, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Studio reports that a local model is loaded, but every message returns HTTP 400

4 participants