Repository navigation
fix: prevent reasoning tags from leaking or hiding visible text - #113205
Conversation
6243e20 to
77d3bff
Compare
|
Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 7:37 AM ET / 11:37 UTC. ClawSweeper reviewWhat this changesThis PR moves reasoning-tag recognition and Markdown code ownership into Markdown Core, then uses that shared logic to prevent static and streamed assistant output from leaking reasoning markup or dropping visible text. Merge readinessKeep this PR open for normal maintainer review. It is an active, mergeable candidate fix for two open deterministic assistant-output bugs, has direct after-fix runtime evidence, and the supplied context does not establish a merged replacement on current main. Priority: P2 Review scores
Verification
How this fits togetherModel responses reach users through a static visible-text sanitizer or a streaming partitioner that separates visible output from hidden reasoning. The PR gives both paths one Markdown-aware parser and reducer so they classify the same model text consistently before channel delivery. flowchart LR
A[Model response or stream chunks] --> B[Markdown Core ownership parser]
B --> C[Reasoning tag reducer]
C --> D[Static visible-text sanitization]
C --> E[Streaming text partitioning]
D --> F[Assistant-visible delivery]
E --> F
Before merge
Agent review detailsSecurityNone. PR surfaceSource +536, Tests +571, Config +3, Other +9. Total +1119 across 13 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land one shared Markdown-aware reasoning-tag contract only after a current-main refresh confirms that static sanitization and streamed partitioning retain the same visible-versus-hidden behavior. Do we have a high-confidence way to reproduce the issue? Yes, from the supplied deterministic inputs and branch evidence: self-closing reasoning tags previously discarded a visible suffix, and unequal backtick runs could preserve reasoning markup. I could not independently execute the current-main path in this read-only review environment. Is this the best way to solve the issue? Yes. A single Markdown-aware parser and reducer for both complete and streamed output is more maintainable than preserving divergent visibility grammars, provided the rebased head keeps the demonstrated behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a62abee4271a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
32297ee to
5632c67
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
5632c67 to
1adeb44
Compare
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph change authorizedThis PR includes dependency graph changes. A repository admin or member of
A later push changes the PR head SHA and requires a fresh security approval. |
1adeb44 to
e900af5
Compare
|
/allow-dependencies-change markdown-core now directly owns its existing mdast/micromark parser dependencies for the commissioned shared static and streaming sanitization contract. |
|
/allow-dependencies-change markdown-core directly owns its existing mdast/micromark parser dependencies for the commissioned shared static and streaming sanitization contract at this exact head. |
|
CI is green. @clawsweeper re-review |
Co-authored-by: 李琪0668001400 <[email protected]>
1a133e2 to
e582955
Compare
|
/allow-dependencies-change markdown-core directly owns its existing mdast/micromark parser dependencies for the commissioned shared static and streaming sanitization contract at this exact head. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
Co-authored-by: Peter Steinberger <[email protected]>
Closes #113144.
Closes #113148.
What Problem This Solves
Fixes an issue where assistant output could lose visible text after self-closing reasoning markers, or expose private reasoning tags when malformed backtick runs and Markdown block transitions were streamed incrementally.
Why This Change Was Made
Static sanitization and
packages/aistreaming now share one block-aware markdown-core contract. CommonMark/GFM parser positions own code-span classification; one iterative, quote-aware tag reducer owns self-closing tags, malformed recovery, orphan closes, and strict/visible modes. Streaming releases only parser-stable prefixes and retains real Markdown context across every chunk boundary.The new surface is internal-only: markdown-core package exports and plugin-visible APIs are unchanged.
This is +530 net non-test lines because it replaces 497 lines of divergent sanitizer regexes, code-region approximation, and AI streaming state with the shared parser/reducer plus bounded incremental state. The old paths were deleted rather than retained as fallbacks.
User Impact
Before<thinking/>Afternow yieldsBeforeAfter.Evidence
Exact head:
e5829559a9f772a55888d898bf6c94c09893c9d1.origin/maindefect probe atd3e043751aed3fa8bedecca23f573510b9113278: self-closing static output wasBefore; unequal-backtick static output preserved<think>private</think>.tbx_01kyhg375ht3sprvnhta0ze0ck: focused tests passed in 55s;pnpm check:changedpassed in 9m07s;pnpm buildpassed in 2m13s.NO-ACTIONABLE-OBJECTION.Direct runtime transcript
Exact-head execution through
src/shared/text/reasoning-tags.tsand thepackages/aipartitioner re-export produced:{ "static": { "selfClosing": { "input": "Before<thinking/>After", "output": "BeforeAfter" }, "unequalBackticks": { "input": "before ```<think>private</think>`` after", "output": "before ````` after" } }, "stream": { "input": "Paragraph `literal\n- <think>private</think> `visible", "chunks": [ "Paragraph `literal\n", "- <thi", "nk>private</th", "ink> `visible" ], "text": "Paragraph `literal\n- `visible", "thinking": "private", "deltas": [ { "kind": "text", "text": "Paragraph `literal\n- " }, { "kind": "thinking", "text": "private" }, { "kind": "text", "text": " `visible" } ], "everySplitPointChecked": 53, "allSplitPointsMatch": true } }