Skip to content

fix(pixel-chat-context): coerce float and string token limits in context trimmer - #5949

Open
vaibhavsrv wants to merge 1 commit into
Osmantic:public-betafrom
vaibhavsrv:fix/pixel-chat-context-token-limits
Open

vaibhavsrv wants to merge 1 commit into
Osmantic:public-betafrom
vaibhavsrv:fix/pixel-chat-context-token-limits

Conversation

@vaibhavsrv

Copy link
Copy Markdown
Contributor

Why this matters

In ods/extensions/services/dashboard-api/pixel_chat_context.py, the public models ContextUsage and ContextModel inherit from _Projection, which declares strict=True in its Pydantic configuration. Because of strict mode, integer token fields such as used, window, and contextWindow strictly reject float values. When upstream inference runtimes (e.g. llama-server or vLLM) or JSON parsers serialize token statistics as decimal numbers (such as 100.0 or 2048.0), Pydantic throws an unhandled ValidationError: 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 to ContextUsage and ContextModel. When incoming numeric values are floats representing whole integers (value.is_integer()), they are automatically coerced to int prior to validation. Non-integer floating point numbers continue to be strictly rejected.

Validation

  • Tested baseline reproduction against unpatched code: passing {"used": 100.0, "window": 2048.0} in context usage triggered a Pydantic ValidationError.
  • Tested post-fix behavior: exact integer floats are coerced to int and validated successfully; non-integer floats (e.g. 100.5) remain rejected.
  • Telemetry statement: "Dashboard-api suites: 1 passed. New-test Ruff, py_compile, and diff checks pass; new regression wired into Linux CI."

Overlap check

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.

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.

1 participant