Skip to content

Commit 9431c66

Browse files
author
Zoo (VP)
committed
fix(telemetry): remove redundant captureException calls that double-count errors
Issue #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 bac8adc commit 9431c66

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

@@ -693,19 +693,8 @@ export async function presentAssistantMessage(cline: Task) {
693693
await cline.say("user_feedback", text, images)
694694
}
695695

696-
// Track tool repetition in telemetry via PostHog exception tracking and event.
696+
// Track tool repetition in telemetry via a named event.
697697
TelemetryService.instance.captureConsecutiveMistakeError(cline.taskId)
698-
TelemetryService.instance.captureException(
699-
new ConsecutiveMistakeError(
700-
`Tool repetition limit reached for ${block.name}`,
701-
cline.taskId,
702-
cline.consecutiveMistakeCount,
703-
cline.consecutiveMistakeLimit,
704-
"tool_repetition",
705-
cline.apiConfiguration.apiProvider,
706-
cline.api.getModel().id,
707-
),
708-
)
709698

710699
// Return tool result message about the repetition
711700
pushToolResult(

‎src/core/task/Task.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
5353
MAX_CHECKPOINT_TIMEOUT_SECONDS,
5454
MIN_CHECKPOINT_TIMEOUT_SECONDS,
55-
ConsecutiveMistakeError,
5655
MAX_MCP_TOOLS_THRESHOLD,
5756
countEnabledMcpTools,
5857
providerIdentifiers,
@@ -2998,21 +2997,10 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
29982997
}
29992998

30002999
if (this.consecutiveMistakeLimit > 0 && this.consecutiveMistakeCount >= this.consecutiveMistakeLimit) {
3001-
// Track consecutive mistake errors in telemetry via event and PostHog exception tracking.
3000+
// Track consecutive mistake errors in telemetry via a named event.
30023001
// The reason is "no_tools_used" because this limit is reached via initiateTaskLoop
30033002
// which increments consecutiveMistakeCount when the model doesn't use any tools.
30043003
TelemetryService.instance.captureConsecutiveMistakeError(this.taskId)
3005-
TelemetryService.instance.captureException(
3006-
new ConsecutiveMistakeError(
3007-
`Task reached consecutive mistake limit (${this.consecutiveMistakeLimit})`,
3008-
this.taskId,
3009-
this.consecutiveMistakeCount,
3010-
this.consecutiveMistakeLimit,
3011-
"no_tools_used",
3012-
this.apiConfiguration.apiProvider,
3013-
getModelId(this.apiConfiguration),
3014-
),
3015-
)
30163004

30173005
const { response, text, images } = await this.ask(
30183006
"mistake_limit_reached",

0 commit comments

Comments
 (0)