The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(search): a real rg error past the stderr cap is not read as permission-only
Teknium95e1b6b7c24b
diff --git a/tests/tools/test_search_unreadable_bound.py b/tests/tools/test_search_unreadable_bound.pyindex f97980243d4..9339c1e2681 100644--- a/tests/tools/test_search_unreadable_bound.py+++ b/tests/tools/test_search_unreadable_bound.py@@ -76,3 +76,15 @@ def test_find_fallback_names_the_unreadable_dir(locked_tree, monkeypatch):assert result.error is Noneassert sorted(os.path.basename(p) for p in result.files) == [f"f{i}.log" for i in range(5)]assert f"Skipped 60 unreadable path(s) with restricted permissions: {locked_tree}/d" in (result.warning or "")+++def test_a_real_error_past_the_stderr_cap_is_not_read_as_permission_only(monkeypatch):+ monkeypatch.setattr(file_operations_search, "_STDERR_RETAIN_BYTES", 1)+ perm = [f"rg: /r/d{i}: Permission denied (os error 13)\n".encode() for i in range(5)]+ lines = perm[:3] + [b"rg: /r/gone: No such file or directory (os error 2)\n"] + perm[3:]+ chunks, omitted = [], [0]+ file_operations_search._drain_stderr_capped(iter(lines), chunks, omitted)+ text = b"".join(chunks).decode()+ assert "No such file or directory" in text+ assert omitted[0] == 4 # permission lines past the cap+ assert not file_operations_search._is_permission_only_error(text)diff --git a/tools/file_operations_search.py b/tools/file_operations_search.pyindex 6be12a7750f..404d7311cb5 100644--- a/tools/file_operations_search.py+++ b/tools/file_operations_search.py@@ -300,10 +300,18 @@ def _find_exit_verdict(exit_code: int, raw_files: list[str], diagnostics: list[sdef _drain_stderr_capped(pipe, chunks: list[bytes], omitted: list[int]) -> None:"""Read ``pipe`` to EOF (rg must never block on a full stderr pipe) but keep only thefirst ``_STDERR_RETAIN_BYTES``; the first line is always kept so a lone huge diagnostic- still names the failure. ``omitted[0]`` counts the dropped lines."""+ still names the failure. ``omitted[0]`` counts the dropped lines. Past the cap the first+ non-permission line is still kept, so a real failure behind a flood of permission+ errors is never classified as a permission-only partial success."""kept = 0+ kept_other = Falsefor raw in pipe or ():if chunks and kept + len(raw) > _STDERR_RETAIN_BYTES:+ line = raw.decode("utf-8", "replace").strip()+ if not kept_other and line and not _PERMISSION_DENIED_RE.match(line):+ chunks.append(raw)+ kept_other = True+ continueomitted[0] += 1continuechunks.append(raw)