Repository navigation
fix(gateway): refuse bodies without items or with a non-string text - #1002
Draft
ShaiShmuel wants to merge 1 commit into
Draft
ShaiShmuel wants to merge 1 commit into
ShaiShmuel wants to merge 1 commit into
Conversation
A native encode or extract body without `items` (or the `input` /
`inputs` aliases) was read as one item built from the whole body. When
the body carried no item content, e.g. `{"params": {...}}`, that empty
item was dispatched and failed in the worker with a 500. The gateway now
answers 400 INVALID_REQUEST "field 'items' is required" for such bodies,
on the JSON and msgpack paths alike. A body that is itself one item
(`text`, `images`, `audio`, `video` or `document` at the top level) is
still accepted as before.
Encode and score items, and the score query, now also reject a `text`
that is neither a string nor null with a 400 naming the path, e.g.
"items[0].text must be a string or null", matching the existing extract
check.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
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 native
POST /v1/encode/{model}or/v1/extract/{model}body withoutitems(and without theinput/inputsaliases) was read as one item built from the whole body. When the body carried no item content, such as{"params": {"output_types": ["dense"]}}, that empty item was dispatched and failed in the worker with a 500 (all_items_failed, "... requires text input"). A non-stringtextinside an encode or score item, such as{"items": [{"text": 5}]}, also passed the gateway and only failed in the worker.Change
Both checks run in the shared parser, so JSON and msgpack bodies behave the same. Errors use the existing 400
INVALID_REQUESTenvelope, the same one already returned for{"items": "x"}.items, noinputorinputsalias, and no item content field (text,images,audio,video,document) now gets 400Failed to parse request body: field 'items' is required.{"text": "hello"}or{"images": [...]}, is still accepted as before. It is not in the published schema, but it works today, so it is kept.textor the scorequery.textthat is neither a string nor null now gets 400items[i].text must be a string or null(orquery.text ...). This matches the existing extract check and theItem.text: str | Nonecontract.nulland absenttext, as in media-only items, still pass.itemswith a 400 and is unchanged. Generate is not touched. The OpenAI-compatible embeddings, rerank and System One routes always build a body withitems, so they are unaffected.Compatibility
This only adds 400s for bodies that previously reached a worker and failed there. Every valid body is accepted as before. There is no schema change, so the OpenAPI specs are not regenerated.
Validation
mise exec -- cargo fmt -p sie-gateway -- --check: passedmise exec -- cargo clippy --locked -p sie-gateway --all-targets -- -D warnings: passedmise exec -- cargo test --locked -p sie-gateway: 1912 passed, 8 ignored, plus the crate's integration test binariesNew unit tests cover:
itemson encode and extract, in JSON and msgpack, rejected with the field namedINVALID_REQUESTresponse for a missingitemstextrejected for encode items, score items and the score query, in both formatstext, including multimodal items, still accepted