Repository navigation
common/peg : handle invalid utf-8 sequences in the AST - #29161
Conversation
|
/bot review |
Automated code reviewReview of PR #29161 ( The approach is sound and well-scoped: record invalid UTF-8 runs during the Blocking / should fix (point 1) The non-strict default silently regresses the tool-call paths built on
Since the flag exists for exactly this, pass Will slow the review (point 2) (point 3) Truncated sequences at the end of a complete message are still silently dropped, not replaced: Nits (point 4) The seq/repeat merge sites copy each child's vector ( (point 5) The Everything else checks out: constructor arity changes are backward compatible, the This review was generated automatically by pi coding agent using |
|
Tested against the issue outlined in #28724 by replaying the observed Ling 3.0 failure shape (valid U+2705 followed by a lone 0x85 continuation byte) through the native PEG parser. |
ServeurpersoCom
left a comment
There was a problem hiding this comment.
LGTM, one place instead of scattered UTF-8 passes, and the raw text stays intact. Small nit: strict has no caller outside the tests, could we drop it (along with its serialization) until something needs it?
Sure. I only included it thinking it was required by the preset parser, but that doesn't seem to be the case. |
ServeurpersoCom
left a comment
There was a problem hiding this comment.
Thanks for the refactor!
* common/peg : handle invalid utf-8 sequences in the AST * cont : return maximal subpart per Unicode recommendations * cont : remove strict argument (cherry picked from commit 3d82ef6) (cherry picked from commit ef06fedd8901ac691867d6d514a4bc2505a17ac1)
* common/peg : handle invalid utf-8 sequences in the AST * cont : return maximal subpart per Unicode recommendations * cont : remove strict argument
* common/peg : handle invalid utf-8 sequences in the AST * cont : return maximal subpart per Unicode recommendations * cont : remove strict argument (cherry picked from commit 3d82ef6)
* common/peg : handle invalid utf-8 sequences in the AST * cont : return maximal subpart per Unicode recommendations * cont : remove strict argument (cherry picked from commit 3d82ef6)
Overview
Models may occasionally emit invalid UTF-8 which fails during parsing. This records invalid utf-8 sequences during parse and provides a
sanitized_text()at every node in the AST.Tool names/args are not passed through this, as they should be grammar constrained to only produce UTF-8. If this becomes a problem, we can easily change them to use
sanitize_text()instead.ref: #28724
fixes #24327
fixes #27543
Additional Information
Invalid UTF-8 runs are replaced with a single
U+FFFD, aka the "maximal subpart" per https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G66453.Requirements