feat/fast and no save sessions flag for quick one shot prompt execution#24717
Conversation
This commit introduces a new `--fast` flag designed to reduce the execution time and API payload size for simple, single-turn prompts.
Key features of Fast Mode:
- **Zero Pre-flight Requests**: Skips all non-essential network calls during initialization, including:
- User quota checks (`/v1internal:retrieveUserQuota`)
- Experiment fetching (`/v1internal:listExperiments`)
- Admin control requests (`/v1internal:fetchAdminControls`)
- OAuth metadata validation (`/tokeninfo`)
- **Minimal Request Payload**: Automatically strips the following from the Gemini API request:
- Default System Prompt (no need for `GEMINI_SYSTEM_MD=/dev/null`)
- Session Context (OS info, current date, directory listings)
- Loaded Context (global, project, and extension memory)
- Tool Definitions (function declarations)
- **Feature Disabling**: Automatically turns off directory tree scanning, system/project hooks, and skill discovery.
- **Persistent Metadata Caching**: Implements a local cache at `~/.gemini/user_data.json` to store the Project ID and account tier. This allows Fast Mode to use your real project ID without needing a network call to fetch it, avoiding 'unknown-project' permission errors.
How to use:
`gemini --fast -p "your simple prompt"`
To warm up the cache after a long period of inactivity or account change:
`gemini --list-sessions`
Includes new unit tests in `packages/core/src/config/config_minimal.test.ts`.
This commit adds a new `--no-save-session` flag (mapped to the `--save-session` boolean option) that allows users to skip saving the chat conversation to disk. This is particularly useful when combined with `--fast` for transient prompts that do not need to be resumed or kept in the session history. Usage: `gemini --fast --no-save-session -p "transient prompt"` By default, sessions continue to be saved to disk (`--save-session=true`).
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 performance optimizations for the CLI by adding a 'fast' mode and a session persistence toggle. These changes are designed to streamline one-shot prompt execution by reducing network overhead and bypassing unnecessary initialization steps, while also providing users with more control over local file system usage. 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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a 'fast mode' and session persistence options to the CLI, aimed at reducing latency by minimizing request payloads and skipping preflight checks such as quota, experiments, and admin controls. While these optimizations improve performance, the review highlights critical security vulnerabilities where the 'fail-open' design allows users to bypass administrative security policies and hooks (e.g., Data Loss Prevention) via CLI flags. It is recommended to ensure security-critical operations are handled in a 'fail-closed' manner and cannot be overridden by less-trusted configuration scopes.
| if ( | ||
| this.config?.getSkipPreflightRequests() && | ||
| method !== 'generateContent' | ||
| ) { | ||
| return {} as T; | ||
| } |
There was a problem hiding this comment.
The requestPost method returns an empty object {} when skipPreflightRequests is enabled. This bypasses security-sensitive operations like fetchAdminControls. Security checks should be implemented in a 'fail-closed' manner; returning an empty object instead of performing the request can lead to an insecure default state. Ensure that security-critical requests are always executed or handled with a safe default that does not bypass policy enforcement.
References
- Security checks should be implemented in a 'fail-closed' manner. If an item's validity cannot be verified, it should be rejected by default.
| enableHooks: (settings.hooksConfig.enabled ?? true) && !argv.fast, | ||
| enableHooksUI: (settings.hooksConfig.enabled ?? true) && !argv.fast, |
There was a problem hiding this comment.
The --fast CLI flag disables the hook system, which is used for security policies such as Data Loss Prevention (DLP). Allowing users to bypass these hooks via a CLI flag undermines the security model. Security-sensitive settings should not allow less-trusted configuration scopes (like a user-provided CLI flag) to completely override or bypass more-trusted security enforcement mechanisms. Ensure security-critical hooks remain active even when performance optimizations are requested.
References
- Security checks should be implemented in a 'fail-closed' manner. If an item's validity cannot be verified, it should be rejected by default.
- Security-sensitive settings should not use a merge strategy that allows less-trusted configuration scopes to completely override more-trusted scopes.
| if (!this.skipPreflightRequests) { | ||
| const adminControlsEnabled = | ||
| experiments?.flags[ExperimentFlags.ENABLE_ADMIN_CONTROLS]?.boolValue ?? | ||
| false; | ||
| const adminControls = await fetchAdminControls( | ||
| codeAssistServer, | ||
| this.getRemoteAdminSettings(), | ||
| adminControlsEnabled, | ||
| (newSettings: AdminControlsSettings) => { | ||
| this.setRemoteAdminSettings(newSettings); | ||
| coreEvents.emitAdminSettingsChanged(); | ||
| }, | ||
| ); | ||
| this.setRemoteAdminSettings(adminControls); | ||
| } |
There was a problem hiding this comment.
The skipPreflightRequests flag skips the retrieval of remote admin controls. If these controls are intended to enforce organization-wide security policies, allowing users to bypass them via a CLI flag constitutes a security policy bypass. Security checks should be mandatory and fail-closed, ensuring that user-level configurations cannot override administrative security restrictions.
References
- Security checks should be implemented in a 'fail-closed' manner. If an item's validity cannot be verified, it should be rejected by default.
- Security-sensitive settings should not use a merge strategy that allows less-trusted configuration scopes to completely override more-trusted scopes.
fixes #16335
feat(cli): implement --fast mode to minimize one-shot prompt overhead
This commit introduces a new
--fastflag designed to reduce the execution time and API payload size for simple, single-turn prompts.Key features of Fast Mode:
/v1internal:retrieveUserQuota)/v1internal:listExperiments)/v1internal:fetchAdminControls)/tokeninfo)GEMINI_SYSTEM_MD=/dev/null)~/.gemini/user_data.jsonto store the Project ID and account tier. This allows Fast Mode to use your real project ID without needing a network call to fetch it, avoiding 'unknown-project' permission errors.How to use:
gemini --fast -p "your simple prompt"To warm up the cache after a long period of inactivity or account change:
gemini --list-sessionsfeat(cli): add --no-save-session flag to skip session persistence
This commit adds a new
--no-save-sessionflag (mapped to the--save-sessionboolean option) that allows users to skip saving the chat conversation to disk.This is particularly useful when combined with
--fastfor transient prompts that do not need to be resumed or kept in the session history.Usage:
gemini --fast --no-save-session -p "transient prompt"By default, sessions continue to be saved to disk (
--save-session=true).