Repository navigation
fix(jev): bound the conversation state sent by JevToolSelectionMiddleware - #3375
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
JevToolSelectionMiddleware previously shipped the complete input.messages() list — system prompt, memory and full history — to Jev on every reasoning step, and split it across chunks when candidates exceeded 254, so each selection call carried an unbounded payload on long-running agents. This PR introduces ContextStrategy with a bounded recent window as the default. Reviewed both sources, the changed tests and the EN/ZH docs; the engine ran against this checkout and the suites are green.
Verdict: approve. The bound is real, the legacy behaviour stays opt-in, and no correctness, thread-safety or credential issue surfaced. Three non-blocking notes inline.
Verified
- Hard bound:
recentWindowStateenforces both limits — aentries.size() < maxMessagesloop guard and aremainingchar budget decremented per message (JevSelectionSupport.java:80-104). A single oversized message is truncated surrogate-safely to the remaining budget and skipped if the cut empties it (:91-103), so the payload is bounded in both message count and characters. - Compatibility:
contextStrategy(FULL_CONVERSATION)keeps the old shape reachable (JevToolSelectionMiddleware.java:355, dispatched at:184); the builder API is only extended. The default does flip toRECENT_WINDOW(:317), so upgraded users can get different tool selections from the same agent — intentional per #3372 and documented indocs/v2/en/jev/index.md+docs/v2/zh/jev/index.md. - Thread safety: all fields final (
:82-89),alwaysIncludeToolsimmutable viaSet.copyOf(:93), andonReasoning/stateFor/selectToolswork only on locals. - No leakage: no new logging; the only new exception message carries tool names, not message text (
:167-171); state-building errors are swallowed by fail-open (:150-158). - Tests: truncation is covered at both levels (oldest-kept cut, surrogate cut, skip-when-empty, drop-beyond-budget, blank-skip/backfill, role lowercasing —
JevSelectionSupportTest.java:144-247,JevToolSelectionMiddlewareTest.java:322,:365), plus the 255-tool two-chunk rerank path (:901).
Notes
- Inline
[Warning]onJevSelectionSupport.java:88: an assistant message carrying only tool calls has blank text and is skipped, so a survivingTOOLresult can appear unpaired in the judge window. The primary model contract is unaffected (input.messages()is passed tonextunchanged,JevToolSelectionMiddleware.java:175-177), but this is exactly the turns tool selection depends on. - Inline
[Info]on:317: a one-line migration note on pinning the old behaviour would make the upgrade less surprising. - Inline
[Info]on tests: the exact 254-candidate single-partition boundary and a window fixture containingTOOL/assistant-tool-call messages are the two gaps.
Review scope
Static review plus running the affected test suites in this PR-head checkout; no CI was triggered from this review and no build of unrelated modules was attempted.
Automated review by github-manager-bot
| continue; | ||
| } | ||
| String text = message.getTextContent(); | ||
| if (text == null || text.isBlank()) { |
There was a problem hiding this comment.
[Warning] Inside the bounded window, an assistant message that carries only tool calls contributes blank text (Msg joins TextBlocks only, Msg.java:544-550), so it is skipped here — which can leave a TOOL result in the window with no preceding assistant tool call. This does not break the primary model contract (input.messages() is passed to next untouched at JevToolSelectionMiddleware.java:175-177), but it degrades the judge's context quality exactly on the turns where tool selection matters most. Consider keeping the assistant tool-call line (its name or a placeholder) when its tool result survives the window. Not blocking.
| private int maxTools = 3; | ||
| private double confidenceThreshold = 0.5; | ||
| private boolean failOpen = true; | ||
| private ContextStrategy contextStrategy = ContextStrategy.RECENT_WINDOW; |
There was a problem hiding this comment.
[Info] Confirming the blast radius of the new default: RECENT_WINDOW now applies to every existing user of the middleware, so the Jev input — and therefore potentially the selected tools — changes silently after an upgrade. FULL_CONVERSATION stays reachable via contextStrategy(...) (:355, dispatched at :184) and both EN/ZH docs are updated, so this is acceptable as the point of #3372. A one-line migration note telling users how to pin the old behaviour would make the upgrade less surprising.
| } | ||
|
|
||
| @Test | ||
| void chunksAndReranksLargeToolSets() { |
There was a problem hiding this comment.
[Info] Coverage is genuinely strong — oldest-kept truncation, surrogate-aware cut, skip-when-empty, drop-beyond-budget, blank-skip/backfill, role lowercasing, and the 255-tool two-chunk rerank path are all asserted. Two gaps: the exact single-partition boundary at 254 candidates (:1086 only exercises 3 tools), and no window fixture containing TOOL-role or assistant-tool-call messages (all fixtures are user messages), which is the case the warning above is about.
92034c5 to
c1a1de6
Compare
Summary
Fixes #3372.
Bound the conversation state sent by
JevToolSelectionMiddlewareon each reasoning step. Updated against current main while preserving its independent per-tool relevance scoring andJevExecutionOFF/SHADOW/ENFORCE modes.Behavior
RECENT_WINDOWis the default context strategy: the latest 8 nonblank text messages, projected as{role, text}, capped at 8000 total text characters.maxContextMessagesandmaxContextCharsconfigure positive window limits. Blank messages do not consume slots; truncation preserves UTF-16 surrogate pairs.LATEST_USER_MESSAGEsends only the latest user text asuserRequest.FULL_CONVERSATIONsends the complete original message list, restoring the previous context scope.JevExecution, so errors are observed and restore the original tool list.The bounded window can omit earlier tool hints in long conversations; tune the limits or choose FULL_CONVERSATION for applications that need that history.
Validation
JevSelectionSupportTestandJevToolSelectionMiddlewareTest: 51 tests passed, including main's selection/mode regressions and context strategy, batch budget, invalid-context fallback, OFF-mode laziness, and builder validation.ReActAgent.Builder.copy()omission by copying configuredagentId; the existingReActAgentTestsuite passes all 26 tests. The inherited HarnessAgentIdTest now explicitly enables legacy session history before asserting legacy state directories, preserving its existing assertions under main's event-log default. Both Core and Harness ID regressions pass. GitHub Ubuntu clean verification, documentation validation, license/module sync and patch coverage checks pass. Windows CI is still running. Local full clean verification passed Core, Harness and JEV, then hit two Session Chat timing timeouts; all 8 ChatSessionsTest cases passed unchanged on a standalone rerun.