Skip to content

[sgl-router] Book the input_ids forwarding outcome only for built bodies - #41307

Closed
ShangmingCai wants to merge 1 commit into
sgl-project:kan/sgl-router-improvefrom
ShangmingCai:smc/input-ids-forwarding-book-after-build
Closed

ShangmingCai wants to merge 1 commit into
sgl-project:kan/sgl-router-improvefrom
ShangmingCai:smc/input-ids-forwarding-book-after-build

Conversation

@ShangmingCai

@ShangmingCai ShangmingCai commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #41185 (targets its branch, so it folds into that PR): move the sgl_router_input_ids_forwarding_total booking to after build_outgoing_body succeeds, so a request rejected while building the outgoing body never counts as dispatched.

The corner it closes

There is exactly one reachable book-then-400 path, and it needs all of:

  1. a body with an f64-overflow numeric literal (e.g. "temperature": 1e400) — the routing-fields fallback (parse_without_sampling_values) accepts it via IgnoredAny, but serde_json::from_slice::<Value> rejects it (number out of range);
  2. needs_tokens == false (forwarding off / no chat formatter, non-token policy, no bucket routing), so parsed_body is None and ingress never parses the full body;
  3. PD mode, whose bootstrap-field injection forces the full re-parse in build_outgoing_body (the non-PD rid/sampling path splices raw bytes and never parses).

That request booked disabled, then the client got a 400 and nothing was dispatched — violating the counter's "exactly once per dispatched request" contract. Verified reachable end to end: a PD worker pair plus a 1e400 body books disabled on the base branch despite the 400 response.

Every other outcome is safe by construction: forwarded / tokenize_failed imply can_forward_input_ids, which guarantees the cached parse, where the build has no failure path. So reordering loses no error bookings, and sgl_router_ingress_tokenize_errors_total semantics are unchanged.

Modifications

  • into_outgoing_body: build the outgoing body first, book record_input_ids_forwarding (and the TokenizeFailed ingress-error bump) only on the Ok path.

Test plan

  • cargo clippy --all-targets -- -D warnings
  • cargo test: all suites pass
  • Reproduced the corner end to end against the base branch (PD pair + 1e400 body → 400 yet disabled booked); with this change nothing is booked

🤖 Generated with Claude Code

A body with an f64-overflow literal (e.g. temperature:1e400) passes the
routing-fields fallback, skips the ingress parse when no tokenization is
needed, and is only rejected by the PD bootstrap re-parse in
build_outgoing_body - after the forwarding outcome was already booked.
Book the metric once the outgoing body exists, so a 400 never counts as
a dispatched request. TokenizeFailed booking is unaffected: it implies a
cached parse, where the build has no failure path.

Co-Authored-By: Claude Fable 5 <[email protected]>
@ShangmingCai
ShangmingCai deleted the branch sgl-project:kan/sgl-router-improve September 26, 2026 05:09
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