Skip to content

Studio: size a Deep Research run to the model it actually runs on - #10220

Merged
oobabooga merged 4 commits into
unslothai:mainfrom
NilayYadav:fix-research-context-external-provider
Sep 4, 2026
Merged

oobabooga merged 4 commits into
unslothai:mainfrom
NilayYadav:fix-research-context-external-provider

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Deep Research checks the local model to decide how much text it can send, even when the run is pointed at a saved cloud connection. With a 4096 token model loaded, a cloud run got a 6144 character prompt budget and about 2000 output tokens instead of the 16384 it asked for. Unload the local model and the same run behaves differently.

The local check is now skipped when the run carries a providerType. Tested on a running server with a real saved connection: the outgoing request carried max_output_tokens 3595 before and 4096 after.

@NilayYadav
NilayYadav force-pushed the fix-research-context-external-provider branch from 54f64a0 to 8807605 Compare September 2, 2026 20:11
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

Focus on studio/backend/core/research_runs.py. The change makes Deep Research skip the local model's context probe when the run carries a providerType, i.e. when it executes on a saved connection rather than on the loaded local model, and threads that run's inferenceRequest down every budgeting helper.

Worth the most scrutiny:

  • whether any call path still reaches _loaded_context_length without the run's inference dict, so the run is half-sized;
  • whether a genuinely local run can ever carry a providerType and so lose clamping it needs;
  • the _synthesis_length_limit_error wording now that an external run never takes the context-wall branch.

Please keep reviewing across rounds until you have no remaining findings — I will fix and re-trigger rather than stopping at the first pass.

@NilayYadav

NilayYadav commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

GitHub Actions A/B reproduction

Two branches on a disposable fork, both built from this PR's merge-base
(c9f98dbd5e3ff4b620067cfbcf28fc29311f6396). Same runner, same install, and the same
probe file byte-for-byte
— md5 db4df1dba0ef742124eeb7b6d91d78b2, printed in both logs.
The only difference is whether this PR is applied.

The probe loads a 4096-token local GGUF, then drives a run whose inferenceRequest
carries providerType, i.e. a saved cloud connection.

observed value main (fix absent) this PR
cloud run, max_output_tokens 2092 16384
local run, max_output_tokens 2092 2092
cloud run, truncation notice "Local model report hit the loaded context window before completion. Increase Context Length in chat settings or reduce the research evidence size." "Connected model report reached its output limit before completion"
local run, truncation notice "Local model report hit the loaded context window…" "Local model report hit the loaded context window…"
result 2 failed, 2 passed 4 passed

Rows 2 and 4 are the guards: a genuinely local run is still clamped to the loaded context
and still pointed at Context Length, on both branches. So the change removes the local
probe only for runs that do not execute locally.

The second defect — a cloud run that stopped at its provider's own output cap still being
told to raise a local Context Length setting — was found while reviewing this PR and fixed
in 0a8ac8eca; the last two rows are its before/after.

The two red upstream checks — Repo tests (CPU) and workflow-trigger lint — both fail on
the same assertion, tests/security/test_scan_packages.py::test_context_dependent_unsloth_zoo_findings_are_digest_pinned
(an unsloth_zoo digest that has drifted). Both are red the same way on unrelated open PRs
#10221 and #10225 and on main at this PR's merge-base, and this PR touches only
studio/backend/core/research_runs.py and its tests, so neither is caused by this change.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0a8ac8ecaf

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Before/after UI evidence

Two isolated Studio installs, merge base c9f98dbd5 vs head 0a8ac8eca, Chromium at
1280×1000. The run is driven end to end through the real ResearchSupervisor against a
saved custom connection served from the scene process — so it is a genuine external
run (providerType set) with no weights, GPU, download or network. The stand-in reports
8192 completion tokens against the 16384 synthesis asked for, which is what a provider
that stopped at its own output cap reports.

PR 10220 truncation notice before/after

BEFORE — a cloud run is blamed on a local model, and the reader is sent to a setting
that does not affect the connection the run used:

Incomplete report. Local model report hit the loaded context window before
completion. Increase Context Length in chat settings or reduce the research evidence size.

AFTER — the notice names what actually capped the run:

Incomplete report. Connected model report reached its output limit before completion.

Facts that moved, from meta.json:

fact before after
notice_blames_local_context true false
notice_names_a_local_model true false
report_chars 825 745

model_phases is identical on both sides — planning, decision, synthesis_audit, synthesis, synthesis_recovery — and run_status is completed on both, so the two
Studios did the same work and only the notice differs. report_chars moves only because
the new notice is shorter.

Two honest limits: this scene loads no local model, so synthesis max_tokens is 16384 on
both sides and it isolates the wording half of the PR — the sizing half is the Actions
A/B above. And the three source pills under the report differ between the sides because
the single research step's search results are not pinned; that is incidental and outside
the claim.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits research_runs.py where _loaded_context_length() is consulted at the budgeting and clamping sites even when the run carries a providerType, so a saved-connection run gets sized to whatever GGUF happens to be loaded. Will get this reviewed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 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-03T19:09:52.168666Z 468ca48 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.

@oobabooga

Copy link
Copy Markdown
Member

Reproduced this myself on both sides, with the llama.cpp backend pinned to a 4096 token context and a run whose inferenceRequest carries providerType:

merge base ec77cf62b head 468ca4810
cloud run max_tokens 2759 16384
local run max_tokens 2759 2759
_prompt_char_budget, cloud run 6144 None (full cap)
truncation notice, cloud run "Local model report hit the loaded context window before completion. Increase Context Length in chat settings" "Connected model report reached its output limit before completion"

The local row not moving is the part that matters: only runs that do not execute on the loaded model lose the probe.

I swept every consumer of _loaded_context_length. All four production paths that reach it now carry the run's inferenceRequest: _clamp_max_tokens_for_context via _resolve_max_tokens, _prompt_char_budget at the planning, decision and synthesis budgets, _completion_hit_context_wall via _synthesis_length_limit_error, and the auto-scrape context floor. _stream_completion already builds the same dict for the outgoing payload, so the sizing site and the routing site read one source. _local_model_ready is the only other local probe left and it fires reactively on a "no model loaded" refusal, which an external-provider request does not take.

On whether a genuinely local run can carry a providerType and lose clamping it needs: _sanitize_config overwrites the client's value with the saved row's provider_type and requires an enabled saved connection, so the field is only ever set for a run routed at that connection. A self-hosted connection stored under the backend openai type is still a separate server rather than the model Studio has loaded, so skipping the probe is right there too.

test_research_runs_hardening.py, test_research_runs_storage.py and test_warm_window_review_fixes.py pass locally, along with the 423 research tests in the backend suite.

30 of the 32 non-skipped checks are green here. The other two, startup macos-15 and Chat UI, API, Update and GGUF inference, have sat queued without a runner for over an hour. I ran this branch against current main on a mirror and both of those workflows passed there, together with the rest of the set on Linux, Windows and macOS.

oobabooga pushed a commit to oobabooga/unsloth that referenced this pull request Sep 3, 2026
@oobabooga

Copy link
Copy Markdown
Member

Thanks @NilayYadav. Deep Research was sizing a run to whatever model happened to be loaded locally, even when the run was pointed at a saved connection and never touched that model.

I reproduced it with a 4096 token GGUF loaded and the run pointed at a saved connection. On the merge base the report call was capped at about 2268 output tokens instead of the 16384 it asked for. The truncation notice also told the reader to raise a local Context Length setting that connection does not use. At head the same run gets its full budget, and the notice names the connected model.

Runs on the local model are unchanged across every backend shape I exercised, including the MLX path. Older runs saved without an inferenceRequest resume the same as before.

@oobabooga
oobabooga merged commit f24334a into unslothai:main Sep 4, 2026
34 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.

3 participants