The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(search): a non-executable rg binary is an error, not a skipped path
Teknium00695283ddde
diff --git a/tests/tools/test_search_permission_degradation.py b/tests/tools/test_search_permission_degradation.pyindex ddd8d598d97..d4007dc9e14 100644--- a/tests/tools/test_search_permission_degradation.py+++ b/tests/tools/test_search_permission_degradation.py@@ -322,6 +322,18 @@ def test_content_search_hard_error_regex_still_surfaced():assert result.warning is None[email protected]("code", [126, 2])+def test_content_search_engine_binary_not_executable_is_an_error(code):+ """The shell refusing to run rg itself is a broken invocation, not a skipped path."""+ env = RecordingEnvironment(rg_output="bash: /usr/bin/rg: Permission denied\n", rg_code=code)++ result = ShellFileOperations(env).search("needle", path="/repo", target="content")++ assert result.error is not None+ assert "/usr/bin/rg: Permission denied" in result.error+ assert "unreadable path" not in (result.warning or "")++# --- content search, grep lane (rg absent) ---------------------------------------diff --git a/tools/file_operations_search.py b/tools/file_operations_search.pyindex 404d7311cb5..46bd4c8a56e 100644--- a/tools/file_operations_search.py+++ b/tools/file_operations_search.py@@ -165,11 +165,15 @@ def _split_tool_diagnostics(output: str) -> tuple[str, str]:# find: ``find: '<path>': Permission denied`` (pruned grep lane; GNU find quotes the# path with ASCII ``'`` or, in a UTF-8 locale, with typographic quotes)# The ``(os error N)`` suffix is ripgrep's Rust io::Error spelling, so it is optional.+# The tool prefix is required: the shell's own ``bash: <path>/rg: Permission denied``+# (the engine binary itself is not executable) is a failed invocation, not a skip._PERMISSION_DENIED_RE = re.compile(- r"^(?:(?P<tool>rg|grep|find): )?(?P<path>.+?): "+ r"^(?P<tool>rg|grep|find): (?P<path>.+?): "r"(?:IO error for operation on .+?: )?Permission denied(?: \(os error \d+\))?$")+_SHELL_EXEC_FAILURE_CODES = frozenset({126, 127})+_FIND_QUOTES_RE = re.compile(r"^['\u2018]|['\u2019]$")# The native rg runner keeps at most this much stderr (a huge tree of unreadable dirs@@ -378,6 +382,10 @@ def _parse_search_output(result, output_mode: str, limit: int, offset: int,usable payload remains. ``warning`` is attached to files_only/content results."""stdout, limit_reason = _search_stdout_and_limit(result)diagnostics, payload = _split_tool_diagnostics(stdout)+ if result.exit_code in _SHELL_EXEC_FAILURE_CODES:+ # The shell could not run the engine at all (126 not executable, 127 not found).+ return SearchResult(error=f"Search failed: {result.stdout.strip() or 'Search error'}",+ total_count=0)if result.exit_code == 2 and not payload.strip():error_msg = diagnostics.strip() or result.stdout.strip() or "Search error"if _is_permission_only_error(error_msg):