Skip to content

fix(core): handle resume/update invalid-argument failures#20434

Open
alexaustin007 wants to merge 1 commit intogoogle-gemini:mainfrom
alexaustin007:fix/18811-invalid-argument
Open

fix(core): handle resume/update invalid-argument failures#20434
alexaustin007 wants to merge 1 commit intogoogle-gemini:mainfrom
alexaustin007:fix/18811-invalid-argument

Conversation

@alexaustin007
Copy link
Contributor

@alexaustin007 alexaustin007 commented Feb 26, 2026

Summary

This PR fixes the Request contains an invalid argument failures seen after resume/update flows (Issue #18811)

Details

Core request normalization:

  • Replaced active looponly thought signature logic with full history normalization.
  • Added two modes:
    • require for modern models (add synthetic thoughtSignature where missing)
    • strip for non-modern paths (remove thoughtSignature)
  • Normalization now runs per API attempt so model fallback is handled correctly.
  • Normalization is re-applied after hook-modified contents.
  • Added one compatibility retry on invalid-argument errors with flipped normalization mode.

Session resume robustness:

  • In convertSessionToClientHistory(), deduplicated function calls that appear in both msg.content and msg.toolCalls.
  • Dedup uses:
    • function call id first
    • stable args fingerprint fallback
    • count-based matching to avoid dropping legitimate repeated calls.

CLI update UX hardening:

  • Added restart-required state after successful auto-update.
  • While restart is required, blocks normal prompts.
  • Allows only /help, /about, and /quit.

Test updates:

  • Expanded core tests for full-history normalization, strip mode, idempotency, fallback behavior, and compatibility retry.
  • Added session dedup tests (id + stable fingerprint count matching).
  • Added CLI tests for restart gating and update-state handling.
  • Added integration resume repro test with signature normalization fixture.
  • Hardened one SDK integration test to use deterministic fake responses.

Related Issues

How to Validate

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@alexaustin007 alexaustin007 requested a review from a team as a code owner February 26, 2026 13:27
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @alexaustin007, 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 and resolves invalid-argument failures encountered during session resume and update flows. It significantly improves the stability and compatibility of API requests by intelligently handling thoughtSignature requirements across different model versions and enhances the reliability of session history reconstruction. Additionally, the user experience for CLI auto-updates is made clearer and more controlled by enforcing a restart state.

Highlights

  • Core Request Normalization: Implemented robust thoughtSignature normalization for API requests, introducing 'require' mode for modern models (adding synthetic signatures where missing) and 'strip' mode for non-modern paths (removing signatures). This normalization now runs per API attempt and after hook modifications, with a compatibility retry mechanism for invalid-argument errors.
  • Session Resume Robustness: Enhanced convertSessionToClientHistory() to deduplicate function calls that might appear in both msg.content and msg.toolCalls during session resume, using function call IDs and stable argument fingerprints for accurate matching.
  • CLI Update User Experience Hardening: Introduced a 'restart-required' state after successful auto-updates in the CLI, which blocks normal prompts and only allows essential commands like /help, /about, and /quit until the application is restarted.
  • Expanded Test Coverage: Added comprehensive tests for full-history normalization, strip mode, idempotency, fallback behavior, compatibility retries, session deduplication, CLI restart gating, and hardened SDK integration tests.
Changelog
  • integration-tests/resume_repro.test.ts
    • Added a new integration test to verify thought signature normalization for modern models during session resume.
  • integration-tests/resume_repro_signature_normalization.responses
    • Added fake API responses to support the new signature normalization integration test.
  • packages/cli/src/ui/AppContainer.tsx
    • Imported shouldBlockPromptForRestart utility.
    • Extracted historyManager.addItem to a local variable addHistoryItem for consistent use.
    • Added restartRequired state variable.
    • Updated setUpdateHandler call to pass setRestartRequired.
    • Implemented logic to block prompts when restartRequired is true, displaying an informative message.
  • packages/cli/src/ui/utils/restartGating.test.ts
    • Added unit tests for isCommandAllowedDuringRestart and shouldBlockPromptForRestart utilities.
  • packages/cli/src/ui/utils/restartGating.ts
    • Added new utility functions isCommandAllowedDuringRestart and shouldBlockPromptForRestart to manage CLI prompt blocking after an update.
  • packages/cli/src/utils/handleAutoUpdate.test.ts
    • Updated setUpdateHandler tests to include the new setRestartRequired callback.
    • Added assertions for setRestartRequired calls in update received, failed, and success scenarios.
  • packages/cli/src/utils/handleAutoUpdate.ts
    • Modified setUpdateHandler to accept and use a setRestartRequired callback.
    • Updated handleUpdateReceived, handleUpdateFailed, and handleUpdateSuccess to set the restartRequired state appropriately.
  • packages/core/src/core/geminiChat.test.ts
    • Added tests for compatibility retry logic on invalid-argument errors, ensuring one retry with flipped normalization mode.
    • Renamed and refactored ensureActiveLoopHasThoughtSignatures tests to normalizeThoughtSignaturesForRequest.
    • Expanded tests for normalizeThoughtSignaturesForRequest to cover full history normalization, require/strip modes, idempotency, and handling of empty/user-only history.
    • Added a test to verify thought signature normalization occurs per API attempt when model compatibility changes due to fallback.
    • Added a test to confirm hook-modified contents are normalized before sending the request.
  • packages/core/src/core/geminiChat.ts
    • Defined new types ThoughtSignatureNormalizationMode, ThoughtSignatureNormalizationStats, and ThoughtSignatureNormalizationContext.
    • Added lastThoughtSignatureNormalizationContext property to GeminiChat class.
    • Implemented compatibility retry logic within sendMessageStream for invalid-argument errors, flipping the thought signature normalization mode on retry.
    • Refactored ensureActiveLoopHasThoughtSignatures into normalizeThoughtSignaturesForRequest and normalizeThoughtSignaturesForRequestWithStats.
    • Introduced getThoughtSignatureNormalizationMode and flipThoughtSignatureNormalizationMode utilities.
    • Updated sendMessageStream to use the new normalization logic, applying it based on model features and re-applying after hook modifications.
  • packages/core/src/utils/sessionUtils.test.ts
    • Added tests for deduplicating function calls by ID when present in both content and tool calls.
    • Added tests for deduplicating function calls using stable argument fingerprints with count-based matching when IDs are absent.
  • packages/core/src/utils/sessionUtils.ts
    • Imported stableStringify utility.
    • Added helper functions incrementCount, consumeCount, and getFunctionCallFingerprint for deduplication.
    • Modified convertSessionToClientHistory to deduplicate function calls from msg.content and msg.toolCalls using IDs and argument fingerprints.
  • packages/sdk/src/agent.integration.test.ts
    • Hardened an integration test by adding fakeResponses to ensure deterministic behavior.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Code Review

This is a comprehensive pull request that effectively addresses the invalid-argument failures during session resume and update flows. The introduction of full-history thoughtSignature normalization with require and strip modes is a robust solution. The compatibility retry on invalid-argument errors is a clever way to handle model differences gracefully. Furthermore, the deduplication of function calls during session resume and the UX hardening for the auto-update process are excellent improvements to the tool's reliability and user experience. The accompanying tests are thorough and cover the new logic well.

Comment on lines +79 to +80
const parsedResult = JSON.parse(result);
expect(parsedResult.response).toContain('List complete.');
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There appears to be an issue with the assertion in this test. The test simulates two runs. The first run consumes the first two responses from the fixture, with the last model response being "List complete.". The second run, which is being asserted on here, consumes the third response from the fixture, which is "Resume complete.". Therefore, the assertion should check for "Resume complete." to correctly validate the behavior of the second run.

Suggested change
const parsedResult = JSON.parse(result);
expect(parsedResult.response).toContain('List complete.');
const parsedResult = JSON.parse(result);
expect(parsedResult.response).toContain('Resume complete.');

@gemini-cli gemini-cli bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality labels Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant