Skip to content

scheduler: answer an over-capacity vision request with 400, not a retryable 500 (#180) - #206

Merged
AzeezIsh merged 2 commits into
mainfrom
fix/vision-capacity-400
Oct 27, 2026
Merged

AzeezIsh merged 2 commits into
mainfrom
fix/vision-capacity-400

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Addresses ask 2 of #180. It does not lift the per-request row cap (ask 1).

What

On TP, a request whose images need more encoder rows than one encode holds fails in vision_transport::validate_state (vision row count 16680 exceeds encoder capacity 16384). That was a plain anyhow error, so blocking clients got a 500 and agent clients resent the same history forever (#180: 18 retries over 80 minutes).

  • validate_state now returns a typed VisionCapacityError { rows, capacity, images }. Its message names all three and tells the client to drop or downscale images.
  • A new lifecycle::send_prefill_error_to_sink routes that error through send_invalid_request_to_sink (HTTP 400; SDKs do not retry 400) in both prefill entry points (prefill_a_step, prefill_b_step). Every other prefill error is unchanged. Streaming clients keep their error frame.

Single-GPU serving never reaches this check: forward_oversized_fallback encodes images one at a time.

For reference, Enntity's fork fixed both asks in 92dd5435: the row window is sized to one prefill chunk, plus 400 vision_input_too_large / 503 vision_capacity_busy. That is a larger change, for upstream to take or not.

Tests

  • New vision_transport::tests::over_capacity_is_a_typed_error. It also checks that the error type survives an added anyhow context, which is the property the scheduler relies on.
  • On sparky against main 504063a:
    • cargo test -p spark-model --lib -- vision_transport: 5 passed.
    • fmt and clippy are clean.
  • I have not reproduced this live: that needs a TP=2 vision setup.

🤖 Generated with Claude Code

…ryable 500 (#180)

A TP request whose images need more encoder rows than one encode holds
failed in validate_state with a plain anyhow error, which the API mapped
to 500. Agent clients resend the same history on 500, so the session
retried forever (#180: 18 retries over 80 min). validate_state now
returns a typed VisionCapacityError naming rows, image count and cap,
and both prefill entry points route it through send_invalid_request_to_sink
(HTTP 400 for blocking clients; streaming keeps its error frame).

Does not lift the cap itself (#180 ask 1).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

I ran an adversarial review on this PR (Qwen3.8-Max) and checked each claim against the code.

Fixed in 1abf05704

  • Streaming clients still got a 500. send_invalid_request_to_sink sent streaming clients the same StreamEvent::Error as any failure, and chat_stream/handle_error.rs always renders {"type":"server_error","code":500}. opencode, Qwen vision: per-request row cap (CEILING_MAX_PATCHES 16384) makes multi-image agent histories unservable; over-cap requests get retried forever #180's client, streams, so the first commit did not help it.
    • New StreamEvent::InvalidRequest, rendered as {"type":"invalid_request_error","code":400}.
    • /v1/responses and /v1/messages streaming consume the chat stream's deltas, so they inherit it.
    • Side effect, which I think is correct: the other send_invalid_request_to_sink callers (strict response_format, oversize tool grammar) now send the same 400 on the stream that they already returned to blocking clients.
  • The field said images but counts grid_count. For video, grids are not images, so it is now named grids. I also added a negative test: an error flattened to a string (anyhow!("{e:#}")) loses the type, which pins down that callers must pass the error itself.

Checked; no change needed

  • TP hang if the leader fails after the worker entered the collective: cannot happen. impl_a2_ep_vision.rs runs validate_state before the command preamble, on purpose ("Otherwise rank 0 could enter the payload collective with metadata that rank 1 rejects first"). After the error, the prefill error path frees the sequence and broadcasts 0xFFFFFFF1 to the worker.
  • Other entry points: ep_broadcast_vision_state_for_seq is called only from chunk 0 (prefill_a_step/vision_dispatch.rs, plus the deferred path with vision disabled) and from prefill_b_step. Later chunks do not re-send vision state, so both sites are covered.
  • Worker-side typed error: the worker validates against the same output_rows() capacity, so on a symmetric pair it never sees a state that the leader passed.

Not done

  • No live TP=2 vision repro. Unit tests, fmt, clippy and the release build are rerunning on sparky now.

🤖 Generated with Claude Code

…grids, not images

Peer review of the first commit: a streaming request (opencode, #180's
client) still got the generic server_error/500 frame, because
send_invalid_request_to_sink sent the same StreamEvent::Error as any
failure. Add StreamEvent::InvalidRequest; the chat stream renders it as
{type: invalid_request_error, code: 400}, and /v1/responses and
/v1/messages streaming inherit it through the chat stream's deltas.
send_invalid_request_to_sink's other callers (strict response_format,
oversize tool grammar) now match their blocking 400 on the stream too.

VisionCapacityError counts grids (grid_count), which is not an image
count for video; say so. Test that a stringified error loses the type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Pushed as fcf3fd3 (the earlier comment cited 1abf05704, the pre-rustfmt version of the same commit). Retest on sparky at main + #205 + #206: cargo fmt --check OK; spark-model vision_transport 5/5; spark-server --bin spark (glm_tool_boundary, chat_blocking, refusal, handle_error, lifecycle) 60/60; clippy -D warnings clean.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Live gate, part 1: BFCL golden ST-995 = 87.44 / 87.32 (n=995, run-1792760075267807876). This was on sparky (GB10), FP4-Local, recipe profile, on a binary built from main 504063a + #205 + #206 at their PR heads (sha256 64bbdec27bd2ffea). That is identical to main's 87.44 / 87.32, so the change is accuracy-neutral. The serve log over the run has only the five standard startup WARNs and 0 ERROR lines. The agentic-webserver 50-iteration leg on the same server is running now, and I'll post it here.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Live gate, part 2: agentic-webserver, 50 iterations, passes: 50/50 webserver_ok, 50/50 followed_directions, 12.344 s/turn, Σwall 4,705 s (run-1792764782219366004). Same server and binary as the BFCL leg (main 504063a + #205 + #206). For comparison, main on the same profile measured 12.43 s/turn. The combined gate passes on both legs: BFCL unchanged at 87.44 / 87.32, agentic 50/50.

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Riding integration train #212 (integ/train-2026-10-27, merged --no-ff at this PR's current head). It's being gated on sparky (GB10) now: control vs main, then agentic-webserver 50 + BFCL ST-995 on FP4-Local. The plan is to merge the train once both legs pass and CI shows only the repo-wide reds, which merges this PR. Results will land on #212 and in the campaign log (#211).

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