[PR #4761] [CLOSED] [Engine] tool parser: quoted Markdown code and thinking blocks stay text #5167

Closed
opened 2026-11-07 16:33:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4761
Author: @Tsury
Created: 10/30/2026
Status: ❌ Closed

Base: main ← Head: fix/parser-markdown-code


📝 Commits (1)

📊 Changes

3 files changed (+78 additions, -31 deletions)

View changed files

📝 serve/frontend.py (+42 -22)
📝 serve/test_parser_track.py (+14 -9)
📝 serve/test_tool_corpus.py (+22 -0)

📄 Description

Problem and result

A quoted example in an answer can run as a real tool call, because the parser's code tracking misses three Markdown shapes:

  • #4702: an inner ``` closes a four-backtick fence, so a call shown inside it is outside "code".
  • #4703: an indented code block is not code at all.
  • #4704: the stray </think> rule (#4077) drops the closing tag of a thinking block the answer quotes, and that reset also ends the fence, so a call in the same example runs. In the plain case, the answer simply loses the tag.

After this change, all four fixtures from these issues give no call and the whole text as the answer, with recover on and off, whole and in pieces.

Fixes #4702, #4703 and #4704. They are one PR because all three change the same tracked state (fence, line, ticks) and its snapshots, so separate PRs would conflict on every line.

Approach

  • fence now holds the opening run, not one character. A fence closes on a line of its own, of the same character and at least as long, as CommonMark says.
  • indented is true after a blank line, and stays true while lines keep a code indent. A call on such a line is a quote. A call indented right after a line of text is still a call, as #4703 suggests.
  • quoted_think counts <think> lines of the answer. A line-start </think> that closes one is kept. I did not use the rule #4704 suggests (keep any </think> inside a fence the answer opened), because 4077-stray-think-in-a-fence needs the opposite: there the fence was opened in the reasoning, and the answer's tracker sees its closing line as an opener.

Validation

Passed:

  • The four fixtures from the issues fail on unchanged main (870aedd9) and pass here, recover on and off, whole and in pieces of 1 and 7. The corpus cases are added too; the corpus also cuts each specimen at every byte.
  • python -m pytest serve on Linux, Python 3.14: 1242 passed, 14 skipped.
  • Before the fix, on a maintained v0.2.8 build on an RTX 5090 Laptop (Qwen3.8-Flash-Next IQ3_S, live server, the model asked to reply with the example as text): all three shapes ran as a real write_file call on Chat, streamed Chat and Responses, 9 of 9.

Not run: a model run of this branch.

Limits

  • A </think> in a fenced example with no <think> before it is still dropped (#4077 cannot tell it from the real end of reasoning).
  • An indented call right after a blank line is now text. A model that indents its real calls that way would lose them; I have not seen one do it.
  • A closing fence with text after it no longer closes, as in CommonMark. The old check accepted it.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4761 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/parser-markdown-code` --- ### 📝 Commits (1) - [`a143449`](https://github.com/Niko1221/Strata/commit/a1434499744fe1ad16188251d619c47bf4e845d8) [Engine] tool parser: quoted Markdown code and thinking blocks stay text (#4702, #4703, #4704) ### 📊 Changes **3 files changed** (+78 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+42 -22) 📝 `serve/test_parser_track.py` (+14 -9) 📝 `serve/test_tool_corpus.py` (+22 -0) </details> ### 📄 Description ## Problem and result A quoted example in an answer can run as a real tool call, because the parser's code tracking misses three Markdown shapes: - #4702: an inner ` ``` ` closes a four-backtick fence, so a call shown inside it is outside "code". - #4703: an indented code block is not code at all. - #4704: the stray `</think>` rule (#4077) drops the closing tag of a thinking block the answer quotes, and that reset also ends the fence, so a call in the same example runs. In the plain case, the answer simply loses the tag. After this change, all four fixtures from these issues give no call and the whole text as the answer, with recover on and off, whole and in pieces. ## Related discussion Fixes #4702, #4703 and #4704. They are one PR because all three change the same tracked state (`fence`, `line`, `ticks`) and its snapshots, so separate PRs would conflict on every line. ## Approach - `fence` now holds the opening run, not one character. A fence closes on a line of its own, of the same character and at least as long, as CommonMark says. - `indented` is true after a blank line, and stays true while lines keep a code indent. A call on such a line is a quote. A call indented right after a line of text is still a call, as #4703 suggests. - `quoted_think` counts `<think>` lines of the answer. A line-start `</think>` that closes one is kept. I did not use the rule #4704 suggests (keep any `</think>` inside a fence the answer opened), because `4077-stray-think-in-a-fence` needs the opposite: there the fence was opened in the reasoning, and the answer's tracker sees its closing line as an opener. ## Validation **Passed:** - The four fixtures from the issues fail on unchanged `main` (870aedd9) and pass here, recover on and off, whole and in pieces of 1 and 7. The corpus cases are added too; the corpus also cuts each specimen at every byte. - `python -m pytest serve` on Linux, Python 3.14: 1242 passed, 14 skipped. - **Before** the fix, on a maintained v0.2.8 build on an RTX 5090 Laptop (Qwen3.8-Flash-Next IQ3_S, live server, the model asked to reply with the example as text): all three shapes ran as a real `write_file` call on Chat, streamed Chat and Responses, 9 of 9. **Not run:** a model run of this branch. ## Limits - A `</think>` in a fenced example with no `<think>` before it is still dropped (#4077 cannot tell it from the real end of reasoning). - An indented call right after a blank line is now text. A model that indents its real calls that way would lose them; I have not seen one do it. - A closing fence with text after it no longer closes, as in CommonMark. The old check accepted it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:33:12 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5167
No description provided.