Repository navigation
LCORE-4621: request model configuration with configurable limit threshold #2957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3165,4 +3165,4 @@ | |
| } | ||
| }, | ||
| "paths": {} | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| from ogx_api.openai_responses import ( | ||
| OpenAIResponseText as Text, | ||
| ) | ||
| from pydantic import BaseModel, field_validator, model_validator | ||
| from pydantic import BaseModel, ValidationInfo, field_validator, model_validator | ||
|
|
||
| from constants import RESPONSES_REQUEST_MAX_SIZE | ||
| from models.common.query import SolrVectorSearchRequest | ||
|
|
@@ -106,7 +106,7 @@ class ResponsesRequest(BaseModel): | |
|
|
||
| @model_validator(mode="before") | ||
| @classmethod | ||
| def validate_body_size(cls, values: Any) -> Any: | ||
| def validate_body_size(cls, values: Any, info: ValidationInfo) -> Any: | ||
| """Validate that the request body does not exceed the maximum allowed size. | ||
|
|
||
| Serializes the raw request payload to JSON and checks the total character | ||
|
|
@@ -132,10 +132,15 @@ def validate_body_size(cls, values: Any) -> Any: | |
| # model instances). The size guard only applies to wire-format HTTP | ||
| # requests which FastAPI always parses into JSON-compatible dicts. | ||
| return values | ||
| if len(serialized) > RESPONSES_REQUEST_MAX_SIZE: | ||
|
|
||
| max_size = (info.context or {}).get( | ||
| "responses_request_max_size", RESPONSES_REQUEST_MAX_SIZE | ||
| ) | ||
|
Comment on lines
+136
to
+138
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
# Inspect request entrypoints and producers of the configured limit.
rg -n -C 4 'ResponsesRequest|responses_request_max_size|model_validate\s*\(' src -g '*.py'Repository: lightspeed-core/lightspeed-stack Length of output: 23396 🏁 Script executed: set -o pipefail
printf '%s\n' '--- configured key references ---'
rg -n -C 6 -F -- 'responses_request_max_size' . -g '*.py' -g '*.yaml' -g '*.yml' -g '*.toml' -g '*.json' || test "$?" -eq 1
printf '%s\n' '--- endpoint definition and route decorators ---'
sed -n '450,515p' src/app/endpoints/responses.py
printf '%s\n' '--- app/router validation hooks ---'
rg -n -C 5 -e 'APIRoute|request.*context|context=.*configuration|validation.*context|model_validate_json|TypeAdapter' src/app src -g '*.py' || test "$?" -eq 1
printf '%s\n' '--- changed file imports and validator ---'
sed -n '1,155p' src/models/api/requests/responses_openai.py
printf '%s\n' '--- PR diff ---'
git diff --find-renames 3e8f1484d5ce41e305968ca198f8fdc8baa0d5f5 14ed214572765076f6656fb62a5b754026b1cd19 -- src/models/api/requests/responses_openai.py src/app/endpoints/responses.pyRepository: lightspeed-core/lightspeed-stack Length of output: 41947 🏁 Script executed: set -o pipefail
printf '%s\n' '--- exact configured key and constant references ---'
rg -n -C 5 --glob '*.py' --glob '*.yaml' --glob '*.yml' --glob '*.toml' --glob '*.json' -F -- 'responses_request_max_size' . || test "$?" -eq 1
rg -n -C 5 --glob '*.py' -F -- 'RESPONSES_REQUEST_MAX_SIZE' src tests || test "$?" -eq 1
printf '%s\n' '--- application construction and router registration ---'
rg -n -C 6 --glob '*.py' -e 'FastAPI\s*\(' -e 'include_router\s*\(' -e 'APIRoute' -e 'route_class' src . || test "$?" -eq 1
printf '%s\n' '--- request validation and dependency binding ---'
rg -n -C 6 --glob '*.py' -e 'ResponsesRequest' -e 'Depends\s*\(' src/app src/main.py src 2>/dev/null || test "$?" -eq 1Repository: lightspeed-core/lightspeed-stack Length of output: 41175 Pass the configured limit into
🤖 Prompt for AI Agents |
||
|
|
||
| if len(serialized) > max_size: | ||
| raise ValueError( | ||
| f"Request body size ({len(serialized)} characters) exceeds maximum " | ||
| f"allowed size of {RESPONSES_REQUEST_MAX_SIZE} characters" | ||
| f"allowed size of {max_size} characters" | ||
| ) | ||
| return values | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Import
ValidationInfobefore using it in the annotation.ValidationInfois undefined. The annotation raisesNameErrorwhen this module loads. Unit and integration test collection, schema generation, and type checks fail in the supplied pipeline logs. ImportValidationInfofrompydanticalongside the other validator imports. (docs.pydantic.dev)🧰 Tools
🪛 GitHub Actions: Integration tests / 1_integration_tests (3.13).txt
[error] 109-109: The integration test step
uv run pytest tests/integration --cov=src --cov=runner --cov-report term-missingfailed during collection:NameError: name 'ValidationInfo' is not defined. This caused 25 collection errors.🪛 GitHub Actions: Integration tests / 2_integration_tests (3.12).txt
[error] 109-109: Integration test collection failed when running
uv run pytest tests/integration --cov=src --cov=runner --cov-report term-missing: NameError: name 'ValidationInfo' is not defined. This caused 25 collection errors and the command exited with code 2.🪛 GitHub Actions: Integration tests / integration_tests (3.12)
[error] 109-109: Command 'uv run pytest tests/integration --cov=src --cov=runner --cov-report term-missing' failed during test collection: NameError: name 'ValidationInfo' is not defined. This caused 25 integration test collection errors and the process exited with code 2.
🪛 GitHub Actions: Integration tests / integration_tests (3.13)
[error] 109-109: The step
uv run pytest tests/integration --cov=src --cov=runner --cov-report term-missingfailed during test collection:NameError: name 'ValidationInfo' is not definedinResponsesRequest.validate_body_size. This caused 25 integration test collection errors.🪛 GitHub Actions: OpenAPI (Spectral) / 0_spectral.txt
[error] 109-109: The OpenAPI schema generation step (
uv run python scripts/generate_openapi_schema.py /tmp/openapi-generated.json) failed withNameError: name 'ValidationInfo' is not defined.🪛 GitHub Actions: OpenAPI (Spectral) / spectral
[error] 109-109: OpenAPI schema generation failed while running
uv run python scripts/generate_openapi_schema.py /tmp/openapi-generated.json:NameError: name 'ValidationInfo' is not definedinvalidate_body_size.🪛 GitHub Actions: Pyright / 0_Pyright.txt
[error] 109-109: uv run pyright src failed: "ValidationInfo" is not defined (reportUndefinedVariable).
🪛 GitHub Actions: Pyright / Pyright
[error] 109-109: uv run pyright src failed: "ValidationInfo" is not defined (reportUndefinedVariable).
🪛 GitHub Actions: Ruff / 0_ruff.txt
[error] 109-109: Ruff F821: Undefined name
ValidationInfo. Theruff check src tests --per-file-ignores=tests/*:S101 --per-file-ignores=scripts/*:S101step failed.🪛 GitHub Actions: Ruff / ruff
[error] 109-109: Ruff F821: Undefined name
ValidationInfo. Theruff check src tests --per-file-ignores=tests/*:S101 --per-file-ignores=scripts/*:S101step failed.🪛 GitHub Actions: Type checks / 0_mypy.txt
[error] 109-109: mypy reported that the name "ValidationInfo" is not defined (name-defined). The type-checking command failed with exit code 1.
🪛 GitHub Actions: Type checks / mypy
[error] 109-109: mypy failed: Name "ValidationInfo" is not defined (name-defined). Command:
uv run mypy --explicit-package-bases --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs --ignore-missing-imports --disable-error-code attr-defined src/.🪛 GitHub Actions: Unit tests / 0_unit_tests (3.13).txt
[error] 109-109: Command 'uv run pytest tests/unit --cov=src --cov=runner --cov-report term-missing' failed during conftest import: NameError: name 'ValidationInfo' is not defined in ResponsesRequest.validate_body_size.
🪛 GitHub Actions: Unit tests / 1_unit_tests (3.12).txt
[error] 109-109: Command 'uv run pytest tests/unit --cov=src --cov=runner --cov-report term-missing' failed with exit code 4 while loading pytest conftest. NameError: name 'ValidationInfo' is not defined in the validate_body_size type annotation.
🪛 GitHub Actions: Unit tests / unit_tests (3.12)
[error] 109-109: The
uv run pytest tests/unit --cov=src --cov=runner --cov-report term-missingstep failed while loading the test configuration:NameError: name 'ValidationInfo' is not definedin theResponsesRequest.validate_body_sizeannotation.🪛 GitHub Actions: Unit tests / unit_tests (3.13)
[error] 109-109: The
uv run pytest tests/unit --cov=src --cov=runner --cov-report term-missingstep failed while loading conftest:NameError: name 'ValidationInfo' is not definedinResponsesRequest.validate_body_size.🤖 Prompt for AI Agents
Source: Pipeline failures