#1080·ds4

Make the 16-image conversation limit configurable and batching-aware

Author: mvdbosCreated Sep 18, 2026Updated Sep 25, 2026

ds4-server rejects requests containing more than 16 images:

c
size_t count = 0;
for (int i = 0; msgs && i < msgs->len; i++)
    count += msgs->v[i].images.len;

if (count > 16) {
    snprintf(err, errlen, "too many images; at most 16 are allowed");
    return false;
}

This counts images across the submitted history, not only the newest turn.

DS4 requires Chat Completions and Anthropic clients to replay conversation history. Its Responses endpoint likewise rejects durable previous_response_id/conversation references and instructs clients to replay the full input.

The request limit therefore becomes a cumulative conversation limit. Once history contains 17 images, every subsequent request fails before inference, including text-only turns. Retrying cannot recover because it submits the same history. The client must rewrite or discard history, and the model cannot handle the condition because it never receives another turn.

This is easy to reach in agent workflows that retain screenshots or other image tool results.

Reproducer

Submit a request containing N small images:

Images Result
16 200
17 400: too many images; at most 16 are allowed

Append a text-only message and replay the same history. The request returns the same 400 before prefill.

Current implementation

The limit was introduced with server-side vision in 4771329 (2026-08-28). It is also embedded in replay bookkeeping:

  • Request validation rejects count > 16.
  • visible_image_key contains offsets[16].
  • visible_prompt_key rejects req->image_count > 16.
  • build_live_prompt_suffix rejects req->image_count > 16 and uses ds4_vision_span spans[16].

Later image-embedding caching avoids encoder execution on cache hits, although request-owned embedding memory still scales with image count.

Relation to --batched-session

Cold image encoding holds the global inference_mu. With --batched-session N>1, an image-heavy request can therefore delay other resident sessions, making a conservative default useful for fairness.

With one resident session, there is no cross-slot inference contention. Request memory and abuse protection still justify a limit, but the case for a low ceiling of 16 is weaker: the operator may prefer accepting higher latency or memory use over making the conversation unusable.

Requested change

Add:

--max-images N

Suggested defaults:

  • --batched-session N>1: default to 16.
  • One resident session: use a higher or resource-derived default.
  • An explicit --max-images value overrides either default.

Implementation would need to replace the fixed [16] replay structures and validation literals with the configured limit.

Also:

  • Document that replayed history counts toward the limit.

  • Include the actual and configured counts in the error:

    request contains 17 images; server limit is 16 (--max-images)

This preserves a conservative fairness bound for batched serving while allowing single-session and replay-heavy deployments to choose an appropriate limit.

Happy to make a PR if the solution direction is ok.