Skip to content

fix(router): account for all output blocks in response chunks - #14613

Merged
jthomson04 merged 1 commit into
ai-dynamo:mainfrom
bzsuni:fix/router-output-block-chunking
Sep 30, 2026
Merged

jthomson04 merged 1 commit into
ai-dynamo:mainfrom
bzsuni:fix/router-output-block-chunking

Conversation

@bzsuni

@bzsuni bzsuni commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Overview:

With --router-track-output-blocks enabled, the router undercounts output blocks when a response chunk crosses more than one block boundary.
This makes its local decode-load estimate depend on how the backend groups tokens into responses.

OutputBlockTracker advances its total to include all newly crossed blocks, but RequestGuard sends only one AddOutputBlock update. Later chunks cannot recover the missing blocks because the tracker has already advanced.

The fix carries the number of new blocks in OutputBlockUpdate and enqueues an update for each through the existing booking-checked scheduler path.
It leaves the decay formula, cleanup, and local-only load updates unchanged. Output-block tracking remains disabled by default; no backend or wire-format changes are needed.

Details:

The regression uses the actual request guard and scheduler, without GPU inference.
For a 16-token prompt, 48 output tokens, and block size 16, single-token chunks count 4 blocks before and after the fix. Grouping the same tokens as [1, 32, 15] exposes the bug.
SGLang's real output accumulator also produces this layout with stream_interval=32 in the CPU producer probe.

Recorded output for the grouped case:

Before — the regression fails:

track_output_blocks=true prompt_tokens=16 output_tokens=48 block_size=16 chunks=[1, 32, 15] initial_blocks=1 observed_blocks=3 expected_blocks=4

After — the same regression passes:

track_output_blocks=true prompt_tokens=16 output_tokens=48 block_size=16 chunks=[1, 32, 15] initial_blocks=1 observed_blocks=4 expected_blocks=4

Where should the reviewer start?

Related Issues

🚫 This PR is NOT linked to an issue:

  • Confirmed — no related issue

Summary by CodeRabbit

  • Bug Fixes

    • Improved scheduler block accounting across multiple block boundaries.
    • Preserved decay behavior and stopped processing after the first failed scheduler update.
    • Ensured output accounting remains consistent regardless of response chunking or prompt length.
    • Corrected cleanup behavior so active requests and tracked blocks reset properly.
  • Tests

    • Added coverage for boundary crossings, partial prompt blocks, decay behavior, and disabled tracking.

@bzsuni
bzsuni requested a review from a team as a code owner September 10, 2026 10:46
@copy-pr-bot

copy-pr-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@bzsuni
bzsuni temporarily deployed to external_collaborator September 10, 2026 10:46 — with GitHub Actions Inactive
@bzsuni
bzsuni temporarily deployed to external_collaborator September 10, 2026 10:46 — with GitHub Actions Inactive
@github-actions github-actions Bot added the fix label Sep 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi bzsuni! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added external-contribution Pull request is from an external contributor router Relates to routing, KV-aware routing, etc. labels Sep 10, 2026
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ef8dfd4c-2968-4456-bbec-3f96a2d17f85

📥 Commits

Reviewing files that changed from the base of the PR and between 287a8e7 and 6607d6c.

📒 Files selected for processing (2)
  • lib/llm/src/kv_router/routing_host/request_guard.rs
  • lib/llm/src/kv_router/routing_host/tests.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

Output block tracking now counts every crossed scheduler block. Request handling enqueues one update per crossed block. Tests cover boundary crossings, decay, disabled tracking, chunk invariance, scheduler load, cleanup, and configurable router setup.

Changes

Output block accounting

Layer / File(s) Summary
Crossed block update processing
lib/llm/src/kv_router/routing_host/request_guard.rs
OutputBlockTracker reports newly crossed blocks. Request processing enqueues one scheduler update for each crossed block and stops after the first enqueue failure. Tests cover boundaries, partial blocks, decay, zero output, and disabled tracking.
Chunk-invariant accounting validation
lib/llm/src/kv_router/routing_host/tests.rs
Tests verify consistent accounting across prompt sizes, response chunk layouts, and tracking settings. Router test construction now accepts a caller-provided KvRouterConfig and removes duplicated configuration setup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 6607d

The change corrects output-block accounting across scheduler boundaries without changing default behavior or wire formats. Regression coverage verifies boundary crossings, cleanup, decay, and disabled tracking, so it is merge-ready.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 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 identifies the router fix for accounting for all output blocks in response chunks. It accurately summarizes the main change.
Description check ✅ Passed The description explains the bug, implementation, regression coverage, expected behavior, and confirms that no issue is linked. The "Where should the reviewer start?" section is still empty, but this …
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

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

Comment thread lib/llm/src/kv_router/routing_host/tests.rs Outdated
Comment thread lib/llm/src/kv_router/routing_host/request_guard.rs Outdated
@bzsuni
bzsuni force-pushed the fix/router-output-block-chunking branch from 6607d6c to fbceccb Compare September 15, 2026 07:53
@bzsuni
bzsuni deployed to external_collaborator September 15, 2026 07:53 — with GitHub Actions Active
@bzsuni
bzsuni force-pushed the fix/router-output-block-chunking branch from fbceccb to b3c24a7 Compare September 21, 2026 12:05
@bzsuni
bzsuni deployed to external_collaborator September 21, 2026 12:05 — with GitHub Actions Active
@bzsuni
bzsuni force-pushed the fix/router-output-block-chunking branch from b3c24a7 to c5fc0c5 Compare September 29, 2026 09:19
@bzsuni
bzsuni deployed to external_collaborator September 29, 2026 09:19 — with GitHub Actions Active

@jthomson04 jthomson04 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.

Reviewed c5fc0c5. No new findings from the source review. Both earlier review comments are addressed. Tests were not run.

@jthomson04

Copy link
Copy Markdown
Contributor

/ok to test c5fc0c5

Track the number of block boundaries crossed by each response chunk and enqueue an update for every new block. Previously, a multi-block token delta advanced the tracker but added only one block to the scheduler load.

Add regression coverage using the real request guard and scheduler across output chunk sizes, partial prompt blocks, and disabled tracking. Preserve decay weighting and verify request cleanup.

Signed-off-by: bzsuni <bingzhe.sun@daocloud.io>
@jthomson04
jthomson04 force-pushed the fix/router-output-block-chunking branch from c5fc0c5 to 9664347 Compare September 30, 2026 04:36
@jthomson04
jthomson04 deployed to external_collaborator September 30, 2026 04:36 — with GitHub Actions Active
@jthomson04

Copy link
Copy Markdown
Contributor

/ok to test 9664347

@jthomson04

Copy link
Copy Markdown
Contributor

Non-blocking follow-up: with output tracking and agent_hints.osl enabled, this loop scans all output blocks once per new block to apply the same decay value. Now that #14666 has merged, we can batch the direct updates and apply decay once per chunk. I’d keep that optimization separate from this accounting fix.

Tracked in #15446.

@jthomson04
jthomson04 merged commit ae83593 into ai-dynamo:main Sep 30, 2026
119 checks passed

This branch was successfully deployed

1 active deployment
external_collaborator — 9664347e Deployed Sep 30, 2026 by jthomson04 via ok-to-test #23963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix router Relates to routing, KV-aware routing, etc. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants