fix(core): deduplicate project memory when JIT context is enabled (#22234)

This commit is contained in:
Sandy Tao
2026-03-13 21:34:53 -07:00
committed by GitHub
parent 64c50d32ac
commit 3682842a5d
2 changed files with 29 additions and 1 deletions

View File

@@ -165,6 +165,29 @@ describe('getEnvironmentContext', () => {
expect(getFolderStructure).not.toHaveBeenCalled();
});
it('should exclude environment memory when JIT context is enabled', async () => {
(mockConfig as Record<string, unknown>)['isJitContextEnabled'] = vi
.fn()
.mockReturnValue(true);
const parts = await getEnvironmentContext(mockConfig as Config);
const context = parts[0].text;
expect(context).not.toContain('Mock Environment Memory');
expect(mockConfig.getEnvironmentMemory).not.toHaveBeenCalled();
});
it('should include environment memory when JIT context is disabled', async () => {
(mockConfig as Record<string, unknown>)['isJitContextEnabled'] = vi
.fn()
.mockReturnValue(false);
const parts = await getEnvironmentContext(mockConfig as Config);
const context = parts[0].text;
expect(context).toContain('Mock Environment Memory');
});
it('should handle read_many_files returning no content', async () => {
const mockReadManyFilesTool = {
build: vi.fn().mockReturnValue({

View File

@@ -57,7 +57,12 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
? await getDirectoryContextString(config)
: '';
const tempDir = config.storage.getProjectTempDir();
const environmentMemory = config.getEnvironmentMemory();
// When JIT context is enabled, project memory is already included in the
// system instruction via renderUserMemory(). Skip it here to avoid sending
// the same GEMINI.md content twice.
const environmentMemory = config.isJitContextEnabled?.()
? ''
: config.getEnvironmentMemory();
const context = `
<session_context>