Refactor: Decompose error_recovery.py into smaller modules #3899

Open
opened 2026-04-06 07:17:07 +00:00 by freemo · 0 comments
Owner

The src/cleveragents/domain/models/core/error_recovery.py file has been identified as a violation of the Single Responsibility Principle and the 500-line limit guideline.

Issues:

  1. Mixed Concerns: The file mixes several distinct concerns:
    • Data Models: ErrorCategory, RecoveryAction, RecoveryHint, ErrorRecord, and ErrorHistory.
    • Policy Logic: The ErrorRecoveryPolicy class.
    • Helper Functions: get_recovery_hints and classify_error.
  2. File Length: The file is over 600 lines long, which makes it difficult to read and maintain.

Recommendation:

Refactor the error_recovery.py file by splitting it into smaller, more focused modules:

  • Keep the data models in src/cleveragents/domain/models/core/error_recovery.py.
  • Move the ErrorRecoveryPolicy class to the src/cleveragents/application layer, possibly in a new policies package.
  • Move the helper functions (get_recovery_hints, classify_error) to a utils or helpers module.

This refactoring will improve the modularity, maintainability, and testability of the error recovery functionality, and it will also resolve the file length issue.


Automated by CleverAgents Bot
Supervisor: Architecture Guard | Agent: ca-architecture-guard

The `src/cleveragents/domain/models/core/error_recovery.py` file has been identified as a violation of the Single Responsibility Principle and the 500-line limit guideline. **Issues:** 1. **Mixed Concerns:** The file mixes several distinct concerns: * **Data Models:** `ErrorCategory`, `RecoveryAction`, `RecoveryHint`, `ErrorRecord`, and `ErrorHistory`. * **Policy Logic:** The `ErrorRecoveryPolicy` class. * **Helper Functions:** `get_recovery_hints` and `classify_error`. 2. **File Length:** The file is over 600 lines long, which makes it difficult to read and maintain. **Recommendation:** Refactor the `error_recovery.py` file by splitting it into smaller, more focused modules: * Keep the data models in `src/cleveragents/domain/models/core/error_recovery.py`. * Move the `ErrorRecoveryPolicy` class to the `src/cleveragents/application` layer, possibly in a new `policies` package. * Move the helper functions (`get_recovery_hints`, `classify_error`) to a `utils` or `helpers` module. This refactoring will improve the modularity, maintainability, and testability of the error recovery functionality, and it will also resolve the file length issue. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: ca-architecture-guard
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#3899
No description provided.