Skip to content

Refactor loadCliConfig to initialize ExtensionManager once during startup #23171

@moisgobg

Description

@moisgobg

Background

During the CLI application startup sequence in packages/cli/src/gemini.tsx, we currently call loadCliConfig twice:

  1. partialConfig: Initial load to determine workspace settings, basic auth, and extension metadata.
  2. config: Final load after authenticating and fetching remote admin policies, to ensure blocked MCP servers or tools are stripped out.

The Problem

Inside loadCliConfig (located in packages/cli/src/config/config.ts), a new instance of ExtensionManager is created and await extensionManager.loadExtensions() is called every time.

Because loadExtensions performs significant disk I/O (reading package.json, checking extension integrity signatures, parsing hooks.json), executing this twice on every CLI boot adds unnecessary latency.

It also historically caused side-effects, such as duplicate UserFeedback warnings being emitted for the same extensions (e.g., warnings about missing settings or the conductor -> sdd replacement). While these duplicate warnings have been temporarily suppressed using a deduplication Set in ExtensionManager.ts, the redundant I/O remains.

Proposed Solution

Refactor the CLI startup lifecycle so that ExtensionManager is instantiated and loaded exactly once.

  1. Instantiate the ExtensionManager and call await loadExtensions() early in the gemini.tsx startup flow.
  2. Update the loadCliConfig signature (and its LoadCliConfigOptions) to accept an already-initialized ExtensionManager instance rather than creating its own.
  3. Ensure that any admin policies fetched between the first and second config generation passes can be dynamically applied to the cached ExtensionManager state.

Impact

  • Performance: Faster startup by halving the extension parsing I/O.
  • Code Quality: Removal of the emittedWarnings deduplication hack in ExtensionManager.
  • Note: This will require updating several test files (e.g., config.test.ts, workspace-policy-cli.test.ts) that currently invoke loadCliConfig() directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalityworkstream-rollupLabel used to tag epics and features that are associated with one of the three primary workstreams🔒 maintainer only⛔ Do not contribute. Internal roadmap item.

    Type

    No fields configured for Bug.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions