fix(prompts): prevent models from hallucinating line numbers in apply_diff#641
fix(prompts): prevent models from hallucinating line numbers in apply_diff#641faitno wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe Changesapply_diff SEARCH Block Line-Number Warnings
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
b0e05a7 to
9b6bd77
Compare
|
Thanks for this, please clean up the CR to keep changes relevant to issues at hand |
7361c07 to
9a63336
Compare
|
Done! Force-pushed the branch with all unrelated changes removed — the PR now only touches |
|
|
||
| const APPLY_DIFF_DESCRIPTION = `Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for.` | ||
| const APPLY_DIFF_DESCRIPTION = `Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for. | ||
| CRITICAL WARNING: The 'read_file' tool outputs line numbers (e.g. '1: ', '2: ') for your convenience, but these line numbers DO NOT exist in the actual file! You MUST STRIP all line numbers from the 'SEARCH' block. Your 'SEARCH' block must match the RAW file content exactly.` |
There was a problem hiding this comment.
The example format looks off — read_file outputs lines as '1 | ' and '2 | ' (space-padded number + pipe), not '1: ' / '2: '. Could a model following this example end up looking for the wrong pattern to strip? (The actual format comes from addLineNumbers() in extract-text.ts:155.)
| >>>>>>> REPLACE` | ||
| >>>>>>> REPLACE | ||
|
|
||
| CRITICAL: DO NOT include line numbers (like '137: ') in the [exact content to find] section! It must match the actual file content, which does not have line numbers.` |
There was a problem hiding this comment.
Same here — read_file produces '137 | content' not '137: content'. Worth aligning the example with the actual output format, since the server-side auto-strip in multi-search-replace.ts also keys on the N | pattern.
|
I opened this issue: #716 |
Description
Models such as Gemini output line numbers in the
read_filetool (e.g.137: ...). When attempting to useapply_diff, models often copy these line numbers verbatim into the<<<<<<< SEARCHblock. Since the actual source files do not contain these line numbers, theapply_difftool strictly fails with anEdit Unsuccessfulerror, eventually leading to aconsecutiveMistakeLimitfailure in the extension.This PR strictly updates the system prompt and instructions for the
apply_difftool to explicitly instruct models to strip line numbers from theSEARCHblock so that it correctly matches the raw file content.Summary by CodeRabbit