google-gemini / google-gemini/gemini-cli

bug: resolved model config tools and systemInstruction are overwritten

Open
#28,650 0 comments 0 reactions 0 assignees View on GitHub
area/agent status/need-triage
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

## What happened?

`GeminiChat` resolves a `GenerateContentConfig` from the model configuration service and then silently overwrites any resolved `systemInstruction` and `tools` values with the chat instance's fields.

In `packages/core/src/core/geminiChat.ts:781-798`:

1. `modelConfigService.getResolvedConfig()` returns `newConfig`.
2. `newConfig` is assigned to `currentGenerateContentConfig`.
3. The final config spreads that object, then unconditionally assigns `systemInstruction: this.systemInstruction` and `tools: this.tools`.

The adjacent TODO explicitly notes that these fields should not be overwritten when supplied through config. There is currently no targeted test covering this precedence behavior.

## How can this be reproduced?

1. Configure a model alias/resolved model config with a distinctive `systemInstruction` or `tools` value.
2. Send a message through `GeminiChat` using that model configuration.
3. Inspect the `GenerateContentConfig` passed to the content generator.
4. The configured value has been replaced by the chat-level value.

The same behavior occurs when a retry switches models and resolves a new model-specific configuration.

## What did you expect to happen?

Configuration precedence should be explicit and consistent. Fields supplied by a resolved model configuration should either be preserved or intentionally merged with chat-level fields, rather than being silently discarded.

## Why this matters

This makes parts of the model-configuration contract ineffective. Specialized aliases can unexpectedly lose model-specific tools or instructions, and the behavior is difficult to diagnose because configuration resolution itself succeeds.

## Suggested direction

- Define precedence/merge semantics for chat invariants versus resolved model configuration.
- Preserve configured values where allowed, or reject unsupported fields during configuration validation.
- Add tests for initial requests and retry-driven model switches.

## Client information

Found by source audit on current `main`, commit `f47d6c6f7`. This is platform-independent core configuration behavior; `/about` output is not applicable.

Contributor guide

Open the contributing guide

Research direction

Start in packages/core/src/core/geminiChat.ts:781-798 and inspect the adjacent TODO and getResolvedConfig() flow. Trace how the final GenerateContentConfig is passed to the content generator during initial requests and retry-driven model switches. Done means precedence or merge semantics are defined and covered by tests for both paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.