Skip to content

Studio: do not run Gemma tool call examples written inside code blocks - #11153

Merged
Lyxot merged 7 commits into
unslothai:mainfrom
NilayYadav:studio-gemma-fenced-tool-calls
Sep 17, 2026
Merged

Lyxot merged 7 commits into
unslothai:mainfrom
NilayYadav:studio-gemma-fenced-tool-calls

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

If you asked Gemma 4 to show the tool call syntax, it wrote call:web_search{...} inside a code block and Studio ran a real search. The example was also removed from the reply, leaving an empty code block.

A bare call inside a fenced block or inline code is now treated as text. It is not run, not picked up while streaming, and stays visible. Real tool calls with Gemma's own tokens are unchanged.

Tested with new unit tests and with Gemma 4 E4B in the chat UI: the code block stays and no search runs, while a normal search request still works.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 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-16T22:03:35.881282Z 0946729 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d81ecee61

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

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0946729625

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

Comment thread studio/backend/core/tool_healing.py Resolved
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 0946729625

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

Copy link
Copy Markdown
Member

Confirmed that on main the bare Gemma call:NAME{...} path in studio/backend/core/inference/tool_call_parser.py has no code-span gate, so an example inside a fence is executed and then stripped out of the reply, and the new gating plus the fence regex fix look right. The unrelated reformatting in studio/backend/main.py, test_bootstrap_banner_password_visibility.py and tests/studio/playwright_queue_localization.py makes this harder to read, could you drop those so the branch is just the parser change?

@Lyxot Lyxot self-assigned this Sep 17, 2026
…call arguments

A raw Gemma call body can contain a fence or backtick run, and the markdown code gate scanned it as prose, so the next bare call was treated as quoted: parsed as nothing and left visible. The parser and the display strip now rescan code spans from the end of a promoted call whenever a span runs out of its arguments, which keeps the common case linear.

Also covers tilde fences quoting backtick fences and vice versa, drops a no-op lookahead from the fence pattern, and tightens the related docstrings.
# Conflicts:
#	tests/studio/playwright_queue_localization.py
@Lyxot

Lyxot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Pushed a follow-up fix and merged the latest main.

Fix: a fence or backtick run inside a promoted Gemma call's own arguments was scanned as markdown code, so the next wrapper-less call in the same turn was treated as a quoted example: it did not run and stayed visible. For example, call:web_search{query:"intro\n```py\nprint(1)"} followed by a second call:web_search{...} parsed as one call instead of two. The parser and the display strip now rescan code spans past a promoted call's arguments, but only when a span runs out of them, so the usual path stays linear. The strip also rescans past a call that runs but stays visible mid-sentence, so parse and display agree on the call after it.

Also:

  • dropped a no-op (?!~) from the fence pattern;
  • added tests for tilde and backtick fences quoting each other, and for a code span opened inside call arguments;
  • renamed two tests to match what they cover;
  • tightened the related docstrings.

Validation:

test_gemma_tool_parse_edge_cases, test_refactor_guard, test_markerless_exec_tool_guard,
test_rehearsal_in_code_block, test_tool_call_arg_healing, test_passthrough_healing,
test_streaming_stripper: 553 passed

@Lyxot

Lyxot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Fixes a real issue: Gemma call syntax quoted in markdown code no longer runs a tool, and parsing, display stripping and streaming detection agree on it. Verified locally and on staging CI; remaining Codex notes are out-of-scope tokenizer edge cases, answered in the threads.

@Lyxot
Lyxot merged commit f10b3de into unslothai:main Sep 17, 2026
4 of 35 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
unslothai#11153)

* Studio: treat Gemma call syntax inside markdown code as documentation, not a tool call

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: close nested code fences correctly and keep inline Gemma examples streaming

* Studio: match inline backtick runs by length when holding streamed Gemma examples

* fix(studio): keep sibling Gemma calls promotable past code opened in call arguments

A raw Gemma call body can contain a fence or backtick run, and the markdown code gate scanned it as prose, so the next bare call was treated as quoted: parsed as nothing and left visible. The parser and the display strip now rescan code spans from the end of a promoted call whenever a span runs out of its arguments, which keeps the common case linear.

Also covers tilde fences quoting backtick fences and vice versa, drops a no-op lookahead from the fence pattern, and tightens the related docstrings.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lyxot <[email protected]>
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