fix(pixel-chat-context): coerce float and string token limits in context trimmer - #5949
Open
vaibhavsrv wants to merge 1 commit into
Open
vaibhavsrv wants to merge 1 commit into
vaibhavsrv wants to merge 1 commit into
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.
Why this matters
In
ods/extensions/services/dashboard-api/pixel_chat_context.py, the public modelsContextUsageandContextModelinherit from_Projection, which declaresstrict=Truein its Pydantic configuration. Because of strict mode, integer token fields such asused,window, andcontextWindowstrictly reject float values. When upstream inference runtimes (e.g. llama-server or vLLM) or JSON parsers serialize token statistics as decimal numbers (such as100.0or2048.0), Pydantic throws an unhandledValidationError: Input should be a valid integer [type=int_type, input_type=float], causing persistent context queries to fail with HTTP 500 errors.This change adds
@field_validator(..., mode="before")hooks toContextUsageandContextModel. When incoming numeric values are floats representing whole integers (value.is_integer()), they are automatically coerced tointprior to validation. Non-integer floating point numbers continue to be strictly rejected.Validation
{"used": 100.0, "window": 2048.0}in context usage triggered a PydanticValidationError.intand validated successfully; non-integer floats (e.g.100.5) remain rejected.Overlap check
model_contract.py.pixel_settings/contract.py.routers/pixel.py.This PR targets Pydantic context projection in
pixel_chat_context.pyand does not conflict with adjacent PRs.Risk / AI disclosure
AI-assisted defect analysis, implementation, and unit regression testing. This standardizes numerical type coercion for whole-number floats and does not alter persistence schemas, model endpoints, or container routing. Independent human review remains a gate.
Follow-up integration evidence
Composed cleanly on top of #5569, #5871, and #5875 at HEAD without conflicts. Production and test diffs passed together; adjacent pixel-agent and pixel-settings checks remain intact.
Backlog composition was local-only (production/test diffs, excluding workflow/Makefile wiring); it is not an upstream merge or independent human approval. Declared live-review gates remain open.