← Back to PRs

#18464: fix(web-search): handle empty query gracefully instead of crashing

by Clawborn open 2026-02-16 18:30 View on GitHub →
agents size: S trusted-contributor
## Description\nWhen a user passes an empty string as a query to `web_search`, the tool previously threw a validation error ('Parameter query cannot be empty') or crashed depending on the provider validation. This returns an empty result set instead, which is more robust for autonomous agents.\n\n## Fix\nAllow empty queries in validation but return early with empty result set.\n\n## AI Transparency\n- **Assisted by**: OpenClaw Agent (Claude 3.5 Sonnet / Opus)\n- **Testing level**: Fully tested with new unit tests\n- **Prompt strategy**: Self-correction loop based on codebase analysis <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR combines two unrelated fixes: empty query handling for `web_search` and process tree termination on Unix. **web-search changes:** - Added `allowEmpty: true` to allow empty query strings without validation errors - Returns early with empty result set (`count: 0, results: []`) when query is empty/whitespace - Added tests for empty and whitespace-only queries **kill-tree changes:** - Fixed orphaned child processes on Unix when parent isn't a process group leader - Added fallback to manual tree traversal using `pgrep -P` when `process.kill(-pid)` fails - Added test for manual traversal scenario **Issues found:** - Redundant `.trim()` call in web-search.ts since `readStringParam` already trims - Test mock doesn't implement `allowEmpty` logic, so it doesn't fully validate the fix - PR title/description only mentions web-search fix but includes unrelated kill-tree changes (consider splitting into separate PRs per the repository's "Group related changes; avoid bundling unrelated refactors" guideline) <h3>Confidence Score: 3/5</h3> - Safe to merge with minor style improvements and test mock concerns - The core logic for both fixes is sound and well-tested. However, there's a redundant `.trim()` call (style), the test mock doesn't fully validate the behavior (test quality), and the PR bundles two unrelated fixes which goes against the repo guidelines of grouping related changes - Pay attention to `src/agents/tools/web-search.empty.test.ts` - the mock doesn't properly test the `allowEmpty` behavior <sub>Last reviewed commit: 4e5eb6d</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs