Skip to content

Studio: let Deep Research wait out a long prompt eval instead of failing at 120s - #17934

Merged
danielhanchen merged 1 commit into
mainfrom
fix-research-prefill-17907
Nov 16, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-research-prefill-17907

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #17907

Problem

Deep Research gives every local model call 120 seconds to produce its first token. Studio's /v1/chat/completions already reports a long prompt eval to clients that did not ask for raw progress: while llama-server's prompt processing advances, it sends a : prefill-progress SSE comment, and stays silent (or sends a plain : keep-alive) when it is stalled. Chat generation runs treat that comment as liveness. Deep Research ignored it, so a decision call whose prompt (earlier steps' results plus notes) takes over two minutes to evaluate failed with Local model never started producing output, even though llama-server was working the whole time.

This matches the report: planning and three steps succeed, then a later "Choosing the next step" call fails exactly 120 seconds in, on a 26B MoE GGUF spilled to system RAM on a 6 GB laptop GPU. The decision prompt grows with every step, and the step counter, query history and research state sit before the gathered evidence, so the evidence is re-evaluated in full on every call.

Change

Before the first token, a : prefill-progress comment restarts the first-output budget, as : admission-done already does. Nothing else changes:

  • a stalled prefill sends no progress comments, so the 120 second guard still fires;
  • once output has started, the comment is ignored and the idle guard applies as before;
  • a finite run time limit still caps the call;
  • external providers never send this comment.

Tests

studio/backend/tests/test_research_runs_hardening.py:

  • test_prefill_progress_renews_the_first_output_budget: fails on main (ModelFirstOutputTimeout), passes here.
  • test_prefill_progress_after_output_does_not_reset_the_idle_guard: the idle guard still fires after output starts.
  • test_prefill_progress_marker_matches_the_inference_route: pins the comment text to the constant the inference route sends.

tests/test_research_runs*.py + tests/test_chat_generation_lease_compat.py: 530 passed.

End to end on a real Studio (GGUF-only install, llama-server on CPU, Qwen3-1.7B Q4_K_M, 128-token prompt batches, first-output budget lowered to 60 seconds so a CPU prefill outlasts it):

Arm First-output budget Prompt batch Prompt eval of the planning call Outcome
main 60 s 128 ~400 s (progress every ~12 s) failed at 63 s: Local model never started producing output
this PR 60 s 128 ~400 s (progress every ~12 s) still planning; streamed the plan title at 679 s and the first step at 994 s (cancelled by the harness at 1500 s, decode on a loaded host)
main 10 s 2048 ~107 s failed at 12 s, same error

The probe stream from the same server shows what a research call receives during that prefill: : prefill-progress comments while llama-server advances, : keep-alive between them, no data: until the first token.

Limit: llama-server reports progress once per prompt batch (2048 tokens by default, and for MoE expert spill), so a machine evaluating under ~17 tokens/second could still spend over 120 seconds inside one batch. A partially offloaded MoE on a discrete GPU runs far faster than that.

@danielhanchen danielhanchen self-assigned this Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T07:44:02.283066Z 609f2c8 Manual request
ℹ️ 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 Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 609f2c8541

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Nov 16, 2026
…apper above it (rest shard red on main) (#17952)

## Summary

`Repo tests (CPU, rest)` fails on current main (seen on #17921, #17934
and the staging run of #17904) in:

```
tests/test_flex_mask_graph_breaks.py::test_compiled_flex_mask_has_no_graph_breaks_and_matches_eager
E   torch._dynamo.exc.Unsupported: Data-dependent branching
E     File ".../unsloth_zoo/temporary_patches/misc.py", line 1318, in flex_attention_mask
E       return original(*bound.args, **bound.kwargs)
E     File ".../unsloth/import_fixes.py", line 2471, in flex_attention_mask
E       return original(*args, **kwargs)
E     File ".../transformers/masking_utils.py", line 685, in flex_attention_mask
E       if attention_mask is not None and not fast_all(attention_mask):
```

It started with unslothai/unsloth-zoo#2551 (the test passes with zoo at
its parent and fails at it). That PR wraps the registered
`flex_attention` mask builder to keep the padding `mask_mod` during
training, and forwards every call as `original(*bound.args,
**bound.kwargs)`, i.e. by position. The wrapper it sits on is Unsloth's
`fix_transformers_flex_mask_graph_breaks` patch, which only handled
keyword calls: with any positional argument it called transformers
directly, so while Dynamo traces the `fast_all(attention_mask)` branch
came back and `fullgraph` tracing broke.

Both patches are right on their own; the Unsloth one was fragile about
how it is called, so this hardens it rather than changing zoo.

## Change

- `unsloth/import_fixes.py`: the flex mask patch binds positional
arguments to the original's signature and continues with keywords (new
helper `_keyword_arguments`, which merges `**kwargs` parameters and
returns `None` for anything it cannot express as keywords; then the call
goes through unchanged, as before).
- `tests/test_flex_mask_graph_breaks.py`: new
`test_a_wrapper_forwarding_by_position_keeps_the_compiled_path`
registers a wrapper that forwards by position above the patch (as zoo's
does) and checks the `fullgraph` compile of a padded batch matches
eager. It does not depend on which zoo is installed.

## Testing

| unsloth | unsloth_zoo | `test_flex_mask_graph_breaks.py` |
|---|---|---|
| main | main | 1 failed (the CI failure) |
| this PR | main | 4 passed, 1 skipped |
| this PR | before #2551 | 4 passed, 1 skipped |
| main | before #2551 | 1 failed: the new positional-wrapper test |

CPU, torch 2.10, transformers 5.17 (the CI pins for this shard).
@danielhanchen
danielhanchen merged commit 1dc5912 into main Nov 16, 2026
@danielhanchen
danielhanchen deleted the fix-research-prefill-17907 branch November 16, 2026 10:38
danielhanchen added a commit that referenced this pull request Nov 16, 2026
…he gloo shard (2100 s cap) (#17969)

## Summary

`Repo tests (CPU, gloo)` is timing out again: the shard's pytest runs
under `timeout --signal=INT 2100` and recent runs were cut off there
with nothing failing:

| run | result |
|---|---|
| #17934 (upstream) | 257 passed, 3 skipped in 2089.55 s, exit 124 |
| staging run of #17904 | 258 passed, 3 skipped in 2095.11 s, exit 124 |
| staging run of #17957 | 251 passed, 1 failed in 2096.44 s, exit 124 |

For comparison the same shard ran 241 tests in 1292 s when #17892 merged
this morning. Since then #17886
(`test_tp_dpo_peft_ref_adapter_gloo.py`), #17930
(`test_cp_ulysses_media_towers_gloo.py`),
`test_cp_ulysses_dynamic_len_gloo.py` and the DeepSeek-V4.1 additions to
`test_parallel_deepseek_v41_gloo.py` landed in it, and a slower runner
now goes over the cap. Every one of those tests passes; the shard just
no longer fits.

## Change

- `.github/workflows/studio-backend-ci.yml`:
`tests/test_tp_[!n]*gloo*.py` (the non-native tensor parallel files:
`tp_env`, `tp_eval`, `tp_full_finetune`, `tp_replica`,
`tp_kv_replicated`, `tp_moe_dropout`, `tp_dpo_peft_ref_adapter`, ...; 12
files) moves out of `gloo` into a new `gloo-tp-env` shard. `gloo` keeps
its other three globs (19 files). Comment added with the numbers above.
- `tests/studio/test_backend_ci_parallel_isolation.py`: the command
scan's expected counts go from 15 parallel runs / 10 repo-root shards to
16 / 11, as its message asks when a shard is added.

## Why that split

Measured locally on main with the shard's exact command (`-n 4 --dist
loadgroup`): 275 passed in 1302.83 s. Of the 40 slowest tests (2815
worker-seconds), 2716 s are in `tests/test_tp_[!n]*gloo*.py`; out of
about 5200 worker-seconds in total, so these 12 files are well over half
of the shard. Each half now has room under the cap on a slower runner.

## Testing

- `tests/test_ci_repo_cpu_shards.py` (every repo test file collected by
exactly one shard, every glob matches a file): 15 passed.
- All 15 test files that read `studio-backend-ci.yml`: 341 passed, 3
skipped.
- The new shard's first run on this PR is the timing check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Deep Research Failed in Unsloth Desktop

1 participant