Skip to content

fix(s16): reject non-integral floats for JSON Schema "integer" - #677

Open
shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s16-integer-schema
Open

shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s16-integer-schema

Conversation

@shuhuNB515

@shuhuNB515 shuhuNB515 commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #676

Problem

SimpleJsonSchema.validate treated integer as an alias of number:

if t in ("number", "integer"):
    ok = isinstance(value, (int, float)) and not isinstance(value, bool)
    return (ok, None if ok else "expected number")

So agent(prompt, schema={"type": "integer"}) accepted 3.7 and passed the float to the caller as a validated result — including on the resume/cache path, which validates the cached value with the same class.

Change

if t == "number":
    ok = isinstance(value, (int, float)) and not isinstance(value, bool)
    return (ok, None if ok else "expected number")
if t == "integer":
    # JSON Schema counts 3.0 as an integer but rejects 3.7.
    ok = (
        isinstance(value, int) and not isinstance(value, bool)
    ) or (isinstance(value, float) and value.is_integer())
    return (ok, None if ok else "expected integer")

_fill_schema is untouched (it already yields int for both types). The embedded s16 snapshot in web/src/data/generated/versions.json is regenerated, so tests/test_web_scenarios.py stays byte-identical.

Verification

Loaded the real module and exercised the validator directly, 16/16 checks:

input type: integer type: number
3 valid valid
3.0 valid (JSON Schema) valid
3.7 expected integer valid
True expected integer expected number
"3" expected integer expected number

Also covered: the error is prefixed by the property name inside object (count: expected integer) and by the index inside array ([1]: expected integer); enum still wins when both are present; an empty schema still accepts anything; _fill_schema still produces a real int; and the three SimpleJsonSchema(schema).validate(...) call sites (fresh run, cached resume, retry) are unchanged.

Nothing in tests/ mentions "integer", so no existing assertion changed meaning.

Whole suite on this branch with tests/test_agent_teams_runtime.py excluded (that file now stops responding in this sandbox even when run alone, on unmodified main too): 433 passed, 43 subtests passed, 3 failed. The three failures are environment-only and reproduce identically on unmodified main — a sandbox mkdir EEXIST in test_s_full_background.py (×2) and one GBK subprocess case. The snapshot equality check that test_web_scenarios.py performs was also verified byte-for-byte directly.

Disclosed AI assistance: found during an AI-assisted review; patch and verification done with AI assistance.

SimpleJsonSchema folded integer into number, so a workflow that asked for
{"type": "integer"} accepted 3.7 and handed the float to the caller. Every
other primitive is checked strictly (3, True and "3" are all rejected for
"number"), so this was an oversight rather than a deliberate shortcut.
Accept a non-bool int or a float whose is_integer() is true (JSON Schema
treats 3.0 as an integer) and report "expected integer" otherwise. Sync the
embedded s16 snapshot in versions.json.

Disclosed AI assistance: found during an AI-assisted review.

This branch has not been deployed

No deployments
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.

s16: "integer" schemas accept non-integral floats (3.7 validates as an integer)

1 participant