Skip to content

Commit 8df7f45

Browse files
authored
[Condense] Add isAutomaticTrigger to condense telemetry (RooCodeInc#3798)
1 parent d7ae811 commit 8df7f45

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/core/condense/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ export type SummarizeResponse = {
6060
* @param {ApiHandler} apiHandler - The API handler to use for token counting.
6161
* @param {string} systemPrompt - The system prompt for API requests, which should be considered in the context token count
6262
* @param {string} taskId - The task ID for the conversation, used for telemetry
63+
* @param {boolean} isAutomaticTrigger - Whether the summarization is triggered automatically
6364
* @returns {SummarizeResponse} - The result of the summarization operation (see above)
6465
*/
6566
export async function summarizeConversation(
6667
messages: ApiMessage[],
6768
apiHandler: ApiHandler,
6869
systemPrompt: string,
6970
taskId: string,
71+
isAutomaticTrigger?: boolean,
7072
): Promise<SummarizeResponse> {
71-
telemetryService.captureContextCondensed(taskId)
73+
telemetryService.captureContextCondensed(taskId, isAutomaticTrigger ?? false)
7274
const response: SummarizeResponse = { messages, cost: 0, summary: "" }
7375
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, -N_MESSAGES_TO_KEEP))
7476
if (messagesToSummarize.length <= 1) {

src/core/sliding-window/__tests__/sliding-window.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,13 @@ describe("truncateConversationIfNeeded", () => {
525525
})
526526

527527
// Verify summarizeConversation was called with the right parameters
528-
expect(summarizeSpy).toHaveBeenCalledWith(messagesWithSmallContent, mockApiHandler, "System prompt", taskId)
528+
expect(summarizeSpy).toHaveBeenCalledWith(
529+
messagesWithSmallContent,
530+
mockApiHandler,
531+
"System prompt",
532+
taskId,
533+
true,
534+
)
529535

530536
// Verify the result contains the summary information
531537
expect(result).toMatchObject({
@@ -663,7 +669,13 @@ describe("truncateConversationIfNeeded", () => {
663669
})
664670

665671
// Verify summarizeConversation was called with the right parameters
666-
expect(summarizeSpy).toHaveBeenCalledWith(messagesWithSmallContent, mockApiHandler, "System prompt", taskId)
672+
expect(summarizeSpy).toHaveBeenCalledWith(
673+
messagesWithSmallContent,
674+
mockApiHandler,
675+
"System prompt",
676+
taskId,
677+
true,
678+
)
667679

668680
// Verify the result contains the summary information
669681
expect(result).toMatchObject({

src/core/sliding-window/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function truncateConversationIfNeeded({
113113
const contextPercent = (100 * prevContextTokens) / contextWindow
114114
if (contextPercent >= autoCondenseContextPercent || prevContextTokens > allowedTokens) {
115115
// Attempt to intelligently condense the context
116-
const result = await summarizeConversation(messages, apiHandler, systemPrompt, taskId)
116+
const result = await summarizeConversation(messages, apiHandler, systemPrompt, taskId, true)
117117
if (result.summary) {
118118
return { ...result, prevContextTokens }
119119
}

src/services/telemetry/TelemetryService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ class TelemetryService {
120120
this.captureEvent(PostHogClient.EVENTS.TASK.CHECKPOINT_RESTORED, { taskId })
121121
}
122122

123-
public captureContextCondensed(taskId: string): void {
124-
this.captureEvent(PostHogClient.EVENTS.TASK.CONTEXT_CONDENSED, { taskId })
123+
public captureContextCondensed(taskId: string, isAutomaticTrigger: boolean): void {
124+
this.captureEvent(PostHogClient.EVENTS.TASK.CONTEXT_CONDENSED, { taskId, isAutomaticTrigger })
125125
}
126126

127127
public captureSlidingWindowTruncation(taskId: string): void {

0 commit comments

Comments
 (0)