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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Stop Codex cancelling its own first turn while llama-server reads the prompt (#9403)
Daniel Hanc8e5ef1bcda1
diff --git a/.github/workflows/local-agent-guides-ci.yml b/.github/workflows/local-agent-guides-ci.ymlindex e36f67a038c..a331bc0a6ea 100644--- a/.github/workflows/local-agent-guides-ci.yml+++ b/.github/workflows/local-agent-guides-ci.yml@@ -123,7 +123,16 @@ env:# prefill-shrinking flags (minimal system prompt + restricted tools) a turn on# a 4B model finishes in a couple of minutes on CPU; this also caps how long a# still-large-prompt agent burns before failing. Well under the 6h job cap.- AGENT_INVOKE_TIMEOUT: '600'+ #+ # Raised from 600. Those flags shrink what the SERVER puts in front of the model;+ # they do not touch a preamble the client assembles for itself, and Codex's is+ # several thousand tokens before the prompt is appended. Measured on this image at+ # 16.1 tok/s, that is ~460s of prompt processing to answer "pong" -- inside 600s on+ # paper, but only just, and the leg that has to survive it is the one that was+ # failing 88% of the time. The cap exists to stop a hang, not to enforce a+ # performance budget, so it is sized off the slowest legitimate turn rather than+ # the fastest. It only ever costs wall-clock on a run that was going to fail.+ AGENT_INVOKE_TIMEOUT: '1200'jobs:# ═════════════════════════════════════════════════════════════════════diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex a4321a532d4..d3441ef0bba 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -48,6 +48,25 @@ start_app = typer.Typer(_CODEX_PROFILE = "unsloth_api"_CODEX_ENV_KEY = "UNSLOTH_STUDIO_AUTH_TOKEN"+# Codex treats an SSE stream with no bytes for this long as lost, cancels it, and+# reconnects. Its default is 300000 (5 minutes), which is measured against the WHOLE+# quiet period -- and llama-server sends nothing at all while it processes the prompt.+#+# That is not a corner case on the hardware Unsloth is for. A local CPU host chews+# through a prompt at low tens of tokens a second, and Codex's own preamble is several+# thousand tokens before the user has typed anything: 16.1 tok/s measured on a 2-core+# box means ~460s of silence for a ~7300-token first turn, so the default trips before+# the first token exists. The reconnect is worse than the wait, because llama-server+# hands the retry a different parallel slot whose KV cache shares no prefix, so each+# attempt restarts prompt processing from zero and the five retries can never converge.+# Observed as a request completing in exactly 300056ms with `Reconnecting... 1/5` and+# no turn ever finishing.+#+# 20 minutes. Sized to be longer than a slow local first turn rather than to any+# server-side budget: nothing here bounds generation, and a genuinely dead stream is+# still caught, just later. Same reason the Codex docs' own local-model example raises+# it for Ollama.+_CODEX_STREAM_IDLE_TIMEOUT_MS = 1_200_000_HERMES_ENV_KEY = "UNSLOTH_API_KEY"_HERMES_PROVIDER = "unsloth"# Skip the installer's interactive setup wizard: `unsloth start hermes` runs@@ -2475,6 +2494,7 @@ def _merge_codex_config(existing: str, base: str) -> str:f'env_key = "{_CODEX_ENV_KEY}"\n''wire_api = "responses"\n'"requires_openai_auth = false\n"+ f"stream_idle_timeout_ms = {_CODEX_STREAM_IDLE_TIMEOUT_MS}\n")diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.pyindex 79ddb2eb7ad..2ac255de662 100644--- a/unsloth_cli/tests/test_start.py+++ b/unsloth_cli/tests/test_start.py@@ -833,6 +833,32 @@ def test_merge_codex_config_fresh():assert provider["requires_openai_auth"] is False+def test_merge_codex_config_raises_the_stream_idle_timeout():+ """Codex's 300s default cancels the stream while llama-server is still reading.++ llama-server emits nothing at all during prompt processing, so the whole wait counts+ as idle. Measured on a 2-core CI host: 16.1 tok/s against Codex's several-thousand+ token preamble is ~460s of silence before the first token exists, and the default+ trips at 300s. The reconnect then lands on a different parallel slot whose KV cache+ shares no prefix, so every retry restarts from zero and the turn never completes --+ a job hung for its full 600s cap with `Reconnecting... 1/5` and one request logged at+ exactly 300056ms.++ Asserted as a floor rather than an equality: raising it further is fine, and the+ number is not the contract. Losing it entirely is the regression.+ """+ provider = _parse_toml(start._merge_codex_config("", BASE))["model_providers"]["unsloth_api"]+ assert "stream_idle_timeout_ms" in provider, (+ "the Codex provider block no longer sets stream_idle_timeout_ms, so Codex falls "+ "back to its 300s default and cancels any first turn whose prompt takes longer "+ "than that to process -- which is an ordinary local CPU host, not a corner case"+ )+ assert provider["stream_idle_timeout_ms"] > 300_000, (+ f"stream_idle_timeout_ms is {provider['stream_idle_timeout_ms']}, at or below "+ f"Codex's own 300000 default, so setting it changes nothing"+ )++def test_merge_codex_config_replaces_stale_block():existing = ('model = "gpt-5"\n'