Repository navigation
fix(agent): validate tool string lengths by Unicode code points - #3937
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Use Unicode code-point length for Agent tool string validation. The current
len(s)measures UTF-8 bytes, so a two-character Chinese string failsmaxLength: 2, while one Chinese character incorrectly passesminLength: 2.Count once with
utf8.RuneCountInStringand use that value for both bounds. Preserve ASCII behavior and error wording. Add cases for Chinese, emoji, accented characters, mixed text, combining code points, empty strings, and ASCII.The constraint counts code points, not grapheme clusters:
efollowed by a combining accent remains length 2. See the JSON Schema string-length reference.Type of Change
Related Issue
Fixes #3935
Testing
Environment: Windows 11, Go 1.26.8 windows/amd64,
CGO_ENABLED=0. Base:bccb4b151bae403508da77fbb174efc79dc47c1a.The 10 new table cases produce 7 failures / 3 passes on the original implementation. After the fix, the independent suite including all existing validator tests passes:
Also ran the casting and validation files together: 12 top-level tests / 32 subtests passed. The separate numeric-preservation contribution is not included in this branch.
Package-level attempt:
The package's existing DuckDB tests require CGO, disabled locally. Restoring both changed production files to base reproduces the same setup failure before any test assertions. The passing file-scoped command uses the actual production validator and its tests. Full-package execution and registry/backend E2E are not verified.
golangci-lintis not installed; focusedgo vetpasses.Prepared, self-reviewed and tested with Codex assistance. No manual human E2E or live model test is claimed.
Checklist
Screenshots / Recordings
Not applicable; backend-only change.