Skip to content

[Tests] Add regression tests for reasoning parser edge cases - #34157

Closed
dinesh20073 wants to merge 0 commit into
sgl-project:mainfrom
dinesh20073:parser-regression-tests
Closed

dinesh20073 wants to merge 0 commit into
sgl-project:mainfrom
dinesh20073:parser-regression-tests

Conversation

@dinesh20073

@dinesh20073 dinesh20073 commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

SGLang issue #20865 asks contributors to improve unit-test coverage for
core runtime components that don't require a GPU, specifically calling out
test_reasoning_parser.py as a starting point. The reasoning parser's
streaming path (parse_streaming_increment) has several edge cases that
were not previously covered: malformed/nested tags, Unicode boundaries
that span multiple streaming chunks, and behavior consistency between
streamed and full-input parsing. Gaps here can lead to silent state
corruption, dropped output, or divergent behavior between streaming and
non-streaming code paths in production.

Modifications

Added 4 new regression tests to TestBaseReasoningFormatDetector in
test/registered/unit/parser/test_reasoning_parser.py:

  • test_parse_malformed_nested_tags — verifies nested <think> tags
    do not corrupt or drop the extracted normal text.
  • test_parse_unicode_grapheme_streaming_chunks — verifies a Unicode
    grapheme cluster (base character + combining accent) split across two
    streaming chunks is reassembled correctly.
  • test_round_trip_consistency — verifies streaming parsing
    (character-by-character and 5-character chunks) produces output
    identical to detect_and_parse on the full input.
  • test_chunk_size_invariance — verifies streaming output is
    identical across chunk sizes 1, 2, 5, and full-length input, guarding
    against buffer/boundary-management bugs.

No production code was touched. Only the test file above was modified.

Accuracy Tests

Not applicable — this PR adds unit tests only and does not change model
output, kernel code, or forward-pass logic.

Speed Tests and Profiling

Not applicable — no inference-path code was changed.

Validation performed locally

  • python -m py_compile on the modified file — passed.
  • flake8 --select=F541,E301,E303 on the modified file — passed.
  • git diff --stat / git status --porcelain — confirmed only
    test/registered/unit/parser/test_reasoning_parser.py was modified.
  • Full pytest execution was not possible locally: this environment
    is Windows, and SGLang's import chain requires the Linux-only resource
    module (ModuleNotFoundError: No module named 'resource' at collection
    time, unrelated to the new tests). Test execution is deferred to this
    PR's CI run.

Submitted by Dinesh (@dinesh20073)


CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.

@hnyls2002

Copy link
Copy Markdown
Collaborator

Heads-up: #34458 (5899674) landed and added TestStreamingChunkSizeInvariance, which overlaps two of the tests here — chunk-size invariance and streaming-vs-detect_and_parse round-trip.

The other two are not covered and are worth keeping: test_parse_malformed_nested_tags and test_parse_unicode_grapheme_streaming_chunks. Multiple reasoning blocks in one turn are still handled the way they were before, so a test pinning that behaviour is useful.

One conflict to expect on rebase: test_finish_drops_partial_end_tag_when_streaming_reasoning was renamed to ..._flushes_... and its assertion flipped, because holdback made its premise (that the buffer had already been emitted) no longer true.

@dinesh20073
dinesh20073 force-pushed the parser-regression-tests branch 2 times, most recently from 85b3ccc to baaa88b Compare August 12, 2026 16:52
@dinesh20073

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@dinesh20073
dinesh20073 force-pushed the parser-regression-tests branch from baaa88b to c049d71 Compare August 12, 2026 17:00
@dinesh20073
dinesh20073 force-pushed the parser-regression-tests branch from c049d71 to b501311 Compare August 16, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants