Skip to content

fix(core): strip only the trailing .json from checkpoint names#28044

Open
he-yufeng wants to merge 1 commit into
google-gemini:mainfrom
he-yufeng:fix/checkpoint-name-json-strip
Open

fix(core): strip only the trailing .json from checkpoint names#28044
he-yufeng wants to merge 1 commit into
google-gemini:mainfrom
he-yufeng:fix/checkpoint-name-json-strip

Conversation

@he-yufeng

Copy link
Copy Markdown

What

processRestorableToolCalls and getCheckpointInfoList strip the .json suffix from checkpoint names with name.replace('.json', ''), which removes the first .json rather than the trailing extension.

generateCheckpointFileName embeds the edited file's basename: ${timestamp}-${basename}-${toolName}. So editing a .json file yields a checkpoint file like 2025-...-config.json-replace.json, and replace('.json', '') turns it into 2025-...-config-replace.json — the inner .json is dropped and the real extension is left behind, corrupting the name used to map and restore the checkpoint.

Fix

  • In processRestorableToolCalls, use the in-scope checkpointFileName directly — it is exactly the name without the .json we just appended.
  • In getCheckpointInfoList, use path.basename(file, '.json'), which strips only the trailing extension. This is what the neighbouring getTruncatedCheckpointNames already does for the same kind of name.

Test

Added two cases to checkpointUtils.test.ts: a checkpoint created for an edited config.json keeps config.json-replace in its mapped name, and a 2025-...-config.json-replace.json checkpoint file resolves to 2025-...-config.json-replace. Both fail on main (the name comes back as config-replace) and pass with this change. vitest run on the file is green (17 tests); prettier and eslint are clean.

@he-yufeng he-yufeng requested a review from a team as a code owner June 19, 2026 17:15
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Checkpoint Naming Fix: Corrected logic in processRestorableToolCalls and getCheckpointInfoList to ensure only the trailing .json extension is stripped from checkpoint filenames.
  • Preventing Name Corruption: Updated the implementation to avoid using .replace('.json', ''), which incorrectly removed internal .json segments from filenames when editing .json files.
  • Regression Testing: Added comprehensive test cases to checkpointUtils.test.ts to verify that checkpoints for edited .json files maintain their integrity.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 19, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 53
  • Additions: +51
  • Deletions: -2
  • Files changed: 2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +182 to +185
// 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'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
// 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$/, ''),

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant