[PR #1362] [CLOSED] serve: preserve Markdown state across skipped tool-call newlines #3407

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1362
Author: @hawkli-1994
Created: 10/7/2026
Status: ❌ Closed

Base: main ← Head: fix/tool-call-newline-markdown-state


📝 Commits (1)

  • 17412c5 serve: track skipped newlines after tool calls

📊 Changes

2 files changed (+32 additions, -0 deletions)

View changed files

📝 serve/frontend.py (+2 -0)
📝 serve/test_reasoning_rescue.py (+30 -0)

📄 Description

Summary
After a real tool call, OutputParser discards leading newlines without advancing its Markdown state. When prose precedes the call, the next code fence is tracked as part of that stale line. A tilde-fenced example can then become an extra tool call, while a backtick fence can hide a later real call.
Track the skipped newlines before discarding them so fenced examples stay text and subsequent real calls still parse.
What changed

  • serve/frontend.py: pass the skipped newlines through the existing _track() helper, preserving the existing fence and call-detection rules.
  • serve/test_reasoning_rescue.py: add regression coverage for both fence delimiters, one or two newlines, whole input, character-by-character input, every two-way split, and stream_tools off/on. Verify content, reasoning, call order, arguments, and streamed call IDs. Extend the existing HTTP test for all three APIs.
    Extra Notes
    Validation on the original base 82f46a8 with this patch, using Python 3.12.14 on Linux:
  • All 2,588 new parser regression subcases fail with the original parser and pass with the patch.
  • python -m unittest serve.test_reasoning_rescue serve.test_reasoning_tools -v: 37 tests pass.
  • python -m unittest discover -s serve -p 'test_*.py' -t . -v: 445 pass, 8 skipped (5 require a pack tokenizer; 3 are Windows-only).
  • Additional loopback HTTP checks: 12/12 pass across OpenAI Chat Completions, Anthropic Messages, and Responses, streamed and non-streamed, with both fence delimiters.
    HTTP checks use MockEngine and ByteTokenizer. GPU execution, model-backed generation, and a real pack tokenizer were not tested. The passing full-suite run used an isolated environment without psutil. A separate run with psutil hit an existing AmdTelemetry.test_readings error when the container returned None for disk I/O counters; this also reproduced with unchanged upstream telemetry 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/1362 **Author:** [@hawkli-1994](https://github.com/hawkli-1994) **Created:** 10/7/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tool-call-newline-markdown-state` --- ### 📝 Commits (1) - [`17412c5`](https://github.com/Niko1221/Strata/commit/17412c50deb60c56e91b14792c2352d85c2baea7) serve: track skipped newlines after tool calls ### 📊 Changes **2 files changed** (+32 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+2 -0) 📝 `serve/test_reasoning_rescue.py` (+30 -0) </details> ### 📄 Description Summary After a real tool call, OutputParser discards leading newlines without advancing its Markdown state. When prose precedes the call, the next code fence is tracked as part of that stale line. A tilde-fenced example can then become an extra tool call, while a backtick fence can hide a later real call. Track the skipped newlines before discarding them so fenced examples stay text and subsequent real calls still parse. What changed - serve/frontend.py: pass the skipped newlines through the existing _track() helper, preserving the existing fence and call-detection rules. - serve/test_reasoning_rescue.py: add regression coverage for both fence delimiters, one or two newlines, whole input, character-by-character input, every two-way split, and stream_tools off/on. Verify content, reasoning, call order, arguments, and streamed call IDs. Extend the existing HTTP test for all three APIs. Extra Notes Validation on the original base 82f46a8 with this patch, using Python 3.12.14 on Linux: - All 2,588 new parser regression subcases fail with the original parser and pass with the patch. - python -m unittest serve.test_reasoning_rescue serve.test_reasoning_tools -v: 37 tests pass. - python -m unittest discover -s serve -p 'test_*.py' -t . -v: 445 pass, 8 skipped (5 require a pack tokenizer; 3 are Windows-only). - Additional loopback HTTP checks: 12/12 pass across OpenAI Chat Completions, Anthropic Messages, and Responses, streamed and non-streamed, with both fence delimiters. HTTP checks use MockEngine and ByteTokenizer. GPU execution, model-backed generation, and a real pack tokenizer were not tested. The passing full-suite run used an isolated environment without psutil. A separate run with psutil hit an existing AmdTelemetry.test_readings error when the container returned None for disk I/O counters; this also reproduced with unchanged upstream telemetry code. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:41:16 +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#3407
No description provided.