Repository navigation
refactor(core): Implement explicit retry policy handling in exceptions - #710
Conversation
- Introduce a `retryPolicy` property to `AskimoException` to define transient vs. terminal errors. - Standardize error classification across the codebase using `ExceptionMapper`. - Define specific user exceptions, such as `UnsupportedSamplingException`, with immediate retry policies. - Refactor streaming message paths to rely on the centralized `ExceptionMapper` for retry decision making. - Improve resilience by correctly differentiating between transient network and context errors.
There was a problem hiding this comment.
🟡 Changes recommended
The streaming empty-HTTP-response detection and terminal rendering path have concrete correctness/performance issues (cause-chain matching and redundant exception mapping/logging) that should be fixed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Implements an explicit retry-policy model on AskimoException and refactors streaming error handling to use centralized exception classification (ExceptionMapper) for consistent retry decisions and localized terminal messaging.
Changes:
- Added
RetryPolicyandAskimoException.retryPolicy, with concrete policies on key user exceptions (network/rate-limit/timeout/context/tool-call/sampling). - Refactored
classifyStreamingErrorand streaming retry side-effects to rely onExceptionMapper, returning the classified exception for deterministic side-effect dispatch. - Expanded streaming error classifier tests to validate retry policy behavior and ensure network/tool/system errors render localized keys when i18n bundles aren’t loaded.
File summaries
| File | Description |
|---|---|
| shared/src/test/kotlin/io/askimo/core/providers/StreamingErrorClassifierTest.kt | Adds coverage for retry-policy classification and localized terminal messaging keys across common streaming failures. |
| shared/src/main/kotlin/io/askimo/core/providers/ModelCapabilitiesCache.kt | Extracts context-length detection into isContextLengthMessage for reuse by ExceptionMapper. |
| shared/src/main/kotlin/io/askimo/core/providers/ChatClientExtensions.kt | Centralizes streaming error classification via ExceptionMapper, returns classified exception on retryable path, and updates retry loop logic accordingly. |
| shared/src/main/kotlin/io/askimo/core/exception/UserException.kt | Assigns explicit retry policies to relevant user exceptions and introduces UnsupportedSamplingException. |
| shared/src/main/kotlin/io/askimo/core/exception/ExceptionMapper.kt | Extends type/message mapping (network + context-length reuse + sampling) to drive consistent classification. |
| shared/src/main/kotlin/io/askimo/core/exception/AskimoException.kt | Introduces RetryPolicy and adds retryPolicy to the exception base type with a safe default. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed correctness issues in the new retry/side-effect flow (cache mutation even when retries are exhausted) and locale-dependent context-length matching that can break classification.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
shared/src/main/kotlin/io/askimo/core/providers/ModelCapabilitiesCache.kt:516
isContextLengthMessageusesmessage.lowercase()which is locale-dependent; in some locales (e.g. Turkish) this can break case-insensitive matching and lead to misclassification. Use locale-stable lowercasing.
shared/src/main/kotlin/io/askimo/core/exception/ExceptionHandler.kt:35- The comment says re-running classification would re-log an "unmapped exception" warning, but
ExceptionMapperlogs the unmapped chain as an error. Adjust wording to avoid implying the wrong log level/message.
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
| // Context window exceeded (checked before generic 400 to avoid misclassification). | ||
| // Reuses the exact same pattern as `Throwable.isContextLengthError()` (the outer | ||
| // context-retry loop in ChatClientExtensions) so the two never drift apart. | ||
| isContextLengthMessage(combinedMessage) -> |
There was a problem hiding this comment.
🔵 Needs a closer look
There are documentation inconsistencies in changed code (stale reference to a removed API and an incorrect “no logging side-effects” claim) that should be corrected before approval.
Review details
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
shared/src/main/kotlin/io/askimo/core/exception/UserException.kt:206
- The KDoc still references
ChatClientExtensions.isMalformedToolCallError, but that helper was removed in this refactor, so the documentation now points to a non-existent API. Update the reference to the current retry/classification path (e.g.sendStreamingMessageWithCallback/ExceptionMapper).
shared/src/main/kotlin/io/askimo/core/providers/ChatClientExtensions.kt:91
classifyStreamingError's KDoc says it has "no side-effects (no logging)", but the implementation callsExceptionHandler.handle(...)for terminal cases, which logs. Either avoid rendering/logging here (return the exception and render at the call site) or adjust the KDoc to reflect the current behavior.
* No side-effects (no logging, no cache mutations) — those stay at the call site so this
* stays fully unit-testable. Delegates to [ExceptionMapper] for classification and retry
* policy, except two cases needing context the mapper doesn't have:
* - [InsufficientContextException]'s message is already fully rendered.
* - The empty-HTTP-response case needs `provider`/`model` to build its hint.
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
- Review effort level: Lite
retryPolicyproperty toAskimoExceptionto define transient vs. terminal errors.ExceptionMapper.UnsupportedSamplingException, with immediate retry policies.ExceptionMapperfor retry decision making.