Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

add reasoning budget controls for llama.cpp models

alkinunaf4e98e2f63f
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 066ffa54ee7..16fc1b305d6 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -110,8 +110,14 @@ from core.inference.llama_server_args import (
parse_cache_override_per_axis,
parse_ctx_override,
parse_gpu_layers_override,
+ parse_reasoning_budget_message_override,
+ parse_reasoning_budget_override,
parse_split_mode_override,
resolve_requested_ctx,
+ resolve_reasoning_budget,
+ resolve_reasoning_budget_message,
+ resolve_reasoning_budget_message_with_env,
+ resolve_reasoning_budget_with_env,
split_policy_starves_devices,
strip_context_only,
strip_shadowing_flags,
@@ -566,6 +572,10 @@ class GgufLoadIntent:
spec_draft_cache_type: Optional[str] = None
ctx_checkpoints: Optional[int] = None
cache_ram: Optional[int] = None
+ # llama.cpp thinking budget (--reasoning-budget / --reasoning-budget-message);
+ # -1 and "" follow the llama.cpp defaults.
+ reasoning_budget: int = -1
+ reasoning_budget_message: str = ""
extra_args: Optional[tuple[str, ...]] = None
# The route materialises inherited extras from the live server, so the list alone
# cannot say whether the caller named it. Duplicate-load checks need the difference:
@@ -6093,6 +6103,18 @@ def _build_ngram_mod_flags(
return []
+def _build_reasoning_budget_flags(
+ caps: Mapping[str, object], reasoning_budget: int, reasoning_budget_message: str
+) -> list[str]:
+ """Build only the reasoning flags advertised by this llama-server."""
+ flags: list[str] = []
+ if reasoning_budget != -1 and caps.get("supports_reasoning_budget"):
+ flags.extend(["--reasoning-budget", str(reasoning_budget)])
+ if reasoning_budget_message and caps.get("supports_reasoning_budget_message"):
+ flags.extend(["--reasoning-budget-message", reasoning_budget_message])
+ return flags
+
+
# Canonical Speculative Decoding modes exposed by the Unsloth chat UI.
# Dropdown renders seven (auto, mtp, dspark, dflash, ngram, mtp+ngram, off); the
# load API also accepts legacy values the original Switch and external callers
@@ -6785,6 +6807,11 @@ class LlamaCppBackend:
self._chat_template_override: Optional[str] = None
self._supports_reasoning: bool = False
self._reasoning_always_on: bool = False
+ self._reasoning_budget: int = -1
+ self._reasoning_budget_message: str = ""
+ # What the load asked for, before the environment. See _runtime_matches_intent.
+ self._requested_reasoning_budget: int = -1
+ self._requested_reasoning_budget_message: str = ""
self._reasoning_style: str = "enable_thinking"
self._reasoning_effort_levels: list = []
self._supports_preserve_thinking: bool = False
@@ -7183,6 +7210,14 @@ class LlamaCppBackend:
0 means Auto. Used by the route to detect Auto-vs-explicit flips."""
return self._requested_n_ctx
+ @property
+ def reasoning_budget(self) -> int:
+ return self._reasoning_budget
+
+ @property
+ def reasoning_budget_message(self) -> str:
+ return self._reasoning_budget_message
+
@property
def extra_args_source(self) -> Optional[tuple[str, Optional[str]]]:
"""(model_identifier, hf_variant) the stored extra_args came from.
@@ -7717,6 +7752,16 @@ class LlamaCppBackend:
return False
extra_args = list(effective_extra_args) if effective_extra_args is not None else None
+ # Request against request. The live EFFECTIVE value can carry an inherited
+ # LLAMA_ARG_THINK_BUDGET* that no request can express, so comparing against it would
+ # tear down a healthy server on every load and never converge.
+ if not self._is_diffusion and (
+ self._requested_reasoning_budget
+ != resolve_reasoning_budget(extra_args, intent.reasoning_budget)
+ or self._requested_reasoning_budget_message
+ != resolve_reasoning_budget_message(extra_args, intent.reasoning_budget_message)
+ ):
+ return False
# A request omitting the extras field inherits the LAUNCHED list; anything else is
# the caller's own. A launch-time rewrite (drafter drop, MTP crash replay) makes
# the two differ, and the equality below wants what the load was INVOKED with.
@@ -8400,6 +8445,9 @@ class LlamaCppBackend:
"supports_no_cache_prompt": False,
"supports_metrics": False,
"supports_slot_save": False,
+ "supports_reasoning_budget": False,
+ "supports_reasoning_budget_message": False,
+ "reasoning_budget_probe_inconclusive": True,
"supports_no_mmproj_offload": False,
"supports_video_fps": False,
"supports_load_mode": False,
@@ -8448,6 +8496,8 @@ class LlamaCppBackend:
supports_no_cache_prompt = False
supports_metrics = False
supports_slot_save = False
+ supports_reasoning_budget = False
+ supports_reasoning_budget_message = False
supports_no_mmproj_offload = False
supports_video_fps = False
supports_load_mode = False
@@ -8674,6 +8724,8 @@ class LlamaCppBackend:
supports_no_cache_prompt = _is_real("--no-cache-prompt")
supports_metrics = _is_real("--metrics")
supports_slot_save = _is_real("--slot-save-path")
+ supports_reasoning_budget = _is_real("--reasoning-budget")
+ supports_reasoning_budget_message = _is_real("--reasoning-budget-message")
supports_no_mmproj_offload = _is_real("--no-mmproj-offload")
supports_video_fps = _is_real("--video-fps")
# --load-mode supersedes --mlock / --no-mmap, which are deprecated.
@@ -8767,6 +8819,9 @@ class LlamaCppBackend:
"supports_no_cache_prompt": supports_no_cache_prompt,
"supports_metrics": supports_metrics,
"supports_slot_save": supports_slot_save,
+ "supports_reasoning_budget": supports_reasoning_budget,
+ "supports_reasoning_budget_message": supports_reasoning_budget_message,
+ "reasoning_budget_probe_inconclusive": not (probe_ok and help_nonempty),
"supports_no_mmproj_offload": supports_no_mmproj_offload,
"supports_video_fps": supports_video_fps,
"supports_load_mode": supports_load_mode,
@@ -8824,6 +8879,97 @@ class LlamaCppBackend:
cls._capability_retry_backoff.pop(cache_key, None)
return info
+ @classmethod
+ def validate_reasoning_budget_capabilities(
+ cls,
+ binary: Optional[str],
+ *,
+ extra_args: Optional[Iterable[str]],
+ reasoning_budget: int,
+ reasoning_budget_message: str,
+ ) -> dict[str, object]:
+ """Reject configured reasoning flags before replacing a live server.
+
+ Explicit config only: the first-class fields and the passthrough extras.
+ LLAMA_ARG_THINK_BUDGET* is a machine-wide llama.cpp default no Studio control
+ can clear, so gating on it would fail loads with no way out of the UI.
+ llama-server validates its own env; effective state still reports it.
+ """
+ effective_budget = resolve_reasoning_budget(extra_args, reasoning_budget)
+ effective_message = resolve_reasoning_budget_message(extra_args, reasoning_budget_message)
+ needs_budget, needs_message = cls.reasoning_budget_settings_requested(
+ extra_args = extra_args,
+ reasoning_budget = effective_budget,
+ reasoning_budget_message = effective_message,
+ )
+ if not needs_budget and not needs_message:
+ return cls.probe_server_capabilities(binary) if binary else {}
+ if not binary:
+ raise ValueError(
+ "Reasoning budget settings require a llama-server runtime. "
+ "Install or update llama.cpp, then try again."
+ )
+
+ caps = cls.probe_server_capabilities(binary)
+ missing = []
+ if needs_budget and not caps.get("supports_reasoning_budget"):
+ missing.append("--reasoning-budget")
+ if needs_message and not caps.get("supports_reasoning_budget_message"):
+ missing.append("--reasoning-budget-message")
+ if missing:
+ verdict = (
+ "could not verify support for"
+ if caps.get("reasoning_budget_probe_inconclusive")
+ else "does not support"
+ )
+ raise ValueError(
+ f"llama-server at {binary} {verdict} {', '.join(missing)}. "
+ "Update llama.cpp or clear the Reasoning Budget settings."
+ )
+ if needs_budget and effective_budget > 0:
+ value_key = f"supports_reasoning_budget_value:{effective_budget}"
+ if value_key not in caps:
+ probe_binary = cls._exec_path_for_launch(binary)
+ probe_env = cls._llama_server_env_for_binary(probe_binary)
+ # Same shape as the --help probe: llama-server parses LLAMA_ARG_* before
+ # argv, so a stale inherited value would read as "rejects the budget".
+ for name in tuple(probe_env):
+ if name.startswith("LLAMA_ARG_"):
+ probe_env.pop(name, None)
+ if sys.platform == "darwin":
+ probe_env["GGML_METAL_DEVICES"] = "0"
+ try:
+ result = subprocess.run(
+ [probe_binary, "--reasoning-budget", str(effective_budget), "--help"],
+ capture_output = True,
+ text = True,
+ encoding = "utf-8",
+ errors = "replace",
+ timeout = 10,
+ check = False,
+ env = probe_env,
+ )
+ caps[value_key] = result.returncode == 0
+ except (OSError, subprocess.SubprocessError):
+ caps[value_key] = False
+ if not caps[value_key]:
+ raise ValueError(
+ f"llama-server at {binary} does not accept positive reasoning budgets. "
+ "Update llama.cpp, use 0 or -1, or clear the Reasoning Budget setting."
+ )
+ return caps
+
+ @staticmethod
+ def reasoning_budget_settings_requested(
+ *, extra_args: Optional[Iterable[str]], reasoning_budget: int, reasoning_budget_message: str
+ ) -> tuple[bool, bool]:
+ budget_override = parse_reasoning_budget_override(extra_args)
+ message_override = parse_reasoning_budget_message_override(extra_args)
+ return (
+ reasoning_budget != -1 or budget_override is not None,
+ bool(reasoning_budget_message) or message_override is not None,
+ )
+
@staticmethod
def _mtp_token_from_spec_help(spec_help: str) -> Optional[str]:
"""Extract ``draft-mtp`` / ``mtp`` from a ``--spec-type`` help snippet.
@@ -16570,6 +16716,10 @@ class LlamaCppBackend:
self._is_audio = False # clear any prior TTS/audio model's routing flag
self._model_identifier = model_identifier
self._cache_type_kv = None
+ self._reasoning_budget = -1
+ self._reasoning_budget_message = ""
+ self._requested_reasoning_budget = -1
+ self._requested_reasoning_budget_message = ""
self._swa_full = False
self._kv_cache_unified = False
self._memory_state = None
@@ -20958,6 +21108,8 @@ class LlamaCppBackend:
cache_ram = intent.cache_ram
extra_args = list(intent.extra_args) if intent.extra_args is not None else None
preserve_multi_gpu_on_layer = intent.preserve_multi_gpu_on_layer
+ reasoning_budget = intent.reasoning_budget
+ reasoning_budget_message = intent.reasoning_budget_message
# Before the serial scope: a queued load still belongs to the lifecycle it
# was requested in.
# The process-wide equivalent, for the same reason. Only _begin_server_lifecycle
@@ -21183,6 +21335,30 @@ class LlamaCppBackend:
_launch_probe_inconclusive = True
return caps
+ _reasoning_requested = any(
+ self.reasoning_budget_settings_requested(
+ extra_args = extra_args,
+ reasoning_budget = reasoning_budget,
+ reasoning_budget_message = reasoning_budget_message,
+ )
+ )
+ if (
+ _reasoning_requested
+ and gguf_path
+ and Path(gguf_path).is_file()
+ and self._gguf_path_is_diffusion(gguf_path, model_identifier)
+ ):
+ raise ValueError(
+ "Reasoning Budget settings are not supported for DiffusionGemma models."
+ )
+ # Nothing configured means nothing to reject; _launch_caps probes the binary anyway.
+ if _reasoning_requested:
+ self.validate_reasoning_budget_capabilities(
+ binary,
+ extra_args = extra_args,
+ reasoning_budget = reasoning_budget,
+ reasoning_budget_message = reasoning_budget_message,
+ )
is_vulkan_backend = self._is_vulkan_backend(binary)
_vulkan_ordinal_pin = (
is_vulkan_backend and bool(gpu_ids) and gpu_ids_are_vulkan_ordinals is not False
@@ -24706,6 +24882,9 @@ class LlamaCppBackend:
"llama-server has no --cache-ram; skipping the requested %s MiB.",
cache_ram,
)
+ # Read early so the effective budget can fold in an inherited
+ # LLAMA_ARG_THINK_BUDGET*; the launch env is rebuilt below before spawn.
+ env = self._llama_server_env_for_binary(binary)
# On every launch, not only where Studio emits --mmproj: a projector
# from the extras or LLAMA_ARG_MMPROJ takes video too.
cmd.extend(_video_fps_flags(server_caps))
@@ -25349,6 +25528,41 @@ class LlamaCppBackend:
)
logger.info(f"Reasoning model: {reasoning_kw} by default")
+ reasoning_budget = resolve_reasoning_budget(extra_args, reasoning_budget)
+ reasoning_budget_message = resolve_reasoning_budget_message(
+ extra_args, reasoning_budget_message
+ )
+ cmd.extend(
+ _build_reasoning_budget_flags(
+ server_caps, reasoning_budget, reasoning_budget_message
+ )
+ )
+ # What was asked for, pass-through flags folded in but not the environment: the
+ # value a client can resend, and the one the reuse check compares against.
+ self._requested_reasoning_budget = reasoning_budget
+ self._requested_reasoning_budget_message = reasoning_budget_message
+ # Only a CONCLUSIVE "no such flag" means the child ignores the environment. A probe
+ # that timed out says nothing, and the child still applies LLAMA_ARG_THINK_BUDGET*,
+ # so recording the bare request there would misreport the running server.
+ _budget_env_applies = server_caps.get(
+ "supports_reasoning_budget"
+ ) or server_caps.get("reasoning_budget_probe_inconclusive")
+ reasoning_budget = (
+ resolve_reasoning_budget_with_env(extra_args, reasoning_budget, env)
+ if _budget_env_applies
+ else reasoning_budget
+ )
+ reasoning_budget_message = (
+ resolve_reasoning_budget_message_with_env(
+ extra_args, reasoning_budget_message, env
+ )
+ if server_caps.get("supports_reasoning_budget_message")
+ or server_caps.get("reasoning_budget_probe_inconclusive")
+ else reasoning_budget_message
+ )
+ self._reasoning_budget = reasoning_budget
+ self._reasoning_budget_message = reasoning_budget_message
+
if launch_mmproj_path and effective_is_vision:
cmd.extend(["--mmproj", launch_mmproj_path])
logger.info(f"Using mmproj for vision: {launch_mmproj_path}")
@@ -29454,6 +29668,10 @@ class LlamaCppBackend:
self._chat_template_override = None
self._supports_reasoning = False
self._reasoning_always_on = False
+ self._reasoning_budget = -1
+ self._reasoning_budget_message = ""
+ self._requested_reasoning_budget = -1
+ self._requested_reasoning_budget_message = ""
self._reasoning_style = "enable_thinking"
self._reasoning_effort_levels = []
self._reasoning_default = True
diff --git a/studio/backend/core/inference/llama_server_args.py b/studio/backend/core/inference/llama_server_args.py
index 14b8ccc8ca1..3f7bfb6586d 100644
--- a/studio/backend/core/inference/llama_server_args.py
+++ b/studio/backend/core/inference/llama_server_args.py
@@ -12,7 +12,9 @@ from __future__ import annotations
import logging
import os
import sys
-from typing import Any, Iterable, Mapping, Optional
+from typing import Any, Callable, Iterable, Mapping, Optional
+
+from utils.reasoning_budget import validate_reasoning_budget_message
logger = logging.getLogger(__name__)
@@ -335,6 +337,8 @@ def validate_extra_args(args: Optional[Iterable[str]]) -> list[str]:
parse_cache_override(out)
parse_split_mode_override(out)
parse_gpu_layers_override(out)
+ parse_reasoning_budget_override(out)
+ parse_reasoning_budget_message_override(out)
return out
@@ -475,6 +479,9 @@ _CONTEXT_FLAGS: frozenset[str] = frozenset({"-c", "--ctx-size"})
_CACHE_TYPE_K_FLAGS: frozenset[str] = frozenset({"-ctk", "--cache-type-k"})
_CACHE_TYPE_V_FLAGS: frozenset[str] = frozenset({"-ctv", "--cache-type-v"})
_CACHE_FLAGS: frozenset[str] = _CACHE_TYPE_K_FLAGS | _CACHE_TYPE_V_FLAGS
+_REASONING_BUDGET_FLAGS: frozenset[str] = frozenset({"--reasoning-budget"})
+_REASONING_BUDGET_MESSAGE_FLAGS: frozenset[str] = frozenset({"--reasoning-budget-message"})
+_REASONING_BUDGET_MAX = 2_147_483_647
_SPEC_FLAGS: frozenset[str] = frozenset(
{
"--spec-default",
@@ -697,7 +704,13 @@ def matches_explicit_ctx_override(args: Optional[Iterable[str]], n_ctx: Any) ->
return False
-def _last_flag_value(args: Optional[Iterable[str]], flags: frozenset[str]) -> Optional[str]:
+def _last_flag_value(
+ args: Optional[Iterable[str]],
+ flags: frozenset[str],
+ *,
+ preserve_raw: bool = False,
+ validate_value: Optional[Callable[[str], object]] = None,
+) -> Optional[str]:
"""Return the last-wins string value among ``flags`` in extras, or None. Handles both
``--flag=value`` and ``--flag value`` forms and raises if a matched flag has no (or an empty)
value. Shared by the single-knob last-wins parsers (cache type, split mode)."""
@@ -723,10 +736,12 @@ def _last_flag_value(args: Optional[Iterable[str]], flags: frozenset[str]) -> Op
raw_value = tokens[i + 1]
i += 2
- value = str(raw_value).strip()
- if not value:
+ raw_value = str(raw_value)
+ if not raw_value.strip():
raise ValueError(f"llama-server flag '{flag}' requires a non-empty value")
- override = value
+ if validate_value is not None:
+ validate_value(raw_value)
+ override = raw_value if preserve_raw else raw_value.strip()
return override
@@ -739,6 +754,80 @@ def parse_cache_override(args: Optional[Iterable[str]]) -> Optional[str]:
return _last_flag_value(args, _CACHE_FLAGS)
+def _validate_reasoning_budget_value(raw_value: str) -> int:
+ try:
+ value = int(raw_value)
+ except ValueError as exc:
+ raise ValueError("llama-server --reasoning-budget requires an integer value") from exc
+ if value < -1:
+ raise ValueError("llama-server --reasoning-budget requires a value of at least -1")
+ if value > _REASONING_BUDGET_MAX:
+ raise ValueError(
+ f"llama-server --reasoning-budget requires a value of at most {_REASONING_BUDGET_MAX}"
+ )
+ return value
+
+
+def parse_reasoning_budget_override(args: Optional[Iterable[str]]) -> Optional[int]:
+ """Return the last user-supplied ``--reasoning-budget`` value."""
+ raw_value = _last_flag_value(
+ args, _REASONING_BUDGET_FLAGS, validate_value = _validate_reasoning_budget_value
+ )
+ return None if raw_value is None else int(raw_value)
+
+
+def parse_reasoning_budget_message_override(args: Optional[Iterable[str]]) -> Optional[str]:
+ """Return the last user-supplied ``--reasoning-budget-message`` value."""
+ value = _last_flag_value(
+ args,
+ _REASONING_BUDGET_MESSAGE_FLAGS,
+ preserve_raw = True,
+ validate_value = validate_reasoning_budget_message,
+ )
+ return value
+
+
+def resolve_reasoning_budget(args: Optional[Iterable[str]], fallback: int) -> int:
+ override = parse_reasoning_budget_override(args)
+ return override if override is not None else fallback
+
+
+def resolve_reasoning_budget_message(args: Optional[Iterable[str]], fallback: str) -> str:
+ override = parse_reasoning_budget_message_override(args)
+ return override if override is not None else fallback
+
+
+def resolve_reasoning_budget_with_env(
+ args: Optional[Iterable[str]],
+ fallback: int,
+ env: Optional[Mapping[str, str]] = None,
+) -> int:
+ """Resolve CLI/first-class intent, then inherit llama.cpp's env default."""
+ override = parse_reasoning_budget_override(args)
+ if override is not None:
+ return override
+ if fallback != -1:
+ return fallback
+ raw_value = (env if env is not None else os.environ).get("LLAMA_ARG_THINK_BUDGET")
+ if raw_value is None:
+ return fallback
+ return _validate_reasoning_budget_value(raw_value)
+
+
+def resolve_reasoning_budget_message_with_env(
+ args: Optional[Iterable[str]],
+ fallback: str,
+ env: Optional[Mapping[str, str]] = None,
+) -> str:
+ """Resolve CLI/first-class intent, then inherit llama.cpp's env default."""
+ override = parse_reasoning_budget_message_override(args)
+ if override is not None:
+ return override
+ if fallback:
+ return fallback
+ return (env if env is not None else os.environ).get("LLAMA_ARG_THINK_BUDGET_MESSAGE", "")
+
+
def parse_gpu_layers_override(args: Optional[Iterable[str]]) -> Optional[int]:
"""Return the last user-supplied GPU layer count from extras. Manual GPU memory mode strips
llama.cpp offload flags because the first-class load fields own them, so callers use this
@@ -1056,6 +1145,8 @@ def strip_shadowing_flags(
strip_tensor_split: bool = False,
strip_offload: bool = False,
strip_device: bool = False,
+ strip_reasoning_budget: bool = False,
+ strip_reasoning_budget_message: bool = False,
strip_mlock: bool = False,
strip_no_mmap: bool = False,
strip_load_mode_aliases: bool = False,
@@ -1101,6 +1192,10 @@ def strip_shadowing_flags(
shadowing |= _OFFLOAD_SHADOWING_FLAGS
if strip_device:
shadowing |= _DEVICE_FLAGS
+ if strip_reasoning_budget:
+ shadowing |= _REASONING_BUDGET_FLAGS
+ if strip_reasoning_budget_message:
+ shadowing |= _REASONING_BUDGET_MESSAGE_FLAGS
if strip_mlock:
shadowing |= _MLOCK_FLAGS
if strip_no_mmap:
diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.py
index c610a07f1ef..0dec97eb9e2 100644
--- a/studio/backend/models/inference.py
+++ b/studio/backend/models/inference.py
@@ -31,6 +31,7 @@ from core.inference.llama_server_args import (
from core.inference.runtime_context import MAX_REQUESTABLE_CONTEXT
from core.inference.video_families import MAX_VIDEO_NUM_FRAMES
from picker.schemas import MAX_CHAT_TEMPLATE_BYTES
+from utils.reasoning_budget import validate_reasoning_budget_message
class LoadRequest(BaseModel):
@@ -331,7 +332,9 @@ class LoadRequest(BaseModel):
),
)
- @field_validator("n_batch", "n_ubatch", "ctx_checkpoints", "cache_ram", mode = "before")
+ @field_validator(
+ "n_batch", "n_ubatch", "ctx_checkpoints", "cache_ram", "reasoning_budget", mode = "before"
+ )
@classmethod
def _no_booleans(cls, value: Any) -> Any:
# bool subclasses int and pydantic parses non-strictly, so `true` arrives as 1 and the load
@@ -366,6 +369,22 @@ class LoadRequest(BaseModel):
"auth, UI/server mode) are rejected. Ignored for non-GGUF models."
),
)
+ reasoning_budget: int = Field(
+ -1,
+ ge = -1,
+ le = 2_147_483_647,
+ description = "llama-server reasoning token budget (-1 = model/default behavior).",
+ )
+ reasoning_budget_message: str = Field(
+ "",
+ description = "Message emitted by llama-server when the reasoning budget is exhausted.",
+ )
+
+ @field_validator("reasoning_budget_message")
+ @classmethod
+ def _validate_reasoning_budget_message(cls, value: str) -> str:
+ return validate_reasoning_budget_message(value)
+
force_cancel_active: bool = Field(
False,
description = (
@@ -565,6 +584,14 @@ class ValidateModelRequest(BaseModel):
"asking for them needs materially more memory than one that does not."
),
)
+ reasoning_budget: int = Field(-1, ge = -1, le = 2_147_483_647)
+ reasoning_budget_message: str = ""
+
+ @field_validator("reasoning_budget_message")
+ @classmethod
+ def _validate_reasoning_budget_message(cls, value: str) -> str:
+ return validate_reasoning_budget_message(value)
+
include_context_length: bool = Field(
False,
description = "Also read the native context length from the local GGUF header. "
@@ -578,9 +605,9 @@ class ValidateModelRequest(BaseModel):
"guard. Only the leased file's own embedded template is read, never sibling sidecars.",
)
- _no_booleans = field_validator("n_batch", "n_ubatch", "ctx_checkpoints", mode = "before")(
- LoadRequest._no_booleans.__func__
- )
+ _no_booleans = field_validator(
+ "n_batch", "n_ubatch", "ctx_checkpoints", "reasoning_budget", mode = "before"
+ )(LoadRequest._no_booleans.__func__)
class TransformersUpgradeInfo(BaseModel):
@@ -1152,6 +1179,19 @@ class _InferenceRuntimeFields(BaseModel):
False,
description = "Whether reasoning is always on (hardcoded <think> tags, not toggleable)",
)
+ reasoning_budget: int = Field(-1, description = "Effective llama-server reasoning token budget.")
+ reasoning_budget_message: str = Field(
+ "", description = "Effective llama-server reasoning-budget exhaustion message."
+ )
+ # The effective pair folds in LLAMA_ARG_THINK_BUDGET*, which no client can send or clear, so a
+ # caller comparing its own request against it reads a machine-wide default as a difference and
+ # reloads forever. These echo what the load ASKED for, which a client can reproduce.
+ requested_reasoning_budget: int = Field(
+ -1, description = "Reasoning token budget this load requested, before the environment."
+ )
+ requested_reasoning_budget_message: str = Field(
+ "", description = "Reasoning-budget message this load requested, before the environment."
+ )
supports_preserve_thinking: bool = Field(
False,
description = "Whether the template understands the optional preserve_thinking kwarg",
diff --git a/studio/backend/routes/chat_history.py b/studio/backend/routes/chat_history.py
index ffaf8bc69a5..b96b173daa6 100644
--- a/studio/backend/routes/chat_history.py
+++ b/studio/backend/routes/chat_history.py
@@ -34,6 +34,7 @@ from core.inference.llama_server_args import (
PARALLEL_MIN,
)
from loggers import get_logger
+from utils.reasoning_budget import validate_reasoning_budget_message
from utils.api_errors import safe_validation_errors
from utils.utils import safe_curated_detail, log_and_http_error
from storage.studio_db import (
@@ -408,6 +409,8 @@ class ChatPresetLoadConfig(BaseModel):
speculativeType: Optional[str] = None
specDraftNMax: Optional[int] = Field(default = None, ge = 1, le = 16)
nParallel: Optional[int] = Field(default = None, ge = PARALLEL_MIN, le = PARALLEL_MAX)
+ reasoningBudget: NotABoolean = Field(default = None, ge = -1, le = 2_147_483_647)
+ reasoningBudgetMessage: Optional[str] = None
# The normalizer emits both keys on every preset (null included) and this model is
# extra="forbid", so without them PUT /api/chat/settings 400s the whole save for any
# preset carrying a loadConfig, including one that only pinned nParallel.
@@ -426,6 +429,11 @@ class ChatPresetLoadConfig(BaseModel):
gpuLayers: Optional[int] = None
nCpuMoe: Optional[int] = Field(default = None, ge = 0)
+ @field_validator("reasoningBudgetMessage")
+ @classmethod
+ def _validate_reasoning_budget_message(cls, value: Optional[str]) -> Optional[str]:
+ return None if value is None else validate_reasoning_budget_message(value)
+
class ChatPreset(BaseModel):
model_config = ConfigDict(extra = "forbid")
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index d9fac49a316..e1d8ab7210c 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -1630,7 +1630,11 @@ try:
drop_managed_flags,
extra_args_disable_mmproj,
parse_gpu_layers_override,
+ parse_reasoning_budget_message_override,
+ parse_reasoning_budget_override,
parse_split_mode_override,
+ resolve_reasoning_budget,
+ resolve_reasoning_budget_message,
resolve_tensor_parallel,
strip_shadowing_flags,
validate_extra_args,
@@ -1688,7 +1692,11 @@ except ImportError:
drop_managed_flags,
extra_args_disable_mmproj,
parse_gpu_layers_override,
+ parse_reasoning_budget_message_override,
+ parse_reasoning_budget_override,
parse_split_mode_override,
+ resolve_reasoning_budget,
+ resolve_reasoning_budget_message,
resolve_tensor_parallel,
strip_shadowing_flags,
validate_extra_args,
@@ -7354,6 +7362,8 @@ def _active_gguf_intent(
strip_spec = False,
strip_template = False,
strip_split_mode = False,
+ strip_reasoning_budget = "reasoning_budget" in request_fields_set,
+ strip_reasoning_budget_message = "reasoning_budget_message" in request_fields_set,
strip_batch = "n_batch" in request_fields_set,
strip_ubatch = "n_ubatch" in request_fields_set,
strip_ctx_checkpoints = "ctx_checkpoints" in request_fields_set,
@@ -12922,6 +12932,60 @@ def _classify_diffusion_gguf(config: ModelConfig) -> Optional[bool]:
return True if name_says_diffusion else None
+async def _validate_reasoning_budget_preflight(
+ config: ModelConfig,
+ diffusion_kind: Optional[bool],
+ extra_args: Optional[list[str]],
+ request: LoadRequest | ValidateModelRequest,
+) -> None:
+ """Reject unsupported reasoning controls before any resident model is torn down.
+
+ Explicit config only, exactly as LlamaCppBackend gates the load itself. Counting
+ an inherited LLAMA_ARG_THINK_BUDGET* as a request rejected every undownloaded
+ GGUF and every DiffusionGemma, naming a setting the UI already shows as default.
+ """
+ if not config.is_gguf:
+ return
+ effective_budget = resolve_reasoning_budget(extra_args, request.reasoning_budget)
+ effective_message = resolve_reasoning_budget_message(
+ extra_args, request.reasoning_budget_message
+ )
+ requested = any(
+ LlamaCppBackend.reasoning_budget_settings_requested(
+ extra_args = extra_args,
+ reasoning_budget = effective_budget,
+ reasoning_budget_message = effective_message,
+ )
+ )
+ if diffusion_kind and requested:
+ raise HTTPException(
+ status_code = 400,
+ detail = "Reasoning Budget settings are not supported for DiffusionGemma models.",
+ )
+ if diffusion_kind is None and requested:
+ raise HTTPException(
+ status_code = 400,
+ detail = (
+ "Reasoning Budget settings cannot be applied until this GGUF is "
+ "downloaded and its architecture can be verified. Load it once with "
+ "the default reasoning budget, then apply these settings."
+ ),
+ )
+ if not requested:
+ return
+ backend = get_llama_cpp_backend()
+ try:
+ await asyncio.to_thread(
+ backend.validate_reasoning_budget_capabilities,
+ backend._find_llama_server_binary(),
+ extra_args = extra_args,
+ reasoning_budget = effective_budget,
+ reasoning_budget_message = effective_message,
+ )
+ except ValueError as exc:
+ raise HTTPException(status_code = 400, detail = str(exc)) from exc
+
+
async def _override_gpu_ids_still_resolve(
gpu_ids: List[int], stored_index_kind: str = "physical"
) -> bool:
@@ -14190,6 +14254,8 @@ def _resolve_inherited_extra_args(
# must not last-wins-override it. auto leaves a user's inherited -ngl
# alone. getattr: a validate request reuses this resolver, no offload fields.
strip_offload = getattr(request, "gpu_memory_mode", "auto") == "manual",
+ strip_reasoning_budget = "reasoning_budget" in fields_set,
+ strip_reasoning_budget_message = "reasoning_budget_message" in fields_set,
# a set field emits its own flag; an inherited -b / -ub would last-wins-override it
strip_batch = "n_batch" in fields_set,
strip_ubatch = "n_ubatch" in fields_set,
@@ -15045,6 +15111,14 @@ async def _load_model_impl(
None if request.llama_extra_args is None else extra_llama_args
)
+ _reasoning_updates = {}
+ _reasoning_budget_override = parse_reasoning_budget_override(extra_llama_args)
+ if _reasoning_budget_override is not None:
+ _reasoning_updates["reasoning_budget"] = _reasoning_budget_override
+ _reasoning_message_override = parse_reasoning_budget_message_override(extra_llama_args)
+ if _reasoning_message_override is not None:
+ _reasoning_updates["reasoning_budget_message"] = _reasoning_message_override
+
# Manual mode owns the offload flags. Preserve an explicit layer count
# by translating its last-wins value into the first-class field before
# stripping the raw flags. This keeps CLI pass-through such as
@@ -15078,6 +15152,8 @@ async def _load_model_impl(
# particular, the already-loaded comparator must not compare the raw
# request's managed offload flags against the stripped launch state.
request = request.model_copy(update = {"llama_extra_args": extra_llama_args})
+ if _reasoning_updates:
+ request = request.model_copy(update = _reasoning_updates)
resolved_ollama_path = await _lease_ollama_model_ref(
request,
@@ -15317,6 +15393,11 @@ async def _load_model_impl(
# Invalid GPU IDs must fail before the training coexistence guard.
placement = await _prepare_load_placement(config, request, extra_llama_args)
+ # Ahead of the diffusion drop below: an explicit reasoning flag is a refusal, not a
+ # silent no-op, and the check needs the authoritative classification.
+ await _validate_reasoning_budget_preflight(
+ config, placement.diffusion_kind, extra_llama_args, request
+ )
if placement.diffusion_kind is True and extra_llama_args:
# The visual runner builds its own command and appends none of these, so
# keeping them would record a load as running arguments the process never
@@ -16385,6 +16466,11 @@ async def validate_model(
# Apply the same placement policy as /load before the frontend unloads
# the current model.
placement = await _prepare_load_placement(config, request, effective_extra_args)
+ # Same ordering as /load: judged before the diffusion drop, or an explicit
+ # pass-through flag would be ignored rather than refused.
+ await _validate_reasoning_budget_preflight(
+ config, placement.diffusion_kind, effective_extra_args, request
+ )
if placement.diffusion_kind is True and effective_extra_args:
# Same drop as /load, and for the same reason: the diffusion runner appends
# none of these, so an estimate that reads a --ctx-size out of them approves
diff --git a/studio/backend/routes/settings.py b/studio/backend/routes/settings.py
index c8ab526721a..a95fb40e1e5 100644
--- a/studio/backend/routes/settings.py
+++ b/studio/backend/routes/settings.py
@@ -78,6 +78,7 @@ from utils.download_transport_settings import (
set_download_transport_mode,
)
from picker.schemas import MAX_CHAT_TEMPLATE_BYTES, chat_template_byte_length
+from utils.reasoning_budget import validate_reasoning_budget_message
from utils.coding_agents import CODING_AGENTS, detect_installed_coding_agents
from utils.model_memory_settings import (
DEFAULT_KEEP_RESIDENT,
@@ -810,6 +811,8 @@ class ModelOverridePayload(BaseModel):
spec_draft_n_max: Optional[int] = Field(default = None, ge = 1, le = 16)
# Parallel decode slots (llama-server --parallel), GGUF-only; None follows the server default.
n_parallel: Optional[int] = Field(default = None, ge = PARALLEL_SLOTS_MIN, le = PARALLEL_SLOTS_MAX)
+ reasoning_budget: Optional[int] = Field(default = None, ge = -1, le = 2_147_483_647)
+ reasoning_budget_message: Optional[str] = None
# prompt batch sizes (--batch-size / --ubatch-size), gguf-only; none = llama.cpp defaults
n_batch: Optional[int] = Field(default = None, ge = BATCH_SIZE_MIN, le = BATCH_SIZE_MAX)
n_ubatch: Optional[int] = Field(default = None, ge = BATCH_SIZE_MIN, le = BATCH_SIZE_MAX)
@@ -825,6 +828,9 @@ class ModelOverridePayload(BaseModel):
# predates them is indistinguishable from a user clearing them. Only a client that sets this may clear by
# omission; default False, so an old payload is the safe case.
mirrors_server_tuning: bool = False
+ # The reasoning pair came later than the four, so a build that mirrors them can still
+ # predate it: its own flag, same contract.
+ mirrors_reasoning_budget: bool = False
tensor_parallel: bool = False
disable_vision: bool = False
# Validated in bytes below: pydantic counts characters, so a multi-byte template would pass.
@@ -854,11 +860,17 @@ class ModelOverridePayload(BaseModel):
raise ValueError(f"Chat template exceeds the {MAX_CHAT_TEMPLATE_BYTES}-byte limit.")
return value
+ @field_validator("reasoning_budget_message")
+ @classmethod
+ def _validate_reasoning_budget_message(cls, value: Optional[str]) -> Optional[str]:
+ return None if value is None else validate_reasoning_budget_message(value)
+
@field_validator(
"max_seq_length",
"custom_context_length",
"spec_draft_n_max",
"n_parallel",
+ "reasoning_budget",
"n_batch",
"n_ubatch",
"ctx_checkpoints",
@@ -1583,6 +1595,43 @@ def _fallback_supplies_extra_args(model_id: str, target_id: str) -> bool:
return False
+def _fallback_supplies_reasoning_flag(model_id: str, target_id: str) -> bool:
+ """Whether a load for this model would still pick a reasoning flag off another entry.
+
+ The -1/"" pair is stored rather than dropped so a qualified row survives as a tombstone that
+ shadows such a flag. A later save leaving the controls at their defaults omits the pair, and
+ without this the row can empty out, be deleted, and hand the reset value straight back.
+ """
+ from core.inference.llama_server_args import (
+ parse_reasoning_budget_message_override,
+ parse_reasoning_budget_override,
+ )
+ from utils.openai_auto_switch_settings import get_model_override
+
+ for candidate in (
+ _bare_model_id(model_id),
+ _legacy_standalone_gguf_key(model_id),
+ ):
+ if not candidate or candidate == target_id:
+ continue
+ stored = get_model_override(candidate)
+ if stored.get("reasoning_budget", -1) != -1 or stored.get("reasoning_budget_message"):
+ return True
+ stored_args = stored.get("llama_extra_args")
+ if not stored_args:
+ continue
+ try:
+ if (
+ parse_reasoning_budget_override(stored_args) is not None
+ or parse_reasoning_budget_message_override(stored_args) is not None
+ ):
+ return True
+ except ValueError:
+ # A malformed stored flag is the loader's problem, not this save's.
+ continue
+ return False
+
+
def _other_quants_remain(bare_id: str, removed_ids: list[str]) -> bool:
"""Whether a quant of ``bare_id`` other than the ones being removed still has an entry. Such a quant has its
own settings and never reads the bare fallback, so this is not "is anyone inheriting" but "is this
@@ -1670,7 +1719,11 @@ def _serialized_override_write(func):
def update_openai_auto_switch_override(
payload: ModelOverridePayload, current_subject: str = Depends(get_current_subject)
) -> ModelOverridesResponse:
- from core.inference.llama_server_args import drop_managed_flags, validate_extra_args
+ from core.inference.llama_server_args import (
+ drop_managed_flags,
+ strip_shadowing_flags,
+ validate_extra_args,
+ )
from utils.openai_auto_switch_settings import get_model_override
try:
@@ -1689,6 +1742,7 @@ def update_openai_auto_switch_override(
"remove",
"fill_absent_fields",
"mirrors_server_tuning",
+ "mirrors_reasoning_budget",
},
exclude_none = True,
)
@@ -1727,6 +1781,22 @@ def update_openai_auto_switch_override(
requested_extra_args = get_model_override(alias_id).get("llama_extra_args")
if requested_extra_args is not None:
break
+ fields_set = payload.model_fields_set
+ reset_reasoning_budget = "reasoning_budget" in fields_set and payload.reasoning_budget == -1
+ reset_reasoning_budget_message = (
+ "reasoning_budget_message" in fields_set and payload.reasoning_budget_message == ""
+ )
+ if not payload.fill_absent_fields and requested_extra_args:
+ requested_extra_args = strip_shadowing_flags(
+ requested_extra_args,
+ strip_context = False,
+ strip_cache = False,
+ strip_spec = False,
+ strip_template = False,
+ strip_split_mode = False,
+ strip_reasoning_budget = reset_reasoning_budget,
+ strip_reasoning_budget_message = reset_reasoning_budget_message,
+ )
# Not validated on an explicit remove: a 400 would only leave the override in place.
if payload.remove is True:
extra_args = []
@@ -1746,8 +1816,13 @@ def update_openai_auto_switch_override(
# the caller never knew about must survive it. Gated on is_removal, not on payload.remove: the documented
# legacy contract is a payload carrying only model_id, which leaves remove None.
_tuning_fields = ("load_mode", "spec_draft_cache_type", "ctx_checkpoints", "cache_ram")
- _kept_tuning = {name: getattr(payload, name) for name in _tuning_fields}
- if not payload.mirrors_server_tuning and not is_removal:
+ _reasoning_fields = ("reasoning_budget", "reasoning_budget_message")
+ _kept_tuning = {name: getattr(payload, name) for name in _tuning_fields + _reasoning_fields}
+ # Each group is carried only for a client that does not mirror it.
+ _carried_fields = (() if payload.mirrors_server_tuning else _tuning_fields) + (
+ () if payload.mirrors_reasoning_budget else _reasoning_fields
+ )
+ if _carried_fields and not is_removal:
# The same spellings the extra-args carry-over walks: a cached repo is not an ordinary folded match,
# so a save under the repo id would find nothing and retire the alias with its tuning.
_alias_ids = [payload.model_id]
@@ -1768,7 +1843,7 @@ def update_openai_auto_switch_override(
_stored_tuning = get_model_override(_alias_id)
if not _stored_tuning:
continue
- for name in _tuning_fields:
+ for name in _carried_fields:
if _kept_tuning[name] is None:
_kept_tuning[name] = _stored_tuning.get(name)
break
@@ -1823,6 +1898,18 @@ def update_openai_auto_switch_override(
and not payload.fill_absent_fields
and _fallback_supplies_extra_args(payload.model_id, target_id)
)
+ # A default the caller did not send still has to be written while a broader entry
+ # would otherwise answer with the flag this row exists to shadow.
+ _kept_reasoning_budget = _kept_tuning["reasoning_budget"]
+ _kept_reasoning_budget_message = _kept_tuning["reasoning_budget_message"]
+ if (
+ not payload.fill_absent_fields
+ and _kept_reasoning_budget is None
+ and _kept_reasoning_budget_message is None
+ and _fallback_supplies_reasoning_flag(payload.model_id, target_id)
+ ):
+ _kept_reasoning_budget = -1
+ _kept_reasoning_budget_message = ""
set_model_override(
target_id,
llama_extra_args = extra_args,
@@ -1834,6 +1921,16 @@ def update_openai_auto_switch_override(
speculative_type = payload.speculative_type,
spec_draft_n_max = payload.spec_draft_n_max,
n_parallel = payload.n_parallel,
+ reasoning_budget = (
+ None
+ if payload.fill_absent_fields and reset_reasoning_budget
+ else _kept_reasoning_budget
+ ),
+ reasoning_budget_message = (
+ None
+ if payload.fill_absent_fields and reset_reasoning_budget_message
+ else _kept_reasoning_budget_message
+ ),
n_batch = payload.n_batch,
n_ubatch = payload.n_ubatch,
load_mode = _kept_tuning["load_mode"],
diff --git a/studio/backend/tests/test_gguf_reload_inheritance.py b/studio/backend/tests/test_gguf_reload_inheritance.py
index 14cb3437f23..d9351ff7397 100644
--- a/studio/backend/tests/test_gguf_reload_inheritance.py
+++ b/studio/backend/tests/test_gguf_reload_inheritance.py
@@ -10,6 +10,7 @@ HF-mode hf_variant fallback, and ``extra_args`` None-vs-[] inherit semantics.
from __future__ import annotations
+import inspect
import sys
import types as _types
from pathlib import Path
@@ -59,6 +60,12 @@ except ImportError:
sys.modules.setdefault("httpx", _httpx_stub)
from core.inference.llama_cpp import GgufLoadIntent, LlamaCppBackend
+from models.inference import (
+ InferenceStatusResponse,
+ LoadRequest,
+ LoadResponse,
+ ValidateModelRequest,
+)
class _FakeProcess:
@@ -85,6 +92,8 @@ def _loaded_backend(**overrides):
backend._hf_variant = "Q4_K_M"
backend._requested_n_ctx = 8192
backend._cache_type_kv = None
+ backend._reasoning_budget = -1
+ backend._reasoning_budget_message = ""
backend._speculative_type = None
backend._requested_spec_mode = "auto"
backend._chat_template_override = None
@@ -278,6 +287,104 @@ def test_extra_args_source_default_is_none():
assert backend.extra_args_source is None
+def test_reasoning_budget_schema_contract():
+ request = LoadRequest(model_path = "owner/repo")
+ assert request.reasoning_budget == -1
+ assert request.reasoning_budget_message == ""
+ assert LoadRequest(model_path = "owner/repo", reasoning_budget = 0).reasoning_budget == 0
+ with pytest.raises(ValueError):
+ LoadRequest(model_path = "owner/repo", reasoning_budget = -2)
+ with pytest.raises(ValueError, match = "8192-byte"):
+ LoadRequest(model_path = "owner/repo", reasoning_budget_message = "😀" * 2_049)
+ with pytest.raises(ValueError, match = "NUL"):
+ LoadRequest(model_path = "owner/repo", reasoning_budget_message = "bad\0message")
+ padded = LoadRequest(model_path = "owner/repo", reasoning_budget_message = " PAD ")
+ assert padded.reasoning_budget_message == " PAD "
+
+ load = LoadResponse(status = "loaded", model = "m", display_name = "m", inference = {})
+ status = InferenceStatusResponse()
+ assert (load.reasoning_budget, load.reasoning_budget_message) == (-1, "")
+ assert (status.reasoning_budget, status.reasoning_budget_message) == (-1, "")
+
+
+def test_reasoning_budget_is_part_of_backend_dedupe():
+ backend = _loaded_backend(
+ _reasoning_budget = 64,
+ _reasoning_budget_message = "limit",
+ _requested_reasoning_budget = 64,
+ _requested_reasoning_budget_message = "limit",
+ )
+ common = dict(
+ model_identifier = "owner/repo",
+ hf_variant = "Q4_K_M",
+ n_ctx = 8192,
+ cache_type_kv = None,
+ speculative_type = None,
+ chat_template_override = None,
+ extra_args = None,
+ is_vision = False,
+ reasoning_budget = 64,
+ reasoning_budget_message = "limit",
+ )
+ assert _matches(backend, **common) is True
+ assert _matches(backend, **{**common, "reasoning_budget": 32}) is False
+ flags = ["--reasoning-budget", "64", "--reasoning-budget-message", "limit"]
+ backend = _loaded_backend(
+ _reasoning_budget = 64,
+ _reasoning_budget_message = "limit",
+ _requested_reasoning_budget = 64,
+ _requested_reasoning_budget_message = "limit",
+ _extra_args = flags,
+ )
+ assert (
+ _matches(
+ backend,
+ **{
+ **common,
+ "reasoning_budget": -1,
+ "reasoning_budget_message": "",
+ "extra_args": flags,
+ },
+ )
+ is True
+ )
+
+
+def test_reasoning_budget_state_resets_on_unload():
+ backend = _loaded_backend(_reasoning_budget = 64, _reasoning_budget_message = "limit")
+ backend.unload_model()
+ assert backend.reasoning_budget == -1
+ assert backend.reasoning_budget_message == ""
+
+
+def test_load_wires_reasoning_args_and_respawn_snapshot():
+ source = inspect.getsource(LlamaCppBackend.load_model)
+ assert "_build_reasoning_budget_flags(" in source
+ # The respawn snapshot is the intent itself, so the fields have to come off it.
+ assert "reasoning_budget = intent.reasoning_budget" in source
+ assert "reasoning_budget_message = intent.reasoning_budget_message" in source
+ assert source.index("validate_reasoning_budget_capabilities") < source.index(
+ "self._kill_process()"
+ )
+
+
+def test_route_checks_reasoning_budget_capabilities_before_teardown():
+ route_source = (Path(__file__).resolve().parent.parent / "routes" / "inference.py").read_text(
+ encoding = "utf-8"
+ )
+ preflight = route_source.index("backend.validate_reasoning_budget_capabilities")
+ diffusion_rejection = route_source.index(
+ "Reasoning Budget settings are not supported for DiffusionGemma models."
+ )
+ unknown_rejection = route_source.index(
+ "Reasoning Budget settings cannot be applied until this GGUF is"
+ )
+ teardown = route_source.index("# Point of no return for the GGUF path")
+ assert preflight < teardown
+ assert diffusion_rejection < teardown
+ assert unknown_rejection < teardown
+
+
class TestRepeatLoadMatchesTheEffectiveCache:
"""A repeat /load of an identical request must reuse the healthy server.
@@ -378,3 +485,66 @@ class TestRepeatLoadMatchesTheEffectiveCache:
load = "".join(inspect.getsource(LlamaCppBackend.load_model).split())
assert "self._effective_cache_types=_effective_main_cache_types(" in load
assert "self._requested_cache_types=_planned_cache_pair" in load
+
+
[email protected]("model", [LoadRequest, ValidateModelRequest])
+def test_reasoning_budget_rejects_booleans(model):
+ # bool subclasses int and pydantic parses lax, so `true` would launch a one-token budget.
+ with pytest.raises(ValueError, match = "Expected a number, got a boolean"):
+ model(model_path = "unsloth/x", reasoning_budget = True)
+ assert model(model_path = "unsloth/x", reasoning_budget = 1).reasoning_budget == 1
+
+
+def test_the_reuse_check_compares_the_request_not_the_environment():
+ """An inherited LLAMA_ARG_THINK_BUDGET* cannot be sent or cleared by any request, so comparing
+ the live EFFECTIVE value against a resolved request tore down a healthy server on every load."""
+ source = inspect.getsource(LlamaCppBackend._runtime_matches_intent)
+ assert "self._requested_reasoning_budget" in source
+ assert (
+ "resolve_reasoning_budget_with_env" not in source
+ ), "the reuse check must not fold the environment into the request"
+
+ launch = inspect.getsource(LlamaCppBackend.load_model)
+ assert "self._requested_reasoning_budget = reasoning_budget" in launch
+ # A probe that could not be read says nothing about the flag, and the child still applies
+ # the environment, so only a conclusive "unsupported" may drop it.
+ assert "reasoning_budget_probe_inconclusive" in launch
+
+
+def test_requested_reasoning_budget_is_reported_separately():
+ from models.inference import InferenceStatusResponse
+
+ fields = InferenceStatusResponse.model_fields
+ for name in ("requested_reasoning_budget", "requested_reasoning_budget_message"):
+ assert name in fields, name
+ assert fields["requested_reasoning_budget"].default == -1
+ assert fields["requested_reasoning_budget_message"].default == ""
+
+
+def test_an_inherited_env_budget_does_not_force_a_reload():
+ """The live EFFECTIVE value carries LLAMA_ARG_THINK_BUDGET*, which no request can send or
+ clear. Comparing against it tore down a healthy server on every load and never converged."""
+ backend = _loaded_backend(
+ # What the environment gave the child...
+ _reasoning_budget = 512,
+ _reasoning_budget_message = "from env",
+ # ...against a load that asked for nothing.
+ _requested_reasoning_budget = -1,
+ _requested_reasoning_budget_message = "",
+ )
+ assert (
+ _matches(
+ backend,
+ model_identifier = "owner/repo",
+ hf_variant = "Q4_K_M",
+ n_ctx = 8192,
+ cache_type_kv = None,
+ speculative_type = None,
+ chat_template_override = None,
+ extra_args = None,
+ is_vision = False,
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ )
+ is True
+ )
diff --git a/studio/backend/tests/test_llama_cpp_mtp_detection.py b/studio/backend/tests/test_llama_cpp_mtp_detection.py
index 90f36a65b81..594053329c1 100644
--- a/studio/backend/tests/test_llama_cpp_mtp_detection.py
+++ b/studio/backend/tests/test_llama_cpp_mtp_detection.py
@@ -70,6 +70,7 @@ from core.inference.llama_cpp import (
_THREAD_OVERRIDE_FLAGS,
_backfill_usage_from_timings,
_build_ngram_mod_flags,
+ _build_reasoning_budget_flags,
_canonicalize_spec_mode,
_extra_args_set_any_flag,
_extra_args_set_spec_type,
@@ -893,6 +894,272 @@ def test_probe_server_capabilities_reports_outdated_binary(tmp_path):
assert caps["mtp_probe_inconclusive"] is False
+@_NEEDS_BASH
+def test_probe_server_capabilities_detects_reasoning_budget_flags(tmp_path):
+ fake = _make_fake_llama_server(
+ tmp_path / "llama-server",
+ # Column 0, the way llama-server really prints its flags; the indented lines are
+ # descriptions. The sibling tests below use the same layout.
+ "--reasoning-budget N\n--reasoning-budget-message MESSAGE\n",
+ )
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["supports_reasoning_budget"] is True
+ assert caps["supports_reasoning_budget_message"] is True
+ assert caps["reasoning_budget_probe_inconclusive"] is False
+
+
+@_NEEDS_BASH
+def test_probe_server_capabilities_reports_missing_reasoning_budget_flags(tmp_path):
+ fake = _make_fake_llama_server(
+ tmp_path / "llama-server",
+ "--gpu-layers N\n",
+ )
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["supports_reasoning_budget"] is False
+ assert caps["supports_reasoning_budget_message"] is False
+ assert caps["reasoning_budget_probe_inconclusive"] is False
+
+
+@_NEEDS_BASH
+def test_probe_ignores_indented_flag_references_in_descriptions(tmp_path):
+ fake = _make_fake_llama_server(
+ tmp_path / "llama-server",
+ "--gpu-layers N\n --reasoning-budget is unavailable on this legacy build\n",
+ )
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["supports_reasoning_budget"] is False
+
+
+def test_reasoning_budget_capability_gate_allows_defaults_on_old_binary(monkeypatch):
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "probe_server_capabilities",
+ classmethod(
+ lambda cls, binary = None: {
+ "supports_reasoning_budget": False,
+ "supports_reasoning_budget_message": False,
+ "reasoning_budget_probe_inconclusive": False,
+ }
+ ),
+ )
+ caps = LlamaCppBackend.validate_reasoning_budget_capabilities(
+ "/old/llama-server",
+ extra_args = None,
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ )
+ assert caps["supports_reasoning_budget"] is False
+ assert _build_reasoning_budget_flags(caps, -1, "") == []
+
+
+def test_reasoning_budget_command_flags_follow_capabilities():
+ caps = {
+ "supports_reasoning_budget": True,
+ "supports_reasoning_budget_message": True,
+ }
+ assert _build_reasoning_budget_flags(caps, -1, "") == []
+ assert _build_reasoning_budget_flags(caps, 64, " PAD ") == [
+ "--reasoning-budget",
+ "64",
+ "--reasoning-budget-message",
+ " PAD ",
+ ]
+
+
+@_NEEDS_BASH
+def test_reasoning_budget_capability_gate_rejects_legacy_positive_range(tmp_path, monkeypatch):
+ fake = tmp_path / "llama-server"
+ fake.write_text(
+ "#!/usr/bin/env bash\n"
+ 'if [[ "$1" == "--reasoning-budget" && "$2" != "0" && "$2" != "-1" ]]; then\n'
+ " exit 1\n"
+ "fi\n"
+ "printf '%s\\n' '--reasoning-budget N' '--reasoning-budget-message TEXT'\n"
+ )
+ fake.chmod(0o755)
+ _clear_caps_cache()
+
+ with pytest.raises(ValueError, match = "does not accept positive reasoning budgets"):
+ LlamaCppBackend.validate_reasoning_budget_capabilities(
+ str(fake),
+ extra_args = None,
+ reasoning_budget = 512,
+ reasoning_budget_message = "",
+ )
+ # A passthrough flag is still an explicit request, so it gates like the field.
+ with pytest.raises(ValueError, match = "does not accept positive reasoning budgets"):
+ LlamaCppBackend.validate_reasoning_budget_capabilities(
+ str(fake),
+ extra_args = ["--reasoning-budget", "512"],
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ )
+ # The env default is not: no Studio control clears it, and llama-server
+ # validates its own env, so failing here is unrecoverable from the UI.
+ monkeypatch.setenv("LLAMA_ARG_THINK_BUDGET", "512")
+ LlamaCppBackend.validate_reasoning_budget_capabilities(
+ str(fake),
+ extra_args = None,
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ )
+ monkeypatch.delenv("LLAMA_ARG_THINK_BUDGET")
+ LlamaCppBackend.validate_reasoning_budget_capabilities(
+ str(fake),
+ extra_args = None,
+ reasoning_budget = 0,
+ reasoning_budget_message = "",
+ )
+
+
+ "kwargs,missing_flag",
+ [
+ ({"reasoning_budget": 64}, "--reasoning-budget"),
+ ({"reasoning_budget_message": "Conclude"}, "--reasoning-budget-message"),
+ (
+ {"extra_args": ["--reasoning-budget", "-1"]},
+ "--reasoning-budget",
+ ),
+ ],
+)
+def test_reasoning_budget_capability_gate_rejects_explicit_old_binary(
+ monkeypatch, kwargs, missing_flag
+):
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "probe_server_capabilities",
+ classmethod(
+ lambda cls, binary = None: {
+ "supports_reasoning_budget": False,
+ "supports_reasoning_budget_message": False,
+ "reasoning_budget_probe_inconclusive": False,
+ }
+ ),
+ )
+ request = {
+ "extra_args": None,
+ "reasoning_budget": -1,
+ "reasoning_budget_message": "",
+ **kwargs,
+ }
+ with pytest.raises(ValueError, match = missing_flag):
+ LlamaCppBackend.validate_reasoning_budget_capabilities("/old/llama-server", **request)
+
+
+def test_reasoning_budget_capability_gate_ignores_env_on_unprobeable_binary(monkeypatch):
+ """An env default must not fail closed on a binary whose --help cannot be read.
+
+ Nothing was configured, so the rejection named a setting the UI shows as default.
+ Effective state still reports the inherited value; only the gate ignores it.
+ """
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "probe_server_capabilities",
+ classmethod(
+ lambda cls, binary = None: {
+ "supports_reasoning_budget": False,
+ "supports_reasoning_budget_message": False,
+ "reasoning_budget_probe_inconclusive": True,
+ }
+ ),
+ )
+ monkeypatch.setenv("LLAMA_ARG_THINK_BUDGET", "512")
+ monkeypatch.setenv("LLAMA_ARG_THINK_BUDGET_MESSAGE", "Wrap up.")
+ LlamaCppBackend.validate_reasoning_budget_capabilities(
+ "/custom/llama-server",
+ extra_args = None,
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ )
+
+
+def test_positive_budget_probe_drops_inherited_llama_env(monkeypatch):
+ """llama-server reads LLAMA_ARG_* before argv, so a stale inherited value fails its own
+ parse and would be recorded as the binary rejecting positive budgets."""
+ import core.inference.llama_cpp as llama_cpp_module
+
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "probe_server_capabilities",
+ classmethod(
+ lambda cls, binary = None: {
+ "supports_reasoning_budget": True,
+ "supports_reasoning_budget_message": True,
+ }
+ ),
+ )
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "_llama_server_env_for_binary",
+ staticmethod(
+ lambda binary: {
+ "PATH": "/usr/bin",
+ "LLAMA_ARG_PORT": "junk",
+ "LLAMA_ARG_THINK_BUDGET": "512",
+ }
+ ),
+ )
+ seen = {}
+
+ def _run(cmd, **kwargs):
+ seen["env"] = dict(kwargs["env"])
+ return _types.SimpleNamespace(returncode = 0, stdout = "", stderr = "")
+
+ monkeypatch.setattr(llama_cpp_module.subprocess, "run", _run)
+ caps = LlamaCppBackend.validate_reasoning_budget_capabilities(
+ "/custom/llama-server",
+ extra_args = None,
+ reasoning_budget = 512,
+ reasoning_budget_message = "",
+ )
+ assert caps["supports_reasoning_budget_value:512"] is True
+ assert not [name for name in seen["env"] if name.startswith("LLAMA_ARG_")]
+ assert seen["env"]["PATH"] == "/usr/bin"
+
+
+def test_reasoning_budget_capability_gate_rejects_inconclusive_probe(monkeypatch):
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "probe_server_capabilities",
+ classmethod(
+ lambda cls, binary = None: {
+ "supports_reasoning_budget": False,
+ "supports_reasoning_budget_message": False,
+ "reasoning_budget_probe_inconclusive": True,
+ }
+ ),
+ )
+ with pytest.raises(ValueError, match = "could not verify"):
+ LlamaCppBackend.validate_reasoning_budget_capabilities(
+ "/custom/llama-server",
+ extra_args = None,
+ reasoning_budget = 64,
+ reasoning_budget_message = "",
+ )
+
+
+def test_explicit_reasoning_budget_rejects_local_diffusion_before_kill(tmp_path, monkeypatch):
+ gguf = tmp_path / "diffusion.gguf"
+ gguf.write_bytes(b"GGUF")
+ backend = LlamaCppBackend()
+ monkeypatch.setattr(backend, "_find_llama_server_binary", lambda *args, **kwargs: "/fake")
+ monkeypatch.setattr(backend, "_gguf_path_is_diffusion", lambda *args, **kwargs: True)
+ monkeypatch.setattr(backend, "_kill_process", lambda: pytest.fail("killed before rejection"))
+
+ with pytest.raises(ValueError, match = "DiffusionGemma"):
+ backend.load_model(
+ GgufLoadIntent(
+ gguf_path = str(gguf),
+ model_identifier = "owner/DiffusionGemma-GGUF",
+ reasoning_budget = 64,
+ )
+ )
+
+
@_NEEDS_BASH
def test_probe_server_capabilities_reads_mtp_from_multiline_help(tmp_path):
# Enum on the indented line: first-line-only probing falsely reported
@@ -3644,3 +3911,35 @@ def test_a_drafter_dropped_as_unloadable_does_not_reload_to_refetch_it():
)
is True
)
+
+
+def test_positive_budget_probe_uses_resolved_launch_path(monkeypatch):
+ import core.inference.llama_cpp as llama_cpp_module
+
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "probe_server_capabilities",
+ classmethod(lambda cls, binary: {"supports_reasoning_budget": True}),
+ )
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "_exec_path_for_launch",
+ staticmethod(lambda binary: "/runtime/bin/llama-server"),
+ )
+ monkeypatch.setattr(
+ LlamaCppBackend,
+ "_llama_server_env_for_binary",
+ staticmethod(lambda binary: {}),
+ )
+
+ def run(cmd, **kwargs):
+ return _types.SimpleNamespace(returncode = 0 if cmd[0] == "/runtime/bin/llama-server" else 1)
+
+ monkeypatch.setattr(llama_cpp_module.subprocess, "run", run)
+ caps = LlamaCppBackend.validate_reasoning_budget_capabilities(
+ "/runtime/llama-server",
+ extra_args = None,
+ reasoning_budget = 32,
+ reasoning_budget_message = "",
+ )
+ assert caps["supports_reasoning_budget_value:32"] is True
diff --git a/studio/backend/tests/test_llama_server_args.py b/studio/backend/tests/test_llama_server_args.py
index 57e43e0a2d6..e072fd34e12 100644
--- a/studio/backend/tests/test_llama_server_args.py
+++ b/studio/backend/tests/test_llama_server_args.py
@@ -27,8 +27,14 @@ parse_cache_override = _lsa.parse_cache_override
parse_cache_override_per_axis = _lsa.parse_cache_override_per_axis
parse_ctx_override = _lsa.parse_ctx_override
parse_gpu_layers_override = _lsa.parse_gpu_layers_override
+parse_reasoning_budget_message_override = _lsa.parse_reasoning_budget_message_override
+parse_reasoning_budget_override = _lsa.parse_reasoning_budget_override
parse_split_mode_override = _lsa.parse_split_mode_override
resolve_cache_type_kv = _lsa.resolve_cache_type_kv
+resolve_reasoning_budget = _lsa.resolve_reasoning_budget
+resolve_reasoning_budget_message = _lsa.resolve_reasoning_budget_message
+resolve_reasoning_budget_message_with_env = _lsa.resolve_reasoning_budget_message_with_env
+resolve_reasoning_budget_with_env = _lsa.resolve_reasoning_budget_with_env
resolve_tensor_parallel = _lsa.resolve_tensor_parallel
strip_shadowing_flags = _lsa.strip_shadowing_flags
strip_split_mode_only = _lsa.strip_split_mode_only
@@ -587,6 +593,117 @@ def test_validate_extra_args_rejects_malformed_gpu_layers_override():
validate_extra_args(["-ngl", "abc"])
+# ── reasoning budget first-class shadows ─────────────────────────────
+
+
+def test_reasoning_budget_overrides_are_last_wins():
+ args = [
+ "--reasoning-budget",
+ "32",
+ "--reasoning-budget=64",
+ "--reasoning-budget-message",
+ "first",
+ "--reasoning-budget-message=limit reached",
+ ]
+ assert parse_reasoning_budget_override(args) == 64
+ assert parse_reasoning_budget_message_override(args) == "limit reached"
+ assert resolve_reasoning_budget(args, -1) == 64
+ assert resolve_reasoning_budget_message(args, "") == "limit reached"
+
+
+ "args",
+ [
+ ["--reasoning-budget-message", " PAD "],
+ ["--reasoning-budget-message= PAD "],
+ ],
+)
+def test_reasoning_budget_message_preserves_verbatim_whitespace(args):
+ assert parse_reasoning_budget_message_override(args) == " PAD "
+ assert resolve_reasoning_budget_message(args, "fallback") == " PAD "
+
+
+def test_reasoning_budget_defaults_inherit_env_but_passthrough_still_wins():
+ env = {
+ "LLAMA_ARG_THINK_BUDGET": "512",
+ "LLAMA_ARG_THINK_BUDGET_MESSAGE": "from env",
+ }
+ assert resolve_reasoning_budget_with_env(None, -1, env) == 512
+ assert resolve_reasoning_budget_message_with_env(None, "", env) == "from env"
+ assert resolve_reasoning_budget_with_env(["--reasoning-budget", "-1"], -1, env) == -1
+ assert (
+ resolve_reasoning_budget_message_with_env(
+ ["--reasoning-budget-message", " CLI "], "", env
+ )
+ == " CLI "
+ )
+
+
+# A NUL trips the generic control-character check on the whole list first, so the
+# flag-specific message is only reachable for the oversize case.
+ "unsafe, message",
+ [("😀" * 2_049, "reasoning-budget-message"), ("bad\0message", "control characters")],
+)
+def test_reasoning_budget_message_validates_every_occurrence(unsafe, message):
+ with pytest.raises(ValueError, match = message):
+ validate_extra_args(
+ [
+ "--reasoning-budget-message",
+ unsafe,
+ "--reasoning-budget-message",
+ "safe final value",
+ ]
+ )
+
+
+ "args",
+ [
+ ["--reasoning-budget"],
+ ["--reasoning-budget", "nope"],
+ ["--reasoning-budget=-2"],
+ ["--reasoning-budget=2147483648"],
+ ["--reasoning-budget-message"],
+ ["--reasoning-budget-message", "😀" * 2_049],
+ ["--reasoning-budget-message", "bad\0message"],
+ ],
+)
+def test_validate_extra_args_rejects_malformed_reasoning_overrides(args):
+ # A NUL is caught by the list-wide control-character check before the flag parser runs.
+ with pytest.raises(ValueError, match = "reasoning-budget|control characters"):
+ validate_extra_args(args)
+
+
+def test_strip_reasoning_shadows_is_granular():
+ args = [
+ "--reasoning-budget",
+ "64",
+ "--reasoning-budget-message",
+ "limit reached",
+ "--top-k",
+ "20",
+ ]
+ assert strip_shadowing_flags(
+ args,
+ strip_context = False,
+ strip_cache = False,
+ strip_spec = False,
+ strip_template = False,
+ strip_split_mode = False,
+ strip_reasoning_budget = True,
+ ) == ["--reasoning-budget-message", "limit reached", "--top-k", "20"]
+ assert strip_shadowing_flags(
+ args,
+ strip_context = False,
+ strip_cache = False,
+ strip_spec = False,
+ strip_template = False,
+ strip_split_mode = False,
+ strip_reasoning_budget_message = True,
+ ) == ["--reasoning-budget", "64", "--top-k", "20"]
+
+
# ── parse_cache_override ─────────────────────────────────────────────
diff --git a/studio/backend/tests/test_model_override_schema_compatibility.py b/studio/backend/tests/test_model_override_schema_compatibility.py
index c91414a0f66..10a07abe1d5 100644
--- a/studio/backend/tests/test_model_override_schema_compatibility.py
+++ b/studio/backend/tests/test_model_override_schema_compatibility.py
@@ -363,3 +363,117 @@ def test_the_disable_aliases_survive_override_normalization():
assert "speculative_type" not in settings.normalize_model_override(
{"speculative_type": "bogus"}
)
+
+
+# The pair the route learned to forward one release after the four: the same replace-on-write
+# exposure, and a build that mirrors the tuning group can still predate it.
+REASONING_PAYLOAD = dict(reasoning_budget = 512, reasoning_budget_message = "Wrap up.")
+
+
+def test_a_client_that_does_not_know_the_reasoning_pair_cannot_erase_it(override_store):
+ _put(
+ MODEL,
+ **PRE_TUNING_PAYLOAD,
+ **REASONING_PAYLOAD,
+ mirrors_server_tuning = True,
+ mirrors_reasoning_budget = True,
+ )
+ before = settings.get_model_override(MODEL)
+ for field, value in REASONING_PAYLOAD.items():
+ assert before[field] == value
+
+ # A build that mirrors the four but predates the pair: it cannot set the new flag.
+ _put(MODEL, **PRE_TUNING_PAYLOAD, mirrors_server_tuning = True)
+ after = settings.get_model_override(MODEL)
+
+ for field, value in REASONING_PAYLOAD.items():
+ assert after[field] == value, f"{field} was deleted by a save that never mentioned it"
+ assert after == before
+ kwargs = settings.model_override_load_kwargs(after, is_gguf = True)
+ for field, value in REASONING_PAYLOAD.items():
+ assert kwargs[field] == value
+
+
+def test_a_client_that_does_know_the_reasoning_pair_still_clears_by_omission(override_store):
+ _put(
+ MODEL,
+ **PRE_TUNING_PAYLOAD,
+ **REASONING_PAYLOAD,
+ mirrors_server_tuning = True,
+ mirrors_reasoning_budget = True,
+ )
+ assert settings.get_model_override(MODEL)["reasoning_budget"] == 512
+
+ _put(MODEL, **PRE_TUNING_PAYLOAD, mirrors_server_tuning = True, mirrors_reasoning_budget = True)
+ after = settings.get_model_override(MODEL)
+ for field in REASONING_PAYLOAD:
+ assert field not in after, f"{field} survived an explicit clear"
+
+
+def test_the_reasoning_flag_is_not_itself_a_saved_field(override_store):
+ _put(MODEL, **PRE_TUNING_PAYLOAD, mirrors_reasoning_budget = True)
+ assert settings.get_model_override(MODEL)
+
+ _put(MODEL, mirrors_reasoning_budget = True)
+ assert settings.get_model_override(MODEL) == {}
+
+
+ "fallback",
+ [
+ {"llama_extra_args": ["--reasoning-budget", "512"]},
+ {"reasoning_budget": 512},
+ {"reasoning_budget": 0},
+ {"reasoning_budget_message": "Wrap up."},
+ ],
+)
+def test_a_reset_tombstone_outlives_a_later_default_save(override_store, fallback):
+ """The -1/"" pair is stored so a qualified row shadows a reasoning flag on a broader entry.
+ A later save with the controls at their defaults omits the pair, and the row must not empty
+ out and be deleted, or the load falls back and hands the reset value straight back."""
+ bare = "unsloth/Repo-GGUF"
+ # The legacy fallback every quant without a row of its own reads.
+ settings.set_model_override(bare, **fallback)
+
+ # The user resets the control on the quant: a tombstone, not an empty row.
+ _put(MODEL, reasoning_budget = -1, mirrors_server_tuning = True, mirrors_reasoning_budget = True)
+ assert settings.get_model_override(MODEL).get("reasoning_budget") == -1
+
+ # An unrelated save from the same build, controls still at their defaults.
+ _put(MODEL, mirrors_server_tuning = True, mirrors_reasoning_budget = True)
+ after = settings.get_model_override(MODEL)
+ assert (
+ after.get("reasoning_budget") == -1
+ ), "the tombstone was dropped, so the bare row's --reasoning-budget 512 applies again"
+
+ # And it still strips the shadowed flag off the load.
+ kwargs = settings.model_override_load_kwargs(after, is_gguf = True)
+ assert kwargs["reasoning_budget"] == -1
+ key, resolved = settings.resolve_override_for_load(bare, variant = "Q4_K_M")
+ assert key == MODEL
+ assert resolved.get("reasoning_budget") == -1
+ assert resolved.get("reasoning_budget_message", "") == ""
+ # Another quant still inherits the original fallback.
+ _, sibling = settings.resolve_override_for_load(bare, variant = "Q8_0")
+ assert sibling == fallback
+
+
+ "fallback", [{"reasoning_budget": 512}, {"reasoning_budget_message": "Stop"}]
+)
+def test_standalone_reasoning_reset_survives_a_later_default_save(override_store, fallback):
+ path = "/srv/models/model-Q4_K_M.gguf"
+ settings.set_model_override(f"{path}:Q4_K_M", **fallback)
+ _put(path, reasoning_budget = -1, reasoning_budget_message = "", mirrors_reasoning_budget = True)
+ _put(path, mirrors_reasoning_budget = True)
+ key, resolved = settings.resolve_override_for_load(path)
+ assert key == path
+ assert resolved.get("reasoning_budget") == -1
+ assert resolved.get("reasoning_budget_message") == ""
+
+
+def test_no_tombstone_is_invented_without_a_fallback_to_shadow(override_store):
+ # The other side: with nothing to shadow, a default save leaves no row at all.
+ _put(MODEL, reasoning_budget = -1, mirrors_server_tuning = True, mirrors_reasoning_budget = True)
+ _put(MODEL, mirrors_server_tuning = True, mirrors_reasoning_budget = True)
+ assert settings.get_model_override(MODEL) == {}
diff --git a/studio/backend/tests/test_openai_auto_switch.py b/studio/backend/tests/test_openai_auto_switch.py
index 998ac99e3c3..60f0cc1167b 100644
--- a/studio/backend/tests/test_openai_auto_switch.py
+++ b/studio/backend/tests/test_openai_auto_switch.py
@@ -1275,6 +1275,31 @@ def test_auto_switch_applies_partial_override(monkeypatch):
assert req.max_seq_length == 0 # untouched default
+def test_auto_switch_applies_reasoning_budget_override(monkeypatch):
+ backend = _FakeBackend(None)
+ rec = _LoadRecorder(backend)
+ _wire(
+ monkeypatch,
+ enabled = True,
+ resolves_to = ("unsloth/B-GGUF", "Q4_K_M", "unsloth/B-GGUF"),
+ backend = backend,
+ recorder = rec,
+ )
+ monkeypatch.setattr(
+ settings,
+ "get_model_override",
+ lambda model_id: {
+ "reasoning_budget": 2048,
+ "reasoning_budget_message": "Conclude now",
+ },
+ )
+
+ _run_hook("unsloth/B-GGUF")
+ req = rec.calls[0]
+ assert req.reasoning_budget == 2048
+ assert req.reasoning_budget_message == "Conclude now"
+
+
def _mock_override_store(monkeypatch):
"""Back the override read + atomic-merge write with an in-memory dict."""
store = {}
@@ -1344,6 +1369,139 @@ def test_model_override_roundtrip(monkeypatch):
assert settings.get_model_overrides() == {}
+def test_reasoning_budget_override_route_roundtrip(monkeypatch):
+ _mock_override_store(monkeypatch)
+
+ response = _put(
+ "unsloth/B-GGUF",
+ reasoning_budget = 2048,
+ reasoning_budget_message = "Conclude now",
+ )
+
+ assert response.overrides["unsloth/B-GGUF"] == {
+ "reasoning_budget": 2048,
+ "reasoning_budget_message": "Conclude now",
+ }
+ assert settings.model_override_load_kwargs(
+ response.overrides["unsloth/B-GGUF"], is_gguf = True
+ ) == {
+ "reasoning_budget": 2048,
+ "reasoning_budget_message": "Conclude now",
+ }
+
+
+def test_reasoning_resets_strip_only_matching_carried_flags(monkeypatch):
+ _mock_override_store(monkeypatch)
+ extras = [
+ "--reasoning-budget",
+ "2048",
+ "--reasoning-budget-message",
+ "Conclude now",
+ "--top-k",
+ "40",
+ ]
+ for suffix in ("budget", "message", "both", "fill"):
+ _put(f"unsloth/B-GGUF:{suffix}", llama_extra_args = extras)
+
+ budget = _put("unsloth/B-GGUF:budget", reasoning_budget = -1).overrides["unsloth/B-GGUF:budget"]
+ assert budget["llama_extra_args"] == [
+ "--reasoning-budget-message",
+ "Conclude now",
+ "--top-k",
+ "40",
+ ]
+ assert budget["reasoning_budget"] == -1
+
+ message = _put("unsloth/B-GGUF:message", reasoning_budget_message = "").overrides[
+ "unsloth/B-GGUF:message"
+ ]
+ assert message["llama_extra_args"] == ["--reasoning-budget", "2048", "--top-k", "40"]
+ assert message["reasoning_budget_message"] == ""
+
+ both = _put(
+ "unsloth/B-GGUF:both",
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ ).overrides["unsloth/B-GGUF:both"]
+ assert both["llama_extra_args"] == ["--top-k", "40"]
+ assert settings.model_override_load_kwargs(both, is_gguf = True) == {
+ "llama_extra_args": ["--top-k", "40"],
+ "reasoning_budget": -1,
+ "reasoning_budget_message": "",
+ }
+
+ filled = _put(
+ "unsloth/B-GGUF:fill",
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ fill_absent_fields = True,
+ ).overrides["unsloth/B-GGUF:fill"]
+ assert filled["llama_extra_args"] == extras
+ assert "reasoning_budget" not in filled
+ assert "reasoning_budget_message" not in filled
+
+
+def test_reasoning_reset_tombstone_blocks_bare_and_legacy_fallbacks(monkeypatch):
+ _mock_override_store(monkeypatch)
+
+ _put("unsloth/B-GGUF", llama_extra_args = ["--reasoning-budget", "2048"])
+ qualified = _put("unsloth/B-GGUF:Q4_K_M", reasoning_budget = -1).overrides
+ assert qualified["unsloth/B-GGUF:Q4_K_M"] == {"reasoning_budget": -1}
+ assert qualified["unsloth/B-GGUF"]["llama_extra_args"] == ["--reasoning-budget", "2048"]
+ assert settings.model_override_load_kwargs(
+ settings.get_model_override("unsloth/B-GGUF:Q4_K_M"), is_gguf = True
+ ) == {"reasoning_budget": -1}
+
+ path = "/tmp/model-Q4_K_M.gguf"
+ _put(f"{path}:Q4_K_M", llama_extra_args = ["--reasoning-budget-message", "Stop"])
+ standalone = _put(path, reasoning_budget_message = "").overrides
+ assert standalone[path] == {"reasoning_budget_message": ""}
+ assert settings.model_override_load_kwargs(settings.get_model_override(path), is_gguf = True) == {
+ "reasoning_budget_message": ""
+ }
+
+
[email protected]("message", ["😀" * 2_049, "bad\0message"])
+def test_reasoning_budget_override_rejects_unsafe_argv(message):
+ import pydantic
+ import routes.settings as settings_route
+
+ with pytest.raises(pydantic.ValidationError):
+ settings_route.ModelOverridePayload(
+ model_id = "unsloth/B-GGUF", reasoning_budget_message = message
+ )
+ assert settings.normalize_model_override({"reasoning_budget_message": message}) == {}
+
+ from routes.chat_history import ChatPresetLoadConfig
+
+ with pytest.raises(pydantic.ValidationError):
+ ChatPresetLoadConfig(reasoningBudgetMessage = message)
+
+
[email protected]("message", ["😀" * 2_049, "bad\0message"])
+def test_unsafe_passthrough_is_rejected_before_backend_lookup(monkeypatch, message):
+ from fastapi import HTTPException
+
+ monkeypatch.setattr(
+ inference_route.api_monitor, "record_lifecycle", lambda **kwargs: "load-event"
+ )
+ monkeypatch.setattr(inference_route.api_monitor, "fail_open", lambda *args, **kwargs: None)
+ monkeypatch.setattr(
+ inference_route,
+ "get_llama_cpp_backend",
+ lambda: pytest.fail("backend lookup happened before argument rejection"),
+ )
+ request = LoadRequest(
+ model_path = "unsloth/B-GGUF",
+ llama_extra_args = ["--reasoning-budget-message", message],
+ )
+
+ with pytest.raises(HTTPException) as excinfo:
+ asyncio.run(inference_route._load_model_impl(request, object(), "tester"))
+
+ assert excinfo.value.status_code == 400
+
+
def test_override_route_rejects_managed_flag_and_removes(monkeypatch):
_mock_override_store(monkeypatch)
@@ -10806,3 +10964,10 @@ def test_speech_probe_refuses_remote_code(monkeypatch, audio_type, allowed):
assert inference_route._target_speech_audio_type("/local/model", False) == (
audio_type if allowed else None
)
+
+
+def test_preset_reasoning_budget_rejects_booleans():
+ from routes.chat_history import ChatPresetLoadConfig
+ with pytest.raises(ValueError, match = "Expected a number, got a boolean"):
+ ChatPresetLoadConfig(reasoningBudget = True)
+ assert ChatPresetLoadConfig(reasoningBudget = 0).reasoningBudget == 0
diff --git a/studio/backend/tests/test_validate_diffusion_unknown.py b/studio/backend/tests/test_validate_diffusion_unknown.py
index 6335c276a4a..56d747bdd15 100644
--- a/studio/backend/tests/test_validate_diffusion_unknown.py
+++ b/studio/backend/tests/test_validate_diffusion_unknown.py
@@ -13,12 +13,17 @@ split from that answer, and /load may then apply it to a diffusion runner: an in
"""
import asyncio
+import importlib
import importlib.util
+import os as _os
+import sys
import unittest
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
+from fastapi import HTTPException
+
from models.inference import ValidateModelRequest
@@ -26,12 +31,19 @@ _BACKEND_ROOT = Path(__file__).resolve().parent.parent
def _load_route_module(name: str):
+ # Some direct llama_cpp tests install a tiny httpx stub during collection.
+ # Latest inference.py imports llama_http, which needs the real package.
+ sys.modules.pop("httpx", None)
+ sys.modules["httpx"] = importlib.import_module("httpx")
spec = importlib.util.spec_from_file_location(name, _BACKEND_ROOT / "routes/inference.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
+_ROUTE = _load_route_module("inf_route_diffusion_unknown")
+
+
async def _noop_gpu_ids(_config, gpu_ids, **_kwargs):
return gpu_ids, False
@@ -43,11 +55,17 @@ class TestValidateReportsDiffusionUnknown(unittest.TestCase):
*,
diffusion_kind,
is_gguf = True,
+ reasoning_budget = -1,
+ reasoning_budget_message = "",
+ capability_error = None,
+ extra_args = None,
):
# Mirrors the real staged-metadata preflight; also skips the training guard.
request = ValidateModelRequest(
model_path = "someone/repacked-gguf",
include_context_length = True,
+ reasoning_budget = reasoning_budget,
+ reasoning_budget_message = reasoning_budget_message,
)
config = SimpleNamespace(
identifier = "someone/repacked-gguf",
@@ -57,6 +75,18 @@ class TestValidateReportsDiffusionUnknown(unittest.TestCase):
is_vision = False,
gguf_file = None,
)
+
+ def _validate_capabilities(*_args, **_kwargs):
+ if capability_error:
+ raise capability_error
+
+ backend = SimpleNamespace(
+ reasoning_budget_settings_requested = (
+ route.LlamaCppBackend.reasoning_budget_settings_requested
+ ),
+ _find_llama_server_binary = lambda: "/server",
+ validate_reasoning_budget_capabilities = _validate_capabilities,
+ )
with (
patch.object(
route,
@@ -64,16 +94,17 @@ class TestValidateReportsDiffusionUnknown(unittest.TestCase):
return_value = ("someone/repacked-gguf", "someone/repacked-gguf", False),
),
patch.object(route.ModelConfig, "from_identifier", return_value = config),
- patch.object(route, "_resolve_inherited_extra_args", return_value = None),
+ patch.object(route, "_resolve_inherited_extra_args", return_value = extra_args),
patch.object(route, "_classify_diffusion_gguf", return_value = diffusion_kind),
patch.object(route, "_resolve_gguf_gpu_ids_for_request", new = _noop_gpu_ids),
patch.object(route, "_effective_load_in_4bit", return_value = True),
+ patch.object(route, "get_llama_cpp_backend", return_value = backend),
):
return asyncio.run(route.validate_model(request, current_subject = "test-user"))
def test_unclassifiable_gguf_is_reported_unknown_not_ordinary(self):
"""The bug: None must not look identical to a confirmed ordinary GGUF."""
- route = _load_route_module("inf_route_diffusion_unknown_1")
+ route = _ROUTE
resp = self._validate(route, diffusion_kind = None)
self.assertFalse(resp.is_diffusion)
self.assertTrue(
@@ -84,20 +115,20 @@ class TestValidateReportsDiffusionUnknown(unittest.TestCase):
)
def test_confirmed_ordinary_gguf_is_not_unknown(self):
- route = _load_route_module("inf_route_diffusion_unknown_2")
+ route = _ROUTE
resp = self._validate(route, diffusion_kind = False)
self.assertFalse(resp.is_diffusion)
self.assertFalse(resp.diffusion_unknown)
def test_confirmed_diffusion_gguf_is_not_unknown(self):
- route = _load_route_module("inf_route_diffusion_unknown_3")
+ route = _ROUTE
resp = self._validate(route, diffusion_kind = True)
self.assertTrue(resp.is_diffusion)
self.assertFalse(resp.diffusion_unknown)
def test_non_gguf_is_never_unknown(self):
"""A transformers model is definitively not a diffusion GGUF."""
- route = _load_route_module("inf_route_diffusion_unknown_4")
+ route = _ROUTE
resp = self._validate(route, diffusion_kind = False, is_gguf = False)
self.assertFalse(resp.is_diffusion)
self.assertFalse(resp.diffusion_unknown)
@@ -109,6 +140,62 @@ class TestValidateReportsDiffusionUnknown(unittest.TestCase):
resp = ValidateModelResponse(valid = True, message = "ok")
self.assertFalse(resp.diffusion_unknown)
+ def test_explicit_budget_is_rejected_during_validate_before_unload(self):
+ route = _ROUTE
+ with self.assertRaises(HTTPException) as raised:
+ self._validate(
+ route,
+ diffusion_kind = False,
+ reasoning_budget = 2048,
+ capability_error = ValueError("llama-server does not support --reasoning-budget"),
+ )
+ self.assertEqual(raised.exception.status_code, 400)
+ self.assertIn("--reasoning-budget", raised.exception.detail)
+
+ def test_explicit_message_is_rejected_for_unknown_diffusion_kind(self):
+ route = _ROUTE
+ with self.assertRaises(HTTPException) as raised:
+ self._validate(
+ route,
+ diffusion_kind = None,
+ reasoning_budget_message = "Conclude now",
+ )
+ self.assertEqual(raised.exception.status_code, 400)
+ self.assertIn("cannot be applied until", raised.exception.detail)
+
+ def test_inherited_env_default_alone_never_rejects_a_load(self):
+ """LLAMA_ARG_THINK_BUDGET* is a machine-wide llama.cpp default, not a request.
+
+ No Studio control writes or clears it, so gating on it refused an undownloaded
+ GGUF and a DiffusionGemma with advice the user cannot follow, and disagreed
+ with LlamaCppBackend's own gate, which reads the explicit values only.
+ """
+ route = _ROUTE
+ env = {
+ "LLAMA_ARG_THINK_BUDGET": "512",
+ "LLAMA_ARG_THINK_BUDGET_MESSAGE": "Wrap up.",
+ }
+ with patch.dict(_os.environ, env, clear = False):
+ self.assertEqual(
+ route.LlamaCppBackend.reasoning_budget_settings_requested(
+ extra_args = None, reasoning_budget = -1, reasoning_budget_message = ""
+ ),
+ (False, False),
+ "the backend's own gate must stay the reference for 'configured'",
+ )
+ for kind in (None, True, False):
+ with self.subTest(diffusion_kind = kind):
+ resp = self._validate(route, diffusion_kind = kind)
+ self.assertTrue(resp.valid)
+
+ def test_extra_args_passthrough_is_still_a_configured_setting(self):
+ """Ignoring the environment must not also ignore an explicit passthrough flag."""
+ route = _ROUTE
+ with self.assertRaises(HTTPException) as raised:
+ self._validate(route, diffusion_kind = True, extra_args = ["--reasoning-budget", "512"])
+ self.assertEqual(raised.exception.status_code, 400)
+ self.assertIn("DiffusionGemma", raised.exception.detail)
+
if __name__ == "__main__":
unittest.main()
diff --git a/studio/backend/utils/openai_auto_switch_settings.py b/studio/backend/utils/openai_auto_switch_settings.py
index cf09d0973b4..fc1238469fc 100644
--- a/studio/backend/utils/openai_auto_switch_settings.py
+++ b/studio/backend/utils/openai_auto_switch_settings.py
@@ -11,6 +11,7 @@ import threading
import time
from typing import Any, Mapping, Optional
+from utils.reasoning_budget import validate_reasoning_budget_message
from utils.account_context import OWNER, run_as
OPENAI_AUTO_SWITCH_SETTING_KEY = "openai_api_auto_switch_model"
@@ -454,6 +455,21 @@ def normalize_model_override(
if n_parallel:
entry["n_parallel"] = n_parallel
+ reasoning_budget = _bounded_int(
+ payload.get("reasoning_budget"), minimum = -1, maximum = 2_147_483_647
+ )
+ # Keep defaults as tombstones: a qualified override must remain present after resetting a legacy
+ # passthrough flag, or a bare/legacy fallback can revive it.
+ if reasoning_budget is not None:
+ entry["reasoning_budget"] = reasoning_budget
+ reasoning_budget_message = payload.get("reasoning_budget_message")
+ if isinstance(reasoning_budget_message, str):
+ try:
+ entry["reasoning_budget_message"] = validate_reasoning_budget_message(
+ reasoning_budget_message
+ )
+ except ValueError:
+ pass
for key in ("n_batch", "n_ubatch"):
parsed = _bounded_int(payload.get(key), minimum = BATCH_SIZE_MIN, maximum = BATCH_SIZE_MAX)
if parsed:
@@ -568,6 +584,8 @@ def model_override_load_kwargs(override: dict[str, Any], *, is_gguf: bool) -> di
("mlx_kv_bits", "mlx_kv_bits"),
("speculative_type", "speculative_type"),
("spec_draft_n_max", "spec_draft_n_max"),
+ ("reasoning_budget", "reasoning_budget"),
+ ("reasoning_budget_message", "reasoning_budget_message"),
("tensor_parallel", "tensor_parallel"),
("disable_vision", "disable_vision"),
("chat_template_override", "chat_template_override"),
@@ -613,6 +631,8 @@ def model_override_load_kwargs(override: dict[str, Any], *, is_gguf: bool) -> di
strip_cache = "cache_type_kv" in kwargs,
strip_spec = "speculative_type" in kwargs or "spec_draft_n_max" in kwargs,
strip_template = "chat_template_override" in kwargs,
+ strip_reasoning_budget = "reasoning_budget" in kwargs,
+ strip_reasoning_budget_message = "reasoning_budget_message" in kwargs,
# Sent only when on, so it is always the Tensor Parallelism toggle overriding the flag; an override that leaves the toggle off keeps a row/none/layer split mode.
strip_split_mode = bool(kwargs.get("tensor_parallel")),
strip_batch = "n_batch" in kwargs,
diff --git a/studio/backend/utils/reasoning_budget.py b/studio/backend/utils/reasoning_budget.py
new file mode 100644
index 00000000000..1ccc72c84b5
--- /dev/null
+++ b/studio/backend/utils/reasoning_budget.py
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Validation shared by every reasoning-budget-message persistence boundary."""
+
+from __future__ import annotations
+
+
+# Keep ample headroom below Windows' total command-line limit and Linux's
+# per-argument MAX_ARG_STRLEN. Budget-exhaustion messages should be short prose.
+MAX_REASONING_BUDGET_MESSAGE_BYTES = 8_192
+
+
+def validate_reasoning_budget_message(value: str) -> str:
+ """Return ``value`` unchanged when it is safe to pass as one argv token."""
+ if "\0" in value:
+ raise ValueError("llama-server --reasoning-budget-message cannot contain NUL characters.")
+ try:
+ size = len(value.encode("utf-8"))
+ except UnicodeEncodeError as exc:
+ raise ValueError(
+ "llama-server --reasoning-budget-message contains invalid Unicode."
+ ) from exc
+ if size > MAX_REASONING_BUDGET_MESSAGE_BYTES:
+ raise ValueError(
+ "llama-server --reasoning-budget-message exceeds the "
+ f"{MAX_REASONING_BUDGET_MESSAGE_BYTES}-byte UTF-8 limit."
+ )
+ return value
diff --git a/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx b/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx
index ad4a2ff4203..a3be3007121 100644
--- a/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx
+++ b/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx
@@ -50,6 +50,12 @@ function describeOverride(override: ApiModelOverride): string[] {
if (override.n_parallel) {
parts.push(plural(override.n_parallel, "parallel slot"));
}
+ if (override.reasoning_budget !== undefined) {
+ parts.push(`reasoning budget ${override.reasoning_budget}`);
+ }
+ if (override.reasoning_budget_message) {
+ parts.push("custom reasoning budget message");
+ }
if (override.n_batch) {
parts.push(`batch ${override.n_batch}`);
}
diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.ts
index a24455e42c7..348affcdc4c 100644
--- a/studio/frontend/src/features/chat/api/chat-adapter.ts
+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts
@@ -2986,6 +2986,8 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
gpu_memory_mode?: "auto" | "manual";
cache_type_kv?: string | null;
tensor_parallel?: boolean | null;
+ reasoning_budget?: number;
+ reasoning_budget_message?: string;
// The projector is part of what the guard sizes: charging for a skipped one refuses loads that fit.
// A load that skips the projector needs ~1 GB less.
disable_vision?: boolean | null;
@@ -3216,6 +3218,10 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
// A remembered manual DiffusionGemma split (0 especially) must not be refused as a full-GGUF occupant.
gpu_layers: effectiveGpuLayers,
n_parallel: config.nParallel ?? null,
+ reasoning_budget: isDiffusion ? -1 : config.reasoningBudget,
+ reasoning_budget_message: isDiffusion
+ ? ""
+ : config.reasoningBudgetMessage,
// omitted when blank: a null counts as set and strips inherited -b / -ub
...(config.nBatch != null ? { n_batch: config.nBatch } : {}),
...(config.nUbatch != null ? { n_ubatch: config.nUbatch } : {}),
@@ -3264,6 +3270,12 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
mlx_kv_bits: config.mlxKvBits ?? null,
speculative_type: effectiveSpeculativeType,
spec_draft_n_max: effectiveSpecDraftNMax,
+ reasoning_budget:
+ candidate.kind === "gguf" && !isDiffusion ? config.reasoningBudget : -1,
+ reasoning_budget_message:
+ candidate.kind === "gguf" && !isDiffusion
+ ? config.reasoningBudgetMessage
+ : "",
tensor_parallel: effectiveTensorParallel,
disable_vision: effectiveDisableVision,
// GGUF-only; the split ratio is never remembered (it is bound to an exact GPU set), so
@@ -3384,6 +3396,30 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
// Click-time value, not the resolved backend echo (see performLoad).
nParallel: committedSlots,
loadedNParallel: committedSlots,
+ reasoningBudget:
+ (loadResp.is_diffusion ?? false)
+ ? -1
+ : (loadResp.reasoning_budget ?? config.reasoningBudget),
+ loadedReasoningBudget:
+ (loadResp.is_diffusion ?? false)
+ ? -1
+ : (loadResp.reasoning_budget ?? config.reasoningBudget),
+ reasoningBudgetMessage:
+ (loadResp.is_diffusion ?? false)
+ ? ""
+ : (loadResp.reasoning_budget_message ??
+ config.reasoningBudgetMessage),
+ loadedReasoningBudgetMessage:
+ (loadResp.is_diffusion ?? false)
+ ? ""
+ : (loadResp.reasoning_budget_message ??
+ config.reasoningBudgetMessage),
+ loadedReasoningBudgetRequested: loadResp.is_diffusion
+ ? -1
+ : (loadResp.requested_reasoning_budget ?? config.reasoningBudget),
+ loadedReasoningBudgetMessageRequested: loadResp.is_diffusion
+ ? ""
+ : (loadResp.requested_reasoning_budget_message ?? config.reasoningBudgetMessage),
nBatch: committedNBatch,
loadedNBatch: committedNBatch,
nUbatch: committedNUbatch,
@@ -3432,6 +3468,12 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
// GGUF-only and never sent here: a staged override would be saved for a model that cannot use it.
nParallel: null,
loadedNParallel: null,
+ reasoningBudget: -1,
+ loadedReasoningBudget: -1,
+ loadedReasoningBudgetRequested: -1,
+ reasoningBudgetMessage: "",
+ loadedReasoningBudgetMessage: "",
+ loadedReasoningBudgetMessageRequested: "",
nBatch: null,
loadedNBatch: null,
nUbatch: null,
@@ -3698,6 +3740,8 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
trust_remote_code: trustRemoteCode,
speculative_type: specSettings.speculativeType,
spec_draft_n_max: specSettings.specDraftNMax,
+ reasoning_budget: -1,
+ reasoning_budget_message: "",
// GPU Memory mode is a standing preference; the per-model layer/MoE/split knobs and context
// pin stay at their defaults, and the GPU pick is the on-screen one the preflight used.
// The GPU pick deliberately differs: it is the picker's on-screen selection, which the canAutoLoad
@@ -3768,6 +3812,12 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
// by the next Apply.
nParallel: null,
loadedNParallel: null,
+ reasoningBudget: -1,
+ loadedReasoningBudget: -1,
+ loadedReasoningBudgetRequested: -1,
+ reasoningBudgetMessage: "",
+ loadedReasoningBudgetMessage: "",
+ loadedReasoningBudgetMessageRequested: "",
nBatch: null,
loadedNBatch: null,
nUbatch: null,
diff --git a/studio/frontend/src/features/chat/api/chat-api.ts b/studio/frontend/src/features/chat/api/chat-api.ts
index 4a46dc5b1af..c8d28a90452 100644
--- a/studio/frontend/src/features/chat/api/chat-api.ts
+++ b/studio/frontend/src/features/chat/api/chat-api.ts
@@ -360,6 +360,8 @@ export async function validateModel(
gpu_layers: payload.gpu_layers,
// Slots scale the KV estimate; keep validate sized like the load.
n_parallel: payload.n_parallel,
+ reasoning_budget: payload.reasoning_budget ?? -1,
+ reasoning_budget_message: payload.reasoning_budget_message ?? "",
// A --ctx-size or cache override in here changes the estimate, so a preflight that dropped them
// would approve a different command from the one that runs.
...(payload.llama_extra_args !== undefined
diff --git a/studio/frontend/src/features/chat/chat-settings-sheet.tsx b/studio/frontend/src/features/chat/chat-settings-sheet.tsx
index a43ba0135ad..f84bab70abd 100644
--- a/studio/frontend/src/features/chat/chat-settings-sheet.tsx
+++ b/studio/frontend/src/features/chat/chat-settings-sheet.tsx
@@ -556,6 +556,18 @@ export function ChatSettingsPanel({
const disableVision = useChatRuntimeStore((s) => s.disableVision);
const specDraftNMax = useChatRuntimeStore((s) => s.specDraftNMax);
const nParallel = useChatRuntimeStore((s) => s.nParallel);
+ // subscribe to the same requested values that preset capture snapshots.
+ const reasoningBudget = useChatRuntimeStore((s) =>
+ s.reasoningBudget === s.loadedReasoningBudget
+ ? (s.loadedReasoningBudgetRequested ?? s.reasoningBudget)
+ : s.reasoningBudget,
+ );
+ const reasoningBudgetMessage = useChatRuntimeStore(
+ (s) =>
+ s.reasoningBudgetMessage === s.loadedReasoningBudgetMessage
+ ? (s.loadedReasoningBudgetMessageRequested ?? s.reasoningBudgetMessage)
+ : s.reasoningBudgetMessage,
+ );
const nBatch = useChatRuntimeStore((s) => s.nBatch);
const nUbatch = useChatRuntimeStore((s) => s.nUbatch);
const speculativeType = useChatRuntimeStore((s) => s.speculativeType);
@@ -741,6 +753,8 @@ export function ChatSettingsPanel({
speculativeType,
specDraftNMax,
nParallel,
+ reasoningBudget,
+ reasoningBudgetMessage,
nBatch,
nUbatch,
params.maxSeqLength,
@@ -764,6 +778,8 @@ export function ChatSettingsPanel({
speculativeType,
specDraftNMax,
nParallel,
+ reasoningBudget,
+ reasoningBudgetMessage,
nBatch,
nUbatch,
params.maxSeqLength,
diff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
index f6a059d6e71..7c3b332bd94 100644
--- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
+++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
@@ -1258,6 +1258,14 @@ export function useChatModelRuntime() {
typeof selection !== "string" && selection.previousConfig
? (selection.previousConfig.nParallel ?? null)
: useChatRuntimeStore.getState().nParallel;
+ const previousReasoningBudget =
+ typeof selection !== "string" && selection.previousConfig
+ ? selection.previousConfig.reasoningBudget
+ : useChatRuntimeStore.getState().reasoningBudget;
+ const previousReasoningBudgetMessage =
+ typeof selection !== "string" && selection.previousConfig
+ ? selection.previousConfig.reasoningBudgetMessage
+ : useChatRuntimeStore.getState().reasoningBudgetMessage;
const previousNBatch =
typeof selection !== "string" && selection.previousConfig
? (selection.previousConfig.nBatch ?? null)
@@ -1435,6 +1443,12 @@ export function useChatModelRuntime() {
pendingLoadConfig?.specDraftNMax ?? stateBeforeUnload.specDraftNMax;
let loadNParallel =
pendingLoadConfig?.nParallel ?? stateBeforeUnload.nParallel;
+ let loadReasoningBudget =
+ pendingLoadConfig?.reasoningBudget ??
+ stateBeforeUnload.reasoningBudget;
+ let loadReasoningBudgetMessage =
+ pendingLoadConfig?.reasoningBudgetMessage ??
+ stateBeforeUnload.reasoningBudgetMessage;
// No store fallback and no reset with the rest below: undefined means "this config never read
// them", and the route preserves the stored flags when the field is omitted, so a fallback
// would clear flags the user set elsewhere.
@@ -1482,6 +1496,12 @@ export function useChatModelRuntime() {
const validateNParallel = resetsPerModelSettings
? (pendingLoadConfig?.nParallel ?? null)
: loadNParallel;
+ const validateReasoningBudget = resetsPerModelSettings
+ ? (pendingLoadConfig?.reasoningBudget ?? -1)
+ : loadReasoningBudget;
+ const validateReasoningBudgetMessage = resetsPerModelSettings
+ ? (pendingLoadConfig?.reasoningBudgetMessage ?? "")
+ : loadReasoningBudgetMessage;
const validateNBatch = resetsPerModelSettings
? (pendingLoadConfig?.nBatch ?? null)
: loadNBatch;
@@ -1540,6 +1560,12 @@ export function useChatModelRuntime() {
// when it fits.
gpu_layers: validateGpuLayers,
n_parallel: validateNParallel,
+ reasoning_budget: targetIsDiffusion
+ ? -1
+ : validateReasoningBudget,
+ reasoning_budget_message: targetIsDiffusion
+ ? ""
+ : validateReasoningBudgetMessage,
// omitted when blank, like the load payload below
...(validateNBatch != null
? { n_batch: validateNBatch }
@@ -1639,6 +1665,12 @@ export function useChatModelRuntime() {
// Per-model too: a different model follows the server default unless its staged config overrides it.
nParallel: null,
loadedNParallel: null,
+ reasoningBudget: -1,
+ loadedReasoningBudget: null,
+ loadedReasoningBudgetRequested: null,
+ reasoningBudgetMessage: "",
+ loadedReasoningBudgetMessage: null,
+ loadedReasoningBudgetMessageRequested: null,
nBatch: null,
loadedNBatch: null,
nUbatch: null,
@@ -1661,6 +1693,9 @@ export function useChatModelRuntime() {
: persistedSpeculativeType;
loadSpecDraftNMax = pendingLoadConfig?.specDraftNMax ?? null;
loadNParallel = pendingLoadConfig?.nParallel ?? null;
+ loadReasoningBudget = pendingLoadConfig?.reasoningBudget ?? -1;
+ loadReasoningBudgetMessage =
+ pendingLoadConfig?.reasoningBudgetMessage ?? "";
loadNBatch = pendingLoadConfig?.nBatch ?? null;
loadNUbatch = pendingLoadConfig?.nUbatch ?? null;
loadServerTuning = {
@@ -1769,6 +1804,10 @@ export function useChatModelRuntime() {
spec_draft_n_max: loadSpecDraftNMax,
// GGUF-only: slots mean nothing for a transformers load.
n_parallel: isGguf ? loadNParallel : null,
+ reasoning_budget:
+ isGguf && !targetIsDiffusion ? loadReasoningBudget : -1,
+ reasoning_budget_message:
+ isGguf && !targetIsDiffusion ? loadReasoningBudgetMessage : "",
// Sent only once known, and [] is the explicit "launch with none": the flags are llama-server's,
// so neither a transformers load nor a diffusion GGUF carries them.
...(isGguf && !targetIsDiffusion && loadLlamaExtraArgs !== undefined
@@ -1980,6 +2019,36 @@ export function useChatModelRuntime() {
// "server default" control.
nParallel: committedSlots,
loadedNParallel: committedSlots,
+ reasoningBudget:
+ (loadResponse.is_gguf ?? false) &&
+ !(loadResponse.is_diffusion ?? false)
+ ? (loadResponse.reasoning_budget ?? loadReasoningBudget)
+ : -1,
+ loadedReasoningBudget:
+ (loadResponse.is_gguf ?? false) &&
+ !(loadResponse.is_diffusion ?? false)
+ ? (loadResponse.reasoning_budget ?? loadReasoningBudget)
+ : -1,
+ reasoningBudgetMessage:
+ (loadResponse.is_gguf ?? false) &&
+ !(loadResponse.is_diffusion ?? false)
+ ? (loadResponse.reasoning_budget_message ??
+ loadReasoningBudgetMessage)
+ : "",
+ loadedReasoningBudgetMessage:
+ (loadResponse.is_gguf ?? false) &&
+ !(loadResponse.is_diffusion ?? false)
+ ? (loadResponse.reasoning_budget_message ??
+ loadReasoningBudgetMessage)
+ : "",
+ loadedReasoningBudgetRequested:
+ loadResponse.is_gguf && !loadResponse.is_diffusion
+ ? (loadResponse.requested_reasoning_budget ?? loadReasoningBudget)
+ : -1,
+ loadedReasoningBudgetMessageRequested:
+ loadResponse.is_gguf && !loadResponse.is_diffusion
+ ? (loadResponse.requested_reasoning_budget_message ?? loadReasoningBudgetMessage)
+ : "",
nBatch: committedNBatch,
loadedNBatch: committedNBatch,
...committedServerTuning,
@@ -2101,6 +2170,10 @@ export function useChatModelRuntime() {
spec_draft_n_max:
stateBeforeUnload.loadedSpecDraftNMax,
n_parallel: stateBeforeUnload.loadedNParallel,
+ reasoning_budget:
+ stateBeforeUnload.loadedReasoningBudgetRequested ?? -1,
+ reasoning_budget_message:
+ stateBeforeUnload.loadedReasoningBudgetMessageRequested ?? "",
// omit unset fields: a null counts as set and would strip the previous server's extras
...(stateBeforeUnload.loadedNBatch != null
? { n_batch: stateBeforeUnload.loadedNBatch }
@@ -2157,6 +2230,20 @@ export function useChatModelRuntime() {
// Control keeps its intent; only the baseline takes the echo.
nParallel: previousNParallel,
loadedNParallel: stateBeforeUnload.loadedNParallel ?? null,
+ reasoningBudget: previousReasoningBudget,
+ loadedReasoningBudget:
+ rollbackResponse.reasoning_budget ?? -1,
+ reasoningBudgetMessage: previousReasoningBudgetMessage,
+ loadedReasoningBudgetMessage:
+ rollbackResponse.reasoning_budget_message ?? "",
+ loadedReasoningBudgetRequested:
+ rollbackResponse.requested_reasoning_budget ??
+ stateBeforeUnload.loadedReasoningBudgetRequested ??
+ -1,
+ loadedReasoningBudgetMessageRequested:
+ rollbackResponse.requested_reasoning_budget_message ??
+ stateBeforeUnload.loadedReasoningBudgetMessageRequested ??
+ "",
nBatch: previousNBatch,
loadedNBatch: stateBeforeUnload.loadedNBatch ?? null,
nUbatch: previousNUbatch,
diff --git a/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts b/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts
index c08f95ec381..54316d798bf 100644
--- a/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts
+++ b/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts
@@ -323,6 +323,34 @@ export function applyActiveModelStatusToStore(
gpuLayers: status.gpu_layers ?? null,
loadedPin: prevState.loadedCustomContextLength ?? null,
});
+ const reasoningBudgetApplicable =
+ status.is_gguf === true && status.is_diffusion !== true;
+ const incomingReasoningBudget = reasoningBudgetApplicable
+ ? (status.reasoning_budget ?? -1)
+ : -1;
+ const incomingReasoningBudgetMessage = reasoningBudgetApplicable
+ ? (status.reasoning_budget_message ?? "")
+ : "";
+ const reasoningBudgetStatusChanged =
+ prevState.loadedReasoningBudget !== incomingReasoningBudget ||
+ prevState.loadedReasoningBudgetMessage !== incomingReasoningBudgetMessage;
+ const reasoningBudgetEditPending =
+ prevState.loadedReasoningBudget !== null &&
+ prevState.reasoningBudget !== prevState.loadedReasoningBudget;
+ const reasoningBudgetMessageEditPending =
+ prevState.loadedReasoningBudgetMessage !== null &&
+ prevState.reasoningBudgetMessage !==
+ prevState.loadedReasoningBudgetMessage;
+ const reasoningBudgetStatusFields = {
+ loadedReasoningBudget: incomingReasoningBudget,
+ loadedReasoningBudgetMessage: incomingReasoningBudgetMessage,
+ ...(!reasoningBudgetEditPending || hydratingExistingModel
+ ? { reasoningBudget: incomingReasoningBudget }
+ : {}),
+ ...(!reasoningBudgetMessageEditPending || hydratingExistingModel
+ ? { reasoningBudgetMessage: incomingReasoningBudgetMessage }
+ : {}),
+ };
const incomingGpuMode = status.is_gguf
? (status.gpu_memory_mode ?? "auto")
: null;
@@ -540,6 +568,31 @@ export function applyActiveModelStatusToStore(
// Per-model: a change underneath this tab blanks the control like performLoad's cross-model
// reset, or the old count follows onto the new model. The baseline still has the rollback.
...(seedLoadParams && slotsModelChanged && { nParallel: null }),
+ ...(seedLoadParams &&
+ (prevState.loadedReasoningBudget === null ||
+ hydratingExistingModel ||
+ reasoningBudgetStatusChanged) &&
+ reasoningBudgetStatusFields),
+ // Rollback needs the request, not the effective environment-resolved value.
+ // Refresh on every settled echo: a same-model reload can change only the request.
+ ...(seedLoadParams && {
+ ...(!reasoningBudgetApplicable ||
+ status.requested_reasoning_budget !== undefined
+ ? {
+ loadedReasoningBudgetRequested: reasoningBudgetApplicable
+ ? (status.requested_reasoning_budget ?? -1)
+ : -1,
+ }
+ : {}),
+ ...(!reasoningBudgetApplicable ||
+ status.requested_reasoning_budget_message !== undefined
+ ? {
+ loadedReasoningBudgetMessageRequested: reasoningBudgetApplicable
+ ? (status.requested_reasoning_budget_message ?? "")
+ : "",
+ }
+ : {}),
+ }),
// AFTER that clear, which both a first hydration and a model change trip: either would leave
// the control blank while the model runs on a remembered override, so the next Apply would
// save the blank over it. Adopted only when the running count matches.
diff --git a/studio/frontend/src/features/chat/lib/resident-config-match.ts b/studio/frontend/src/features/chat/lib/resident-config-match.ts
index dcbd82445c2..88582e19c80 100644
--- a/studio/frontend/src/features/chat/lib/resident-config-match.ts
+++ b/studio/frontend/src/features/chat/lib/resident-config-match.ts
@@ -26,6 +26,10 @@ type ResidentRuntime = Pick<
| "requested_load_mode"
| "requested_spec_draft_cache_type"
| "requested_ctx_checkpoints"
+ | "reasoning_budget"
+ | "reasoning_budget_message"
+ | "requested_reasoning_budget"
+ | "requested_reasoning_budget_message"
| "requested_cache_ram"
| "tensor_parallel"
| "disable_vision"
@@ -335,6 +339,22 @@ const SETTING_CHECKS: SettingCheck[] = [
pinned: () => true,
agrees: (c, s) => (c.cacheRam ?? null) === (s.requested_cache_ram ?? null),
},
+ {
+ // The status echoes the EFFECTIVE budget, so a default control against a server the
+ // environment shaped reads as a reload: the safe direction, like the rest.
+ chatOnly: true,
+ pinned: () => true,
+ agrees: (c, s) =>
+ (c.reasoningBudget ?? -1) ===
+ (s.requested_reasoning_budget ?? s.reasoning_budget ?? -1),
+ },
+ {
+ chatOnly: true,
+ pinned: () => true,
+ agrees: (c, s) =>
+ (c.reasoningBudgetMessage ?? "") ===
+ (s.requested_reasoning_budget_message ?? s.reasoning_budget_message ?? ""),
+ },
{
// Not nullable, so it always has an opinion; a status omitting it ran without.
pinned: () => true,
diff --git a/studio/frontend/src/features/chat/presets/preset-load-config.ts b/studio/frontend/src/features/chat/presets/preset-load-config.ts
index 6e5b73e0563..3191798e18b 100644
--- a/studio/frontend/src/features/chat/presets/preset-load-config.ts
+++ b/studio/frontend/src/features/chat/presets/preset-load-config.ts
@@ -17,6 +17,7 @@ import {
N_BATCH_MIN,
N_PARALLEL_MAX,
N_PARALLEL_MIN,
+ isReasoningBudgetMessageValid,
canonicalizeLoadMode,
isServedByLlamaCpp,
isServedByMlx,
@@ -48,6 +49,8 @@ export type PresetLoadConfig = Pick<
| "speculativeType"
| "specDraftNMax"
| "nParallel"
+ | "reasoningBudget"
+ | "reasoningBudgetMessage"
| "nBatch"
| "nUbatch"
| "loadMode"
@@ -72,6 +75,8 @@ export const EMPTY_PRESET_LOAD_CONFIG: PresetLoadConfig = {
speculativeType: null,
specDraftNMax: null,
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
loadMode: null,
@@ -168,6 +173,19 @@ export function normalizePresetLoadConfig(
Math.min(N_PARALLEL_MAX, Math.round(partial.nParallel)),
)
: null,
+ reasoningBudget:
+ typeof partial.reasoningBudget === "number" &&
+ Number.isFinite(partial.reasoningBudget)
+ ? Math.max(
+ -1,
+ Math.min(2_147_483_647, Math.trunc(partial.reasoningBudget)),
+ )
+ : -1,
+ reasoningBudgetMessage:
+ typeof partial.reasoningBudgetMessage === "string" &&
+ isReasoningBudgetMessageValid(partial.reasoningBudgetMessage)
+ ? partial.reasoningBudgetMessage
+ : "",
nBatch:
typeof partial.nBatch === "number" && Number.isFinite(partial.nBatch)
? Math.max(N_BATCH_MIN, Math.min(N_BATCH_MAX, Math.round(partial.nBatch)))
@@ -238,6 +256,9 @@ export function capturePresetLoadConfig(): PresetLoadConfig | undefined {
loadedContextLength: store.loadedContextLength,
}),
);
+ // A diffusion GGUF is still a GGUF: its resolved context has to capture like
+ // any other. Only the reasoning flags, which it takes none of, are suppressed.
+ const capturesReasoning = isGguf && !store.loadedIsDiffusion;
const captured: PresetLoadConfig = {
customContextLength: effectiveContextLength ?? null,
maxSeqLength: isMlx ? null : normalizeMaxSeqLength(snapshot.maxSeqLength),
@@ -246,6 +267,10 @@ export function capturePresetLoadConfig(): PresetLoadConfig | undefined {
speculativeType: normalizeSpeculativeType(snapshot.speculativeType),
specDraftNMax: snapshot.specDraftNMax ?? null,
nParallel: snapshot.nParallel ?? null,
+ reasoningBudget: capturesReasoning ? snapshot.reasoningBudget : -1,
+ reasoningBudgetMessage: capturesReasoning
+ ? snapshot.reasoningBudgetMessage
+ : "",
nBatch: snapshot.nBatch ?? null,
nUbatch: snapshot.nUbatch ?? null,
loadMode: snapshot.loadMode ?? null,
@@ -293,37 +318,40 @@ function coalesceDefaultLoadKnobs(
return result;
}
-export function applyPresetLoadConfig(
- config?: PresetLoadConfig | null,
-): void {
+export function applyPresetLoadConfig(config?: PresetLoadConfig | null): void {
if (config == null) {
return;
}
const store = useChatRuntimeStore.getState();
- applyPerModelConfigToRuntime({
- ...DEFAULT_PER_MODEL_CONFIG,
- maxSeqLength: normalizeMaxSeqLength(config.maxSeqLength) ?? DEFAULT_MAX_SEQ_LENGTH,
- customContextLength: config.customContextLength ?? null,
- kvCacheDtype: config.kvCacheDtype ?? null,
- mlxKvBits: config.mlxKvBits ?? null,
- speculativeType: config.speculativeType ?? null,
- specDraftNMax: config.specDraftNMax ?? null,
- nParallel: config.nParallel ?? null,
- nBatch: config.nBatch ?? null,
- nUbatch: config.nUbatch ?? null,
- loadMode: config.loadMode ?? null,
- specDraftCacheDtype: config.specDraftCacheDtype ?? null,
- ctxCheckpoints: config.ctxCheckpoints ?? null,
- cacheRam: config.cacheRam ?? null,
- tensorParallel: config.tensorParallel ?? false,
- disableVision: config.disableVision ?? false,
- chatTemplateOverride: null,
- gpuMemoryMode: config.gpuMemoryMode,
- gpuLayers: config.gpuLayers,
- nCpuMoe: config.nCpuMoe,
- selectedGpuIds: store.selectedGpuIds,
- selectedGpuIndexKind: store.selectedGpuIndexKind,
- });
+ applyPerModelConfigToRuntime(
+ {
+ ...DEFAULT_PER_MODEL_CONFIG,
+ maxSeqLength: normalizeMaxSeqLength(config.maxSeqLength) ?? DEFAULT_MAX_SEQ_LENGTH,
+ customContextLength: config.customContextLength ?? null,
+ kvCacheDtype: config.kvCacheDtype ?? null,
+ mlxKvBits: config.mlxKvBits ?? null,
+ speculativeType: config.speculativeType ?? null,
+ specDraftNMax: config.specDraftNMax ?? null,
+ nParallel: config.nParallel ?? null,
+ nBatch: config.nBatch ?? null,
+ nUbatch: config.nUbatch ?? null,
+ loadMode: config.loadMode ?? null,
+ specDraftCacheDtype: config.specDraftCacheDtype ?? null,
+ ctxCheckpoints: config.ctxCheckpoints ?? null,
+ cacheRam: config.cacheRam ?? null,
+ reasoningBudget: config.reasoningBudget ?? -1,
+ reasoningBudgetMessage: config.reasoningBudgetMessage ?? "",
+ tensorParallel: config.tensorParallel ?? false,
+ disableVision: config.disableVision ?? false,
+ chatTemplateOverride: null,
+ gpuMemoryMode: config.gpuMemoryMode,
+ gpuLayers: config.gpuLayers,
+ nCpuMoe: config.nCpuMoe,
+ selectedGpuIds: store.selectedGpuIds,
+ selectedGpuIndexKind: store.selectedGpuIndexKind,
+ },
+ { isDiffusion: store.loadedIsDiffusion },
+ );
}
export function formatPresetLoadConfigSummary(
@@ -348,6 +376,14 @@ export function formatPresetLoadConfigSummary(
if (config.nParallel != null) {
parts.push(`${config.nParallel} slots`);
}
+ if (config.reasoningBudget !== -1) {
+ parts.push(`Reasoning ${config.reasoningBudget}`);
+ }
+ // A marker, not the text: the message is free prose up to 8 KiB. Without it a
+ // message-only preset is non-default but summarises to null, hiding both lines.
+ if (config.reasoningBudgetMessage) {
+ parts.push("Budget msg");
+ }
if (config.nBatch != null) {
parts.push(`Batch ${config.nBatch}`);
}
diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsx
index ca5ec2ee7c2..ee753ecc204 100644
--- a/studio/frontend/src/features/chat/shared-composer.tsx
+++ b/studio/frontend/src/features/chat/shared-composer.tsx
@@ -1503,6 +1503,12 @@ export function SharedComposer({
gpu_layers: effectiveGpuLayers,
// Slots scale the KV estimate; keep validate sized like the load.
n_parallel: ownConfig.nParallel ?? null,
+ reasoning_budget: resolvedIsDiffusion
+ ? -1
+ : ownConfig.reasoningBudget,
+ reasoning_budget_message: resolvedIsDiffusion
+ ? ""
+ : ownConfig.reasoningBudgetMessage,
// Only when this panel has read the stored value: omitted, the load inherits it, which is what
// keeps CLI-set flags working.
...(ownConfig.llamaExtraArgs !== undefined
@@ -1580,6 +1586,14 @@ export function SharedComposer({
mlx_kv_bits: ownConfig.mlxKvBits ?? null,
speculative_type: effectiveSpeculativeType,
spec_draft_n_max: effectiveSpecDraftNMax,
+ reasoning_budget:
+ targetIsGguf && !resolvedIsDiffusion
+ ? ownConfig.reasoningBudget
+ : -1,
+ reasoning_budget_message:
+ targetIsGguf && !resolvedIsDiffusion
+ ? ownConfig.reasoningBudgetMessage
+ : "",
tensor_parallel: effectiveTensorParallel,
disable_vision: effectiveDisableVision,
force_cancel_active:
@@ -1679,6 +1693,30 @@ export function SharedComposer({
// Click-time value, not the resolved echo (see the single-model load).
nParallel: committedSlots,
loadedNParallel: committedSlots,
+ reasoningBudget:
+ targetIsGguf && !(resp.is_diffusion ?? false)
+ ? (resp.reasoning_budget ?? ownConfig.reasoningBudget)
+ : -1,
+ loadedReasoningBudget:
+ targetIsGguf && !(resp.is_diffusion ?? false)
+ ? (resp.reasoning_budget ?? ownConfig.reasoningBudget)
+ : -1,
+ reasoningBudgetMessage:
+ targetIsGguf && !(resp.is_diffusion ?? false)
+ ? (resp.reasoning_budget_message ??
+ ownConfig.reasoningBudgetMessage)
+ : "",
+ loadedReasoningBudgetMessage:
+ targetIsGguf && !(resp.is_diffusion ?? false)
+ ? (resp.reasoning_budget_message ??
+ ownConfig.reasoningBudgetMessage)
+ : "",
+ loadedReasoningBudgetRequested: targetIsGguf && !resp.is_diffusion
+ ? (resp.requested_reasoning_budget ?? ownConfig.reasoningBudget)
+ : -1,
+ loadedReasoningBudgetMessageRequested: targetIsGguf && !resp.is_diffusion
+ ? (resp.requested_reasoning_budget_message ?? ownConfig.reasoningBudgetMessage)
+ : "",
nBatch: committedNBatch,
loadedNBatch: committedNBatch,
nUbatch: committedNUbatch,
diff --git a/studio/frontend/src/features/chat/stores/chat-runtime-store.ts b/studio/frontend/src/features/chat/stores/chat-runtime-store.ts
index ad097cc7489..f3a3368b487 100644
--- a/studio/frontend/src/features/chat/stores/chat-runtime-store.ts
+++ b/studio/frontend/src/features/chat/stores/chat-runtime-store.ts
@@ -2342,6 +2342,13 @@ type ChatRuntimeStore = {
/** Slots the last successful load sent (null = default); a rollback re-sends them so a failed
* switch cannot lose the override. */
loadedNParallel: number | null;
+ reasoningBudget: number;
+ loadedReasoningBudget: number | null;
+ /** Request baseline for rollback; effective values can include server environment defaults. */
+ loadedReasoningBudgetRequested: number | null;
+ reasoningBudgetMessage: string;
+ loadedReasoningBudgetMessage: string | null;
+ loadedReasoningBudgetMessageRequested: string | null;
/** user --batch-size override for gguf loads (null = llama.cpp default 2048) */
nBatch: number | null;
loadedNBatch: number | null;
@@ -4015,6 +4022,12 @@ export const useChatRuntimeStore = create<ChatRuntimeStore>((set, get) => ({
loadedSpecDraftNMax: null,
nParallel: null,
loadedNParallel: null,
+ reasoningBudget: -1,
+ loadedReasoningBudget: null,
+ loadedReasoningBudgetRequested: null,
+ reasoningBudgetMessage: "",
+ loadedReasoningBudgetMessage: null,
+ loadedReasoningBudgetMessageRequested: null,
nBatch: null,
loadedNBatch: null,
loadedLlamaExtraArgs: null,
@@ -4921,6 +4934,12 @@ export const useChatRuntimeStore = create<ChatRuntimeStore>((set, get) => ({
loadedSpecDraftNMax: null,
nParallel: null,
loadedNParallel: null,
+ reasoningBudget: -1,
+ loadedReasoningBudget: null,
+ loadedReasoningBudgetRequested: null,
+ reasoningBudgetMessage: "",
+ loadedReasoningBudgetMessage: null,
+ loadedReasoningBudgetMessageRequested: null,
nBatch: null,
loadedNBatch: null,
loadedLlamaExtraArgs: null,
diff --git a/studio/frontend/src/features/chat/types/api.ts b/studio/frontend/src/features/chat/types/api.ts
index 3966d82ac80..adda79a9ced 100644
--- a/studio/frontend/src/features/chat/types/api.ts
+++ b/studio/frontend/src/features/chat/types/api.ts
@@ -76,6 +76,10 @@ export interface LoadModelRequest {
/** Parallel decode slots for llama-server (--parallel), 1..64. Omit/null = the launch default. The
* VRAM fitter may launch fewer to stay on GPU. */
n_parallel?: number | null;
+ /** llama.cpp thinking token budget: -1 unrestricted, 0 end immediately, >0 token cap. */
+ reasoning_budget?: number;
+ /** Message emitted when the reasoning budget is exhausted. */
+ reasoning_budget_message?: string;
/** prompt batch size (--batch-size), 1..65536; omit/null = llama.cpp default 2048, gguf only */
n_batch?: number | null;
/** prompt micro-batch size (--ubatch-size), 1..65536; omit/null = llama.cpp default 512, capped at the batch size */
@@ -285,6 +289,13 @@ export interface LoadModelResponse {
requested_gpu_ids?: number[] | null;
/** Slots the load was invoked with (else the --parallel default). Null for non-GGUF loads. */
requested_parallel_slots?: number | null;
+ reasoning_budget?: number;
+ reasoning_budget_message?: string;
+ /** What the load ASKED for, before LLAMA_ARG_THINK_BUDGET*: the value a client can resend. */
+ // biome-ignore lint/style/useNamingConvention: API schema
+ requested_reasoning_budget?: number;
+ // biome-ignore lint/style/useNamingConvention: API schema
+ requested_reasoning_budget_message?: string;
/** Slots llama-server actually runs, after any fit-time reduction. Null for non-GGUF loads. */
parallel_slots?: number | null;
/** batch size (--batch-size) the load was invoked with; null = default */
@@ -389,6 +400,13 @@ export interface InferenceStatusResponse {
requested_gpu_ids?: number[] | null;
/** Slots the active load was invoked with (else the --parallel default). Null when no GGUF model is loaded. */
requested_parallel_slots?: number | null;
+ reasoning_budget?: number;
+ reasoning_budget_message?: string;
+ /** What the load ASKED for, before LLAMA_ARG_THINK_BUDGET*: the value a client can resend. */
+ // biome-ignore lint/style/useNamingConvention: API schema
+ requested_reasoning_budget?: number;
+ // biome-ignore lint/style/useNamingConvention: API schema
+ requested_reasoning_budget_message?: string;
/** Slots llama-server actually runs, after any fit-time reduction. Null when no GGUF model is loaded. */
parallel_slots?: number | null;
/** batch size (--batch-size) the active load was invoked with; null = default */
diff --git a/studio/frontend/src/features/model-picker/api/model-overrides.ts b/studio/frontend/src/features/model-picker/api/model-overrides.ts
index 645f7ce37d5..a793a855923 100644
--- a/studio/frontend/src/features/model-picker/api/model-overrides.ts
+++ b/studio/frontend/src/features/model-picker/api/model-overrides.ts
@@ -41,6 +41,10 @@ export interface ApiModelOverride {
// biome-ignore lint/style/useNamingConvention: API schema
n_parallel?: number;
// biome-ignore lint/style/useNamingConvention: API schema
+ reasoning_budget?: number;
+ // biome-ignore lint/style/useNamingConvention: API schema
+ reasoning_budget_message?: string;
+ // biome-ignore lint/style/useNamingConvention: API schema
n_batch?: number;
// biome-ignore lint/style/useNamingConvention: API schema
n_ubatch?: number;
@@ -304,6 +308,9 @@ export function fromApiOverride(
specDraftCacheDtype:
override.spec_draft_cache_type ?? local.specDraftCacheDtype,
nParallel: override.n_parallel ?? local.nParallel,
+ reasoningBudget: override.reasoning_budget ?? local.reasoningBudget,
+ reasoningBudgetMessage:
+ override.reasoning_budget_message ?? local.reasoningBudgetMessage,
nBatch: override.n_batch ?? local.nBatch,
nUbatch: override.n_ubatch ?? local.nUbatch,
loadMode: override.load_mode ?? local.loadMode,
@@ -363,6 +370,12 @@ export function toApiOverride(config: PerModelConfig | null): ApiModelOverride {
if (config.nParallel && config.nParallel > 0) {
payload.n_parallel = config.nParallel;
}
+ if (config.reasoningBudget !== -1) {
+ payload.reasoning_budget = config.reasoningBudget;
+ }
+ if (config.reasoningBudgetMessage) {
+ payload.reasoning_budget_message = config.reasoningBudgetMessage;
+ }
// blank follows the llama.cpp defaults (2048 / 512)
if (config.nBatch && config.nBatch > 0) {
payload.n_batch = config.nBatch;
@@ -443,6 +456,9 @@ export interface PutModelOverrideOptions {
* local entry for the storage budget is not a forget, so it must not take
* `llama_extra_args` the page can neither show nor restore. */
keepLaunchFlags?: boolean;
+ /** Remove a legacy passthrough value only after this control was explicitly reset. */
+ resetReasoningBudget?: boolean;
+ resetReasoningBudgetMessage?: boolean;
}
export async function putModelOverride(
@@ -491,6 +507,10 @@ async function sendModelOverride(
// knew to send. An older backend ignores the key.
// biome-ignore lint/style/useNamingConvention: API schema
mirrors_server_tuning: true,
+ // Same contract for the reasoning pair, which a build mirroring the tuning group
+ // can still predate.
+ // biome-ignore lint/style/useNamingConvention: API schema
+ mirrors_reasoning_budget: true,
// Only sent when set, so an older backend is not handed an unknown key every save.
...(options?.fillAbsentFields
? // biome-ignore lint/style/useNamingConvention: API schema
@@ -506,6 +526,20 @@ async function sendModelOverride(
{ llama_extra_args: [] }
: {}),
...toApiOverride(config),
+ // Write-only reset markers let the backend remove legacy passthrough flags
+ // shadowing these controls. Fill-only migration must never delete stored flags.
+ ...(options?.resetReasoningBudget && config?.reasoningBudget === -1
+ ? {
+ // biome-ignore lint/style/useNamingConvention: API schema
+ reasoning_budget: -1,
+ }
+ : {}),
+ ...(options?.resetReasoningBudgetMessage && config?.reasoningBudgetMessage === ""
+ ? {
+ // biome-ignore lint/style/useNamingConvention: API schema
+ reasoning_budget_message: "",
+ }
+ : {}),
}),
});
if (!res.ok) {
diff --git a/studio/frontend/src/features/model-picker/components/model-config-page.tsx b/studio/frontend/src/features/model-picker/components/model-config-page.tsx
index 3476469bac3..30740557fde 100644
--- a/studio/frontend/src/features/model-picker/components/model-config-page.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-config-page.tsx
@@ -153,6 +153,7 @@ import {
deletePerModelConfig,
floorMaxSeqLength,
isDefaultConfig,
+ isReasoningBudgetMessageValid,
contextPinPatch,
isServedByMlx,
savedContextPin,
@@ -264,6 +265,8 @@ function hasNonDefaultAdvanced(config: PerModelConfig): boolean {
config.specDraftNMax != null ||
config.specDraftCacheDtype != null ||
config.nParallel != null ||
+ config.reasoningBudget !== -1 ||
+ config.reasoningBudgetMessage !== "" ||
config.nBatch != null ||
config.nUbatch != null ||
config.loadMode != null ||
@@ -294,6 +297,8 @@ function withoutUnsupportedDiffusionSettings(
(config.gpuMemoryMode ?? "auto") === "auto" &&
config.gpuLayers == null &&
config.nCpuMoe == null &&
+ config.reasoningBudget === -1 &&
+ config.reasoningBudgetMessage === "" &&
!config.tensorParallel &&
!config.disableVision &&
config.nBatch == null &&
@@ -308,6 +313,8 @@ function withoutUnsupportedDiffusionSettings(
gpuMemoryMode: "auto",
gpuLayers: undefined,
nCpuMoe: undefined,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel: false,
disableVision: false,
// the diffusion runner ignores the llama-server batch flags
@@ -1470,6 +1477,67 @@ function GgufAdvancedSettings({
</div>
)}
+ {!isDiffusion && (
+ <div className={ROW_CLASS}>
+ <div className="flex min-w-0 items-center gap-1.5">
+ <span className={LABEL_CLASS}>Reasoning Budget</span>
+ <InfoHint>
+ Maximum thinking tokens. -1 is unrestricted, 0 ends reasoning
+ immediately, and a positive value sets a token budget.
+ </InfoHint>
+ </div>
+ <input
+ type="number"
+ min={-1}
+ max={2_147_483_647}
+ step={1}
+ value={config.reasoningBudget}
+ onChange={(event) => {
+ const raw = event.target.value;
+ if (raw === "") {
+ update({ reasoningBudget: -1 });
+ return;
+ }
+ const parsed = Number.parseInt(raw, 10);
+ if (Number.isFinite(parsed)) {
+ update({
+ reasoningBudget: Math.max(
+ -1,
+ Math.min(2_147_483_647, parsed),
+ ),
+ });
+ }
+ }}
+ aria-label="Reasoning Budget"
+ className={NUMBER_INPUT_CLASS}
+ />
+ </div>
+ )}
+
+ {!isDiffusion && (
+ <div className={ROW_CLASS}>
+ <div className="flex min-w-0 items-center gap-1.5">
+ <span className={LABEL_CLASS_WRAP}>Reasoning Budget Message</span>
+ <InfoHint>
+ Optional text injected before the end-of-thinking tag when the
+ model reaches its reasoning budget.
+ </InfoHint>
+ </div>
+ <input
+ type="text"
+ value={config.reasoningBudgetMessage}
+ placeholder="None"
+ onChange={(event) => {
+ if (isReasoningBudgetMessageValid(event.target.value)) {
+ update({ reasoningBudgetMessage: event.target.value });
+ }
+ }}
+ aria-label="Reasoning Budget Message"
+ className={`h-8 w-[180px] min-w-0 ${CONTROL_SURFACE} px-3 py-0 text-ui-13 font-medium text-nav-fg outline-none focus-visible:ring-0`}
+ />
+ </div>
+ )}
+
<GpuMemorySettings
config={config}
update={update}
@@ -2836,7 +2904,13 @@ export function ModelConfigPage({
hasPending || peerChanged ? { ...baseConfig, ...pendingPatch } : baseConfig;
const effectiveConfig = resolvedIsDiffusion
? withoutUnsupportedDiffusionSettings(committedConfig, gpuIndexKind)
- : committedConfig;
+ : target.isGguf
+ ? committedConfig
+ : {
+ ...committedConfig,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
+ };
// pinFixedLayerContext above was computed from the render-time config, before the same-click
// GPU Layers draft was committed, so recompute from effectiveConfig or a later fresh load
// recreates the OOM.
@@ -2893,6 +2967,16 @@ export function ModelConfigPage({
configId,
target.ggufVariant,
remember ? normalizedRuntimeConfig : null,
+ remember
+ ? {
+ resetReasoningBudget:
+ baseline.reasoningBudget !== -1 &&
+ normalizedRuntimeConfig.reasoningBudget === -1,
+ resetReasoningBudgetMessage:
+ baseline.reasoningBudgetMessage !== "" &&
+ normalizedRuntimeConfig.reasoningBudgetMessage === "",
+ }
+ : undefined,
);
}
// Only once the write landed: a blocked or full localStorage leaves the values on screen,
diff --git a/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts b/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
index dd204f2d0a1..ecf10816653 100644
--- a/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
+++ b/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
@@ -31,6 +31,18 @@ export function useActiveModelConfig(): ActiveModelConfigState {
const speculativeType = useChatRuntimeStore((s) => s.speculativeType);
const specDraftNMax = useChatRuntimeStore((s) => s.specDraftNMax);
const nParallel = useChatRuntimeStore((s) => s.nParallel);
+ // preserve inherited launch intent until the corresponding control changes.
+ const reasoningBudget = useChatRuntimeStore((s) =>
+ s.reasoningBudget === s.loadedReasoningBudget
+ ? (s.loadedReasoningBudgetRequested ?? s.reasoningBudget)
+ : s.reasoningBudget,
+ );
+ const reasoningBudgetMessage = useChatRuntimeStore(
+ (s) =>
+ s.reasoningBudgetMessage === s.loadedReasoningBudgetMessage
+ ? (s.loadedReasoningBudgetMessageRequested ?? s.reasoningBudgetMessage)
+ : s.reasoningBudgetMessage,
+ );
const nBatch = useChatRuntimeStore((s) => s.nBatch);
const nUbatch = useChatRuntimeStore((s) => s.nUbatch);
const specDraftCacheDtype = useChatRuntimeStore(
@@ -85,6 +97,8 @@ export function useActiveModelConfig(): ActiveModelConfigState {
speculativeType: speculativeType ?? "auto",
specDraftNMax: specDraftNMax ?? null,
nParallel: nParallel ?? null,
+ reasoningBudget: isGguf ? reasoningBudget : -1,
+ reasoningBudgetMessage: isGguf ? reasoningBudgetMessage : "",
nBatch: nBatch ?? null,
nUbatch: nUbatch ?? null,
specDraftCacheDtype: specDraftCacheDtype ?? null,
@@ -117,6 +131,8 @@ export function useActiveModelConfig(): ActiveModelConfigState {
speculativeType,
specDraftNMax,
nParallel,
+ reasoningBudget,
+ reasoningBudgetMessage,
nBatch,
nUbatch,
specDraftCacheDtype,
diff --git a/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts b/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
index c312edae8fc..9bf10673025 100644
--- a/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
+++ b/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
@@ -56,6 +56,10 @@ export function applyPerModelConfigToRuntime(
specDraftNMax: config.specDraftNMax ?? null,
specDraftCacheDtype: config.specDraftCacheDtype ?? null,
nParallel: config.nParallel ?? null,
+ reasoningBudget: options.isDiffusion ? -1 : config.reasoningBudget,
+ reasoningBudgetMessage: options.isDiffusion
+ ? ""
+ : config.reasoningBudgetMessage,
// the diffusion runner ignores the llama-server batch flags
nBatch: options.isDiffusion ? null : (config.nBatch ?? null),
nUbatch: options.isDiffusion ? null : (config.nUbatch ?? null),
@@ -114,6 +118,14 @@ export function currentRuntimePerModelConfig(
specDraftNMax: s.specDraftNMax ?? null,
specDraftCacheDtype: s.specDraftCacheDtype ?? null,
nParallel: s.nParallel ?? null,
+ reasoningBudget:
+ s.reasoningBudget === s.loadedReasoningBudget
+ ? (s.loadedReasoningBudgetRequested ?? s.reasoningBudget)
+ : s.reasoningBudget,
+ reasoningBudgetMessage:
+ s.reasoningBudgetMessage === s.loadedReasoningBudgetMessage
+ ? (s.loadedReasoningBudgetMessageRequested ?? s.reasoningBudgetMessage)
+ : s.reasoningBudgetMessage,
nBatch: s.nBatch ?? null,
nUbatch: s.nUbatch ?? null,
loadMode: s.loadMode ?? null,
@@ -147,6 +159,8 @@ export function perModelConfigsEqual(
(a.specDraftNMax ?? null) === (b.specDraftNMax ?? null) &&
(a.specDraftCacheDtype ?? null) === (b.specDraftCacheDtype ?? null) &&
(a.nParallel ?? null) === (b.nParallel ?? null) &&
+ a.reasoningBudget === b.reasoningBudget &&
+ a.reasoningBudgetMessage === b.reasoningBudgetMessage &&
(a.nBatch ?? null) === (b.nBatch ?? null) &&
(a.nUbatch ?? null) === (b.nUbatch ?? null) &&
(a.loadMode ?? null) === (b.loadMode ?? null) &&
diff --git a/studio/frontend/src/features/model-picker/model-config/config-signature.ts b/studio/frontend/src/features/model-picker/model-config/config-signature.ts
index de2cffc4d72..d9e69fe358a 100644
--- a/studio/frontend/src/features/model-picker/model-config/config-signature.ts
+++ b/studio/frontend/src/features/model-picker/model-config/config-signature.ts
@@ -53,6 +53,8 @@ export function loadedConfigSignature(
config.specDraftNMax ?? "",
config.specDraftCacheDtype ?? "",
config.nParallel ?? "",
+ config.reasoningBudget ?? "",
+ `${(config.reasoningBudgetMessage ?? "").length}:${hashString(config.reasoningBudgetMessage ?? "")}`,
config.nBatch ?? "",
config.nUbatch ?? "",
config.loadMode ?? "",
diff --git a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
index 9d0fc124bc0..aa723d23011 100644
--- a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
+++ b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
@@ -28,6 +28,8 @@ export interface PerModelConfig {
* Optional so older blobs parse. */
specDraftCacheDtype?: string | null;
nParallel: number | null;
+ reasoningBudget: number;
+ reasoningBudgetMessage: string;
nBatch: number | null;
nUbatch: number | null;
/** --load-mode; null lets the fit decide (`none` when the load fits, else no flag).
@@ -64,6 +66,8 @@ export const DEFAULT_PER_MODEL_CONFIG: PerModelConfig = {
specDraftNMax: null,
specDraftCacheDtype: null,
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
loadMode: null,
@@ -296,8 +300,10 @@ const LEGACY_STORAGE_KEY = "unsloth_load_settings";
const LEGACY_MIGRATION_FLAG = "unsloth_model_configs_migrated";
// would normalize the unknown field straight back out of the record.
// v2 added nBatch/nUbatch, v3 llamaExtraArgs, v4 disableVision, v5 the llama-server tuning group
-// (loadMode / specDraftCacheDtype / ctxCheckpoints / cacheRam); a client from before any of them
-const STORAGE_SCHEMA_VERSION = 5;
+// (loadMode / specDraftCacheDtype / ctxCheckpoints / cacheRam), v6 the reasoning budget pair; a
+// client from before any of them
+const STORAGE_SCHEMA_VERSION = 6;
+const PRE_REASONING_BUDGET_SCHEMA_VERSION = 5;
const PRE_SERVER_TUNING_SCHEMA_VERSION = 4;
const PRE_VISION_SCHEMA_VERSION = 3;
const PRE_EXTRA_ARGS_SCHEMA_VERSION = 2;
@@ -305,6 +311,25 @@ const PRE_BATCH_SCHEMA_VERSION = 1;
const MAX_ENTRIES = 500;
const MAX_PER_MODEL_CONFIG_STORAGE_BYTES = 1024 * 1024;
export const MAX_CHAT_TEMPLATE_BYTES = 65_536;
+export const MAX_REASONING_BUDGET_MESSAGE_BYTES = 8_192;
+
+export function isReasoningBudgetMessageValid(value: string): boolean {
+ if (value.includes("\0")) return false;
+ for (let i = 0; i < value.length; i += 1) {
+ const code = value.charCodeAt(i);
+ if (code >= 0xd800 && code <= 0xdbff) {
+ const next = value.charCodeAt(i + 1);
+ if (next < 0xdc00 || next > 0xdfff) return false;
+ i += 1;
+ } else if (code >= 0xdc00 && code <= 0xdfff) {
+ return false;
+ }
+ }
+ return (
+ new TextEncoder().encode(value).byteLength <=
+ MAX_REASONING_BUDGET_MESSAGE_BYTES
+ );
+}
type StoredPerModelConfig = PerModelConfig & {
version: number;
@@ -322,6 +347,8 @@ const STORED_CONFIG_FIELDS = new Set([
"specDraftNMax",
"specDraftCacheDtype",
"nParallel",
+ "reasoningBudget",
+ "reasoningBudgetMessage",
"nBatch",
"nUbatch",
"loadMode",
@@ -722,6 +749,8 @@ function legacyEntryToConfig(raw: Record<string, unknown>): PerModelConfig {
typeof raw.specDraftNMax === "number" ? raw.specDraftNMax : null,
// Legacy blobs predate the parallel-slots knob.
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel:
typeof raw.tensorParallel === "boolean" ? raw.tensorParallel : false,
disableVision:
@@ -941,6 +970,19 @@ function normalizeV1(partial: RawConfig): PerModelConfig {
typeof partial.nUbatch === "number" && Number.isFinite(partial.nUbatch)
? Math.max(N_BATCH_MIN, Math.min(N_BATCH_MAX, Math.round(partial.nUbatch)))
: null,
+ reasoningBudget:
+ typeof partial.reasoningBudget === "number" &&
+ Number.isFinite(partial.reasoningBudget)
+ ? Math.max(
+ -1,
+ Math.min(2_147_483_647, Math.trunc(partial.reasoningBudget)),
+ )
+ : DEFAULT_PER_MODEL_CONFIG.reasoningBudget,
+ reasoningBudgetMessage:
+ typeof partial.reasoningBudgetMessage === "string" &&
+ isReasoningBudgetMessageValid(partial.reasoningBudgetMessage)
+ ? partial.reasoningBudgetMessage
+ : DEFAULT_PER_MODEL_CONFIG.reasoningBudgetMessage,
tensorParallel:
typeof partial.tensorParallel === "boolean"
? partial.tensorParallel
@@ -978,28 +1020,40 @@ function normalize(raw: unknown): PerModelConfig {
return normalizeV1(partial);
}
-function toStoredConfig(config: PerModelConfig): StoredPerModelConfig {
- const normalized = normalize(config);
- // Stamped with the OLDEST version that still understands every field present, so a record an older client can
- // safely rewrite stays in its reach. Only a TRUE disableVision needs v4: false is what a pre-vision client
- // reconstructs anyway, and stamping every record v4 would put the whole store out of reach. The tuning group
- // follows the same rule.
+/** The OLDEST version that still understands every field present, so a record an older client can
+ * safely rewrite stays in its reach. Only a TRUE disableVision needs v4: false is what a pre-vision
+ * client reconstructs anyway, and stamping every record v4 would put the whole store out of reach.
+ * The tuning group and the reasoning pair follow the same rule. */
+function storedSchemaVersion(normalized: PerModelConfig): number {
+ const hasReasoningBudget =
+ normalized.reasoningBudget !== -1 || normalized.reasoningBudgetMessage !== "";
+ if (hasReasoningBudget) {
+ return STORAGE_SCHEMA_VERSION;
+ }
const hasServerTuning =
normalized.loadMode != null ||
normalized.specDraftCacheDtype != null ||
normalized.ctxCheckpoints != null ||
normalized.cacheRam != null;
- const version = hasServerTuning
- ? STORAGE_SCHEMA_VERSION
- : normalized.disableVision
- ? PRE_SERVER_TUNING_SCHEMA_VERSION
- : normalized.llamaExtraArgs != null && normalized.llamaExtraArgs.length > 0
- ? PRE_VISION_SCHEMA_VERSION
- : normalized.nBatch != null || normalized.nUbatch != null
- ? PRE_EXTRA_ARGS_SCHEMA_VERSION
- : PRE_BATCH_SCHEMA_VERSION;
+ if (hasServerTuning) {
+ return PRE_REASONING_BUDGET_SCHEMA_VERSION;
+ }
+ if (normalized.disableVision) {
+ return PRE_SERVER_TUNING_SCHEMA_VERSION;
+ }
+ if (normalized.llamaExtraArgs != null && normalized.llamaExtraArgs.length > 0) {
+ return PRE_VISION_SCHEMA_VERSION;
+ }
+ if (normalized.nBatch != null || normalized.nUbatch != null) {
+ return PRE_EXTRA_ARGS_SCHEMA_VERSION;
+ }
+ return PRE_BATCH_SCHEMA_VERSION;
+}
+
+function toStoredConfig(config: PerModelConfig): StoredPerModelConfig {
+ const normalized = normalize(config);
return {
- version,
+ version: storedSchemaVersion(normalized),
...normalized,
};
}
@@ -1146,6 +1200,9 @@ export function isDefaultConfig(config: PerModelConfig): boolean {
config.speculativeType === DEFAULT_PER_MODEL_CONFIG.speculativeType &&
config.specDraftNMax == null &&
config.nParallel == null &&
+ config.reasoningBudget === DEFAULT_PER_MODEL_CONFIG.reasoningBudget &&
+ config.reasoningBudgetMessage ===
+ DEFAULT_PER_MODEL_CONFIG.reasoningBudgetMessage &&
config.nBatch == null &&
config.nUbatch == null &&
// The tuning group, for the same reason as the arguments below: savePerModelConfig deletes an entry it judges
diff --git a/studio/frontend/src/features/recipe-studio/hooks/use-recipe-executions.ts b/studio/frontend/src/features/recipe-studio/hooks/use-recipe-executions.ts
index 02e770aa89c..c42949bbeb9 100644
--- a/studio/frontend/src/features/recipe-studio/hooks/use-recipe-executions.ts
+++ b/studio/frontend/src/features/recipe-studio/hooks/use-recipe-executions.ts
@@ -75,6 +75,12 @@ type LocalModelSelection = {
aliases: string[];
requestedContextLength?: number | null;
isMlx?: boolean;
+ /** What that load ASKED for, captured the same way as the context request: a restore
+ * replays it, while a recipe's own target runs at the defaults. Requested rather than
+ * effective, because the effective pair folds in a LLAMA_ARG_THINK_BUDGET* no request can
+ * express, and comparing against that would reload on every run and never converge. */
+ reasoningBudget?: number;
+ reasoningBudgetMessage?: string;
};
type LocalModelLoadPlan =
@@ -266,7 +272,13 @@ function contextIntent(
export async function isLocalModelAlreadyLoaded(
selection: LocalModelSelection,
): Promise<boolean> {
- const { target, ggufVariant, requestedContextLength } = selection;
+ const {
+ target,
+ ggufVariant,
+ requestedContextLength,
+ reasoningBudget,
+ reasoningBudgetMessage,
+ } = selection;
try {
const status = await getInferenceStatus();
if (
@@ -281,9 +293,19 @@ export async function isLocalModelAlreadyLoaded(
}
// A different context intent is a different load: asking for nothing inherits no pin.
const residentIsMlx = status.is_mlx ?? false;
- return (
- contextIntent(requestedContextLength, residentIsMlx) ===
+ if (
+ contextIntent(requestedContextLength, residentIsMlx) !==
contextIntent(status.requested_context_length, residentIsMlx)
+ ) {
+ return false;
+ }
+ // Same rule for reasoning: a recipe asked for the defaults, so Chat's budget would
+ // otherwise change what the run produces. Both sides are REQUESTED values, so an
+ // inherited environment default reads as equal and cannot loop.
+ return (
+ (reasoningBudget ?? -1) === (status.requested_reasoning_budget ?? -1) &&
+ (reasoningBudgetMessage ?? "") ===
+ (status.requested_reasoning_budget_message ?? "")
);
} catch {
return false;
@@ -293,7 +315,13 @@ export async function isLocalModelAlreadyLoaded(
async function loadLocalModelSelection(
selection: LocalModelSelection,
): Promise<string | null> {
- const { target, ggufVariant, requestedContextLength } = selection;
+ const {
+ target,
+ ggufVariant,
+ requestedContextLength,
+ reasoningBudget,
+ reasoningBudgetMessage,
+ } = selection;
const modelLabel = ggufVariant ? `${target} (${ggufVariant})` : target;
let loadToastDismissed = false;
const toastId = toast.message(`Loading ${modelLabel}...`, {
@@ -324,6 +352,10 @@ async function loadLocalModelSelection(
DEFAULT_MAX_SEQ_LENGTH,
),
// biome-ignore lint/style/useNamingConvention: api schema
+ reasoning_budget: reasoningBudget ?? -1,
+ // biome-ignore lint/style/useNamingConvention: api schema
+ reasoning_budget_message: reasoningBudgetMessage ?? "",
+ // biome-ignore lint/style/useNamingConvention: api schema
load_in_4bit: true,
// biome-ignore lint/style/useNamingConvention: api schema
is_lora: false,
@@ -382,6 +414,8 @@ async function getActiveLocalModelSelection(): Promise<LocalModelSelection | nul
aliases: ["previous Chat model"],
requestedContextLength: status.requested_context_length ?? null,
isMlx: status.is_mlx ?? false,
+ reasoningBudget: status.requested_reasoning_budget ?? -1,
+ reasoningBudgetMessage: status.requested_reasoning_budget_message ?? "",
};
} catch {
return null;
@@ -408,6 +442,8 @@ async function getRestorableActiveLocalModelSelection(): Promise<RestorableLocal
aliases: ["previous Chat model"],
requestedContextLength: status.requested_context_length ?? null,
isMlx: status.is_mlx ?? false,
+ reasoningBudget: status.requested_reasoning_budget ?? -1,
+ reasoningBudgetMessage: status.requested_reasoning_budget_message ?? "",
},
unrestorableLabel: null,
};
@@ -425,7 +461,9 @@ function isSameLocalModelSelection(
left.target.toLowerCase() === right.target.toLowerCase() &&
left.ggufVariant === right.ggufVariant &&
contextIntent(left.requestedContextLength, left.isMlx) ===
- contextIntent(right.requestedContextLength, right.isMlx),
+ contextIntent(right.requestedContextLength, right.isMlx) &&
+ (left.reasoningBudget ?? -1) === (right.reasoningBudget ?? -1) &&
+ (left.reasoningBudgetMessage ?? "") === (right.reasoningBudgetMessage ?? ""),
);
}
diff --git a/studio/frontend/tests/active-reasoning-intent.test.ts b/studio/frontend/tests/active-reasoning-intent.test.ts
new file mode 100644
index 00000000000..0d97f55ae0d
--- /dev/null
+++ b/studio/frontend/tests/active-reasoning-intent.test.ts
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+import type { ActiveModelConfigState } from "../src/features/model-picker/hooks/use-active-model-config.ts";
+import { loadWithStubs } from "./helpers/module-stubs.ts";
+
+function activeConfig(patch: Record<string, unknown> = {}) {
+ const state = {
+ params: { checkpoint: "unsloth/Qwen3-0.6B-GGUF", maxSeqLength: 2048 },
+ reasoningBudget: 32,
+ reasoningBudgetMessage: "Conclude now.",
+ loadedReasoningBudget: 32,
+ loadedReasoningBudgetMessage: "Conclude now.",
+ loadedReasoningBudgetRequested: -1,
+ loadedReasoningBudgetMessageRequested: "",
+ ...patch,
+ };
+ const { useActiveModelConfig } = loadWithStubs<{
+ useActiveModelConfig: () => ActiveModelConfigState;
+ }>(
+ new URL(
+ "../src/features/model-picker/hooks/use-active-model-config.ts",
+ import.meta.url,
+ ),
+ {
+ "@/features/chat": {
+ isExternalModelId: () => false,
+ useChatRuntimeStore: (select: (value: typeof state) => unknown) =>
+ select(state),
+ },
+ "@/config/env": { usePlatformStore: () => ({ deviceType: "cpu" }) },
+ react: { useMemo: (factory: () => unknown) => factory() },
+ "../model-config/per-model-config": {
+ isServedByLlamaCpp: () => true,
+ residentIsServedByMlx: () => false,
+ },
+ },
+ );
+ const config = useActiveModelConfig().config!;
+ const { currentRuntimePerModelConfig } = loadWithStubs<{
+ currentRuntimePerModelConfig: () => NonNullable<
+ ActiveModelConfigState["config"]
+ >;
+ }>(
+ new URL(
+ "../src/features/model-picker/model-config/apply-per-model-config.ts",
+ import.meta.url,
+ ),
+ {
+ "@/features/chat/stores/chat-runtime-store": {
+ useChatRuntimeStore: { getState: () => state },
+ normalizeSpeculativeType: (value: unknown) => value ?? null,
+ },
+ "@/features/chat/presets/preset-policy": {},
+ "./config-signature": {},
+ "./per-model-config": {},
+ },
+ );
+ const snapshot = currentRuntimePerModelConfig();
+ assert.equal(snapshot.reasoningBudget, config.reasoningBudget);
+ assert.equal(snapshot.reasoningBudgetMessage, config.reasoningBudgetMessage);
+ return config;
+}
+
+test("unrelated edits preserve inherited reasoning launch intent", () => {
+ const config = activeConfig({ nBatch: 256 });
+ assert.equal(config.reasoningBudget, -1);
+ assert.equal(config.reasoningBudgetMessage, "");
+ assert.equal(config.nBatch, 256);
+});
+
+test("an edited reasoning control overrides only its own inherited value", () => {
+ const budget = activeConfig({ reasoningBudget: 0 });
+ assert.equal(budget.reasoningBudget, 0);
+ assert.equal(budget.reasoningBudgetMessage, "");
+ const message = activeConfig({ reasoningBudgetMessage: "Finish." });
+ assert.equal(message.reasoningBudget, -1);
+ assert.equal(message.reasoningBudgetMessage, "Finish.");
+});
+
+test("explicit and legacy reasoning values remain available", () => {
+ assert.equal(
+ activeConfig({ loadedReasoningBudgetRequested: 32 }).reasoningBudget,
+ 32,
+ );
+ const legacy = activeConfig({
+ loadedReasoningBudgetRequested: null,
+ loadedReasoningBudgetMessageRequested: null,
+ });
+ assert.equal(legacy.reasoningBudget, 32);
+ assert.equal(legacy.reasoningBudgetMessage, "Conclude now.");
+});
diff --git a/studio/frontend/tests/adopt-legacy-config-key.test.ts b/studio/frontend/tests/adopt-legacy-config-key.test.ts
index df582b1b813..e0761e991de 100644
--- a/studio/frontend/tests/adopt-legacy-config-key.test.ts
+++ b/studio/frontend/tests/adopt-legacy-config-key.test.ts
@@ -38,6 +38,8 @@ function config(
speculativeType: null,
specDraftNMax: null,
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
tensorParallel: false,
diff --git a/studio/frontend/tests/batch-schema-version.test.ts b/studio/frontend/tests/batch-schema-version.test.ts
index 85c009c891d..e10b97f7f88 100644
--- a/studio/frontend/tests/batch-schema-version.test.ts
+++ b/studio/frontend/tests/batch-schema-version.test.ts
@@ -28,6 +28,8 @@ function config(nBatch: number | null, nUbatch: number | null = null) {
nParallel: 4,
nBatch,
nUbatch,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel: false,
disableVision: false,
chatTemplateOverride: null,
diff --git a/studio/frontend/tests/batch-upgrade-downgrade-compat.test.ts b/studio/frontend/tests/batch-upgrade-downgrade-compat.test.ts
index 5a37d3b1afd..7763f4dfb76 100644
--- a/studio/frontend/tests/batch-upgrade-downgrade-compat.test.ts
+++ b/studio/frontend/tests/batch-upgrade-downgrade-compat.test.ts
@@ -40,6 +40,8 @@ function config(overrides: Record<string, unknown> = {}) {
nParallel: null,
nBatch: null,
nUbatch: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel: false,
disableVision: false,
chatTemplateOverride: null,
diff --git a/studio/frontend/tests/mlx-context-pin-record-compat.test.ts b/studio/frontend/tests/mlx-context-pin-record-compat.test.ts
index ca0cef527f1..1ce40749ce4 100644
--- a/studio/frontend/tests/mlx-context-pin-record-compat.test.ts
+++ b/studio/frontend/tests/mlx-context-pin-record-compat.test.ts
@@ -204,12 +204,12 @@ const ROWS: Row[] = [
mlxRequest: 32768,
transformersRequest: 32768,
note:
- "The task called v4 the 'future' record. It is not: STORAGE_SCHEMA_VERSION is 5 " +
- "in this tree and in main, not 3, so v4 is a v4-client record and reads normally.",
+ "The task called v4 the 'future' record. It is not: STORAGE_SCHEMA_VERSION is 6 " +
+ "in this tree, not 3, so v4 is a v4-client record and reads normally.",
},
{
- name: "version 6 (genuinely future)",
- raw: { version: 6, customContextLength: 32768 },
+ name: "version 7 (genuinely future)",
+ raw: { version: 7, customContextLength: 32768 },
normalizedPin: null,
rawPin: 32768,
isDefault: true,
@@ -342,6 +342,10 @@ test("both pin shapes are stamped version 1, so neither is distinguishable by ve
);
assert.equal(
stage({ version: 6, customContextLength: 32768 }).remembered,
+ true,
+ );
+ assert.equal(
+ stage({ version: 7, customContextLength: 32768 }).remembered,
false,
);
});
diff --git a/studio/frontend/tests/model-config-draft.test.ts b/studio/frontend/tests/model-config-draft.test.ts
index b2a9b43cf54..5b735a81e07 100644
--- a/studio/frontend/tests/model-config-draft.test.ts
+++ b/studio/frontend/tests/model-config-draft.test.ts
@@ -35,6 +35,8 @@ const SEED: PerModelConfig = {
speculativeType: "auto",
specDraftNMax: null,
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
tensorParallel: false,
diff --git a/studio/frontend/tests/model-config-instance-key.test.ts b/studio/frontend/tests/model-config-instance-key.test.ts
index f70c05d85bb..0b744a4aa0d 100644
--- a/studio/frontend/tests/model-config-instance-key.test.ts
+++ b/studio/frontend/tests/model-config-instance-key.test.ts
@@ -18,6 +18,8 @@ const LIVE: PerModelConfig = {
speculativeType: "ngram",
specDraftNMax: 6,
nParallel: 4,
+ reasoningBudget: 2048,
+ reasoningBudgetMessage: "Budget exhausted",
nBatch: 4096,
nUbatch: 1024,
tensorParallel: true,
@@ -37,6 +39,8 @@ const SAVED: PerModelConfig = {
speculativeType: "auto",
specDraftNMax: null,
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
tensorParallel: false,
@@ -107,6 +111,8 @@ test("every mirrored setting moves the instance key", () => {
{ ...LIVE, speculativeType: "off" },
{ ...LIVE, specDraftNMax: 4 },
{ ...LIVE, nParallel: 1 },
+ { ...LIVE, reasoningBudget: 0 },
+ { ...LIVE, reasoningBudgetMessage: "Done thinking" },
{ ...LIVE, tensorParallel: false },
{ ...LIVE, chatTemplateOverride: "{{ bos_token }}" },
{ ...LIVE, gpuMemoryMode: "auto" },
diff --git a/studio/frontend/tests/model-identity.test.ts b/studio/frontend/tests/model-identity.test.ts
index 2cfedd534e6..f8b81d2f1a6 100644
--- a/studio/frontend/tests/model-identity.test.ts
+++ b/studio/frontend/tests/model-identity.test.ts
@@ -48,6 +48,8 @@ function config(maxSeqLength: number, kvCacheDtype: string | null = null) {
speculativeType: null,
specDraftNMax: null,
nParallel: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
tensorParallel: false,
diff --git a/studio/frontend/tests/preset-reasoning-subscription.test.ts b/studio/frontend/tests/preset-reasoning-subscription.test.ts
new file mode 100644
index 00000000000..c007a734a8d
--- /dev/null
+++ b/studio/frontend/tests/preset-reasoning-subscription.test.ts
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+import ts from "typescript";
+import { readSrc } from "./helpers/kit.ts";
+
+const source = ts.createSourceFile(
+ "sheet.tsx",
+ readSrc("features/chat/chat-settings-sheet.tsx"),
+ ts.ScriptTarget.Latest,
+ true,
+ ts.ScriptKind.TSX,
+);
+const selectors = new Map<
+ string,
+ (state: Record<string, unknown>) => unknown
+>();
+function visit(node: ts.Node): void {
+ if (
+ ts.isVariableDeclaration(node) &&
+ ts.isIdentifier(node.name) &&
+ ["reasoningBudget", "reasoningBudgetMessage"].includes(node.name.text) &&
+ node.initializer &&
+ ts.isCallExpression(node.initializer)
+ ) {
+ selectors.set(
+ node.name.text,
+ new Function(
+ `return (${node.initializer.arguments[0].getText(source)});`,
+ )(),
+ );
+ }
+ ts.forEachChild(node, visit);
+}
+visit(source);
+
+for (const [field, effective, inherited] of [
+ ["reasoningBudget", 32, -1],
+ ["reasoningBudgetMessage", "Conclude now.", ""],
+] as const) {
+ test(`preset subscription sees requested-only changes to ${field}`, () => {
+ const select = selectors.get(field)!;
+ const loaded = `loaded${field[0].toUpperCase()}${field.slice(1)}`;
+ const explicit = {
+ [field]: effective,
+ [loaded]: effective,
+ [loaded + "Requested"]: effective,
+ };
+ const changed = { ...explicit, [loaded + "Requested"]: inherited };
+ assert.equal(select(explicit), effective);
+ assert.equal(select(changed), inherited);
+ assert.notEqual(select(explicit), select(changed));
+ });
+}
diff --git a/studio/frontend/tests/reasoning-budget-config.test.ts b/studio/frontend/tests/reasoning-budget-config.test.ts
new file mode 100644
index 00000000000..bbf8bcb662b
--- /dev/null
+++ b/studio/frontend/tests/reasoning-budget-config.test.ts
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ installLocalStorageFake,
+ registerBundlerResolver,
+} from "./helpers/kit.ts";
+
+registerBundlerResolver();
+const { store } = installLocalStorageFake();
+
+const {
+ DEFAULT_PER_MODEL_CONFIG,
+ isDefaultConfig,
+ isReasoningBudgetMessageValid,
+ normalizePerModelConfig,
+ resolveInitialConfig,
+ savePerModelConfig,
+} = await import(
+ "../src/features/model-picker/model-config/per-model-config.ts"
+);
+
+test("reasoning budget fields normalize to the backend defaults", () => {
+ const normalized = normalizePerModelConfig({});
+ assert.equal(normalized.reasoningBudget, DEFAULT_PER_MODEL_CONFIG.reasoningBudget);
+ assert.equal(
+ normalized.reasoningBudgetMessage,
+ DEFAULT_PER_MODEL_CONFIG.reasoningBudgetMessage,
+ );
+ assert.equal(
+ normalizePerModelConfig({ reasoningBudget: -10 }).reasoningBudget,
+ -1,
+ );
+ assert.equal(
+ normalizePerModelConfig({ reasoningBudget: 12.9 }).reasoningBudget,
+ 12,
+ );
+ assert.equal(isDefaultConfig(DEFAULT_PER_MODEL_CONFIG), true);
+ assert.equal(
+ isDefaultConfig({ ...DEFAULT_PER_MODEL_CONFIG, reasoningBudget: 0 }),
+ false,
+ );
+});
+
+test("reasoning budget messages use the subprocess byte boundary", () => {
+ assert.equal(isReasoningBudgetMessageValid("😀".repeat(2_048)), true);
+ assert.equal(isReasoningBudgetMessageValid("😀".repeat(2_049)), false);
+ assert.equal(isReasoningBudgetMessageValid("bad\0message"), false);
+ assert.equal(isReasoningBudgetMessageValid(" PAD "), true);
+ assert.equal(
+ normalizePerModelConfig({ reasoningBudgetMessage: "😀".repeat(2_049) })
+ .reasoningBudgetMessage,
+ "",
+ );
+ assert.equal(
+ normalizePerModelConfig({ reasoningBudgetMessage: " PAD " })
+ .reasoningBudgetMessage,
+ " PAD ",
+ );
+});
+
+test("reasoning budget and message round-trip through per-model storage", () => {
+ store.clear();
+ const config = {
+ ...DEFAULT_PER_MODEL_CONFIG,
+ reasoningBudget: 2048,
+ reasoningBudgetMessage: "Reasoning budget exhausted",
+ };
+ assert.equal(savePerModelConfig("unsloth/Test-GGUF", "Q4_K_M", config), true);
+
+ const resolved = resolveInitialConfig("unsloth/Test-GGUF", "Q4_K_M");
+ assert.equal(resolved.remembered, true);
+ assert.equal(resolved.config.reasoningBudget, 2048);
+ assert.equal(
+ resolved.config.reasoningBudgetMessage,
+ "Reasoning budget exhausted",
+ );
+});
+
+test("a record only claims v6 when it carries a reasoning setting", () => {
+ // toStoredConfig stamps the oldest version that understands every field present,
+ // so a v5 client can still rewrite a record that pins nothing newer than its own.
+ const storedVersion = () =>
+ (
+ Object.values(
+ JSON.parse(store.get("unsloth_model_configs") ?? "{}"),
+ ) as { version: number }[]
+ )[0]?.version;
+ store.clear();
+ assert.equal(
+ savePerModelConfig("unsloth/Test-GGUF", "Q4_K_M", {
+ ...DEFAULT_PER_MODEL_CONFIG,
+ nBatch: 512,
+ }),
+ true,
+ );
+ assert.equal(storedVersion(), 2);
+ store.clear();
+ assert.equal(
+ savePerModelConfig("unsloth/Test-GGUF", "Q4_K_M", {
+ ...DEFAULT_PER_MODEL_CONFIG,
+ reasoningBudget: 2048,
+ }),
+ true,
+ );
+ assert.equal(storedVersion(), 6);
+});
diff --git a/studio/frontend/tests/reasoning-budget-rollback.test.ts b/studio/frontend/tests/reasoning-budget-rollback.test.ts
new file mode 100644
index 00000000000..b1151e0bcf8
--- /dev/null
+++ b/studio/frontend/tests/reasoning-budget-rollback.test.ts
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+import { readSrc } from "./helpers/kit.ts";
+
+// Execute the shipped status patch and rollback payload, like resident-status-baselines.test.ts.
+// The browser store graph is not needed to exercise the request/effective round trip.
+const applier = readSrc("features/chat/lib/apply-inference-status-to-store.ts");
+const start = applier.indexOf(" // Rollback needs the request,");
+const end = applier.indexOf(" // AFTER that clear,", start);
+assert.ok(start >= 0 && end > start);
+type State = {
+ loadedReasoningBudget: number;
+ loadedReasoningBudgetMessage: string;
+ loadedReasoningBudgetRequested: number | null;
+ loadedReasoningBudgetMessageRequested: string | null;
+};
+const hydrate = new Function(
+ "previous",
+ "status",
+ "seedLoadParams",
+ "reasoningBudgetApplicable",
+ `return { ...previous, ${applier.slice(start, end)} };`,
+) as (
+ previous: State,
+ status: Record<string, unknown>,
+ settled: boolean,
+ gguf: boolean,
+) => State;
+
+const runtime = readSrc("features/chat/hooks/use-chat-model-runtime.ts");
+const rollbackStart = runtime.indexOf(
+ "n_parallel: stateBeforeUnload.loadedNParallel,",
+);
+const rollbackEnd = runtime.indexOf("// omit unset fields:", rollbackStart);
+assert.ok(rollbackStart >= 0 && rollbackEnd > rollbackStart);
+const rollback = new Function(
+ "stateBeforeUnload",
+ `return { ${runtime.slice(rollbackStart, rollbackEnd)} };`,
+) as (state: State) => {
+ reasoning_budget: number;
+ reasoning_budget_message: string;
+};
+
+const inherited: State = {
+ loadedReasoningBudget: 512,
+ loadedReasoningBudgetMessage: "from env",
+ loadedReasoningBudgetRequested: null,
+ loadedReasoningBudgetMessageRequested: null,
+};
+
+test("adoption then rollback preserves inherited defaults rather than making them explicit", () => {
+ const adopted = hydrate(
+ inherited,
+ {
+ reasoning_budget: 512,
+ reasoning_budget_message: "from env",
+ requested_reasoning_budget: -1,
+ requested_reasoning_budget_message: "",
+ },
+ true,
+ true,
+ );
+ const request = rollback(adopted);
+ assert.equal(request.reasoning_budget, -1);
+ assert.equal(request.reasoning_budget_message, "");
+ assert.equal(adopted.loadedReasoningBudget, 512);
+});
+
+test("a same-model reload updates the request even when its effective value is unchanged", () => {
+ const explicit = hydrate(
+ inherited,
+ {
+ requested_reasoning_budget: 512,
+ requested_reasoning_budget_message: "from env",
+ },
+ true,
+ true,
+ );
+ assert.equal(rollback(explicit).reasoning_budget, 512);
+ const next = hydrate(
+ explicit,
+ {
+ requested_reasoning_budget: -1,
+ requested_reasoning_budget_message: "",
+ },
+ true,
+ true,
+ );
+ assert.equal(rollback(next).reasoning_budget, -1);
+ assert.equal(rollback(next).reasoning_budget_message, "");
+});
+
+test("zero budget and verbatim messages survive the rollback request", () => {
+ const state = hydrate(
+ inherited,
+ {
+ requested_reasoning_budget: 0,
+ requested_reasoning_budget_message: " conclude now ",
+ },
+ true,
+ true,
+ );
+ assert.equal(rollback(state).reasoning_budget, 0);
+ assert.equal(rollback(state).reasoning_budget_message, " conclude now ");
+});
+
+test("a mid-load poll and an older backend cannot overwrite a known request", () => {
+ const known = {
+ ...inherited,
+ loadedReasoningBudgetRequested: 128,
+ loadedReasoningBudgetMessageRequested: "Stop",
+ };
+ assert.deepEqual(
+ hydrate(
+ known,
+ {
+ requested_reasoning_budget: 0,
+ requested_reasoning_budget_message: "other model",
+ },
+ false,
+ true,
+ ),
+ known,
+ );
+ assert.deepEqual(
+ hydrate(known, { reasoning_budget: 512 }, true, true),
+ known,
+ );
+});
+
+test("non-GGUF and diffusion adoption retires the previous request", () => {
+ const cleared = hydrate(
+ {
+ ...inherited,
+ loadedReasoningBudgetRequested: 128,
+ loadedReasoningBudgetMessageRequested: "Stop",
+ },
+ {},
+ true,
+ false,
+ );
+ assert.equal(rollback(cleared).reasoning_budget, -1);
+ assert.equal(rollback(cleared).reasoning_budget_message, "");
+});
diff --git a/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts b/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts
index 70c688c7e06..7fe07c3ff1a 100644
--- a/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts
+++ b/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts
@@ -69,6 +69,8 @@ const BLANK = {
nParallel: null,
nBatch: null,
nUbatch: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel: false,
disableVision: false,
chatTemplateOverride: null,
@@ -207,6 +209,18 @@ const FIELDS: FieldCase[] = [
same: 4096,
different: 8192,
},
+ {
+ key: "reasoningBudget",
+ statusKey: "reasoning_budget",
+ same: 1024,
+ different: 512,
+ },
+ {
+ key: "reasoningBudgetMessage",
+ statusKey: "reasoning_budget_message",
+ same: "Wrap up.",
+ different: "Stop here.",
+ },
{
key: "chatTemplateOverride",
statusKey: "chat_template_override",
diff --git a/studio/frontend/tests/resident-config-match.test.ts b/studio/frontend/tests/resident-config-match.test.ts
index 3f2beb50f9b..e4611c0db1c 100644
--- a/studio/frontend/tests/resident-config-match.test.ts
+++ b/studio/frontend/tests/resident-config-match.test.ts
@@ -32,6 +32,8 @@ const DEFAULT_ISH = {
nParallel: null,
nBatch: null,
nUbatch: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel: false,
disableVision: false,
chatTemplateOverride: null,
@@ -47,6 +49,8 @@ const BLANK = {
nParallel: null,
nBatch: null,
nUbatch: null,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
tensorParallel: false,
disableVision: false,
chatTemplateOverride: null,
@@ -1888,3 +1892,38 @@ test("a remembered manual split the resident load does not run is still a reload
false,
);
});
+
+
+test("inherited reasoning defaults do not reload an unchanged resident", () => {
+ assert.equal(matches({
+ reasoning_budget: 32,
+ reasoning_budget_message: "Conclude now.",
+ requested_reasoning_budget: -1,
+ requested_reasoning_budget_message: "",
+ }, BLANK), true);
+});
+
+test("pinning the effective reasoning value changes the resident request", () => {
+ assert.equal(matches({
+ reasoning_budget: 32,
+ requested_reasoning_budget: -1,
+ }, { ...BLANK, reasoningBudget: 32 }), false);
+ assert.equal(matches({
+ reasoning_budget_message: "Conclude now.",
+ requested_reasoning_budget_message: "",
+ }, { ...BLANK, reasoningBudgetMessage: "Conclude now." }), false);
+});
+
+test("an explicit zero reasoning request can reuse the resident", () => {
+ assert.equal(matches({
+ reasoning_budget: 0,
+ requested_reasoning_budget: 0,
+ }, { ...BLANK, reasoningBudget: 0 }), true);
+});
+
+test("legacy status without reasoning request echoes keeps its comparison", () => {
+ assert.equal(matches({
+ reasoning_budget: 32,
+ reasoning_budget_message: "Conclude now.",
+ }, { ...BLANK, reasoningBudget: 32, reasoningBudgetMessage: "Conclude now." }), true);
+});
diff --git a/studio/frontend/tests/resident-remembered-config.test.ts b/studio/frontend/tests/resident-remembered-config.test.ts
index 7a80d42b053..cc45787b57d 100644
--- a/studio/frontend/tests/resident-remembered-config.test.ts
+++ b/studio/frontend/tests/resident-remembered-config.test.ts
@@ -36,6 +36,8 @@ function config(nParallel: number | null, maxSeqLength: number | null = null) {
speculativeType: null,
specDraftNMax: null,
nParallel,
+ reasoningBudget: -1,
+ reasoningBudgetMessage: "",
nBatch: null,
nUbatch: null,
tensorParallel: false,
diff --git a/studio/frontend/tests/saved-reasoning-settings-summary.test.ts b/studio/frontend/tests/saved-reasoning-settings-summary.test.ts
new file mode 100644
index 00000000000..7faa501d7fe
--- /dev/null
+++ b/studio/frontend/tests/saved-reasoning-settings-summary.test.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { stripTypeScriptTypes } from "node:module";
+import test from "node:test";
+import type { ApiModelOverride } from "../src/features/model-picker/api/model-overrides.ts";
+import { readSrc } from "./helpers/kit.ts";
+
+const source = readSrc(
+ "features/api-monitor/components/saved-model-settings.tsx",
+);
+const describeOverride = new Function(
+ `${stripTypeScriptTypes(source.slice(source.indexOf("function plural("), source.indexOf("export function SavedModelSettingsPanel")))}\nreturn describeOverride;`,
+)() as (override: ApiModelOverride) => string[];
+
+for (const budget of [0, 32]) {
+ test(`saved reasoning budget ${budget} is visible in the API load summary`, () => {
+ assert.ok(
+ describeOverride({ reasoning_budget: budget }).includes(
+ `reasoning budget ${budget}`,
+ ),
+ );
+ });
+}
+
+test("a saved budget message alone does not appear as app defaults", () => {
+ assert.ok(
+ describeOverride({
+ reasoning_budget_message: " Conclude now. ",
+ }).includes("custom reasoning budget message"),
+ );
+});
+
+test("absent reasoning overrides leave the default summary unchanged", () => {
+ assert.deepEqual(describeOverride({}), []);
+});
diff --git a/studio/frontend/tests/server-tuning-settings.test.ts b/studio/frontend/tests/server-tuning-settings.test.ts
index d81443de8a1..127ec617676 100644
--- a/studio/frontend/tests/server-tuning-settings.test.ts
+++ b/studio/frontend/tests/server-tuning-settings.test.ts
@@ -113,9 +113,14 @@ test("a record only claims the new schema version when it carries one", () => {
// toStoredConfig stamps the OLDEST version that understands every field
// present, so an older client can still rewrite a record it fully knows.
const source = readSrc("features/model-picker/model-config/per-model-config.ts");
- assert.match(source, /const STORAGE_SCHEMA_VERSION = 5;/);
+ assert.match(source, /const STORAGE_SCHEMA_VERSION = 6;/);
+ assert.match(source, /const PRE_REASONING_BUDGET_SCHEMA_VERSION = 5;/);
assert.match(source, /const PRE_SERVER_TUNING_SCHEMA_VERSION = 4;/);
- assert.match(source, /hasServerTuning\s*\n?\s*\?\s*STORAGE_SCHEMA_VERSION/);
+ assert.match(source, /hasReasoningBudget\)\s*\{\s*return STORAGE_SCHEMA_VERSION;/);
+ assert.match(
+ source,
+ /hasServerTuning\)\s*\{\s*return PRE_REASONING_BUDGET_SCHEMA_VERSION;/,
+ );
});
test("blank knobs are omitted from the load payload", () => {
diff --git a/tests/studio/test_chat_preset_load_config.py b/tests/studio/test_chat_preset_load_config.py
index 42e5955511c..e4ad526bd91 100644
--- a/tests/studio/test_chat_preset_load_config.py
+++ b/tests/studio/test_chat_preset_load_config.py
@@ -86,6 +86,75 @@ def test_preset_load_config_carries_parallel_slots():
)
+def test_preset_load_config_carries_reasoning_budget():
+ source = _read("studio/frontend/src/features/chat/presets/preset-load-config.ts")
+ assert '| "reasoningBudget"' in source
+ assert '| "reasoningBudgetMessage"' in source
+ assert "reasoningBudget: capturesReasoning ? snapshot.reasoningBudget : -1" in source
+ assert "? snapshot.reasoningBudgetMessage" in source
+ routes = _read("studio/backend/routes/chat_history.py")
+ # NotABoolean: bool subclasses int, so a lax parse would take `true` for a budget of 1.
+ assert "reasoningBudget: NotABoolean" in routes
+ assert "reasoningBudgetMessage: Optional[str]" in routes
+
+
+def test_diffusion_suppresses_reasoning_without_dropping_gguf_context():
+ """loadedIsDiffusion gates the reasoning fields only, never the GGUF test.
+
+ A loaded DiffusionGemma reports is_gguf and is_diffusion, so folding the
+ diffusion check into isGguf made effectiveContextLength fall back to null and
+ stopped capturing store.ggufContextLength. On auto sizing that is the whole
+ load config, so the preset saved none at all.
+ """
+ source = _read("studio/frontend/src/features/chat/presets/preset-load-config.ts")
+ capture = source[source.index("export function capturePresetLoadConfig") :]
+ capture = capture[: capture.index("\n}")]
+ gguf_test = capture[capture.index("const isGguf") : capture.index("const capturesReasoning")]
+ assert (
+ "loadedIsDiffusion" not in gguf_test
+ ), "a diffusion GGUF is still a GGUF; its resolved context has to capture"
+ assert "const capturesReasoning = isGguf && !store.loadedIsDiffusion" in capture
+
+
+def test_preset_summary_marks_a_budget_message():
+ """hasPresetLoadConfig() counts the message, so the summary has to as well.
+
+ perModelConfigsEqual compares reasoningBudgetMessage, so a preset that sets only
+ the message is non-default and does change llama-server behaviour. With no part
+ for it the formatter returned null, and the sheet hides both "Active now" and
+ "Saved in preset" on null. A marker, never the text: it can reach 8 KiB.
+ """
+ source = _read("studio/frontend/src/features/chat/presets/preset-load-config.ts")
+ body = source[source.index("export function formatPresetLoadConfigSummary") :]
+ body = body[: body.index("\n}")]
+ assert "config.reasoningBudgetMessage" in body, (
+ "a message-only preset summarises to null, so the Preset section shows no "
+ "load settings at all for a config that is not default"
+ )
+ assert (
+ "${config.reasoningBudgetMessage}" not in body
+ ), "the message is free prose up to 8 KiB; the summary takes a marker only"
+
+
+def test_preset_sheet_reacts_to_a_reasoning_budget_change():
+ """capturePresetLoadConfig() reads the runtime store through getState().
+
+ A captured field the sheet neither subscribes to nor lists as a memo dependency
+ cannot move the Update button or the summary: with the sheet open, changing only
+ the reasoning budget left both stale until some unrelated setting changed.
+ """
+ sheet = _read("studio/frontend/src/features/chat/chat-settings-sheet.tsx")
+ for field in ("reasoningBudget", "reasoningBudgetMessage"):
+ assert f"(s) => s.{field}" in sheet, (
+ f"the preset sheet never subscribes to {field}, so a change to it "
+ "does not re-render the component whose memos capture it"
+ )
+ # Both memos: hasUnsavedPresetChanges (dirty state) and currentLoadSummary.
+ assert (
+ sheet.count(f"\n {field},\n") + sheet.count(f"\n {field},\n") == 2
+ ), f"{field} is missing from a capturePresetLoadConfig() memo dependency list"
+
+
def test_a_preset_records_a_self_sizing_load_s_pin_and_not_its_window():
"""A preset must reproduce the setup that ran. A window nobody pinned is reached again
on replay, so only the pin is stored -- in the one field that means "pinned"."""
diff --git a/tests/studio/test_model_picker_contracts.py b/tests/studio/test_model_picker_contracts.py
index 77d53fc74d3..d6e63bd515a 100644
--- a/tests/studio/test_model_picker_contracts.py
+++ b/tests/studio/test_model_picker_contracts.py
@@ -2745,6 +2745,86 @@ def test_evicted_local_configs_drop_their_server_overrides():
assert "modelIdFromStorageKey(" in store and "ggufVariantFromStorageKey(" in store
+def test_reasoning_resets_reach_the_server_without_making_backfill_destructive():
+ api = " ".join(_read("features/model-picker/api/model-overrides.ts").split())
+ assert "options?.resetReasoningBudget && config?.reasoningBudget === -1" in api
+ assert "reasoning_budget: -1" in api
+ assert 'options?.resetReasoningBudgetMessage && config?.reasoningBudgetMessage === ""' in api
+ assert 'reasoning_budget_message: ""' in api
+
+ route = _read_backend("routes/settings.py")
+ assert "fields_set = payload.model_fields_set" in route
+ assert '"reasoning_budget" in fields_set and payload.reasoning_budget == -1' in route
+ assert (
+ '"reasoning_budget_message" in fields_set and payload.reasoning_budget_message == ""'
+ in route
+ )
+ assert "if not payload.fill_absent_fields and requested_extra_args:" in route
+
+ page = _read("features/model-picker/components/model-config-page.tsx")
+ assert "baseline.reasoningBudget !== -1" in page
+ assert "normalizedRuntimeConfig.reasoningBudget === -1" in page
+ assert 'baseline.reasoningBudgetMessage !== ""' in page
+ assert 'normalizedRuntimeConfig.reasoningBudgetMessage === ""' in page
+
+
+def test_a_recipe_restores_the_previous_model_at_its_reasoning_budget():
+ """Captured from /status beside the context request and replayed the same way; a recipe's
+ own target carries neither and runs at the defaults."""
+ src = _read("features/recipe-studio/hooks/use-recipe-executions.ts")
+ assert src.count("reasoningBudget: status.requested_reasoning_budget ?? -1,") == 2, src
+ assert (
+ src.count('reasoningBudgetMessage: status.requested_reasoning_budget_message ?? "",') == 2
+ ), src
+ assert "reasoning_budget: reasoningBudget ?? -1," in src
+ assert 'reasoning_budget_message: reasoningBudgetMessage ?? "",' in src
+ assert "(left.reasoningBudget ?? -1) === (right.reasoningBudget ?? -1)" in src
+
+ api = " ".join(_read("features/model-picker/api/model-overrides.ts").split())
+ assert "mirrors_reasoning_budget: true," in api
+
+
+def test_reasoning_settings_hydrate_from_a_server_authored_override():
+ """A row written by another browser or an API client carries the pair, and fromApiOverride has
+ to copy it or the panel shows local defaults and the next save writes them back."""
+ api = _read("features/model-picker/api/model-overrides.ts")
+ hydrate = api.split("export function fromApiOverride", 1)[1]
+ hydrate = hydrate[: hydrate.index("\n}")]
+ assert "reasoningBudget: override.reasoning_budget ?? local.reasoningBudget" in hydrate
+ assert "override.reasoning_budget_message ?? local.reasoningBudgetMessage" in hydrate
+
+
+def test_a_recipe_compares_the_requested_reasoning_budget():
+ """Requested, never effective: the effective pair folds in LLAMA_ARG_THINK_BUDGET*, which no
+ request can express, so comparing it would reload the weights on every run forever."""
+ src = _read("features/recipe-studio/hooks/use-recipe-executions.ts")
+ reuse = src.split("async function isLocalModelAlreadyLoaded", 1)[1]
+ reuse = reuse[: reuse.index("\n}")]
+ assert "status.requested_reasoning_budget" in reuse
+ assert (
+ "status.reasoning_budget" not in reuse
+ ), "the reuse check must compare the request, never the environment-resolved value"
+
+
+def test_validate_sends_reasoning_controls_before_the_runtime_unloads():
+ api = _read("features/chat/api/chat-api.ts")
+ validate_body = api.split("export async function validateModel", 1)[1].split(
+ "export async function", 1
+ )[0]
+ assert "reasoning_budget: payload.reasoning_budget ?? -1" in validate_body
+ assert 'reasoning_budget_message: payload.reasoning_budget_message ?? ""' in validate_body
+
+ runtime = _read("features/chat/hooks/use-chat-model-runtime.ts")
+ validation = runtime.index("const validation = await validateModel({")
+ unload = runtime.index("await unloadModel(", validation)
+ assert validation < unload
+ validate_payload = runtime[validation:unload]
+ assert "reasoning_budget:" in validate_payload
+ assert "validateReasoningBudget" in validate_payload
+ assert "reasoning_budget_message:" in validate_payload
+ assert "validateReasoningBudgetMessage" in validate_payload
+
+
def test_backfill_compares_server_keys_by_normalized_identity():
"""app_settings has no schema version, so an install predating identity normalization
holds rows keyed by whatever id was typed, e.g."""