The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(search): accept bounded rg SIGPIPE and full SemVer
Royalaid4c189cfd41f7
diff --git a/tests/tools/test_search_files_engine_selection.py b/tests/tools/test_search_files_engine_selection.pyindex 0e4a13e9ebb..317f290ee25 100644--- a/tests/tools/test_search_files_engine_selection.py+++ b/tests/tools/test_search_files_engine_selection.py@@ -81,7 +81,21 @@ def test_modified_zero_match_exit_one_is_valid_without_capability_error():@pytest.mark.parametrize("version",- ["ripgrep 13.0.0\n", "ripgrep unknown\n", "ripgrep 14 garbage\n"],+ [+ "ripgrep 13.0.0\n",+ "ripgrep unknown\n",+ "ripgrep 14 garbage\n",+ "ripgrep 14\n",+ "ripgrep 14.1\n",+ "ripgrep 14.1.1-\n",+ "ripgrep 14.1.1+\n",+ "ripgrep 14.1.1-alpha..1\n",+ "ripgrep 14.1.1+build..2\n",+ "ripgrep 14.1.1-01\n",+ "ripgrep 014.1.1\n",+ "ripgrep 14.01.1\n",+ "ripgrep 14.1.01\n",+ ],)def test_modified_requires_parseable_ripgrep_14_before_search(version):env = RecordingEnvironment()@@ -125,6 +139,28 @@ def test_modified_accepts_complete_ripgrep_semver_with_revision_text():assert len(env.rg_commands) == 1+def test_modified_accepts_ripgrep_semver_with_prerelease_and_build_metadata():+ env = RecordingEnvironment()+ original_execute = env.execute++ def execute(command, **kwargs):+ if "--version" in command:+ env.commands.append(command)+ return {+ "output": "ripgrep 14.1.1-alpha.1+build.2\n",+ "returncode": 0,+ }+ return original_execute(command, **kwargs)++ env.execute = execute+ result = ShellFileOperations(env).search(+ "*.py", path="/repo", target="files", order="modified"+ )++ assert result.error is None+ assert len(env.rg_commands) == 1++def test_empty_discovery_output_is_zero_matches_without_retry():env = RecordingEnvironment(rg_output="", rg_code=0)ops = ShellFileOperations(env)@@ -162,6 +198,33 @@ def test_rg_partial_output_with_error_exit_fails_closed(order):assert len(env.rg_commands) == 1[email protected]("order", ["discovery", "modified"])+def test_rg_sigpipe_is_benign_only_after_fetch_limit_paths(order):+ output = "".join(f"/repo/{name}.py\n" for name in ("a", "b", "c", "d"))+ env = RecordingEnvironment(rg_output=output, rg_code=141)++ result = ShellFileOperations(env).search(+ "*.py", path="/repo", target="files", limit=2, offset=1, order=order+ )++ assert result.error is None+ assert result.files == ["/repo/b.py", "/repo/c.py"]+ assert result.truncated is True++[email protected]("order", ["discovery", "modified"])+def test_rg_sigpipe_with_fewer_than_fetch_limit_paths_fails_closed(order):+ env = RecordingEnvironment(rg_output="/repo/partial.py\n", rg_code=141)++ result = ShellFileOperations(env).search(+ "*.py", path="/repo", target="files", limit=2, offset=1, order=order+ )++ assert result.error is not None+ assert result.files == []+ assert result.total_count == 0++def test_invalid_direct_file_order_returns_structured_error():env = RecordingEnvironment()ops = ShellFileOperations(env)diff --git a/tools/file_operations.py b/tools/file_operations.pyindex 7a9ec3a0321..56956e6d9a5 100644--- a/tools/file_operations.py+++ b/tools/file_operations.py@@ -1107,8 +1107,13 @@ class ShellFileOperations(FileOperations):quoted = self._quote_executable(executable)result = self._exec(f"{quoted} --version", timeout=10)match = re.search(- r"(?im)^ripgrep\s+(\d+)\.\d+\.\d+"- r"(?:[-+][0-9A-Za-z.-]+)?(?:\s|$)",+ r"(?m)^ripgrep\s+((?:0|[1-9]\d*))\."+ r"(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)"+ r"(?:-(?:(?:0|[1-9]\d*)|(?:[0-9A-Za-z-]*[A-Za-z-]"+ r"[0-9A-Za-z-]*))(?:\.(?:(?:0|[1-9]\d*)|"+ r"(?:[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)))*)?"+ r"(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?"+ r"(?:\s+\(rev [^)]+\))?\s*$",result.stdout or "",)if result.exit_code == 0 and match and int(match.group(1)) >= 14:@@ -3828,8 +3833,9 @@ class ShellFileOperations(FileOperations):result = self._exec(cmd, timeout=60)stdout, limit_reason = _search_stdout_and_limit(result)all_files = [f for f in stdout.splitlines() if f]+ bounded_sigpipe = result.exit_code == 141 and len(all_files) >= fetch_limit- if result.exit_code not in {0, 1, 124}:+ if result.exit_code not in {0, 1, 124} and not bounded_sigpipe:if order == "modified":return SearchResult(error=("Exact modification-time order failed; ripgrep 14+ is "