Skip to content

fix(harness): bound read_file output with Unicode-safe pagination - #3821

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
wzq-xzwj:fix/oversized-tool-result-recovery
Oct 29, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
wzq-xzwj:fix/oversized-tool-result-recovery

Conversation

@wzq-xzwj

@wzq-xzwj wzq-xzwj commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2951.

read_file(offset=0, limit=1) can currently return an arbitrarily long single line. Reading an offloaded browser snapshot without line limits also puts the entire artifact back into context, while read_file is excluded from default result eviction.

Bound returned file content to 16,000 Unicode code points by default, with an explicit hard maximum of 32,000. Optional char_offset pages within the selected line range; truncation guidance supplies the next offset. Existing line selection and the four-argument Java entry point are preserved, and only the new overload is registered as a tool. Small results remain unchanged. EN/ZH documentation explains pagination, stable-file assumptions and encoded binary data.

Validation:

  • Two regression probes fail on unchanged main 4100c86 and pass with this change.
  • 37 tests pass: BoundedFileReadTest (7), FilesystemToolTest (23), ToolResultEvictionMiddlewareTest (7), including Unicode reconstruction, the hard maximum, invalid offsets, optional defaults and unique tool registration.
  • Spotless apply/check and git diff --check pass.
  • Documentation: 13 unit tests pass; navigation/syntax/local-link checks pass for 432 pages and 584 redirects; Mintlify build validation passes.
  • Full mvn -B -T1C clean verify attempted. Initial attempt hit a Maven dependency TLS handshake error; retry reached 2,830 core tests (0 assertion failures, 2 errors, 9 skipped). Both errors are existing DangerousPathBypassTest symlink creation cases requiring Windows privileges. The reactor stopped before the remaining modules, so this is not a passing local full build.
  • GitHub CI: Ubuntu and Windows build jobs, documentation validation, license and module-sync checks all pass.
  • Local Mintlify broken-links reports 2,218 links across 326 files on Windows, despite the repository's local-link checker and Mintlify build validation passing. This PR adds no links or headings; the reported links were not modified. This separate check is not claimed as passing.

This is an output bound, not a bound on filesystem backend allocation/I/O or total model-request tokens. Pagination can still accumulate context over many reads. It does not attempt to backport the separate 2.1 streaming recovery changes to 2.0.x.

@mintlify

mintlify Bot commented Oct 28, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit b4f06ec.

Approve preview

@jujn
jujn merged commit 0ee7812 into agentscope-ai:main Oct 29, 2026
7 checks passed
jujn pushed a commit that referenced this pull request Nov 5, 2026
## Description

Closes #3984.

### Summary

After #3821, a `read_file` call requesting 64,000 Unicode code points is
always clamped to 32,000. Applications with larger context budgets
cannot adjust that maximum through the Harness builder.

```diff
- Math.min(maxChars, MAX_READ_CHARS)
+ Math.min(maxChars, readFileMaxChars)
```

Add `HarnessAgent.Builder.readFileMaxChars(int)` and a matching
`FilesystemTool` constructor. The maximum defaults to 32,000 and must be
at least 16,000. A tool call omitting `max_chars` still reads 16,000;
requests above the configured maximum are paginated as before.
Automatically constructed general-purpose and declared subagents inherit
the setting. Existing constructors, Unicode-safe continuation, and line
selection remain compatible. Update the tool description and
English/Chinese filesystem documentation.
jujn pushed a commit that referenced this pull request Nov 13, 2026
## Description

Fixes #4098

`session_search` only caps the number of matches (#3270), not their
size. Each match embeds a whole stored message, so a handful of matches
can exceed the eviction threshold. Because `session_search` was in
`ToolResultEvictionConfig.DEFAULT_EXCLUDED_TOOLS`, such results were
never offloaded and could push the next model request over budget.

Changes:
- Remove `session_search` from
`ToolResultEvictionConfig.DEFAULT_EXCLUDED_TOOLS`. Results under the
threshold (80K chars by default) are unchanged; larger ones get the
usual head/tail preview and a `read_file` pointer. Long single-line
offload files are readable since #3821.
- Update the `SessionSearchTool` comment that relied on the exclusion.
- Update the default exclusion list in
`docs/v2/{en,zh}/docs/harness/context.md`.

The prune exclusion in `CompactionConfig.PruneConfig` is left unchanged:
once a large result is offloaded, only the preview stays inline.
chickenlj added a commit that referenced this pull request Nov 13, 2026
)

Source: 0ee7812
Candidate: 9221b57c85b2f3d4b15a453a621150d8afbee026
Union-Of: execution53+skill-union(810c7d7) + tasks-standalone(511fd8a5)
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.

[Bug]: read_file line pagination can return unbounded output for a single-line file

2 participants