Skip to content

[Bug] Run the E+PD encode stage when a replica inflight cap is set - #3200

Merged
varungup90 merged 4 commits into
vllm-project:mainfrom
theminjunchoi:fix/epd-encode-with-inflight-cap
Oct 21, 2026
Merged

varungup90 merged 4 commits into
vllm-project:mainfrom
theminjunchoi:fix/epd-encode-with-inflight-cap

Conversation

@theminjunchoi

Copy link
Copy Markdown
Contributor

Pull Request Description

With requestsInflight set, selectTargetPod returned straight from routeWithEarlyAdmission, so the encodeMedia call after Route never ran and E+PD requests skipped their roleset's encoders. Responses were still correct, since the serving pod encodes missing items itself, but the encode offload was lost.

Both routing paths now fall through to a single encodeMedia call, so a new branch can't skip it the same way. I added the case from the issue (two serving pods, requestsInflight of 1) to Test_selectTargetPod_EPlusPD; it fails on main and passes with this change. go test -race ./pkg/plugins/gateway/... passes.

Thanks to @Jackmeson1 for the report and repro.

Related Issues

Resolves: #3198

With requestsInflight set, selectTargetPod returned straight from
routeWithEarlyAdmission and never reached the encodeMedia call after Route,
so multimodal requests skipped their roleset's encoders. Route through either
path and run the encode stage once afterwards.

Signed-off-by: MinJun Choi <[email protected]>
Add the case from vllm-project#3198: two serving pods and requestsInflight of 1.

Signed-off-by: MinJun Choi <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the selectTargetPod function in gateway.go to ensure that media encoding is performed when routing with early admission (when a replica inflight limit is configured), rather than returning early. It also adds a new test case in gateway_epd_test.go to verify this behavior under an inflight limit. There are no review comments, and I have no feedback to provide.

@varungup90 varungup90 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation: approve with nits. The fix is correct and small, and the new test fails without it. Two nits concern the interaction with the inflight cap, which the PR now makes reachable. This is a review comment, not a formal GitHub approval.

What I checked (head b224022e)

  • The bug is as described. On main, the capped path was return s.routeWithEarlyAdmission(...), which left selectTargetPod before the if err == nil { s.encodeMedia(...) } below it, so E+PD media was never offered to the roleset's encoders when requestsInflight was set. The PR assigns addr, err from either route call and keeps one encodeMedia call after both. err is the variable already declared by Select above, so the assignment is fine.
  • PD requests are not double-encoded. For pd, selectTargetPod does not split the encoders off (if !isPD { … SplitEncoders }), so encoders is nil and encodeMedia returns at its first line. The PD router runs its own encode stage, as Test_selectTargetPod_PDKeepsEncoders covers.
  • The single-candidate fast path is unaffected: it already calls encodeMedia before returning.

What I ran (scratch worktree at the head, Go 1.24.7)

  • gofmt -l and go vet on pkg/plugins/gateway are clean. go test -race -count=1 ./pkg/plugins/gateway/... passed (all 16 packages).
  • Fail-before: I restored main's gateway.go and kept the PR's test. Test_selectTargetPod_EPlusPD/media_is_encoded_with_a_replica_inflight_cap fails.
  • Mutants of gateway.go:
    • skip encodeMedia on the capped path (the original bug): killed by that subtest;
    • encode even when routing failed (drop the err == nil guard): survives.
  • CI at the time of review: Go Lint and Unit Tests, Go Integration Tests, Installation Smoke / Helm, DCO and triage are green. Installation E2E Tests was still running, and build was skipped. I did not wait for the E2E job.

Not run: golangci-lint locally, and a real encoder.

Nits (non-blocking)

  1. A failed route must not encode, and nothing pins that. Dropping the err == nil guard keeps every test green. That guard now matters: with the cap set, a full target makes an admission-aware router fail Route (ErrTargetReplicaInflightExceeded), and the guard is what stops an E+PD request that is about to get a 429 from paying for the encode HTTP calls. I wrote a throw-away probe (deleted afterwards) with one full pod: a router that calls AdmitTarget gets that error and 0 encodes, as intended. A subtest like that with the encoder counter at 0 would pin it.
  2. Routers that do not call AdmitTarget still encode before admission. Using the same probe with the plain firstPodRouter, selectTargetPod returns success and the encoder is called once for a pod that is at its cap. The cap is only enforced afterwards, in enforceReplicaInflight, which runs after selectTargetPod. So under saturation these requests still pay for an encode and are then rejected, which is what I noted on #3153. It is not a regression from this PR, since before it the encode never ran with a cap. If it matters, running the encode stage after the admission step, in HandleRequestBody, would fix it for every router. I would not hold this PR for that.

Verdict: approve with nits. It restores the encode offload for capped E+PD deployments, and the new case pins the reported scenario.


Generated by Claude Code

varungup90 and others added 2 commits October 20, 2026 10:57
With a replica inflight cap, a router that admits its target fails Route
when the target is full. Check that selectTargetPod returns that error
without calling the encoders.

Signed-off-by: MinJun Choi <[email protected]>
@theminjunchoi

Copy link
Copy Markdown
Contributor Author

@varungup90 Thanks! I added Test_selectTargetPod_EPlusPDFullTargetSkipsEncode for the first nit: one full pod, a router that calls AdmitTarget, and it checks that routing fails with ErrTargetReplicaInflightExceeded and the encoder is never called. With the err == nil guard removed, the test now fails.

On the second one, agreed that routers that don't call AdmitTarget still encode before the cap is checked. That was already the case before this PR, though, so I've left it out of this one.

@varungup90
varungup90 merged commit 60c8f28 into vllm-project:main Oct 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] E+PD requests skip the encode stage when requestsInflight is set

2 participants