Skip to content

feat(core): implement tool repair and continuation auto-recovery - #25959

Closed
achernez wants to merge 6 commits into
google-gemini:mainfrom
achernez:feat/core-auto-repair-continuation
Closed

achernez wants to merge 6 commits into
google-gemini:mainfrom
achernez:feat/core-auto-repair-continuation

Conversation

@achernez

Copy link
Copy Markdown

This PR implements two key reliability features in the core package:

  1. Tool Repair: The scheduler now uses fuzzy matching and normalization to automatically repair slightly misspelled or incorrectly formatted tool names from the model.
  2. Continuation Auto-recovery: Legacy agent sessions now automatically detect responses truncated by token limits and prompt the model to continue, maintaining full conversation context.

Includes new utility fuzzy-matcher.ts and comprehensive tests for both features.

@achernez
achernez requested a review from a team as a code owner April 25, 2026 02:50
@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 introduces critical reliability enhancements to the core agent session and scheduler. By implementing automatic tool name repair and intelligent response continuation, the system becomes significantly more resilient to common LLM-related issues like hallucinated tool names and token truncation. Additionally, minor infrastructure improvements were made to build and linting processes to improve stability.

Highlights

  • Tool Repair: Implemented automatic repair for misspelled or incorrectly formatted tool names using normalization and fuzzy matching.
  • Continuation Auto-recovery: Added support for automatically detecting and recovering from truncated model responses due to token limits, ensuring conversation continuity.
  • Build and Lint Improvements: Updated build scripts to use a more robust workspace discovery method and replaced curl with wget in linting scripts for better compatibility.
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 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 counter productive. 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. ↩

@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 implements auto-continuation for truncated agent responses (MAX_TOKENS) and introduces a tool name repair mechanism using fuzzy matching and normalization to handle hallucinated tool calls. Review feedback highlights a bug in the continuation logic that duplicates conversation history, a regression in workspace detection robustness within the build script, and a reduction in script portability caused by switching from curl to wget in the linting setup.

);
this._emit([continuationMessage]);

currentParts = [...currentParts, { text: continuationPrompt }];

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

The continuation logic incorrectly appends the continuation prompt to the previous turn's input (currentParts). In LegacyAgentProtocol, currentParts is intended to be the input for the next model turn. Appending to it will cause the previous turn's input to be duplicated in the conversation history. It should be replaced with only the continuation prompt to ensure legacy behavior remains consistent with modern counterparts.

Suggested change
currentParts = [...currentParts, { text: continuationPrompt }];
currentParts = [{ text: continuationPrompt }];
References
  1. Legacy prompts should be kept consistent with their modern counterparts to ensure uniform behavior.

Comment thread scripts/build.js
Comment on lines +71 to 73
const parallelWorkspaces = getWorkspaces().filter(
(name) => name !== '@google/gemini-cli-core',
);

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

Replacing npm query .workspace with a manual getWorkspaces function is a regression in robustness. The manual implementation is fragile, assumes a specific directory structure (packages/*), and ignores the workspaces field in the root package.json. Reverting to the original npm query approach is more robust and maintainable. The getWorkspaces helper function should also be removed.

  const workspaceInfo = JSON.parse(
    execSync('npm query .workspace --json', { cwd: root, encoding: 'utf-8' }),
  );
  const parallelWorkspaces = workspaceInfo
    .map((w) => w.name)
    .filter((name) => name !== '@google/gemini-cli-core');

Comment thread scripts/lint.js Outdated
: `
mkdir -p "${TEMP_DIR}/actionlint"
curl -sSLo "${TEMP_DIR}/.actionlint.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.tar.gz"
wget -O "${TEMP_DIR}/.actionlint.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.tar.gz"

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

Changing curl to wget reduces the portability of the script. curl is more commonly available in minimal CI environments and containers. Unless there is a specific reason for this change, it is recommended to stick with curl.

Suggested change
wget -O "${TEMP_DIR}/.actionlint.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.tar.gz"
curl -sSLo "${TEMP_DIR}/.actionlint.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.tar.gz"

Comment thread scripts/lint.js Outdated
: `
mkdir -p "${TEMP_DIR}/shellcheck"
curl -sSLo "${TEMP_DIR}/.shellcheck.txz" "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${platformArch.shellcheck}.tar.xz"
wget -O "${TEMP_DIR}/.shellcheck.txz" "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${platformArch.shellcheck}.tar.xz"

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

Changing curl to wget reduces the portability of the script. curl is more commonly available in minimal CI environments and containers. Unless there is a specific reason for this change, it is recommended to stick with curl.

Suggested change
wget -O "${TEMP_DIR}/.shellcheck.txz" "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${platformArch.shellcheck}.tar.xz"
curl -sSLo "${TEMP_DIR}/.shellcheck.txz" "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${platformArch.shellcheck}.tar.xz"

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Apr 25, 2026
@achernez

Copy link
Copy Markdown
Author

I've addressed the review feedback:

  • Fixed the history duplication bug in the continuation logic by sending only the continuation prompt for subsequent calls.
  • Improved the portability of the linting script by prioritizing curl and falling back to wget.
  • Updated the build script to use npm query for more robust workspace discovery.
  • Verified that fast-levenshtein is correctly listed as a dependency in packages/core/package.json.

@achernez

Copy link
Copy Markdown
Author

/gemini review

@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 introduces auto-continuation for truncated LLM responses and a tool name hallucination repair mechanism. When a response is cut off due to token limits (MAX_TOKENS), the agent now automatically prompts for the remainder of the content, up to a limit of three continuations. Additionally, the scheduler now attempts to correct minor errors in tool names by normalizing kebab-case to snake_case and performing fuzzy matching using Levenshtein distance. Infrastructure improvements include refactored workspace detection in build scripts and a wget fallback for dependency installation in linting scripts. I have no feedback to provide as there were no review comments to evaluate.

@achernez

Copy link
Copy Markdown
Author

Closing in favor of split PRs #26158 (Tool Repair) and #26159 (Continuation Auto-recovery) to meet the project's atomicity and contribution guidelines.

@achernez achernez closed this Apr 29, 2026
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large 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.

2 participants