Repository navigation
[Fix] PostHog captures one exception per API error - #2330
zoomote[bot] wants to merge 3 commits into
Conversation
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one): 1
Please check the settings in the CodeRabbit UI or the
|
|
No new code issues found. See session
Reviewed 17181aa |
Review statusThis PR was opened by an automated account. A human maintainer must verify the change intent, provenance, and validation before merging. Current step: Mark the PR ready. Required CI must pass before CodeRabbit starts. Review-state labels are managed by this workflow; do not edit them manually. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
2b1b074 to
5a48226
Compare
Related GitHub Issue
Closes: #513
Description
Providers caught API errors, sent one
$exceptionevent, and re-threw the same failure. The retry loop inTask#attemptApiRequestre-entered the provider on every attempt. One persistent API error produced three to six$exceptionevents. PR #1702 fixed Bugs 1 and 3 of issue #513. This PR fixes Bug 2 and Bug 4 and adds client-side deduplication.This PR picks Option B from the issue.
TelemetryService#captureExceptionnow enforces one capture per error occurrence with two guards:ApiProviderErrorgains acapturedflag. The first capture sets it. Re-throws of the same instance are no-ops. This guard also covers Bug 4.Providers keep their catch blocks and their captures. No telemetry is removed. The issue asked for an audit of capture paths outside the retry loop before this choice.
completePromptand similar paths capture once at the provider and keep doing so. The policy does not drop that telemetry.Bug 4:
OpenRouterHandler#handleStreamingErrorstays the single capture point for mid-stream OpenRouter errors. It now throws the sameApiProviderErrorinstance it captured, so an enclosing capture of that instance is a no-op through the flag. The caller-facing message text is unchanged. One payload note: the PostHog message now carries theOpenRouter API Error <code>:prefix, because one object is both captured and thrown.Test Procedure
New tests:
packages/telemetry/src/__tests__/TelemetryService.exception-single-capture.test.ts. Pins the flag, the window, window expiry, sliding refresh, distinct errors, plain errors, and the not-ready path. Eight tests.src/core/task/__tests__/Task.spec.tsadds a fault-injection test. It drives the real retry loop inattemptApiRequest. The provider seam captures and throws on attempts one and two and recovers on attempt three. The test asserts exactly one clientcaptureExceptioncall and a successful recovery.Consecutive Mistake Errorevent fires andcaptureExceptionnever runs.ConsecutiveMistakeErrortherefore never reaches$exception.src/api/providers/__tests__/openrouter.spec.tsexpects the captured message with theOpenRouter API Error <code>:prefix on the fourhandleStreamingErrorpaths.Commands and results:
pnpm --filter @roo-code/telemetry test: 59 tests pass.pnpm --dir src exec vitest run api/providers/__tests__/openrouter.spec.ts: 41 tests pass.pnpm --dir src exec vitest run core/task/__tests__/Task.spec.ts: 204 tests pass.pnpm testfrom the repository root: 565 test files pass, zero failures. Two unrelatedextension.spec.tstests flaked once under full-suite parallelism. The same flake reproduces on a cleanmaintree and is not caused by this change.tsc --noEmitpasses insrc,@roo-code/types, and@roo-code/telemetry.--prune-suppressionspasses on every changed file. No suppression count increases.Pre-Submission Checklist
src/test-utils/,@/utils/test-utils) are used only for mechanical duplication; test intent and scenario-specific mocks remain visible.Visual Snapshots
N/A. No UI changes.
Videos (interaction / animation only)
N/A.
Documentation Updates
Additional Notes
completePromptcall site. The retry loop has no bounded final failure under auto-approval. Option B removes no telemetry and keeps every capture site in place.$exceptionper distinct occurrence and follows the PostHog guidance on deduplication in retry loops. An identical error re-captures once a quiet gap exceeds the window.capturedflag reads asundefineduntil the first capture, so untouched error instances stay unchanged.Get in Touch
Discord: 0x7777777_.