unslothai/unsloth · error · ValueError
Media auto-unload idle seconds must be a non-negative intege
Error message
Media auto-unload idle seconds must be a non-negative integer.
What it means
Raised by set_openai_auto_switch in openai_auto_switch_settings.py:305-306 when media_idle_seconds is provided but _coerce_int cannot parse it — same coercion rules as the main idle: int() must succeed; decimals-as-strings ("1.5"), non-numeric strings, lists, dicts, and empty strings all fail. Negative ints are clamped to 0.
Source
Thrown at studio/backend/utils/openai_auto_switch_settings.py:306
"""One-transaction write; ``None`` leaves a stored value untouched."""
parsed_enabled = _coerce_bool(enabled)
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)View on GitHub (pinned to 203007d190)
Solutions
- Parse to int before calling; strip units in the UI layer
- Send plain integers or integer strings
- Reject fractional values client-side
- Leave the argument as Python None (or omit it) to keep the stored value
Example fix
# before set_openai_auto_switch(enabled=True, media_idle_seconds="1.5") # after set_openai_auto_switch(enabled=True, media_idle_seconds=90)
Defensive patterns
Strategy: validation
Validate before calling
def parse_media_idle(v) -> int | None:
if v is None:
return None
try:
return max(0, int(str(v).strip()))
except (TypeError, ValueError):
return None Type guard
def is_coercible_nonneg_int(v: object) -> bool:
try:
return int(v) >= 0
except (TypeError, ValueError):
return False Try / catch
try:
set_openai_auto_switch(enabled=True, media_idle_seconds=media_idle)
except ValueError as exc:
raise HTTPException(400, str(exc)) from exc Prevention
- Use a numeric input with integer step for media idle
- Pass Python None to leave the stored value untouched
- Never forward raw text-field strings
When it happens
Trigger: set_openai_auto_switch(enabled=True, media_idle_seconds="45s"), media_idle_seconds=2.5, media_idle_seconds="", or media_idle_seconds=None-as-string. Note Python None is fine (leaves the stored value untouched).
Common situations: Media/GPU idle settings entered as free text in the UI; JSON configs with floats; copy-pasting '90 sec' from documentation.
Related errors
- Auto-unload idle seconds must be a non-negative integer.
- Embedding model must be a Hugging Face repo id (e.g. 'unslot
- Helper LLM startup pre-cache must be true or false.
- OpenAI auto-switch must be true or false.
- Auto-unload idle seconds must be 0 (off) or at least {MIN_AU
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/f4d2721c8a856922.
Report an issue: GitHub.