unslothai/unsloth · error · ValueError

Media auto-unload idle seconds must be 0 (off) or at least {

Error message

Media auto-unload idle seconds must be 0 (off) or at least {MIN_AUTO_UNLOAD_IDLE_SECONDS}.

What it means

Raised by set_openai_auto_switch in openai_auto_switch_settings.py:307-311. media_idle_seconds obeys the same floor as the main idle: 0 (off) or >= MIN_AUTO_UNLOAD_IDLE_SECONDS (60). Values 1..59 are rejected so media workloads cannot trigger rapid load/unload cycles.

Source

Thrown at studio/backend/utils/openai_auto_switch_settings.py:308

    if parsed_enabled is None:
        raise ValueError("OpenAI auto-switch must be true or false.")
    parsed_idle = None
    if idle_seconds is not None:
        parsed_idle = _coerce_int(idle_seconds)
        if parsed_idle is None:
            raise ValueError("Auto-unload idle seconds must be a non-negative integer.")
        if 0 < parsed_idle < MIN_AUTO_UNLOAD_IDLE_SECONDS:
            raise ValueError(
                f"Auto-unload idle seconds must be 0 (off) or at least "
                f"{MIN_AUTO_UNLOAD_IDLE_SECONDS}."
            )
    parsed_media_idle = None
    if media_idle_seconds is not None:
        parsed_media_idle = _coerce_int(media_idle_seconds)
        if parsed_media_idle is None:
            raise ValueError("Media auto-unload idle seconds must be a non-negative integer.")
        if 0 < parsed_media_idle < MIN_AUTO_UNLOAD_IDLE_SECONDS:
            raise ValueError(
                f"Media auto-unload idle seconds must be 0 (off) or at least "
                f"{MIN_AUTO_UNLOAD_IDLE_SECONDS}."
            )
    parsed_keep_kv = None
    if keep_kv is not None:
        parsed_keep_kv = _coerce_bool(keep_kv)
        if parsed_keep_kv is None:
            raise ValueError("Keep KV on idle unload must be true or false.")
    parsed_auto_download = None
    if auto_download is not None:
        parsed_auto_download = _coerce_bool(auto_download)
        if parsed_auto_download is None:
            raise ValueError("Auto-download missing models must be true or false.")
    parsed_api_only = None
    if api_only is not None:
        parsed_api_only = _coerce_bool(api_only)
        if parsed_api_only is None:
            raise ValueError("Auto-unload API-loaded only must be true or false.")

View on GitHub (pinned to 203007d190)

Solutions

  1. Use 0 to disable media auto-unload or pick a value >= 60
  2. Clamp the UI control to 0 or [60, infinity)
  3. Normalize before calling: v = 0 if 0 < v < 60 else v is wrong for 'off' semantics — instead reject and prompt the user

Example fix

# before
set_openai_auto_switch(enabled=True, media_idle_seconds=45)

# after
set_openai_auto_switch(enabled=True, media_idle_seconds=90)
Defensive patterns

Strategy: validation

Validate before calling

def valid_media_idle(v: int) -> bool:
    return v == 0 or v >= 60  # MIN_AUTO_UNLOAD_IDLE_SECONDS

Type guard

def is_valid_media_idle(v: object) -> bool:
    return isinstance(v, int) and not isinstance(v, bool) and (v == 0 or v >= 60)

Try / catch

try:
    set_openai_auto_switch(enabled=True, media_idle_seconds=media_idle)
except ValueError as exc:
    return {"ok": False, "error": str(exc)}, 400

Prevention

When it happens

Trigger: set_openai_auto_switch(enabled=True, media_idle_seconds=45) — any value in 1..59. media_idle_seconds=0 or >=60 passes; negatives were clamped to 0 earlier.

Common situations: Tuning media pipeline memory reclaim too aggressively (e.g. 15s); sliders permitting sub-minute values; default configs copied from an older version with a lower minimum.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/aa1bc8ec77467d9a. Report an issue: GitHub.