Skip to content

Commit 5faea74

Browse files
committed
fix(telemetry): respect consent and stabilize CI tests
1 parent 3d0d2b5 commit 5faea74

7 files changed

Lines changed: 31 additions & 5 deletions

File tree

apps/vscode-e2e/src/fixtures/subtasks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const SUBTASK_API_HANG_PARENT_PROMPT = `${SUBTASK_API_HANG_PARENT_MARKER}
3232
export const SUBTASK_API_HANG_RESUME_MESSAGE = "Continue after provider hang."
3333
export const SUBTASK_API_HANG_CHILD_RESULT = "Hung child completed"
3434
export const SUBTASK_API_HANG_PARENT_RESULT = "API hang parent resumed"
35+
export const SUBTASK_API_HANG_RESPONSE_LATENCY_MS = 15_000
3536

3637
// Abandon-subtask scenario (#559) — separate markers to avoid sequenceIndex collisions with the
3738
// interrupted-child-resumes tests above, which exhaust the sequence count for INTERRUPT markers.
@@ -262,7 +263,7 @@ export function addSubtaskFixtures(mock: InstanceType<typeof LLMock>) {
262263
sequenceIndex: 0,
263264
},
264265
// Keep the first child response pending long enough for the e2e test to cancel an in-flight API request.
265-
latency: 15_000,
266+
latency: SUBTASK_API_HANG_RESPONSE_LATENCY_MS,
266267
response: {
267268
toolCalls: [
268269
{

apps/vscode-e2e/src/suite/subtasks.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SUBTASK_API_HANG_PARENT_PROMPT,
1818
SUBTASK_API_HANG_PARENT_RESULT,
1919
SUBTASK_API_HANG_RESUME_MESSAGE,
20+
SUBTASK_API_HANG_RESPONSE_LATENCY_MS,
2021
SUBTASK_CHILD_FOLLOWUP_ANSWER,
2122
SUBTASK_FAST_CHILD_RESULT,
2223
SUBTASK_FAST_PARENT_PROMPT,
@@ -72,6 +73,12 @@ const waitForAimockRequestContaining = async (expectedText: string, excludeText?
7273
suite("Roo Code Subtasks", function () {
7374
setDefaultSuiteTimeout(this)
7475

76+
// Task cancellation aborts the client request asynchronously. Let the extension host
77+
// finish disposing it before the next test reuses the mock server.
78+
teardown(async () => {
79+
await sleep(1_500)
80+
})
81+
7582
test("child completing on its first response returns to parent", async () => {
7683
const api = globalThis.api
7784
const says: Record<string, ClineMessage[]> = {}
@@ -580,6 +587,9 @@ suite("Roo Code Subtasks", function () {
580587
await api.clearCurrentTask()
581588
}
582589
await waitFor(() => api.getCurrentTaskStack().length === 0).catch(() => {})
590+
// aimock does not cancel delayed server-side streams when the client aborts.
591+
// Drain this fixture before the next test can open another streamed request.
592+
await sleep(SUBTASK_API_HANG_RESPONSE_LATENCY_MS)
583593
}
584594
})
585595

packages/telemetry/src/TelemetryService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export class TelemetryService {
150150
return
151151
}
152152

153+
if (!this.isTelemetryEnabled()) {
154+
return
155+
}
156+
153157
if (this.shouldDropForCircuitBreaker(eventName)) {
154158
return
155159
}

src/__tests__/history-resume-delegation.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ describe("History resume delegation - parent metadata transitions", () => {
12551255
userMessageContent: [],
12561256
consecutiveMistakeCount: 0,
12571257
emitFinalTokenUsageUpdate: vi.fn(),
1258+
flushTelemetryInstallment: vi.fn(),
12581259
} as unknown as import("../core/task/Task").Task
12591260

12601261
const block = {

src/api/providers/fetchers/__tests__/modelCache.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ vi.mock("@roo-code/telemetry", () => ({
55
TelemetryService: {
66
instance: {
77
captureEvent: vi.fn(),
8+
isTelemetryEnabled: vi.fn().mockReturnValue(true),
89
},
910
},
1011
}))

src/api/providers/fetchers/modelCache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ function captureModelCacheEmptyResponseOnce(
5959
return
6060
}
6161

62+
if (!TelemetryService.instance.isTelemetryEnabled()) {
63+
return
64+
}
65+
6266
reportedEmptyModelResponse.add(cacheKey)
6367
TelemetryService.instance.captureEvent(TelemetryEventName.MODEL_CACHE_EMPTY_RESPONSE, { provider, ...properties })
6468
}

src/extension.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,22 @@ export async function activate(context: vscode.ExtensionContext) {
174174
}
175175

176176
const contextProxy = await ContextProxy.getInstance(context)
177+
const updateTelemetryState = () => {
178+
const telemetrySetting = contextProxy.getGlobalState("telemetrySetting") ?? "unset"
179+
TelemetryService.instance.updateTelemetryState(
180+
isTelemetryOptedIn(telemetrySetting) && vscode.env.isTelemetryEnabled,
181+
)
182+
}
183+
184+
updateTelemetryState()
177185

178186
// React live to VS Code's global telemetry toggle (recommended over only reading
179187
// telemetry.telemetryLevel, which PostHogTelemetryClient still checks as a secondary gate).
180188
// vscode.env.isTelemetryEnabled is ANDed in directly because the deprecated
181189
// telemetry.telemetryLevel setting the client checks doesn't reflect this live event.
182190
context.subscriptions.push(
183191
vscode.env.onDidChangeTelemetryEnabled(() => {
184-
const telemetrySetting = contextProxy.getGlobalState("telemetrySetting") ?? "unset"
185-
TelemetryService.instance.updateTelemetryState(
186-
isTelemetryOptedIn(telemetrySetting) && vscode.env.isTelemetryEnabled,
187-
)
192+
updateTelemetryState()
188193

189194
// Push the new vscode.env.isTelemetryEnabled value to the webview too, so its
190195
// own PostHog client (gated separately in TelemetryClient.ts) can't keep

0 commit comments

Comments
 (0)