Skip to content

fix(agent): validate tool string lengths by Unicode code points - #3937

Merged
lyingbug merged 1 commit into
Tencent:mainfrom
icearia0219:fix/unicode-parameter-length
Oct 7, 2026
Merged

lyingbug merged 1 commit into
Tencent:mainfrom
icearia0219:fix/unicode-parameter-length

Conversation

@icearia0219

Copy link
Copy Markdown
Contributor

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 fails maxLength: 2, while one Chinese character incorrectly passes minLength: 2.

Count once with utf8.RuneCountInString and 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: e followed by a combining accent remains length 2. See the JSON Schema string-length reference.

Type of Change

  • Bug fix
  • Test

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:

go test internal/agent/tools/param_validate.go internal/agent/tools/param_validate_test.go internal/agent/tools/param_validate_unicode_test.go -v -count=1
PASS — 3 top-level tests / 27 subtests; no failures

go vet internal/agent/tools/param_validate.go internal/agent/tools/param_validate_test.go internal/agent/tools/param_validate_unicode_test.go
exit 0

gofmt -l internal/agent/tools/param_validate.go internal/agent/tools/param_validate_unicode_test.go
no output

git diff --check
exit 0

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:

go test ./internal/agent/tools -run 'TestCastParams|TestValidateParams|TestFormatValidationErrors' -count=1
FAIL [setup failed]: github.com/duckdb/duckdb-go-bindings/lib/windows-amd64:
build constraints exclude all Go files

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-lint is not installed; focused go vet passes.

Prepared, self-reviewed and tested with Codex assistance. No manual human E2E or live model test is claimed.

Checklist

  • Diff whitespace check passes
  • Changed source files are formatted
  • Focused helper tests pass; package setup limitation documented
  • Diff-scoped golangci-lint (unavailable locally)
  • Environment-dependent failures documented above
  • Self-reviewed with Codex
  • Added regression tests
  • Documentation update (internal behavior only)
  • No breaking API changes

Screenshots / Recordings

Not applicable; backend-only change.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lyingbug
lyingbug merged commit 5289300 into Tencent:main Oct 7, 2026
4 checks passed
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.

[Bug]: Agent tool string length validation counts UTF-8 bytes instead of Unicode code points

3 participants