Skip to content

Gemini CLI is fond of using unsafe object cloning #22863

@gundermanc

Description

@gundermanc

I frequently see Gemini generate code that contains unsafe clones of objects where it only partially implements the target type: https://github.com/google-gemini/gemini-cli/pull/22718/changes#diff-f55318278466b9e64c975f9b3d4946a89d4bc5093f4eef67bcf4ae4d487cc7dfR67

 // Create a proxy/override of the config to provide the agent-specific registries.
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, no-restricted-syntax
  const agentConfig: Config = Object.create(config);
  agentConfig.getToolRegistry = () => toolRegistry;
  agentConfig.getMessageBus = () => toolRegistry.messageBus;

  if (promptRegistry) {
    agentConfig.getPromptRegistry = () => promptRegistry;
  }
  if (resourceRegistry) {
    agentConfig.getResourceRegistry = () => resourceRegistry;
  }

  // Override toolRegistry property so AgentLoopContext reads the agent-specific registry.
  Object.defineProperty(agentConfig, 'toolRegistry', {
    get: () => toolRegistry,
    configurable: true,
  });

The risk of this coding pattern is that it bypasses the compiler checks for the type and creates a variable of type Config that isn't actually a full config implementation. This is really a sign of an architectural problem in the codebase which we'd like to see the agent either avoid introducing.. or better yet.. incrementally improve.

Metadata

Metadata

Assignees

Labels

area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualityworkstream-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

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions