Skip to content

fix(gateway): refuse bodies without items or with a non-string text - #1002

Draft
ShaiShmuel wants to merge 1 commit into
mainfrom
fix/gateway-items-required
Draft

ShaiShmuel wants to merge 1 commit into
mainfrom
fix/gateway-items-required

Conversation

@ShaiShmuel

Copy link
Copy Markdown
Contributor

Problem

A native POST /v1/encode/{model} or /v1/extract/{model} body without items (and without the input / inputs aliases) 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-string text inside 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_REQUEST envelope, the same one already returned for {"items": "x"}.

  • Missing items. An encode or extract body with no items, no input or inputs alias, and no item content field (text, images, audio, video, document) now gets 400 Failed to parse request body: field 'items' is required.
  • Single-item body kept. A body that is itself one item, such as {"text": "hello"} or {"images": [...]}, is still accepted as before. It is not in the published schema, but it works today, so it is kept.
  • Non-string text. In encode and score, an item text or the score query.text that is neither a string nor null now gets 400 items[i].text must be a string or null (or query.text ...). This matches the existing extract check and the Item.text: str | None contract. null and absent text, as in media-only items, still pass.
  • Unchanged routes and paths. Score already answered a missing items with a 400 and is unchanged. Generate is not touched. The OpenAI-compatible embeddings, rerank and System One routes always build a body with items, 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: passed
  • mise exec -- cargo clippy --locked -p sie-gateway --all-targets -- -D warnings: passed
  • mise exec -- cargo test --locked -p sie-gateway: 1912 passed, 8 ignored, plus the crate's integration test binaries

New unit tests cover:

  • missing items on encode and extract, in JSON and msgpack, rejected with the field named
  • the full 400 INVALID_REQUEST response for a missing items
  • the single-item body still accepted, both text and image-only
  • non-string text rejected for encode items, score items and the score query, in both formats
  • string, null and absent text, including multimodal items, still accepted

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>
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

1 participant