Skip to content

fix(libsy): keep classifier history from orphaning a tool result - #309

Merged
eric-liu-nvidia merged 2 commits into
mainfrom
eric-liu/libsy-classifier-tool-pair-trim
Aug 5, 2026
Merged

fix(libsy): keep classifier history from orphaning a tool result#309
eric-liu-nvidia merged 2 commits into
mainfrom
eric-liu/libsy-classifier-tool-pair-trim

Conversation

@eric-liu-nvidia

@eric-liu-nvidia eric-liu-nvidia commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Issue

LlmClassifier trims conversation history by message count, so the window can begin on a tool result and leave out the assistant tool call that introduced its id. The classifier subrequest then carries an orphan tool result, which violates the tool-call protocol and can be rejected by the classifier backend or scored on structurally incomplete context.

Solution

The window start now moves back to the nearest index that keeps every tool call and its result together. If no earlier start can pair a result, the counted start is kept, so an unanswerable result cannot widen the window to the whole conversation.

Summary by CodeRabbit

  • Bug Fixes
    • Conversation history trimming now preserves complete tool-call and tool-result pairs when preparing input for classification.
    • Plain conversation history continues to use the requested trailing window without changes.

@eric-liu-nvidia
eric-liu-nvidia requested a review from a team as a code owner August 5, 2026 18:48
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The classifier now preserves complete tool-call and tool-result pairs when trimming judge conversation history. The requested trailing window remains unchanged for plain conversations. Tests cover paired tools, orphan results, and standard message windows.

Changes

LLM history trimming

Layer / File(s) Summary
Pair-aware trimming and validation
crates/libsy/src/algorithms/llm_class.rs
trim_messages adjusts the window start when a retained tool result requires its originating tool call. New fixtures and tests verify paired-tool preservation and unchanged plain-conversation trimming.

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

Poem

I’m a rabbit with tools in my pack,
Keeping each call with its result intact.
The window moves back,
No orphan hops the track,
Plain messages stay on their exact stack.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing classifier history trimming from orphaning tool results.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch eric-liu/libsy-classifier-tool-pair-trim

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

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

🧹 Nitpick comments (1)
crates/libsy/src/algorithms/llm_class.rs (1)

1518-1538: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the retained tool pair directly.

Line 1537 passes if a regression removes ToolResult("call-1") from the retained window. Assert that kept contains both ToolCall("call-1") and ToolResult("call-1"). Add a fallback test where the call is before the first user message and assert that trimming keeps the original counted boundary.

🤖 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 `@crates/libsy/src/algorithms/llm_class.rs` around lines 1518 - 1538,
Strengthen the test trimming_keeps_the_call_that_introduced_a_kept_tool_result
by directly asserting that kept contains both ToolCall("call-1") and
ToolResult("call-1"), rather than only checking orphan_tool_results. Add a
fallback test covering a tool call before the first user message, and verify
trimming preserves the original counted boundary.
🤖 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 `@crates/libsy/src/algorithms/llm_class.rs`:
- Around line 1518-1538: Strengthen the test
trimming_keeps_the_call_that_introduced_a_kept_tool_result by directly asserting
that kept contains both ToolCall("call-1") and ToolResult("call-1"), rather than
only checking orphan_tool_results. Add a fallback test covering a tool call
before the first user message, and verify trimming preserves the original
counted boundary.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1404a642-abe6-4a9e-bf34-010973bf12e3

📥 Commits

Reviewing files that changed from the base of the PR and between 54d4b66 and 9b0036d.

📒 Files selected for processing (1)
  • crates/libsy/src/algorithms/llm_class.rs

@eric-liu-nvidia
eric-liu-nvidia force-pushed the eric-liu/libsy-classifier-tool-pair-trim branch from 9b0036d to d6419a8 Compare August 5, 2026 19:04
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

🚀 View preview at
https://NVIDIA-NeMo.github.io/Switchyard/pr-preview/pr-309/

Built to branch gh-pages at 2026-08-05 20:18 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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

The current scan revisits a long classifier history for every candidate start, and it accepts a tool result when a matching call appears later. The regression test also stays green if trimming drops the pair. I ran cargo fmt --all --check, workspace clippy with warnings denied, and cargo test -p switchyard-libsy; all passed.

Comment thread crates/libsy/src/algorithms/llm_class.rs Outdated
Comment thread crates/libsy/src/algorithms/llm_class.rs Outdated
Comment thread crates/libsy/src/algorithms/llm_class.rs Outdated
@elyasmnvidian
elyasmnvidian self-requested a review August 5, 2026 20:14

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

please fix merge conflicts

Signed-off-by: Eric Liu <zengyuanl@nvidia.com>
Signed-off-by: Eric Liu <zengyuanl@nvidia.com>
@eric-liu-nvidia
eric-liu-nvidia force-pushed the eric-liu/libsy-classifier-tool-pair-trim branch from d6419a8 to 8b34b91 Compare August 5, 2026 20:17
@eric-liu-nvidia
eric-liu-nvidia merged commit 702383e into main Aug 5, 2026
19 checks passed
@eric-liu-nvidia
eric-liu-nvidia deleted the eric-liu/libsy-classifier-tool-pair-trim branch August 5, 2026 20:26
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.

2 participants