-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add API error telemetry to OpenRouter provider #9953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes ApiError: Expected toolResult blocks for mismatched IDs ## Problem Tool_result blocks sometimes had incorrect tool_use_id values, causing the Anthropic API to reject requests with errors like: "Expected toolResult blocks at messages.6.content for the following Ids: toolu_ABC, but found: toolu_XYZ" ## Solution Added centralized validation in addToApiConversationHistory() that: - Validates tool_result IDs against tool_use IDs from previous assistant message - Fixes mismatches using position-based matching - Logs warnings for debugging when corrections are made ## Changes - Added src/core/task/validateToolResultIds.ts with validation logic - Added src/core/task/__tests__/validateToolResultIds.spec.ts (12 tests) - Modified src/core/task/Task.ts to call validation - Simplified src/core/assistant-message/presentAssistantMessage.ts by removing redundant source-level validation
Review complete. No new issues found. The latest commit (ba3c0ce) reverts the unrelated tool_result ID validation changes that were accidentally included from #9952. This addresses the reviewer feedback. The revert is clean and correctly removes the Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the posthog error handling instead of just events? https://posthog.com/docs/error-tracking
- Replace .slice().reverse().find() with direct backwards loop - Avoids creating two intermediate arrays for large conversation histories - Applied to both addToApiConversationHistory and flushPendingToolResultsToHistory
- Replace manual backwards loop with findLastIndex in both addToApiConversationHistory and flushPendingToolResultsToHistory - Improves clarity and consistency with existing code patterns
- Add new TelemetryEventName.API_ERROR to telemetry types - Log API errors to PostHog with sanitized error messages - Use sanitizeErrorMessage to redact sensitive info (URLs, paths, IPs, emails) - Add tests for telemetry capture in error scenarios
- Add EXPECTED_API_ERROR_CODES and shouldReportApiErrorToTelemetry to types package - Filter out 429 rate limit errors from telemetry (expected behavior) - Add tests to verify 429 errors don't trigger telemetry
5b144be to
0d0ab5d
Compare
Summary
Add API error telemetry to the OpenRouter provider using PostHog's
captureExceptionfor structured error tracking.Changes
ApiProviderErrorgeneric error class in@roo-code/typesfor structured error tracking via PostHog (can be reused by other providers)createMessagemethod (both SDK errors and streaming errors)completePromptmethod (both SDK errors and response errors)shouldReportApiErrorToTelemetry()to filter out expected errors like 429 rate limitsDepends on
captureExceptionto TelemetryService)Test plan