Repository navigation
[TRTLLM-8489][feat] Support stream interval for Responses API - #10109
JunyiXu-nv wants to merge 1 commit into
Conversation
38fda8b to
f3663d9
Compare
Signed-off-by: Junyi Xu <219237550+JunyiXu-nv@users.noreply.github.com>
f3663d9 to
b0c20c4
Compare
|
/bot run |
📝 WalkthroughWalkthroughThis pull request modifies streaming response handling in the Harmony adapter and response utilities. Method signatures are updated to return tuples including a contents dictionary alongside messages. Streaming delta emission logic is refactored to handle reasoning deltas, text deltas, and final content separately with improved state management across Harmony and non-Harmony paths. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tensorrt_llm/serve/harmony_adapter.py (1)
148-191:⚠️ Potential issue | 🔴 CriticalCritical: content deltas are accumulated before
parser.process(token), producing off-by-one shifted output.In the existing
process_token_batchmethod (line 141),last_content_deltais read afterself.parser.process(token). Inprocess_token_batch_to_messages, the contents accumulation at lines 162-164 readsself.parser.last_content_deltabeforeself.parser.process(token). This creates a timing mismatch:
- Each iteration appends the delta from the previous token, not the current one.
- The delta from the last token in every batch is never included in that batch's
contents.- The first iteration may capture a stale delta from the parser's previous state.
Move the content accumulation block after
self.parser.process(token)to match the pattern inprocess_token_batchand ensure each token's delta is correctly captured in the current batch.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tensorrt_llm/serve/harmony_adapter.py` around lines 148 - 191, process_token_batch_to_messages has the content accumulation happening before calling self.parser.process(token), causing off-by-one deltas; move the block that reads/updates contents using self.parser.last_content_delta so it runs after self.parser.process(token) (same pattern as process_token_batch) to ensure each token's delta is captured for the current token and the final token's delta isn't dropped; keep the existing logic that initializes contents[self.parser.current_channel] and reading self.parser.current_channel/current_recipient but perform those reads after processing the token.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tensorrt_llm/serve/responses_utils.py`:
- Around line 1559-1567: The code currently yields a reasoning/text delta event
even when the delta is whitespace-only, which can emit a delta before the
corresponding output-item-added/content-part-added events; update the logic in
the block handling reasoning_delta_text (and the analogous block for delta_text)
so that the yield of
streaming_events_helper.get_reasoning_text_delta_event(reasoning_delta_text)
(and streaming_events_helper.get_text_delta_event(delta_text)) is only executed
after you have emitted the added events — either by moving the delta yield
inside the if reasoning_delta_text.strip() branch or by forcing
streaming_events_helper.get_reasoning_output_added_events()/get_output_added_events()
to run whenever a delta is truthy; ensure you reference the existing helpers
(streaming_events_helper.is_reasoning_sent, get_reasoning_output_added_events,
get_reasoning_text_delta_event, get_output_added_events, get_text_delta_event)
when making the change.
---
Outside diff comments:
In `@tensorrt_llm/serve/harmony_adapter.py`:
- Around line 148-191: process_token_batch_to_messages has the content
accumulation happening before calling self.parser.process(token), causing
off-by-one deltas; move the block that reads/updates contents using
self.parser.last_content_delta so it runs after self.parser.process(token) (same
pattern as process_token_batch) to ensure each token's delta is captured for the
current token and the final token's delta isn't dropped; keep the existing logic
that initializes contents[self.parser.current_channel] and reading
self.parser.current_channel/current_recipient but perform those reads after
processing the token.
| # Reasoning delta may exist with text delta | ||
| if reasoning_delta_text: | ||
| if reasoning_delta_text.strip(): | ||
| if not streaming_events_helper.is_reasoning_sent: | ||
| streaming_events_helper.is_reasoning_sent = True | ||
| yield from streaming_events_helper.get_reasoning_output_added_events( | ||
| ) | ||
| yield streaming_events_helper.get_reasoning_text_delta_event( | ||
| reasoning_delta_text) |
There was a problem hiding this comment.
Reasoning delta emitted before output-item-added when text is whitespace-only.
If reasoning_delta_text is truthy but contains only whitespace (e.g. " "), the strip() check on Line 1561 is falsy so the output-item-added / content-part-added events are skipped, yet the reasoning text delta event on Line 1566 is still yielded. This violates the Responses API streaming protocol, which expects response.output_item.added and response.content_part.added to precede any delta event for that item.
The same pattern exists for delta_text on Lines 1588-1593.
Proposed fix: gate the delta yield behind the added-events guard, or always send added events when any delta is emitted
# Reasoning delta may exist with text delta
if reasoning_delta_text:
- if reasoning_delta_text.strip():
- if not streaming_events_helper.is_reasoning_sent:
- streaming_events_helper.is_reasoning_sent = True
- yield from streaming_events_helper.get_reasoning_output_added_events(
- )
+ if not streaming_events_helper.is_reasoning_sent:
+ streaming_events_helper.is_reasoning_sent = True
+ yield from streaming_events_helper.get_reasoning_output_added_events()
yield streaming_events_helper.get_reasoning_text_delta_event(
reasoning_delta_text)
# ...
# Send delta events for ongoing content
if delta_text:
- if delta_text.strip():
- if not streaming_events_helper.is_text_sent:
- streaming_events_helper.is_text_sent = True
- yield from streaming_events_helper.get_message_output_added_events()
+ if not streaming_events_helper.is_text_sent:
+ streaming_events_helper.is_text_sent = True
+ yield from streaming_events_helper.get_message_output_added_events()
yield streaming_events_helper.get_text_delta_event(delta_text, [])Alternatively, if there is a deliberate reason to skip whitespace-only leading deltas, move the delta yield inside the if .strip(): block as well.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tensorrt_llm/serve/responses_utils.py` around lines 1559 - 1567, The code
currently yields a reasoning/text delta event even when the delta is
whitespace-only, which can emit a delta before the corresponding
output-item-added/content-part-added events; update the logic in the block
handling reasoning_delta_text (and the analogous block for delta_text) so that
the yield of
streaming_events_helper.get_reasoning_text_delta_event(reasoning_delta_text)
(and streaming_events_helper.get_text_delta_event(delta_text)) is only executed
after you have emitted the added events — either by moving the delta yield
inside the if reasoning_delta_text.strip() branch or by forcing
streaming_events_helper.get_reasoning_output_added_events()/get_output_added_events()
to run whenever a delta is truthy; ensure you reference the existing helpers
(streaming_events_helper.is_reasoning_sent, get_reasoning_output_added_events,
get_reasoning_text_delta_event, get_output_added_events, get_text_delta_event)
when making the change.
|
PR_Github #36454 [ run ] triggered by Bot. Commit: |
|
PR_Github #36454 [ run ] completed with state
|
|
/bot run |
|
PR_Github #36620 [ run ] triggered by Bot. Commit: |
|
PR_Github #36620 [ run ] completed with state
|
|
👋 As part of an effort to reduce the TensorRT-LLM open-PR backlog, we're checking in on PRs with no activity in over 120 days. This one qualifies. Could you let us know whether you still plan to land it?
If we don't hear back within 14 days, we'll close this PR to keep the review queue manageable. Closing isn't a rejection: the branch, commits, and discussion are all preserved, and you can reopen or resubmit at any time. Thanks for the contribution! |
|
👋 Closing this as part of the TensorRT-LLM open-PR backlog cleanup. We pinged on 2026-08-10 about 120+ days of inactivity and didn't hear back within the 14-day window. This isn't a rejection — your branch, commits, and discussion are all preserved. If it's still relevant, just reopen the PR any time and we'll pick it back up; please rebase onto the latest |
Summary by CodeRabbit
Description
Waiting for #9908.
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.