Refactor: Decompose session.py into smaller modules #4167

Closed
opened 2026-04-06 12:15:00 +00:00 by freemo · 1 comment
Owner

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

Issues:

  1. Mixed Concerns: The file mixes several distinct concerns:
    • Data Models: Session, SessionMessage, and SessionTokenUsage.
    • Enum: MessageRole.
    • Exceptions: SessionServiceError, SessionNotFoundError, SessionExportError, and SessionImportError.
    • Service Contract: The SessionService abstract base class.
  2. File Length: The file is over 600 lines long, which makes it extremely difficult to read, understand, and maintain.

Recommendation:

Perform a major refactoring of the session.py file by splitting it into smaller, more focused modules:

  • Keep the data models in src/cleveragents/domain/models/core/session.py.
  • Move the MessageRole enum to src/cleveragents/domain/models/core/enums.py.
  • Move the custom exceptions to a central exceptions module (e.g., src/cleveragents/core/exceptions.py).
  • Move the SessionService abstract base class to the src/cleveragents/application layer, possibly in a new sessions package, as it defines a service contract.

This refactoring is critical for improving the architecture of the session-related functionality and making the codebase more modular and maintainable.


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

The `src/cleveragents/domain/models/core/session.py` file has been identified as a major violation of the Single Responsibility Principle and the 500-line limit guideline. **Issues:** 1. **Mixed Concerns:** The file mixes several distinct concerns: * **Data Models:** `Session`, `SessionMessage`, and `SessionTokenUsage`. * **Enum:** `MessageRole`. * **Exceptions:** `SessionServiceError`, `SessionNotFoundError`, `SessionExportError`, and `SessionImportError`. * **Service Contract:** The `SessionService` abstract base class. 2. **File Length:** The file is over 600 lines long, which makes it extremely difficult to read, understand, and maintain. **Recommendation:** Perform a major refactoring of the `session.py` file by splitting it into smaller, more focused modules: * Keep the data models in `src/cleveragents/domain/models/core/session.py`. * Move the `MessageRole` enum to `src/cleveragents/domain/models/core/enums.py`. * Move the custom exceptions to a central exceptions module (e.g., `src/cleveragents/core/exceptions.py`). * Move the `SessionService` abstract base class to the `src/cleveragents/application` layer, possibly in a new `sessions` package, as it defines a service contract. This refactoring is critical for improving the architecture of the session-related functionality and making the codebase more modular and maintainable. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: ca-architecture-guard
Author
Owner

DUPLICATE: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations"

This refactoring task for decomposing session.py into smaller modules is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic to enable coordinated planning and execution.

Action: Closing as duplicate in favor of Epic #4179

**DUPLICATE**: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations" This refactoring task for decomposing `session.py` into smaller modules is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic to enable coordinated planning and execution. **Action**: Closing as duplicate in favor of Epic #4179
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#4167
No description provided.