The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
chore(file-ops): log compound probe fallbacks at debug level
Alex Jiae1c0c4bb6e21
diff --git a/tests/tools/test_file_ops_single_roundtrip.py b/tests/tools/test_file_ops_single_roundtrip.pyindex 33c26f74b2b..1c779682aec 100644--- a/tests/tools/test_file_ops_single_roundtrip.py+++ b/tests/tools/test_file_ops_single_roundtrip.py@@ -7,6 +7,7 @@ line count, trailing newline), so each proves the compound reply carriesthat answer."""+import loggingimport osimport sysimport threading@@ -448,3 +449,23 @@ class TestCompoundFallback:assert r.error is None and r.content == "1|one\n2|two\n3|"assert r.total_lines == 2+ def test_fallback_is_logged_at_debug(self, shell, tmp_path, caplog):+ """A backend that keeps falling back shows up in debug logs."""+ ops, calls = shell+ p = _write(tmp_path, "a.txt", b"one\n")+ real_exec = ops._exec++ def garbled(command, *args, **kwargs):+ if READ_PROBE_MARK in command:+ return ExecuteResult(stdout="garbage\n", exit_code=0)+ return real_exec(command, *args, **kwargs)++ with caplog.at_level(logging.DEBUG, logger="tools.file_operations"), \+ patch.object(ops, "_exec", side_effect=garbled):+ r = ops.read_file(p)+ assert r.error is None and r.content == "1|one\n2|"+ assert any(+ "falling back to sequential probes" in rec.getMessage()+ and str(p) in rec.getMessage()+ for rec in caplog.records+ )diff --git a/tools/file_operations.py b/tools/file_operations.pyindex 0440d08deb8..f988be4ac49 100644--- a/tools/file_operations.py+++ b/tools/file_operations.py@@ -34,6 +34,7 @@ import sysimport difflibimport hashlibimport json+import loggingimport unicodedatafrom abc import ABC, abstractmethodfrom dataclasses import dataclass, field@@ -48,6 +49,8 @@ from agent.file_safety import (is_write_denied as _shared_is_write_denied,)+logger = logging.getLogger(__name__)+# ---------------------------------------------------------------------------# Write-path deny list — blocks writes to sensitive system/credential files@@ -1596,10 +1599,20 @@ class ShellFileOperations(FileOperations):return self._read_file_missing(path, offset, limit)if marker == NOT_REGULAR_SENTINEL:return self._not_regular_error(path)+ logger.debug(+ "read_file: compound probe reply for %s has no sentinel "+ "(exit %s, %d chars); falling back to sequential probes",+ path, probe.exit_code, len(output),+ )return self._read_file_sequential(path, offset, limit)segments = _split_segments(output, sentinel)if probe.exit_code != 0 or len(segments) != 6:+ logger.debug(+ "read_file: compound probe for %s returned exit %s with %d "+ "segments (want 6); falling back to sequential probes",+ path, probe.exit_code, len(segments),+ )return self._read_file_sequential(path, offset, limit)size_seg, sample_seg, page_seg, wc_seg, tail_seg, status_seg = segments@@ -1607,6 +1620,11 @@ class ShellFileOperations(FileOperations):try:sample_rc, read_rc = int(status[0]), int(status[1])except (IndexError, ValueError):+ logger.debug(+ "read_file: compound probe for %s has unparseable status %r; "+ "falling back to sequential probes",+ path, status_seg[-40:],+ )return self._read_file_sequential(path, offset, limit)try:@@ -1621,6 +1639,11 @@ class ShellFileOperations(FileOperations):if sample_bytes is not None:is_binary = self._is_likely_binary_bytes(sample_bytes)else:+ logger.debug(+ "read_file: no usable base64 sample for %s (base64 exit %s); "+ "paying one extra round-trip for the text heuristic",+ path, sample_rc,+ )sample_cmd = f"head -c 1000 {self._escape_shell_arg(path)} 2>/dev/null"sample_result = self._exec(sample_cmd)sample_output = _strip_terminal_fence_leaks(sample_result.stdout)@@ -2354,16 +2377,31 @@ class ShellFileOperations(FileOperations):if _strip_terminal_fence_leaks(output).strip() == MISSING_SENTINEL:ending = _detect_line_ending(pre_content) if pre_content else Nonereturn False, pre_content, ending+ logger.debug(+ "write_file: pre-write probe reply for %s has no sentinel "+ "(exit %s, %d chars); falling back to sequential probes",+ path, probe.exit_code, len(output),+ )return self._probe_write_target_sequential(path, pre_content, want_pre)segments = _split_segments(output, sentinel)if probe.exit_code != 0 or len(segments) != 2:+ logger.debug(+ "write_file: pre-write probe for %s returned exit %s with %d "+ "segments (want 2); falling back to sequential probes",+ path, probe.exit_code, len(segments),+ )return self._probe_write_target_sequential(path, pre_content, want_pre)head_seg, body = segmentshead_bytes = self._decode_base64_sample(head_seg)if head_bytes is None:# No clean base64 on this shell; ask the way we used to.+ logger.debug(+ "write_file: no usable base64 head for %s; paying one extra "+ "round-trip for the BOM probe",+ path,+ )has_bom = self._file_has_bom(path, pre_content)else:has_bom = head_bytes.startswith(_UTF8_BOM.encode("utf-8"))