[PR #1839] [CLOSED] fix(serve): preserve literal closing thinking tags #3711

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1839
Author: @CC-David-CC
Created: 10/10/2026
Status: ❌ Closed

Base: main ← Head: fix/literal-think-output


📝 Commits (9)

  • 85ced52 serve: a reply that ends inside its thinking with no answer is continued (#1814)
  • 68c2d07 serve: report a reply that ended inside its thinking, guard or no guard (#1814)
  • 549efc6 serve: put the tag back into the reasoning before the close, and test it (#1814)
  • d41047c fix(serve): distinguish reasoning marker identity from literal text
  • e603e90 fix(serve): route literal thinking tags by token identity
  • fc98b38 test(serve): cover literal repair cancellation and budget
  • 3d66ab0 test(serve): verify literal thinking tags across HTTP APIs
  • 471bcd5 fix(serve): continue after EOS inside reasoning code
  • b83016b fix(serve): compose literal guard with end detection

📊 Changes

8 files changed (+818 additions, -13 deletions)

View changed files

📝 docs/DETAILS.md (+10 -0)
➕ serve/fixtures/literal_think_specimens.json (+30 -0)
📝 serve/frontend.py (+32 -6)
📝 serve/prometheus.py (+5 -0)
📝 serve/server.py (+173 -7)
➕ serve/test_literal_think.py (+226 -0)
➕ serve/test_literal_think_guard.py (+236 -0)
➕ serve/test_literal_think_parser.py (+106 -0)

📄 Description

Follow-up to #537 and related to #1814. When ordinary text tokens spell </think> during reasoning, the parser must keep those bytes as reasoning text; only the tokenizer's dedicated end-of-thinking token should close the block. This change makes parser transitions depend on token identity.

The bounded literal_think_guard handles dedicated <think> / </think> tokens in answer text or inside reasoning code spans by rendering the tag with ordinary text-token IDs and resuming from the preserved prefix. If end-of-turn arrives inside an unclosed reasoning code span before any answer or tool call, it similarly inserts literal </think> text and resumes. The guard is enabled by default to match #1814 and can be disabled with "literal_think_guard": false. It is capped at 64 repairs per reply, respects client stops, and accounts for inserted tokens against the output budget.

Evidence

  • Controlled ordinary-text tag case: the original parser misrouted the tag in 12/12 requests; token-identity parsing handled all 12 with the same generated token IDs.
  • A live RTX PRO 6000 run naturally emitted dedicated closing-tag IDs inside reasoning code. The guard replaced them and continued from the verified prefix, but those replies reached their output cap while still reasoning; this verifies repair mechanics, not complete answers.
  • A Linux stress test with 4,106- and 8,370-token parser/tool histories produced one baseline stop after an opening backtick in 8 requests. No dedicated closing-tag ID appeared in any of 16 baseline/guard requests. Its synthetic history included the expected symptom, so it is not an independent reproduction of the reporter's agent session.
  • We could not test the reported two RTX 3090 GPUs, and the exact dedicated-token-then-stop sequence remains unobserved.

Validation

  • Focused parser/service/HTTP tests: 30 passed on Windows and Linux.
  • Full Windows serving suite: 623 passed, 10 skipped (438.513s).
  • Full Linux serving suite from a native WSL filesystem with regex and jsonschema available: 623 passed, 12 skipped (339.043s).

Related but separate work: #1818 covers CPU IQ expert dispatch and draft-grouping independence; #1813 covers speculative/TCP parity; #1773 covers Q8 TCP parity/timings.


🔄 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/1839 **Author:** [@CC-David-CC](https://github.com/CC-David-CC) **Created:** 10/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/literal-think-output` --- ### 📝 Commits (9) - [`85ced52`](https://github.com/Niko1221/Strata/commit/85ced52a9550e328c1b7672a3faa69a4810c8a95) serve: a reply that ends inside its thinking with no answer is continued (#1814) - [`68c2d07`](https://github.com/Niko1221/Strata/commit/68c2d076ccf05c0b1841f4792c942f1e57df85c8) serve: report a reply that ended inside its thinking, guard or no guard (#1814) - [`549efc6`](https://github.com/Niko1221/Strata/commit/549efc6cef5b33583596442e828f47903d1d503f) serve: put the tag back into the reasoning before the close, and test it (#1814) - [`d41047c`](https://github.com/Niko1221/Strata/commit/d41047c6404310a4811773ae518d9a532943cd88) fix(serve): distinguish reasoning marker identity from literal text - [`e603e90`](https://github.com/Niko1221/Strata/commit/e603e9060d49836988afdb9208dc36988b836cfb) fix(serve): route literal thinking tags by token identity - [`fc98b38`](https://github.com/Niko1221/Strata/commit/fc98b38d40e4bdf03994673d22ca1bb3a00e6aa4) test(serve): cover literal repair cancellation and budget - [`3d66ab0`](https://github.com/Niko1221/Strata/commit/3d66ab0edf4a719ec7cbb9446116745d9f46e70d) test(serve): verify literal thinking tags across HTTP APIs - [`471bcd5`](https://github.com/Niko1221/Strata/commit/471bcd5e17130f89cb30e04bed8ecc983dd9fe3c) fix(serve): continue after EOS inside reasoning code - [`b83016b`](https://github.com/Niko1221/Strata/commit/b83016b21b54f7f2dc192f7efaa1efaea754cfa7) fix(serve): compose literal guard with end detection ### 📊 Changes **8 files changed** (+818 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+10 -0) ➕ `serve/fixtures/literal_think_specimens.json` (+30 -0) 📝 `serve/frontend.py` (+32 -6) 📝 `serve/prometheus.py` (+5 -0) 📝 `serve/server.py` (+173 -7) ➕ `serve/test_literal_think.py` (+226 -0) ➕ `serve/test_literal_think_guard.py` (+236 -0) ➕ `serve/test_literal_think_parser.py` (+106 -0) </details> ### 📄 Description Follow-up to #537 and related to #1814. When ordinary text tokens spell `</think>` during reasoning, the parser must keep those bytes as reasoning text; only the tokenizer's dedicated end-of-thinking token should close the block. This change makes parser transitions depend on token identity. The bounded `literal_think_guard` handles dedicated `<think>` / `</think>` tokens in answer text or inside reasoning code spans by rendering the tag with ordinary text-token IDs and resuming from the preserved prefix. If end-of-turn arrives inside an unclosed reasoning code span before any answer or tool call, it similarly inserts literal `</think>` text and resumes. The guard is enabled by default to match #1814 and can be disabled with `"literal_think_guard": false`. It is capped at 64 repairs per reply, respects client stops, and accounts for inserted tokens against the output budget. ### Evidence - Controlled ordinary-text tag case: the original parser misrouted the tag in 12/12 requests; token-identity parsing handled all 12 with the same generated token IDs. - A live RTX PRO 6000 run naturally emitted dedicated closing-tag IDs inside reasoning code. The guard replaced them and continued from the verified prefix, but those replies reached their output cap while still reasoning; this verifies repair mechanics, not complete answers. - A Linux stress test with 4,106- and 8,370-token parser/tool histories produced one baseline stop after an opening backtick in 8 requests. No dedicated closing-tag ID appeared in any of 16 baseline/guard requests. Its synthetic history included the expected symptom, so it is not an independent reproduction of the reporter's agent session. - We could not test the reported two RTX 3090 GPUs, and the exact dedicated-token-then-stop sequence remains unobserved. ### Validation - Focused parser/service/HTTP tests: 30 passed on Windows and Linux. - Full Windows serving suite: 623 passed, 10 skipped (438.513s). - Full Linux serving suite from a native WSL filesystem with `regex` and `jsonschema` available: 623 passed, 12 skipped (339.043s). Related but separate work: [#1818](https://github.com/Niko1221/Strata/pull/1818) covers CPU IQ expert dispatch and draft-grouping independence; [#1813](https://github.com/Niko1221/Strata/pull/1813) covers speculative/TCP parity; [#1773](https://github.com/Niko1221/Strata/pull/1773) covers Q8 TCP parity/timings. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:14 +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#3711
No description provided.