Skip to content

feat(analytics): enhance error categorization and enrich analytics events for tools - #232

Merged
andyMrtnzP merged 2 commits into
mainfrom
feat/log-tool-failures-auto-274
Aug 4, 2026
Merged

feat(analytics): enhance error categorization and enrich analytics events for tools#232
andyMrtnzP merged 2 commits into
mainfrom
feat/log-tool-failures-auto-274

Conversation

@andyMrtnzP

@andyMrtnzP andyMrtnzP commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added consistent analytics categorization for user errors, API failures, timeouts, network issues, and unknown errors.
    • Analytics now include normalized success status, execution duration, and version information.
    • Agent and crawl operations report clearer failure details, including validation, connection, and timeout errors.
    • Prevented duplicate analytics events during tool execution.
  • Bug Fixes

    • Ensured failures are recorded before being surfaced to callers.
    • Improved consistency of analytics for unsuccessful tool and crawl executions.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change adds coarse analytics error categories, enriches tool events with normalized outcome data, prevents duplicate final events, and classifies failures in agent and crawl execution paths.

Changes

Analytics outcome reporting

Layer / File(s) Summary
Analytics classification contracts
src/@types/types.d.ts, src/lib/error-classifier.ts, test/lib/error-classifier.spec.ts
Adds AnalyticsErrorCategory and maps detailed, status-based, and thrown errors to analytics categories.
defineTool analytics lifecycle
src/lib/define-tool.ts, test/lib/define-tool.spec.ts
Adds event enrichment, duration and status normalization, categorized failure reporting, and duplicate-event prevention with tests.
Agent and crawl classifications
src/tools/agent.ts, src/tools/crawl.ts, test/tools/agent.spec.ts, test/tools/crawl.spec.ts
Adds categorized analytics for agent and crawl validation, connection, command, backend, initiation, timeout, and terminal-status paths.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ToolCaller
  participant defineTool
  participant ErrorClassifier
  participant AnalyticsHelper
  ToolCaller->>defineTool: Execute tool
  defineTool->>ErrorClassifier: Classify thrown error
  ErrorClassifier-->>defineTool: Return analytics category
  defineTool->>AnalyticsHelper: Emit enriched success or failure event
  defineTool-->>ToolCaller: Return result or rethrow error
Loading

Possibly related PRs

Poem

A rabbit logs each outcome bright,
Labels errors left and right.
Timeouts wear a careful name,
Duplicate events leave the frame.
One clean report, then hops away.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided, so the required summary, related issues, changes, test plan, and checklist are missing. Add a description that follows the repository template, including the change summary, related issues, test results, and checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes to analytics error categorization and enriched tool analytics events.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/log-tool-failures-auto-274

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/define-tool.ts`:
- Around line 257-261: Finalize success analytics only after all invocation work
succeeds: in src/lib/define-tool.ts lines 257-261, call def.format before the
default analytics emission; in test/lib/define-tool.spec.ts lines 170-182, add
coverage for formatter failure with default successful analytics properties; in
src/tools/crawl.ts lines 365-370, move the terminal crawl event emission until
after page content fetching and result construction complete.

In `@src/lib/error-classifier.ts`:
- Around line 161-171: Unify HTTP 4xx analytics classification by extracting the
shared status-to-category policy from ANALYTICS_CATEGORY and the mapper in
define-tool.ts into one reusable mapper. Update both the error classification
path and the status mapping path to use it, ensuring UNAUTHORIZED, FORBIDDEN,
and NOT_FOUND resolve consistently as user_error.

In `@src/tools/agent.ts`:
- Around line 617-619: Ensure every failure path in the agent flow assigns a
concrete analytics category before the self-emission block builds
`error_category`, including the getOrCreateSession catch and
normalizeUploadCommand errors. Update the relevant handlers around
getOrCreateSession, normalizeUploadCommand, and the outer failure emitter so
caught errors are categorized or passed through a centralized failure emitter,
preventing the defineTool latch from receiving an unknown category.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 117332f7-04b0-413d-af39-ec75e0c6d8bb

📥 Commits

Reviewing files that changed from the base of the PR and between 4990103 and c3de5c9.

📒 Files selected for processing (8)
  • src/@types/types.d.ts
  • src/lib/define-tool.ts
  • src/lib/error-classifier.ts
  • src/tools/agent.ts
  • src/tools/crawl.ts
  • test/lib/define-tool.spec.ts
  • test/tools/agent.spec.ts
  • test/tools/crawl.spec.ts

Comment thread src/lib/define-tool.ts Outdated
Comment thread src/lib/error-classifier.ts Outdated
Comment thread src/tools/agent.ts Outdated
@andyMrtnzP
andyMrtnzP merged commit 323ae67 into main Aug 4, 2026
5 of 6 checks passed
@andyMrtnzP
andyMrtnzP deleted the feat/log-tool-failures-auto-274 branch August 4, 2026 23:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/lib/error-classifier.spec.ts (1)

170-198: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Pin the complete analytics normalization contract in these tests.

The HTTP loop uses categoryFromStatus(status) as its expected value. If categoryFromStatus and toAnalyticsCategory regress together, the test can still pass. Assert the concrete 'user_error' and 'api_error' values.

Add assertions for NAVIGATION_FAILED, INVALID_PARAMS, and UNKNOWN. These ErrorCategory values are not covered by the current non-HTTP test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/lib/error-classifier.spec.ts` around lines 170 - 198, Update the
analytics category tests in the “analytics categories” suite to assert concrete
HTTP outputs of user_error for 401/403/404 and api_error for 500, rather than
comparing to categoryFromStatus. Extend the non-HTTP coverage in the
toAnalyticsCategory test with NAVIGATION_FAILED, INVALID_PARAMS, and UNKNOWN,
asserting their expected normalized categories.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/lib/error-classifier.spec.ts`:
- Around line 170-198: Update the analytics category tests in the “analytics
categories” suite to assert concrete HTTP outputs of user_error for 401/403/404
and api_error for 500, rather than comparing to categoryFromStatus. Extend the
non-HTTP coverage in the toAnalyticsCategory test with NAVIGATION_FAILED,
INVALID_PARAMS, and UNKNOWN, asserting their expected normalized categories.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f9641b26-851f-490d-b573-7b6dbbbceafb

📥 Commits

Reviewing files that changed from the base of the PR and between c3de5c9 and 061e4ba.

📒 Files selected for processing (6)
  • src/lib/define-tool.ts
  • src/lib/error-classifier.ts
  • src/tools/agent.ts
  • src/tools/crawl.ts
  • test/lib/define-tool.spec.ts
  • test/lib/error-classifier.spec.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • test/lib/define-tool.spec.ts
  • src/tools/agent.ts
  • src/tools/crawl.ts
  • src/lib/error-classifier.ts
  • src/lib/define-tool.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant