Skip to content

feat(core): improve exception mapping and analytics reporting - #760

Merged
haiphucnguyen merged 2 commits into
mainfrom
feature/improvements
Oct 11, 2026
Merged

haiphucnguyen merged 2 commits into
mainfrom
feature/improvements

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

Summary

  • Enhance ExceptionMapper to identify the deepest root cause in the exception chain.
  • Add specific handling for models that do not support multimodal inputs.
  • Expand AnalyticsEvent to capture both raw error messages and rendered user messages.
  • Add more granular error types to analytics (e.g., insufficient_credits, system_error).
  • Filter OpenAI-compatible models to only include catalog models (prefixed with @cf/).
  • Decouple message rendering from logging in ExceptionHandler.
  • Add unit tests for ExceptionMapper.

Related Issue(s)

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Enhance ExceptionMapper to identify the deepest root cause in the exception chain.
- Add specific handling for models that do not support multimodal inputs.
- Expand AnalyticsEvent to capture both raw error messages and rendered user messages.
- Add more granular error types to analytics (e.g., `insufficient_credits`, `system_error`).
- Filter OpenAI-compatible models to only include catalog models (prefixed with @cf/).
- Decouple message rendering from logging in ExceptionHandler.
- Add unit tests for ExceptionMapper.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 18:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Analytics can transmit sensitive raw error data, and new user-facing guidance bypasses localization.

3 open findings
What changed in this PR

Improves exception classification, user-facing rendering, telemetry categorization, and Cloudflare model discovery.

Changes:

  • Adds root-cause, local-server, model, and multimodal error handling.
  • Expands analytics error metadata and decouples rendering from logging.
  • Filters Cloudflare results to compatible catalog models and adds mapper tests.
File Description
ExceptionMapperTest.kt Tests exception classification and rendering.
TelemetryChatModelListener.kt Maps errors into detailed analytics categories.
OpenAiCompatibleTemplate.kt Filters Cloudflare models by @cf/.
ExceptionMapper.kt Enhances exception extraction and classification.
ExceptionHandler.kt Adds rendering without logging.
AnalyticsEvent.kt Documents expanded error analytics.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Free-form error excerpts can still violate the analytics privacy contract, and some error classifications are inaccurate.

3 open findings
3 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Select the deepest non-blank cause message

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​exception/​ExceptionMapper.kt:95

If the deepest cause has no message but an intermediate cause does, this falls back to the shallow wrapper and discards the useful diagnostic that may have driven matchByMessage. Select the deepest non-blank message across the chain instead.

Medium severity Do not classify all network errors as connection refused

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​telemetry/​TelemetryChatModelListener.kt:181

NetworkException also represents DNS failures, unreachable routes, and generic failed connections, so labeling every instance connection_refused makes analytics inaccurate (for example, UnknownHostException is not a refusal). Use a general network_error category, or preserve enough subtype information to distinguish actual refusals, and update the event contract accordingly.

🧠 Review effort: Balanced

"step_count" to stepCount.toString(),
"error_type" to "missing_input",
"error_message" to (e.message ?: "unknown"),
"error_excerpt" to redactErrorText(e.message ?: "unknown"),
Comment on lines +199 to +204
mapOf(
"error_type" to errorType,
"provider" to provider,
"message_key" to mapped.getMessageKey(),
"error_excerpt" to redactErrorText(ExceptionMapper.rootCauseMessage(error)),
),
* A categorised error occurred.
* Properties: `error_type=provider_timeout|rate_limit|auth_error|context_length|connection_refused|model_not_found|server_error|network_error|provider_error`,
* `provider` (when relevant), `error_message` (sanitised, no PII, up to 4000 chars).
* Properties: `error_type=provider_timeout|rate_limit|auth_error|context_length|connection_refused|model_not_found|server_error|local_server_error|insufficient_credits|unsupported_sampling|malformed_tool_call|max_tool_calling_round_trips|invalid_request|system_error|provider_error`,
@haiphucnguyen
haiphucnguyen merged commit ed0b822 into main Oct 11, 2026
11 of 13 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/improvements branch October 11, 2026 20:15
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.

2 participants