Repository navigation
fix: preserve numeric enum constraints during canonicalization - #24
Open
JunkaiWang-TheoPhy wants to merge 1 commit into
Open
JunkaiWang-TheoPhy wants to merge 1 commit into
JunkaiWang-TheoPhy wants to merge 1 commit into
Conversation
The numeric type matcher reports a mismatch as an error, so enum validation stops before trying a nullable alternative. Its no-op simplifier then makes Canonical exhaust its retries and return an unconstrained schema. Try the remaining types, then use the existing enum-intersection rewrite for an unreachable member while preserving the previous numeric diagnostic. Constraint: MFJS supports numeric types paired with null and prunes unreachable enum values Rejected: Change IsTypeMatch globally | its error contract is used by numeric validation and existing diagnostics Confidence: high Scope-risk: narrow Tested: Seven public-API regressions; rollback 5 failed/2 passed, fixed 7 passed; full Go suite, race, vet, build Not-tested: CI-pinned Go 1.23 and Linux Python/CGO suite
This branch has not been deployed
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.
Problem
A tool parameter with
type: ["integer", "null"]andenum: [1, null]is valid, but default validation rejects its null member as "not a valid integer". Reversing the type order passes. The same problem affects nullable numbers.More seriously,
Canonical()retries that error without changing the schema and eventually returns{}, dropping all constraints on the tool parameters. A numeric enum containing an unreachable fractional or string value takes the same path instead of preserving its reachable values.Change
Try every declared type before rejecting an enum member. When no type matches, retain the existing numeric diagnostic but use the existing enum-intersection simplifier, which removes only unreachable enum values. Numeric helper behavior, validation levels, public APIs and dependencies are unchanged.
This follows the existing documented rule in
docs/validation-principles.md: enum members excluded by the declared type are pruned during canonicalization while the other constraints survive.Validation
The same new regression was run with the implementation restored to unmodified main and then with the fix:
The failures identify valid nullable numeric enums being rejected and canonicalization returning
{}. The null-first cases are passing controls. The regression also covers pruning fractional integer values and strings while preserving the object and required-field constraints.Additional checks on Go 1.26.1 / macOS arm64:
go test ./...: passed; JSON test events report 279 passing tests/subtests.go test -race ./...: passed.go vet ./...: passed.go build ./...: passed.git diff --check: passed.The same Go suite also passed on the CI's Go 1.23.0 toolchain. CI-pinned golangci-lint v1.64.8 passed. Building the native library with Go 1.23.0 succeeded, and an actual Python/CGO smoke check validated and canonicalized the nullable integer schema without changing it. The three existing Python regression tests are Linux-specific and were skipped on this macOS host; Linux CGO behavior is left to upstream CI. The locally generated macOS library is not included in the patch.
The leader reviewed the matching/simplification contract and independently reran all seven new regression cases successfully.
AI assistance: investigated, implemented and tested with OpenAI Codex.