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
2 changes: 2 additions & 0 deletions packages/core/src/core/geminiChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
logContentRetry,
logContentRetryFailure,
} from '../telemetry/loggers.js';
import { clearDetailedSpanState } from '../telemetry/detailed-span-attributes.js';
import { type ChatRecordingService } from '../services/chatRecordingService.js';
import {
ChatCompressionService,
Expand Down Expand Up @@ -1400,6 +1401,7 @@ export class GeminiChat {
this.setHistory(newHistory);
debugLogger.debug('[FILE_READ_CACHE] clear after auto tryCompress');
this.config.getFileReadCache().clear();
clearDetailedSpanState();
this.lastPromptTokenCount = info.newTokenCount;
this.telemetryService?.setLastPromptTokenCount(info.newTokenCount);
// Reset the consecutive-failure counter on success so a forced /compress
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/telemetry/detailed-span-attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,28 @@ describe('detailed-span-attributes', () => {
addSystemPromptAttributes(config, span2, 'Same prompt');
expect(span2.attrs['system_prompt']).toBe('Same prompt');
});

it('resets seenHashes so tool schema full body is re-emitted after compression', () => {
const config = createMockConfig();
const tools = [
{ name: 'Read', description: 'Read a file', parameters: {} },
];

const span1 = createMockSpan();
addToolSchemaAttributes(config, span1, tools);
expect(span1.events.length).toBe(1);
expect(span1.events[0]!.attributes['tool_definition']).toBeDefined();

const span2 = createMockSpan();
addToolSchemaAttributes(config, span2, tools);
expect(span2.events.length).toBe(0);

clearDetailedSpanState();

const span3 = createMockSpan();
addToolSchemaAttributes(config, span3, tools);
expect(span3.events.length).toBe(1);
expect(span3.events[0]!.attributes['tool_definition']).toBeDefined();
});
});
});
4 changes: 2 additions & 2 deletions packages/core/src/telemetry/detailed-span-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { safeJsonStringify } from '../utils/safeJsonStringify.js';
const MAX_CONTENT_SIZE = 60 * 1024; // 60KB
const SYSTEM_PROMPT_PREVIEW_LENGTH = 500;

// Process-global; intentionally never cleared in production. Bounded by the
// number of unique system prompts + tool schemas seen in one session.
// Process-global dedup set. Cleared on chat compression so post-compaction
// spans re-emit full system prompts and tool schemas.
const seenHashes = new Set<string>();

function isEnabled(config: Config): boolean {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,5 @@ export {
addToolInputAttributes,
addToolResultAttributes,
truncateContent,
clearDetailedSpanState,
} from './detailed-span-attributes.js';
Loading