fix(libsy): keep classifier history from orphaning a tool result - #309
Conversation
WalkthroughThe 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. ChangesLLM history trimming
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/libsy/src/algorithms/llm_class.rs (1)
1518-1538: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the retained tool pair directly.
Line 1537 passes if a regression removes
ToolResult("call-1")from the retained window. Assert thatkeptcontains bothToolCall("call-1")andToolResult("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
📒 Files selected for processing (1)
crates/libsy/src/algorithms/llm_class.rs
9b0036d to
d6419a8
Compare
|
elyasmnvidian
left a comment
There was a problem hiding this comment.
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.
elyasmnvidian
left a comment
There was a problem hiding this comment.
please fix merge conflicts
Signed-off-by: Eric Liu <zengyuanl@nvidia.com>
Signed-off-by: Eric Liu <zengyuanl@nvidia.com>
d6419a8 to
8b34b91
Compare
Issue
LlmClassifiertrims 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