Skip to content

fix(servicer): never fail a served request on a media identity it cannot build - #2652

Merged
slin1237 merged 1 commit into
mainfrom
fix/guard-media-identity-build
Sep 23, 2026
Merged

slin1237 merged 1 commit into
mainfrom
fix/guard-media-identity-build

Conversation

@hello-alexmcc

Copy link
Copy Markdown
Collaborator

Description

Problem

From the review of #2627: on a PD prefill leg the servicer calls build_media_identity(prompt) after self._mm_processor.process(...) has already succeeded, and the engine has already answered. build_media_identity can raise on shapes it did not anticipate: prompt["prompt_token_ids"] evaluated before its early return, torch.stack over grids of mixed dtypes (only shapes are checked), prompt_token_ids[r.offset + first], torch.as_tensor on a non-tensor element. Any of those turned a request the engine had served into an error to the client. The identity is an optimisation with a working fallback: the router warns and the decode leg reprocesses the media.

Solution

The build is wrapped: a failure logs Request %s: media identity not built (%s); the decode leg will reprocess the media, with the request id and the exception, and the leg answers without an identity.

Test Plan

  • test_vllm_pd_media_identity.py::test_an_identity_that_cannot_be_built_does_not_fail_the_request (vLLM lane, like the rest of that file): build_media_identity raises, the request completes with its output ids and no identity, and the warning names the cause.
  • pytest grpc_servicer/tests: 406 passed, 10 skipped (vLLM-gated). Ruff clean.
Checklist
  • cargo +nightly fmt passes (no Rust change)
  • cargo clippy --all-targets -- -D warnings passes (no Rust change)
  • (Optional) Documentation updated
  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs

…not build

build_media_identity ran after the engine had answered and could raise
on shapes it did not anticipate (a missing prompt_token_ids key, mixed
grid dtypes, a non-tensor element), turning a served request into a
client error. The identity is an optimisation with a fallback, decode
reprocessing the media, so the build is now guarded: a failure logs
one warning with the request id and the leg answers without it.

Signed-off-by: Alex McC <319643551+hello-alexmcc@users.noreply.github.com>
@github-actions github-actions Bot added grpc gRPC client and router changes tests Test changes labels Sep 23, 2026
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: e8407c96-b48e-44f5-a929-efbaa6f7bb65

📥 Commits

Reviewing files that changed from the base of the PR and between dceb98c and 076c8d4.

📒 Files selected for processing (2)
  • grpc_servicer/smg_grpc_servicer/vllm/servicer.py
  • grpc_servicer/tests/test_vllm_pd_media_identity.py

Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Media identity generation failures during prefill no longer fail the request; processing can continue so the decode stage can reprocess the media.

Walkthrough

Generate now catches exceptions during prefill media identity construction, logs a warning, and continues without a media identity. A regression test checks that the request completes and the warning includes the failure details.

Changes

Prefill media identity handling

Layer / File(s) Summary
Identity failure fallback and regression test
grpc_servicer/smg_grpc_servicer/vllm/servicer.py, grpc_servicer/tests/test_vllm_pd_media_identity.py
Generate logs identity-building failures and leaves the media identity unset. The test checks that processing runs once, output [42] is returned, and the warning includes the exception detail.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 076c8

The reported fallback lets affected requests complete when media identity construction fails. No actionable merge-blocking risk is identified; normal checks remain appropriate.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing media identity build failures from failing served requests.
Description check ✅ Passed The description directly explains the failure scenario, the guarded identity build, the fallback behavior, logging, and test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@claude

claude Bot commented Sep 23, 2026

Copy link
Copy Markdown

👋 The PR description doesn't fully follow
PULL_REQUEST_TEMPLATE.md:

  • Missing header: ## Changes

Please update the PR description so reviewers have the context they need.

Comment on lines +334 to +339
logger.warning(
"Request %s: media identity not built (%s); the decode leg "
"will reprocess the media",
request_id,
e,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit: This warning logs only str(e), which drops the exception type and traceback. For a bare KeyError — one of the failure modes this PR anticipates (prompt["prompt_token_ids"]) — the log reads media identity not built ('prompt_token_ids'), with no hint of what went wrong or where. Since this catch exists precisely for unanticipated shapes, the traceback is the diagnostic you'll want. This file already does that for the analogous best-effort fallback at _notify_kv_rejected (line 502-507): keep the message as-is and add exc_info=True (the test's getMessage() assertions are unaffected).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the full diff. The fallback is well-scoped: except Exception doesn't swallow cancellation, build_media_identity never mutates the prompt it reads, and the new test verifies the request completes, the identity is absent, and the warning names the cause. One 🟡 nit inline about logging the traceback (exc_info=True) to match this file's existing convention for unexpected-failure fallbacks.

@slin1237
slin1237 merged commit 115c33a into main Sep 23, 2026
31 of 38 checks passed
@slin1237
slin1237 deleted the fix/guard-media-identity-build branch September 23, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

grpc gRPC client and router changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants