Skip to content

Commit 0ad0342

Browse files
committed
Add file reading guardrails to prevent review agent hallucination loops
The root review agent was entering infinite loops of guessing file paths that don't exist, burning through the entire 40-minute timeout without ever posting a review. In one observed case, the agent made 500+ consecutive read_file calls to hallucinated paths like "gordon/raft.md", "gordon/six-sigma.md", etc. This adds explicit guardrails to the root agent instructions: - Circuit breaker: stop after 3 consecutive "not found" reads - Cap total file reads at 10 for the root agent - Prohibit guessing file paths (use list_directory first) - Prohibit enumerating general concepts as file paths - Remove directory_tree from root agent toolset to discourage deep exploration (drafter/verifier handle file analysis)
1 parent 68c6c67 commit 0ad0342

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

review-pr/agents/pr-review.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ agents:
134134
135135
Find **real bugs in the changed code**, not style issues. If the changed code works correctly, approve it.
136136
137+
## CRITICAL: File Reading Guardrails
138+
139+
The root agent MUST NOT exhaustively explore the repository. Follow these rules strictly:
140+
141+
1. **Only read files that are directly relevant**: the diff, AGENTS.md/CLAUDE.md, and files
142+
explicitly referenced in the diff (e.g., imported modules, configuration files mentioned
143+
in changed code). Do NOT speculatively read files to "understand the project."
144+
2. **Never guess file paths**: If you need to check whether a file exists, use `list_directory`
145+
first. Do NOT try `read_file` on paths you are guessing — this wastes time and tokens.
146+
3. **Circuit breaker**: If 3 consecutive `read_file` calls return "not found", STOP reading
147+
files immediately and proceed with what you have. The drafter and verifier have their own
148+
`read_file` access and will read source files as needed during analysis.
149+
4. **Cap total file reads**: The root agent should read at most 10 files total (excluding the
150+
diff itself). The drafter and verifier handle deeper file analysis.
151+
5. **Never enumerate topics as file paths**: Do NOT try to read files named after general
152+
concepts (e.g., `consensus.md`, `raft.md`, `six-sigma.md`). Only read files that
153+
appear in the diff, the project tree, or are referenced by other files you've already read.
154+
137155
## Delivering the Review
138156
139157
You MUST always deliver a review, even if no issues were found.
@@ -200,7 +218,7 @@ agents:
200218

201219
toolsets:
202220
- type: filesystem
203-
tools: [read_file, read_multiple_files, list_directory, directory_tree]
221+
tools: [read_file, read_multiple_files, list_directory]
204222
- type: shell
205223
- type: memory
206224
path: .cache/pr-review-memory.db

0 commit comments

Comments
 (0)