fix(core-tools): bypass LLM correction for JSON and IPYNB files in write_file and replace#28223
fix(core-tools): bypass LLM correction for JSON and IPYNB files in write_file and replace#28223amelidev wants to merge 3 commits into
Conversation
… in write_file and replace
|
📊 PR Size: size/M
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
|
/gemini review |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a targeted fix to prevent file corruption in .json and .ipynb files when using the write_file and replace tools. By bypassing LLM-based correction and unescaping logic for these specific file types, the system now preserves the integrity of structured data that was previously being incorrectly modified. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request disables LLM correction for JSON and Jupyter Notebook files (specifically targeting .json, .ipynb, .jsonc, and .json5 extensions) during file editing and writing tasks. This is implemented in edit.ts and write-file.ts by checking the file extension and skipping the correction steps if a match is found. Corresponding unit tests have been added to edit.test.ts and write-file.test.ts to verify this behavior. No review comments were provided, and I have no additional feedback.
There was a problem hiding this comment.
Code Review
This pull request skips LLM correction for JSON and Jupyter Notebook files (.json, .ipynb, .jsonc, and .json5) in both the edit and write-file tools to prevent potential corruption of structured data formats. Unit tests have been added to verify that the correction functions are not called for these file extensions. I have no feedback to provide as there are no review comments.
DavidAPierce
left a comment
There was a problem hiding this comment.
The only minor nit I might have is that since the list(s) of isJsonOrIpynb fileExt(s) are identical and re-used, it might be better to store and export the list as a const, or export the check for the lists inclusion and import them. Then the logic for determining which files do or do not qualify for this check, should it ever need to be changed, can be updated in a singular location without fear of de-synchronizing the logic of the checks.
LGTM either way.
Summary
This is a surgical PR that resolves a critical failure where both the
write_fileandreplacetools corrupted or failed to modify.ipynb(Jupyter Notebook) and.jsonfiles. This fix is designed to be highly focused and target only this issue to avoid regressions.Details
.ipynb/.jsonfile corruption issue and does nothing else. Any secondary or automatic reviews (including other Gemini reviews) must take this explicit surgical design constraint into account.write_file: Bypassed callingensureCorrectFileContent(which invokesunescapeStringForGeminiBug) for.json,.ipynb,.jsonc, and.json5extensions. This prevents unescaping of JSON strings (which corrupts backslashes like\\nand\\").replace: Bypassed invokingattemptSelfCorrection(which calls LLM-basedFixLLMEditWithInstruction) for.json,.ipynb,.jsonc, and.json5extensions. This prevents the LLM from trying to output search/replace strings on structured files with incorrect JSON-level escaping, avoiding file corruption on failure.Related Issues
Resolves the issue with
.ipynband.jsoncorruption reported inissue.md.How to Validate
Run relevant unit tests
Ensure both test files run and pass perfectly:
Run build and lint
Pre-Merge Checklist