Fix Studio safetensors tool reprompt reasoning leakage#7134
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the _reprompt_intent_text helper function to extract visible text from assistant responses containing <think> or [THINK] reasoning blocks. This ensures that the plan-without-action classifier evaluates only the visible content when present, preventing unnecessary re-prompts when a visible answer is already provided alongside reasoning. Unit tests have been added to verify this behavior. There are no review comments, so no additional feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR adjusts Studio’s safetensors tool-loop “plan-without-action” re-prompt heuristic to ignore intent phrases that appear only inside private reasoning spans, preventing unintended re-prompts and resulting reasoning/content leakage into persisted assistant messages.
Changes:
- Add
_reprompt_intent_text()to classify intent using visible answer text (falling back to reasoning only when no visible text exists). - Update the safetensors re-prompt gate to use the classified intent text.
- Add regression tests covering “reasoning intent + visible answer” and “reasoning-only intent still reprompts and uses a tool”.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| studio/backend/core/inference/safetensors_agentic.py | Introduces visible-vs-reasoning intent extraction and uses it in the safetensors re-prompt gate. |
| studio/backend/tests/test_safetensors_tool_loop.py | Adds tests to prevent reprompt-trigger leakage when visible answer text is present and to preserve reprompt behavior for reasoning-only stalls. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a19ee10 to
6939f05
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6939f0504e
ℹ️ 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".
6939f05 to
152569d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 152569dfdd
ℹ️ 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".
152569d to
38b6572
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38b65727e2
ℹ️ 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".
38b6572 to
85598ca
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 85598ca0c4
ℹ️ 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".
85598ca to
9c5e369
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Looks right overall, and One edge case to harden before merge: with |
…s-tool-attempts # Conflicts: # studio/backend/core/inference/orchestrator.py # studio/backend/core/inference/safetensors_agentic.py
|
This edge case is already handled now: when The regression test covering this is
So the later private think block is stripped and does not trigger a reprompt. |
Confirmed on latest head: this now handles the close-then-later- |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Fixes #7122
Summary
This updates the Studio safetensors tool loop so the plan-without-action reprompt heuristic classifies visible answer text when a response contains both reasoning and answer content. If the model emits only reasoning, the loop still falls back to that reasoning text so stalled tool-use attempts can be nudged as before.
The regression coverage adds cases for explicit reasoning spans, prefilled reasoning before a generated
</think>close marker, re-emitted explicit<think>...</think>spans before visible text, later generated think blocks after a prefilled close, reasoning-only prefilled stalls with and without a close marker, reasoning-only tool-use stalls, and re-prompt history matching the same text surface used by the classifier.Root Cause
Safetensors reasoning and answer text share the cumulative text stream. The reprompt heuristic was evaluating the raw accumulated text, so a phrase such as
Let me ...inside private reasoning could be treated as a visible plan to call a tool even when the model had already produced a normal visible answer. For safetensors templates that prefill an opening<think>, the tool-loop classifier also needs the same prefilled-mode boundary as the route reasoning extractor: text before the first generated close marker is private reasoning, and later generated<think>...</think>blocks remain private reasoning.Validation