Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,9 @@ export class Config {
private sessionService: SessionService | undefined = undefined;
private chatRecordingService: ChatRecordingService | undefined = undefined;
private fileCheckpointingEnabled: boolean;
// Object (not primitive) so sub-agents via Object.create(parentConfig)
// share the same budget instance through prototype lookup.
private readonly toolResultBudget = { bytesWritten: 0 };
private fileHistoryService: FileHistoryService | undefined;
private readonly proxy: string | undefined;
private cwd: string;
Expand Down Expand Up @@ -2269,6 +2272,7 @@ export class Config {
// constructed via Object.create — those should clear their own
// cache, not the parent's.
this.getFileReadCache().clear();
this.toolResultBudget.bytesWritten = 0;
this.getMemoryPressureMonitor()?.resetForNewSession();
this.fileHistoryService = undefined;
refreshSessionContext(this.sessionId);
Expand Down Expand Up @@ -4245,6 +4249,14 @@ export class Config {
return this.toolOutputBatchBudget;
}

trackToolResultBytes(n: number): void {
this.toolResultBudget.bytesWritten += n;
}

getToolResultBytesWritten(): number {
return this.toolResultBudget.bytesWritten;
}

getOutputFormat(): OutputFormat {
return this.outputFormat;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/config/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ export class Storage {
return targetDir;
}

getToolResultsDir(): string {
return path.join(this.getProjectTempDir(), 'tool-results');
}

ensureProjectTempDirExists(): void {
fs.mkdirSync(this.getProjectTempDir(), { recursive: true });
}
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/core/__snapshots__/prompts.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -308,6 +309,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -553,6 +555,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -778,6 +781,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -1003,6 +1007,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -1228,6 +1233,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -1453,6 +1459,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -1678,6 +1685,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -1903,6 +1911,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -2128,6 +2137,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -2376,6 +2386,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -2687,6 +2698,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -2935,6 +2947,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -3242,6 +3255,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down Expand Up @@ -3467,6 +3481,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
**Key Principle:** Start with a reasonable plan based on available information, then adapt as you learn. Users prefer seeing progress quickly rather than waiting for perfect understanding.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
- When you see a <persisted-output> tag in a tool result, the full output was saved to disk because it was too large. Use the read_file tool to access the complete content if the preview is insufficient.

## New Applications

Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import process from 'node:process';
// Config
import { ApprovalMode, type Config } from '../config/config.js';
import { createDebugLogger } from '../utils/debugLogger.js';
import { cleanupOldToolResults } from '../utils/toolResultCleanup.js';
import { Storage } from '../config/storage.js';
import { recordStartupEvent } from '../utils/startupEventSink.js';
import {
microcompactHistory,
Expand Down Expand Up @@ -311,6 +313,12 @@ export class GeminiClient {
}

this.initializedSessionId = sessionId;

// Clean up stale tool result files from previous sessions (fire-and-forget)
void cleanupOldToolResults(
Storage.getGlobalTempDir(),
24 * 60 * 60 * 1000,
);
}

/**
Expand Down Expand Up @@ -642,6 +650,11 @@ export class GeminiClient {
// pointing at content the model can no longer retrieve.
debugLogger.debug('[FILE_READ_CACHE] clear after resetChat');
this.config.getFileReadCache().clear();
// Clean up old tool result overflow files on /clear
void cleanupOldToolResults(
Storage.getGlobalTempDir(),
24 * 60 * 60 * 1000,
);
this.config.getBaseLlmClient().clearPerModelGeneratorCache();
// Abort any in-flight auto-memory recall so the stale controller
// does not leak into the next session.
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/core/coreToolScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,10 @@ describe('CoreToolScheduler', () => {
}),
storage: {
getProjectTempDir: () => '/tmp',
getToolResultsDir: () => '/tmp/tool-results',
},
getToolResultBytesWritten: () => 0,
trackToolResultBytes: vi.fn(),
getTruncateToolOutputThreshold: () =>
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
Expand Down Expand Up @@ -3030,7 +3033,10 @@ describe('CoreToolScheduler', () => {
}),
storage: {
getProjectTempDir: () => '/tmp',
getToolResultsDir: () => '/tmp/tool-results',
},
getToolResultBytesWritten: () => 0,
trackToolResultBytes: vi.fn(),
getTruncateToolOutputThreshold: () =>
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
Expand Down Expand Up @@ -3119,7 +3125,10 @@ describe('CoreToolScheduler', () => {
}),
storage: {
getProjectTempDir: () => '/tmp',
getToolResultsDir: () => '/tmp/tool-results',
},
getToolResultBytesWritten: () => 0,
trackToolResultBytes: vi.fn(),
getTruncateToolOutputThreshold: () =>
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
Expand Down Expand Up @@ -8103,7 +8112,10 @@ describe('Fire hook functions integration', () => {
}),
storage: {
getProjectTempDir: () => '/tmp',
getToolResultsDir: () => '/tmp/tool-results',
},
getToolResultBytesWritten: () => 0,
trackToolResultBytes: vi.fn(),
getTruncateToolOutputThreshold: () =>
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
getTruncateToolOutputLines: () => DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES,
Expand Down
Loading
Loading