Skip to content

Commit 0ac21e8

Browse files
Zoo (VP)edelauna
authored andcommitted
fix(telemetry): remove redundant captureException calls that double-count errors
Issue Zoo-Code-Org#513 identified captureException sites where the same error is captured again downstream or where a named telemetry event already carries the signal: - Task.ts: captureException(new ConsecutiveMistakeError(...)) fired right after captureConsecutiveMistakeError(), routing a deliberate control-flow limit into error tracking as a duplicate. - presentAssistantMessage.ts: same redundant pairing for the tool_repetition guard. - openai-native.ts: handleStreamResponse captured stream-processing failures and rethrew, after which createMessage's catch captured the same failure again. The openrouter handleStreamingError capture was left in place: in current code its rethrown error is not captured anywhere downstream (createMessage has no enclosing catch for the stream loop and completePrompt invokes it outside its try/catch), so removing it would drop the only capture for mid-stream OpenRouter errors.
1 parent fafad20 commit 0ac21e8

3 files changed

Lines changed: 5 additions & 30 deletions

File tree

‎src/api/providers/openai-native.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,8 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
11291129
// If we didn't get any content, don't throw - the API might have returned an empty response
11301130
// This can happen in certain edge cases and shouldn't break the flow
11311131
} catch (error) {
1132-
const errorMessage = error instanceof Error ? error.message : String(error)
1133-
const apiError = new ApiProviderError(errorMessage, this.providerName, model.id, "createMessage")
1134-
TelemetryService.instance.captureException(apiError)
1135-
1132+
// No captureException here: the createMessage catch captures this
1133+
// failure once when the rethrown error propagates.
11361134
if (error instanceof Error) {
11371135
throw new Error(`Error processing response stream: ${error.message}`)
11381136
}

‎src/core/assistant-message/presentAssistantMessage.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { serializeError } from "serialize-error"
22
import { Anthropic } from "@anthropic-ai/sdk"
33

44
import type { ToolName, ClineAsk, ToolProgressStatus } from "@roo-code/types"
5-
import { ConsecutiveMistakeError, TelemetryEventName } from "@roo-code/types"
5+
import { TelemetryEventName } from "@roo-code/types"
66
import { TelemetryService } from "@roo-code/telemetry"
77
import { customToolRegistry } from "@roo-code/core"
88

@@ -835,19 +835,8 @@ async function presentAssistantMessageBlock(cline: Task): Promise<void> {
835835
await cline.say("user_feedback", text, images)
836836
}
837837

838-
// Track tool repetition in telemetry via PostHog exception tracking and event.
838+
// Track tool repetition in telemetry via a named event.
839839
TelemetryService.instance.captureConsecutiveMistakeError(cline.taskId)
840-
TelemetryService.instance.captureException(
841-
new ConsecutiveMistakeError(
842-
`Tool repetition limit reached for ${block.name}`,
843-
cline.taskId,
844-
cline.consecutiveMistakeCount,
845-
cline.consecutiveMistakeLimit,
846-
"tool_repetition",
847-
cline.apiConfiguration.apiProvider,
848-
cline.api.getModel().id,
849-
),
850-
)
851840

852841
// Return tool result message about the repetition
853842
pushToolResult(

‎src/core/task/Task.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import {
5555
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
5656
MAX_CHECKPOINT_TIMEOUT_SECONDS,
5757
MIN_CHECKPOINT_TIMEOUT_SECONDS,
58-
ConsecutiveMistakeError,
5958
MAX_MCP_TOOLS_THRESHOLD,
6059
countEnabledMcpTools,
6160
providerIdentifiers,
@@ -3782,21 +3781,10 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
37823781
}
37833782

37843783
if (this.consecutiveMistakeLimit > 0 && this.consecutiveMistakeCount >= this.consecutiveMistakeLimit) {
3785-
// Track consecutive mistake errors in telemetry via event and PostHog exception tracking.
3784+
// Track consecutive mistake errors in telemetry via a named event.
37863785
// The reason is "no_tools_used" because this limit is reached via initiateTaskLoop
37873786
// which increments consecutiveMistakeCount when the model doesn't use any tools.
37883787
TelemetryService.instance.captureConsecutiveMistakeError(this.taskId)
3789-
TelemetryService.instance.captureException(
3790-
new ConsecutiveMistakeError(
3791-
`Task reached consecutive mistake limit (${this.consecutiveMistakeLimit})`,
3792-
this.taskId,
3793-
this.consecutiveMistakeCount,
3794-
this.consecutiveMistakeLimit,
3795-
"no_tools_used",
3796-
this.apiConfiguration.apiProvider,
3797-
getModelId(this.apiConfiguration),
3798-
),
3799-
)
38003788

38013789
const { response, text, images } = await this.ask(
38023790
"mistake_limit_reached",

0 commit comments

Comments
 (0)