Skip to content

Studio: keep a still-advancing llama.cpp prefill from timing out - #10172

Merged
oobabooga merged 4 commits into
unslothai:mainfrom
oobabooga:prefill-progress-watchdog
Sep 3, 2026
Merged

oobabooga merged 4 commits into
unslothai:mainfrom
oobabooga:prefill-progress-watchdog

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Addresses the 20-minute cancellation reported on Reddit, in #9037, and again here. Related reports: #5756 and bug 3 of #5130.

Problem

_DEFAULT_FIRST_TOKEN_TIMEOUT_S counts 1200 seconds from when the request starts. _iter_text_cancellable stops that clock only when an SSE event carries generated output. llama-server's prefill progress events do not count, so prompt processing never resets the deadline.

A prompt that takes longer than 20 minutes to prefill is therefore cancelled even though the server is healthy and still advancing. From the reporter's log, at 93% and climbing:

task 5331 | prompt processing, n_tokens = 152589, progress = 0.93, t = 1184.24 s / 128.85 tok/s
srv stop: cancel task, id_task = 5331
slot release: id 0 | task 5331 | stop processing: n_tokens = 154065, truncated = 0

The user loses the whole prefill and gets a message advising them to shrink the model. No UI setting affects the module constant. #5841 already raised it from 120 seconds, but long active prefills can still hit the new ceiling.

Fix

Studio now requests return_progress on all three chat streams instead of only when a perf callback is attached. timings_per_token stays opt-in, and older servers ignore the progress field.

_iter_text_cancellable renews first_token_deadline whenever prompt_progress.processed increases. The constant is unchanged: 1200 seconds now means 20 minutes without progress instead of 20 minutes total. Silence and repeated progress values still time out.

The JSON decode shared by both readers moved into _sse_event_payload, so each event is parsed once.

Verification

tools/server/server-context.cpp emits an initial event and one progress event per prompt batch. llama.cpp's test_return_progress asserts that processed strictly increases per batch, so the watchdog relies on an upstream contract.

With the bundled llama-server, a 351-token prompt at -b 32 produced 12 events from 0 through 351. All parsed as increasing prefill progress without being misclassified as generated output. A warm-cache repeat correctly produced two events, processed == cache == 341 then 342.

At the default 2048 batch, prefill has to fall under roughly 2 tok/s before the window can still trip. The reported case was running at about 130 tok/s, an event roughly every 16 seconds.

Tests:

  • Three added to test_llama_cpp_stall_timeout.py: advancing progress survives 4000 seconds of fake time, a repeated processed value still times out, and content-free events with no progress field still time out. The first fails on the parent commit with the same ReadTimeout this PR removes.
  • 224 passed across the llama.cpp streaming, tool-loop, continuation, secure-tools and cursor-reset suites, plus 25 in the passthrough suite.
  • Three fail only when the stall-timeout test's existing empty structlog stub shares their process; running those files separately gives 151 passed.

Scope

This stops the cancellation. It does not make the prefill faster, and it does not touch the cache invalidation in #9037 that forces the full re-prefill in the first place, so that issue should stay open. Users will still wait, but Studio now lets the wait finish.

A server that advances indefinitely is now held open instead of cancelled. That is the deliberate trade in treating progress as liveness, and Stop still works.

Builds without prompt_progress keep the fixed cutoff. The passthrough path in routes/inference.py already disarms its deadline on any received item, so unifying the two paths is separate work. The timeout also remains non-configurable, as originally requested in #5756.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-03T17:34:25.371039Z 919a080 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed main only sets return_progress when a perf callback is attached, so prompt_progress events never renew the first-token deadline in _iter_text_cancellable, and an advancing prefill past 1200s still gets cancelled. Will get this reviewed.

@oobabooga

oobabooga commented Sep 3, 2026 •

Copy link
Copy Markdown
Member Author

A prompt that takes more than 20 minutes to prefill is no longer cancelled while the server is still working on it. The deadline now resets each time llama.cpp reports more prompt tokens processed, so 1200 seconds means 20 minutes without progress rather than 20 minutes total, and it still fires on a server that has gone silent or is replaying the same progress value. I checked both against a real llama-server: with the previous payload the request times out at the deadline, with this one the prefill completes.

Nothing else about the reply changes. Output is identical with and without return_progress, both on the wire and through the two chat generators, and the backend suite matched a control branch on Linux, Windows, macOS and WSL. The deliberate trade is that a server which keeps reporting progress is now held open rather than cancelled, and Stop is what ends it.

Two limits to be aware of. The passthrough path in routes/inference.py still has the flat cutoff, as the description says, and I did not exercise the diffusion shim, which receives the new request field but never emits progress.

@oobabooga
oobabooga merged commit 4e64d17 into unslothai:main Sep 3, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants