fix(harness): mark optional FilesystemTool params as required=false#2227
Open
wzq-xzwj wants to merge 6 commits into
Open
fix(harness): mark optional FilesystemTool params as required=false#2227wzq-xzwj wants to merge 6 commits into
wzq-xzwj wants to merge 6 commits into
Conversation
read_file(offset,limit), grep_files(path,glob) and glob_files(path) are documented as optional and the AbstractFilesystem implementation already handles null/default values, but they lacked required=false and therefore appeared as required in the generated tool schema. Align the annotations with the descriptions and the implementation. Schema-only, no behavior change. Mirrors the existing edit_file.replace_all annotation.
a89f2f6 to
bd74c43
Compare
…potless The sessionId @ToolParam line exceeded the 100-column AOSP limit enforced by spotless:check, causing the build to fail on every PR touching this module. Wrap it as spotless expects. Formatting-only, no behavior change.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
The execute tool's working_directory (documented "optional") and timeout (documented "default: 30") lacked required=false and therefore appeared as required in the generated tool schema. The implementation already handles their absence (blank working_directory is skipped; timeout falls back to 30 via `timeout > 0 ? timeout : 30`). Align the annotations with the descriptions and the implementation. Schema-only, no behavior change.
AgentScopeJavaBot
left a comment
Collaborator
There was a problem hiding this comment.
🤖 AI Review
| Aspect | Count |
|---|---|
| 🟢 Nitpick (信息性建议,不阻塞合并) | 1 |
| 🟡 Recommended (建议修复,但不阻塞合并) | 2 |
Overall Assessment: COMMENT — Schema-only fix with correct downstream handling; minor description improvements suggested for optional params.
AgentScopeJavaBot
left a comment
Collaborator
There was a problem hiding this comment.
🤖 AI Review
| Aspect | Count |
|---|---|
| 🟢 Nitpick (信息性建议,不阻塞合并) | 1 |
| 🟡 Recommended (建议修复,但不阻塞合并) | 2 |
Overall Assessment: COMMENT — Schema-only fix with correct downstream handling; minor description improvements suggested for optional params.
Marking a primitive int parameter as required=false is unsafe: when the model omits it, the framework binds null and the reflective (MethodHandle) invocation throws "Cannot invoke java.lang.Number.intValue() because the return value of ValueConversions.primitiveConversion(...) is null". Change read_file's offset/limit and execute's timeout from int to Integer and apply null-safe defaults in the body (offset/limit -> 0, timeout -> 30). This mirrors edit_file's existing Boolean replace_all parameter. Without this, the required=false change alone makes these tools crash whenever the optional argument is omitted.
Add unit tests covering the null-safe defaulting introduced when boxing the optional numeric parameters: - FilesystemToolTest: read_file with omitted offset/limit defaults both to 0; explicit values are passed through. - ShellExecuteToolTest (new): execute with omitted timeout defaults to 30; explicit timeout is passed through; working_directory prefixes a cd. Covers the previously-uncovered branches flagged by codecov/patch.
Author
|
@jujn 请审核一下,实际使用中影响感觉还是很明显的,检查和自测均已通过。 |
Collaborator
最近任务比较多。可能会稍晚一些。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several
@ToolParamparameters on the harness built-in tools are documented asoptional (their descriptions say "Default: ...", "optional") and the underlying
implementation already handles missing / null / default values gracefully.
However, they are not annotated with
required = false.Because
ToolParam.required()defaults totrue, these parameters end up in thegenerated JSON schema as required, contradicting both their descriptions and
the implementation. This misleads models into always supplying them.
Affected parameters:
read_fileoffsetread_filelimitgrep_filespathgrep_filesglobglob_filespathexecuteworking_directoryexecutetimeoutImportant: optional numeric params must be boxed types
Simply adding
required = falseto a primitiveintparameter is not enough— it introduces a runtime crash. When the model omits the argument, the framework
binds
nulland the reflective (MethodHandle) invocation fails with:So this PR also changes
read_file'soffset/limitandexecute'stimeoutfrom
inttoInteger, applying null-safe defaults in the method body(
offset/limit-> 0,timeout-> 30). This mirrorsedit_file's existingBoolean replace_allparameter, which was already correctly boxed and optional.Verified end-to-end: with the fix,
read_filecalled withoutoffset/limitreturns the file contents; before the fix it returned the
intValue()NPE as atool error.
Implementation is already optional-safe
LocalFilesystem.grep(...):resolvePath(rc, path != null ? path : ".")LocalFilesystem.glob(...): handlespath == null-> falls back to cwdripgrepSearch/javaSearch:if (includeGlob != null && !includeGlob.isBlank())LocalFilesystem.read(...):int startIdx = Math.max(0, offset),limit > 0 ? ... : allShellExecuteTool.execute(...): blankworking_directoryskipped;timeout > 0 ? timeout : 30Change
required = falseto the parameters listed above.int->Integer) with null-safe defaults.SessionSearchToolso the module passesspotless:check.Testing
mvn -pl agentscope-harness spotless:check-> BUILD SUCCESS.read_filewithout offset/limit and gets file contents(previously crashed with an unboxing NPE).