You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: session_search maxResults is unbounded — model-supplied limit bypasses result bounding while session_search is excluded from tool-result eviction #3270
session_search accepts a model-controlled maxResults with no upper bound — the same hole #3266 described for memory_search and that PR #3267 just closed for that tool (hard ceiling MAX_RESULTS_CEILING = 100, clamped via Math.min).
A model that passes maxResults=100000 scans every session entry and collects matches with only a 200-char preview cap per entry — the result count itself is unbounded.
Two aggravating factors:
session_search is in ToolResultEvictionConfig.DEFAULT_EXCLUDED_TOOLS (ToolResultEvictionConfig.java:66-73) with the rationale "bounded results", so ToolResultEvictionMiddleware.maybeEvict() returns early for it regardless of result size — nothing downstream trims an oversized result.
SessionSearchTool.searchInSessionFile (:269-308) loads and parses the full SessionTree of every session file while collecting matches, so a huge maxResults also amplifies I/O, not just output size.
Impact
Long-running agents with many accumulated sessions (agents/<id>/sessions/*.log.jsonl) can get a single oversized session_search tool result injected straight into the next model call — context overflow on exactly the long-lived agents the harness targets. Medium severity; no data corruption.
Expected behavior
Clamp the model-supplied maxResults to a hard ceiling the way #3267 does for memory_search (e.g. Math.min(maxResults, 100)), and state the bound in the @ToolParam description ("default: 10, max: 100") so the model is not surprised by a silent clamp.
Environment
AgentScope-Java Version: 2.0.4-SNAPSHOT (main)
Java Version: 21
OS: macOS
Additional context
Raised in the review of #3267 (inline comment on ToolResultEvictionConfig.java:61): the eviction-exclusion rationale "bounded results" is only honest if both search tools bound their model-supplied limits. Happy to submit a PR mirroring the #3267 fix (clamp + @ToolParam description + regression test).
Cross-linking: this was flagged during the review of #3267 (PR for #3266) — the eviction-exclusion rationale in ToolResultEvictionConfig.java:61 reads "bounded results", which only stays honest if both search tools clamp their model-supplied limits. I can pick this up after #3267 lands, mirroring its fix: Math.min clamp + (default: 10, max: 100) in the @ToolParam description + a regression test.
Category: bug (area/harness) | Status: Confirmed | Severity: medium
Verified against main @ 6e6406610 (engine-assisted read of agentscope-harness). All four claims hold; line references in the report are accurate as filed.
Claim-by-claim check
Claim
Result
Evidence
session_search accepts a model-supplied maxResults with no upper bound
TRUE
SessionSearchTool.java:71 (required = false), :77int limit = maxResults != null && maxResults > 0 ? maxResults : 10; — only a > 0 sanity check, no clamp
session_search is excluded from tool-result eviction, so nothing downstream trims an oversized result
TRUE
ToolResultEvictionConfig.java:66-73 contains "session_search"; ToolResultEvictionMiddleware.maybeEvict() (middleware/ToolResultEvictionMiddleware.java:188-192) returns early on the excluded-name check before the size check at :194
Huge maxResults amplifies I/O, not just output size
TRUE
SessionSearchTool.java:279-283 constructs a SessionTree per session file and calls tree.load(), which reads and JSON-parses every line (SessionTree.java:245-266, parseJsonlEntries 659-667); the outer loop :84-89 only breaks once results.size() >= limit
The ceiling cited from #3267 (MAX_RESULTS_CEILING = 100, Math.min) is not on main yet
TRUE
gh pr view 3267 → state OPEN, mergedAt: null; MemorySearchTool.java:64-89 on main still has no maxResults parameter at all
Root cause. Same shape as #3266, different tool: the model controls the result count, the tool trusts it verbatim, and the eviction layer that would otherwise cap an oversized tool result is deliberately switched off for this tool name — the javadoc at ToolResultEvictionConfig.java:61 claims "bounded previews" for the excluded search tools, which the session_search code path does not guarantee.
Impact. A single session_search call with e.g. maxResults=100000 on a long-running agent can inject an arbitrarily large tool result straight into the next model call — context overflow on exactly the long-lived agents the harness targets. Medium severity; no data corruption, no security boundary crossed.
Fix shape (as proposed, and workable). Mirror #3267 exactly: shared hard ceiling (Math.min(maxResults, 100)) + per-file/total early break so SessionTree.load() is skipped once the limit is reached + @ToolParam description changed to "default: 10, max: 100" so a clamp is not silent to the model.
Two notes for whoever implements it.
session_history has the identical unbounded pattern at SessionSearchTool.java:186 (lastN != null && lastN > 0 ? lastN : 20). Fixing only session_search leaves the same hole one method down in the same file.
No PR from us. The reporter explicitly offered to submit one against this exact shape, so a competing automated PR would duplicate community work.
Testability: yes, no external services needed — write several *.log.jsonl + context files with repeated matches, call sessionSearch(..., maxResults=100000) and assert (a) results <= 100, (b) the description text advertises the max, (c) session files beyond the limit are never parsed. No test in the repo today invokes sessionSearch/maxResults at all, so nothing currently guards this.
Hi, I'd like to work on this. Following the #3267/#3267 pattern (MAX_RESULTS_CEILING = 100, Math.min clamp), I'll add the same ceiling to SessionSearchTool's model-supplied maxResults, plus regression tests for the clamp and the excluded-from-eviction interplay. PR coming shortly.
Activity
aMetric commentedon Sep 23, 2026
Cross-linking: this was flagged during the review of #3267 (PR for #3266) — the eviction-exclusion rationale in
ToolResultEvictionConfig.java:61reads "bounded results", which only stays honest if both search tools clamp their model-supplied limits. I can pick this up after #3267 lands, mirroring its fix:Math.minclamp +(default: 10, max: 100)in the@ToolParamdescription + a regression test.oss-maintainer commentedon Sep 24, 2026
Issue Evaluation
Category:
bug(area/harness) | Status: Confirmed | Severity: mediumVerified against
main@6e6406610(engine-assisted read ofagentscope-harness). All four claims hold; line references in the report are accurate as filed.Claim-by-claim check
session_searchaccepts a model-suppliedmaxResultswith no upper boundSessionSearchTool.java:71(required = false),:77int limit = maxResults != null && maxResults > 0 ? maxResults : 10;— only a> 0sanity check, no clampsession_searchis excluded from tool-result eviction, so nothing downstream trims an oversized resultToolResultEvictionConfig.java:66-73contains"session_search";ToolResultEvictionMiddleware.maybeEvict()(middleware/ToolResultEvictionMiddleware.java:188-192) returns early on the excluded-name check before the size check at:194maxResultsamplifies I/O, not just output sizeSessionSearchTool.java:279-283constructs aSessionTreeper session file and callstree.load(), which reads and JSON-parses every line (SessionTree.java:245-266,parseJsonlEntries659-667); the outer loop:84-89only breaks onceresults.size() >= limitMAX_RESULTS_CEILING = 100,Math.min) is not onmainyetgh pr view 3267→ stateOPEN,mergedAt: null;MemorySearchTool.java:64-89onmainstill has nomaxResultsparameter at allRoot cause. Same shape as #3266, different tool: the model controls the result count, the tool trusts it verbatim, and the eviction layer that would otherwise cap an oversized tool result is deliberately switched off for this tool name — the javadoc at
ToolResultEvictionConfig.java:61claims "bounded previews" for the excluded search tools, which thesession_searchcode path does not guarantee.Impact. A single
session_searchcall with e.g.maxResults=100000on a long-running agent can inject an arbitrarily large tool result straight into the next model call — context overflow on exactly the long-lived agents the harness targets. Medium severity; no data corruption, no security boundary crossed.Fix shape (as proposed, and workable). Mirror #3267 exactly: shared hard ceiling (
Math.min(maxResults, 100)) + per-file/total early break soSessionTree.load()is skipped once the limit is reached +@ToolParamdescription changed to"default: 10, max: 100"so a clamp is not silent to the model.Two notes for whoever implements it.
session_historyhas the identical unbounded pattern atSessionSearchTool.java:186(lastN != null && lastN > 0 ? lastN : 20). Fixing onlysession_searchleaves the same hole one method down in the same file.No PR from us. The reporter explicitly offered to submit one against this exact shape, so a competing automated PR would duplicate community work.
Testability: yes, no external services needed — write several
*.log.jsonl+ context files with repeated matches, callsessionSearch(..., maxResults=100000)and assert (a)results <= 100, (b) the description text advertises the max, (c) session files beyond the limit are never parsed. No test in the repo today invokessessionSearch/maxResultsat all, so nothing currently guards this.Automated evaluation by github-manager-bot
aiyili commentedon Oct 1, 2026
Hi, I'd like to work on this. Following the #3267/#3267 pattern (MAX_RESULTS_CEILING = 100, Math.min clamp), I'll add the same ceiling to SessionSearchTool's model-supplied maxResults, plus regression tests for the clamp and the excluded-from-eviction interplay. PR coming shortly.
fix(harness): session_search/session_history 的模型可控 limit 加硬上限(100)
fix(harness): clamp model-supplied limits in session_search / session…
fix(harness): allow eviction of oversized session_search results (#4099)