Skip to content

[None][fix] Enforce Responses conversation history capacity - #15043

Merged
zhaoyangwang-nvidia merged 2 commits into
NVIDIA:mainfrom
fallintoplace:fix/responses-history-capacity
Aug 9, 2026
Merged

[None][fix] Enforce Responses conversation history capacity#15043
zhaoyangwang-nvidia merged 2 commits into
NVIDIA:mainfrom
fallintoplace:fix/responses-history-capacity

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Description

ConversationHistoryStore is meant to cap the number of stored messages per conversation, but two store paths were trimming through a response id that either was not mapped yet or skipped trimming after appending final output messages.

This changes trimming to operate on the conversation id after the store path has selected the conversation. That keeps normal stored Responses requests within conversation_capacity and avoids the previous-response append path spinning without making progress.

Test Coverage

  • Added focused unit coverage in tests/unittest/llmapi/test_responses_utils.py for the pre-stored request path and previous-response append path.
  • pre-commit run --files tensorrt_llm/serve/responses_utils.py tests/unittest/llmapi/test_responses_utils.py
  • python3 -m py_compile tests/unittest/llmapi/test_responses_utils.py
  • Not run locally: python3 -m pytest tests/unittest/llmapi/test_responses_utils.py because this local Python environment does not have pytest installed.

PR Checklist

  • Please check this after reviewing the above items as appropriate for this PR.

Summary by CodeRabbit

  • Refactor

    • Updated ConversationHistoryStore to trim conversations by conversation_id.
    • Prevented trimming through unmapped response IDs.
    • Ensured trimming runs after final output messages are appended.
    • Prevented the previous-response append path from looping without progress.
  • Tests

    • Added test_store_response_trims_pre_stored_request_conversation().
    • Added test_store_response_trims_previous_response_conversation(monkeypatch).
    • Tests verify capacity trimming and response mapping consistency.

Dev Engineer Review

  • The implementation centralizes capacity trimming in _trim_conversation(conversation_id).
  • _pop_conversation delegates deletion to _pop_conversation_by_conversation_id.
  • Missing conversations are handled safely.
  • No public API declarations or configuration files changed.
  • No test-list files changed.
  • The focused implementation and test changes are consistent with the stated objective.

QA Engineer Review

  • Added test_store_response_trims_pre_stored_request_conversation().
  • Added test_store_response_trims_previous_response_conversation(monkeypatch).
  • These tests are unit tests outside tests/integration/test_lists/.
  • No test-db/ or qa/ coverage entries were added.
  • The unit test suite was not run because pytest was unavailable.
  • Verdict: needs follow-up.

@fallintoplace
fallintoplace requested a review from a team as a code owner June 6, 2026 14:00
@fallintoplace
fallintoplace requested a review from hchings June 6, 2026 14:00
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Review 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: 6d6b4de9-d1eb-4e26-b963-26eb4d06cadf

📥 Commits

Reviewing files that changed from the base of the PR and between 0b650e6 and 6b8372a.

📒 Files selected for processing (2)
  • tensorrt_llm/serve/responses_utils.py
  • tests/unittest/llmapi/test_responses_utils.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unittest/llmapi/test_responses_utils.py
  • tensorrt_llm/serve/responses_utils.py

Walkthrough

This PR centralizes conversation capacity trimming in ConversationHistoryStore. It adds helper methods for repeated range removal and missing-conversation handling. Unit tests cover pre-stored requests and chained responses.

Changes

Conversation History Trimming Refactor

Layer / File(s) Summary
Trimming helpers and call sites
tensorrt_llm/serve/responses_utils.py
store_response and store_messages use _trim_conversation. The helper repeatedly removes message ranges through conversation-ID-based deletion.
Conversation trimming tests
tests/unittest/llmapi/test_responses_utils.py
Tests verify capacity limits after response storage, chained response mappings, and rejection of unmapped response IDs.

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

Suggested reviewers: yihuilu512

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. 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 follows the required format and clearly describes the fix to enforce Responses conversation history capacity.
Description check ✅ Passed The description explains the issue, solution, test coverage, test limitation, and checklist status with sufficient detail.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

🧹 Nitpick comments (2)
tensorrt_llm/serve/responses_utils.py (1)

372-377: ⚡ Quick win

Add parameter type annotations to new helper methods.

The new helpers introduce untyped parameters; please type conversation_id (and align _pop_conversation/_pop_conversation_by_conversation_id signatures consistently) to match repo typing standards.

Suggested patch
-    def _pop_conversation(self, resp_id) -> None:
+    def _pop_conversation(self, resp_id: str) -> None:
@@
-    def _trim_conversation(self, conversation_id) -> None:
+    def _trim_conversation(self, conversation_id: str) -> None:
         while len(self.conversations[conversation_id]
                   ) > self.conversation_capacity:
             self._pop_conversation_by_conversation_id(conversation_id)

-    def _pop_conversation_by_conversation_id(self, conversation_id) -> None:
+    def _pop_conversation_by_conversation_id(self, conversation_id: str) -> None:

As per coding guidelines, “Always annotate functions; make the return type None if the function does not return anything.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/serve/responses_utils.py` around lines 372 - 377, The helper
methods lack parameter type annotations; update
_trim_conversation(conversation_id) and
_pop_conversation_by_conversation_id(conversation_id) to annotate
conversation_id with the same type used by the existing _pop_conversation
signature (e.g., the repo's ConversationId type or Union[str, int]) and keep the
return type as -> None; ensure both signatures are consistent with each other
and the project's typing conventions.

Source: Coding guidelines

tests/unittest/llmapi/test_responses_utils.py (1)

57-60: ⚡ Quick win

Strengthen trimming assertions to verify latest output is preserved, not only capped.

Both tests currently assert only len(conversation) <= conversation_capacity; they can miss over-trimming regressions that drop the newly appended assistant output. Add explicit checks that "final" / "next" remains in the stored history after trimming.

Suggested patch
@@
     conversation = await store.get_conversation_history("resp_1")

     assert len(conversation) <= store.conversation_capacity
+    assert any(
+        msg.get("role") == "assistant" and msg.get("content") == "final"
+        for msg in conversation
+    )
@@
     conversation = await store.get_conversation_history("resp_next")

     assert len(conversation) <= store.conversation_capacity
+    assert any(
+        msg.get("role") == "assistant" and msg.get("content") == "next"
+        for msg in conversation
+    )
     assert (
         store.response_to_conversation["resp_next"] == store.response_to_conversation["resp_prev"]
     )

As per coding guidelines for tests/**, coverage review should be actionable and explicit about sufficiency; this is a targeted follow-up to make trimming coverage sufficient for data-retention behavior.

Also applies to: 86-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/llmapi/test_responses_utils.py` around lines 57 - 60, The test
currently only checks trimming by asserting len(conversation) <=
store.conversation_capacity; update the assertions to also verify the
most-recent assistant output is retained after trimming by checking that the
saved conversation (from await store.get_conversation_history("resp_1") and the
analogous call in the second test) contains the expected assistant message text
("final" in the first case and "next" in the second). Keep the existing length
check, then add an explicit membership/assertion against conversation entries
(or their text field) to ensure the latest assistant output is present after
trimming.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tensorrt_llm/serve/responses_utils.py`:
- Around line 372-377: The helper methods lack parameter type annotations;
update _trim_conversation(conversation_id) and
_pop_conversation_by_conversation_id(conversation_id) to annotate
conversation_id with the same type used by the existing _pop_conversation
signature (e.g., the repo's ConversationId type or Union[str, int]) and keep the
return type as -> None; ensure both signatures are consistent with each other
and the project's typing conventions.

In `@tests/unittest/llmapi/test_responses_utils.py`:
- Around line 57-60: The test currently only checks trimming by asserting
len(conversation) <= store.conversation_capacity; update the assertions to also
verify the most-recent assistant output is retained after trimming by checking
that the saved conversation (from await store.get_conversation_history("resp_1")
and the analogous call in the second test) contains the expected assistant
message text ("final" in the first case and "next" in the second). Keep the
existing length check, then add an explicit membership/assertion against
conversation entries (or their text field) to ensure the latest assistant output
is present after trimming.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 22a070f0-e030-4632-8673-40623139fa76

📥 Commits

Reviewing files that changed from the base of the PR and between e47f26e and 4ad810d.

📒 Files selected for processing (2)
  • tensorrt_llm/serve/responses_utils.py
  • tests/unittest/llmapi/test_responses_utils.py

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

LGTM. Thanks for catching this issue.

@hchings

hchings commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53477 [ run ] triggered by Bot. Commit: 4ad810d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53477 [ run ] completed with state SUCCESS. Commit: 4ad810d
/LLM/main/L0_MergeRequest_PR pipeline #42640 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@hchings
hchings force-pushed the fix/responses-history-capacity branch from 4ad810d to 3910b63 Compare June 11, 2026 21:45
@hchings

hchings commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53692 [ run ] triggered by Bot. Commit: 3910b63 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53692 [ run ] completed with state SUCCESS. Commit: 3910b63
/LLM/main/L0_MergeRequest_PR pipeline #42827 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@hchings

hchings commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54233 [ run ] triggered by Bot. Commit: 3910b63 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54233 [ run ] completed with state SUCCESS. Commit: 3910b63
/LLM/main/L0_MergeRequest_PR pipeline #43309 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@hchings

hchings commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54743 [ run ] triggered by Bot. Commit: 3910b63 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54743 [ run ] completed with state FAILURE. Commit: 3910b63
/LLM/main/L0_MergeRequest_PR pipeline #43762 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@hchings
hchings force-pushed the fix/responses-history-capacity branch from 3910b63 to eb06536 Compare June 23, 2026 22:23
@hchings

hchings commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@hchings
hchings enabled auto-merge (squash) June 23, 2026 22:24
@fallintoplace

Copy link
Copy Markdown
Contributor Author

@hchings Thank you for your attention Erin.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55333 [ run ] triggered by Bot. Commit: eb06536 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55333 [ run ] completed with state FAILURE. Commit: eb06536
/LLM/main/L0_MergeRequest_PR pipeline #44284 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@hchings
hchings force-pushed the fix/responses-history-capacity branch from eb06536 to be7ab43 Compare June 25, 2026 22:06
@hchings

hchings commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55898 [ run ] triggered by Bot. Commit: be7ab43 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55898 [ run ] completed with state FAILURE. Commit: be7ab43
/LLM/main/L0_MergeRequest_PR pipeline #44783 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@fallintoplace

Copy link
Copy Markdown
Contributor Author

Not sure why CI is still failing. Let me know if I need to do anything.

@hchings

hchings commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63084 [ run ] triggered by Bot. Commit: 2bed890 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63084 [ run ] completed with state FAILURE. Commit: 2bed890
/LLM/main/L0_MergeRequest_PR pipeline #51176 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

auto-merge was automatically disabled August 1, 2026 16:29

Head branch was pushed to by a user without write access

@fallintoplace
fallintoplace force-pushed the fix/responses-history-capacity branch from 2bed890 to 01122f8 Compare August 1, 2026 16:29
@fallintoplace

Copy link
Copy Markdown
Contributor Author

Since CI failed, I just rebased the PR.

@zhaoyangwang-nvidia zhaoyangwang-nvidia 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.

The root-cause analysis is right — trimming keyed on an unmapped resp_id made the while loop a no-op (and the capacity cap a no-op with it). Keying on conversation_id after the mapping is established is the correct fix, and the two new tests cover both paths. Approving; two non-blocking nits inline.

One heads-up: the PR description says pytest wasn't run locally (no pytest in that env). Could you confirm CI is green on tests/unittest/llmapi/test_responses_utils.py before merge? mergeable_state is currently blocked.

Comment thread tensorrt_llm/serve/responses_utils.py Outdated
Comment thread tensorrt_llm/serve/responses_utils.py Outdated
@zhaoyangwang-nvidia

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@zhaoyangwang-nvidia
zhaoyangwang-nvidia enabled auto-merge (squash) August 4, 2026 07:59
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63708 [ run ] triggered by Bot. Commit: 1ceb77e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63708 [ run ] completed with state SUCCESS. Commit: 1ceb77e
/LLM/main/L0_MergeRequest_PR pipeline #51660 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@fallintoplace

Copy link
Copy Markdown
Contributor Author

As Blossom is failing, let me know if there is anything I can do.

Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
@hchings
hchings force-pushed the fix/responses-history-capacity branch from 1ceb77e to 6b8372a Compare August 6, 2026 07:04
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@hchings

hchings commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@pcastonguay pcastonguay added ci: post-merge approved Approved by TRT-LLM CI approvers for broad post-merge CI requests ci: full pre-merge approved labels Aug 6, 2026
@hchings

hchings commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@hchings

hchings commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Hi @fallintoplace - CI had 11 tests failure unrelated to this MR. I've retriggered one. TRTLLM CI is unstable lately and as soon as we get a green one we can merge.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64393 [ run ] triggered by Bot. Commit: 6b8372a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64393 [ run ] completed with state FAILURE. Commit: 6b8372a
/LLM/main/L0_MergeRequest_PR pipeline #52276 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@hchings

hchings commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@hchings

hchings commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Please do not rebase for now, as I'm trying to reuse CI stages.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64695 [ run ] triggered by Bot. Commit: 6b8372a Link to invocation

@fallintoplace

Copy link
Copy Markdown
Contributor Author

Okay. I will keep an eye on this.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64695 [ run ] completed with state SUCCESS. Commit: 6b8372a
/LLM/main/L0_MergeRequest_PR pipeline #52551 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@hchings

hchings commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

CI is green, please don't rebase. Should only lack one more approval from runtime devs.

@zhaoyangwang-nvidia
zhaoyangwang-nvidia merged commit d16d01f into NVIDIA:main Aug 9, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: full pre-merge approved ci: post-merge approved Approved by TRT-LLM CI approvers for broad post-merge CI requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants