fix(core): strip only the trailing .json from checkpoint names#28044
fix(core): strip only the trailing .json from checkpoint names#28044he-yufeng wants to merge 1 commit into
Conversation
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 addresses a bug in checkpoint filename handling where the use of a global string replacement was causing corruption in filenames containing multiple '.json' segments. By switching to more precise path handling and utilizing existing variables, the fix ensures that only the final file extension is removed, maintaining the correct mapping for restorable tool calls. 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
|
|
📊 PR Size: size/M
|
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where checkpoint names were corrupted when editing files that already contained '.json' in their name, by ensuring only the trailing '.json' extension is stripped. The reviewer pointed out that using path.basename to strip the extension might inadvertently remove directory paths and introduce platform-dependent behavior, suggesting a safer regex-based replacement file.replace(/\.json$/, '') instead.
| // basename(file, '.json') strips only the trailing extension; a | ||
| // plain replace('.json', '') would corrupt names from edited .json | ||
| // files (e.g. "...-config.json-replace.json"). | ||
| checkpoint: path.basename(file, '.json'), |
There was a problem hiding this comment.
Using path.basename(file, '.json') will strip any directory components from the path (e.g., subdir/file.json becomes file). If the checkpoint files contain directory paths, this will corrupt the checkpoint name. Additionally, path.basename is platform-dependent and may behave inconsistently on Windows vs. POSIX environments depending on the path separators used.
Using a regular expression like file.replace(/\.json$/, '') is safer as it only strips the trailing .json extension while preserving any directory structure and avoiding platform-specific path issues.
| // basename(file, '.json') strips only the trailing extension; a | |
| // plain replace('.json', '') would corrupt names from edited .json | |
| // files (e.g. "...-config.json-replace.json"). | |
| checkpoint: path.basename(file, '.json'), | |
| // Strip only the trailing .json extension while preserving any directory structure. | |
| checkpoint: file.replace(/\.json$/, ''), |
What
processRestorableToolCallsandgetCheckpointInfoListstrip the.jsonsuffix from checkpoint names withname.replace('.json', ''), which removes the first.jsonrather than the trailing extension.generateCheckpointFileNameembeds the edited file's basename:${timestamp}-${basename}-${toolName}. So editing a.jsonfile yields a checkpoint file like2025-...-config.json-replace.json, andreplace('.json', '')turns it into2025-...-config-replace.json— the inner.jsonis dropped and the real extension is left behind, corrupting the name used to map and restore the checkpoint.Fix
processRestorableToolCalls, use the in-scopecheckpointFileNamedirectly — it is exactly the name without the.jsonwe just appended.getCheckpointInfoList, usepath.basename(file, '.json'), which strips only the trailing extension. This is what the neighbouringgetTruncatedCheckpointNamesalready does for the same kind of name.Test
Added two cases to
checkpointUtils.test.ts: a checkpoint created for an editedconfig.jsonkeepsconfig.json-replacein its mapped name, and a2025-...-config.json-replace.jsoncheckpoint file resolves to2025-...-config.json-replace. Both fail onmain(the name comes back asconfig-replace) and pass with this change.vitest runon the file is green (17 tests); prettier and eslint are clean.