Skip to content

qwen3 reasoning parser re-enters reasoning on a later <think> and deletes the markers #87

Open

Description

@gdevenyi

After </think>, streaming treats the first <think> it sees as a new reasoning block, even inside a tool-call argument. It strips the markers and moves the text between them into reasoning_content. Non-streaming instead deletes every <think> from the text and splits at the first </think>. Asking the model to edit code that quotes the markers (such as this parser) therefore corrupts the tool call, and differently in each mode.

from freetoken.server.reasoning_parser import ReasoningParser
toks = ["plan", "</think>", "\n\n", "Edit:", "<tool_call>", "\n<function=edit>\n<parameter=new>\n",
        'START = "', "<think>", '"\nEND = "', "</think>", '"\n', "</parameter>\n</function>\n", "</tool_call>"]
p = ReasoningParser("qwen3", force_reasoning=True); R = C = ""
for t in toks: r, c = p.parse_stream_chunk(t); R += r; C += c
print(repr(R))   # 'plan"\nEND = "'  <- argument text leaked into reasoning
print(ReasoningParser("qwen3", force_reasoning=True).parse_non_stream("".join(toks)))  # <think> deleted

Fixed on 5080deploy by 362719c (merged in 1542d52); stream/non-stream parity tests are in tests/server/test_streaming_model_matrix.py.

Activity

  1. gdevenyi commented on Oct 16, 2026

    @gdevenyi
    OwnerAuthor

    Upstream: FlashML-org#711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions