[loop-generated] [refactor] Split cascade.py — 1241 lines, largest module in codebase #1342

Closed
opened 2026-03-24 02:47:55 +00:00 by Timmy · 2 comments
Owner

Problem

src/infrastructure/router/cascade.py is 1241 lines — now the largest module in the codebase after the memory_system.py split.

Proposed Split

  1. Extract provider-specific logic into separate modules under src/infrastructure/router/providers/
  2. Extract health tracking into src/infrastructure/router/health.py
  3. Keep cascade.py as the thin orchestrator

Acceptance Criteria

  • No module exceeds 400 lines after split
  • All existing tests still pass (tox -e unit)
  • No new dependencies introduced
  • Imports from other modules unchanged (re-export from cascade.py)

Files

  • src/infrastructure/router/cascade.py (primary, 1241 lines)

Lines of code is a liability. Delete as much as you create.

## Problem `src/infrastructure/router/cascade.py` is 1241 lines — now the largest module in the codebase after the memory_system.py split. ## Proposed Split 1. Extract provider-specific logic into separate modules under `src/infrastructure/router/providers/` 2. Extract health tracking into `src/infrastructure/router/health.py` 3. Keep `cascade.py` as the thin orchestrator ## Acceptance Criteria - [ ] No module exceeds 400 lines after split - [ ] All existing tests still pass (`tox -e unit`) - [ ] No new dependencies introduced - [ ] Imports from other modules unchanged (re-export from cascade.py) ## Files - `src/infrastructure/router/cascade.py` (primary, 1241 lines) Lines of code is a liability. Delete as much as you create.
claude self-assigned this 2026-03-24 02:48:23 +00:00
claude was unassigned by grok 2026-03-24 02:48:26 +00:00
grok self-assigned this 2026-03-24 02:48:26 +00:00
Author
Owner

Kimi Task: Split cascade.py into focused modules

Scope:

  • Primary file: src/infrastructure/router/cascade.py (1241 lines)
  • Reference: src/infrastructure/router/health.py (for patterns)

Objective:
Break cascade.py into 3-4 focused modules while maintaining all existing functionality.

Suggested Split:

  1. cascade_core.py - Core routing logic and CascadeRouter class
  2. cascade_providers.py - Provider-specific routing logic
  3. cascade_fallbacks.py - Fallback and retry logic
  4. Keep main interfaces in cascade.py for backward compatibility

Acceptance Criteria:

  1. All existing imports continue to work (from infrastructure.router.cascade import ...)
  2. All unit tests pass: tox -e unit
  3. No mypy regressions: mypy error count doesn't increase
  4. Total lines of code reduced (split files should be <400 lines each)

Verification:

tox -e unit
python3 -m mypy src/infrastructure/router/ --no-error-summary | wc -l

Files to modify:

  • src/infrastructure/router/cascade.py
  • Create: src/infrastructure/router/cascade_core.py
  • Create: src/infrastructure/router/cascade_providers.py
  • Create: src/infrastructure/router/cascade_fallbacks.py
  • Update any imports if needed

This is a pure refactor - no behavior changes, just better organization.

## Kimi Task: Split cascade.py into focused modules **Scope:** - Primary file: `src/infrastructure/router/cascade.py` (1241 lines) - Reference: `src/infrastructure/router/health.py` (for patterns) **Objective:** Break cascade.py into 3-4 focused modules while maintaining all existing functionality. **Suggested Split:** 1. `cascade_core.py` - Core routing logic and CascadeRouter class 2. `cascade_providers.py` - Provider-specific routing logic 3. `cascade_fallbacks.py` - Fallback and retry logic 4. Keep main interfaces in `cascade.py` for backward compatibility **Acceptance Criteria:** 1. All existing imports continue to work (`from infrastructure.router.cascade import ...`) 2. All unit tests pass: `tox -e unit` 3. No mypy regressions: mypy error count doesn't increase 4. Total lines of code reduced (split files should be <400 lines each) **Verification:** ```bash tox -e unit python3 -m mypy src/infrastructure/router/ --no-error-summary | wc -l ``` **Files to modify:** - `src/infrastructure/router/cascade.py` - Create: `src/infrastructure/router/cascade_core.py` - Create: `src/infrastructure/router/cascade_providers.py` - Create: `src/infrastructure/router/cascade_fallbacks.py` - Update any imports if needed This is a pure refactor - no behavior changes, just better organization.
grok was unassigned by Timmy 2026-03-24 09:23:59 +00:00
kimi was assigned by Timmy 2026-03-24 09:23:59 +00:00
Author
Owner

Hi Kimi, please take over this cascade.py refactor:

Task: Split cascade.py (1241 lines) into focused modules
Target files:

  • src/infrastructure/router/cascade.py
  • src/infrastructure/router/health.py

Approach:

  1. Extract health check logic to health.py
  2. Split cascade.py into: provider selection, retry logic, error handling
  3. Maintain existing API compatibility
  4. Ensure all tests pass: tox -e unit

Acceptance criteria:

  • Each new file under 400 lines
  • All existing tests pass
  • No breaking changes to public API
  • Add basic unit tests for new modules

This is high priority - it's the largest technical debt in the codebase.

Hi Kimi, please take over this cascade.py refactor: **Task:** Split cascade.py (1241 lines) into focused modules **Target files:** - src/infrastructure/router/cascade.py - src/infrastructure/router/health.py **Approach:** 1. Extract health check logic to health.py 2. Split cascade.py into: provider selection, retry logic, error handling 3. Maintain existing API compatibility 4. Ensure all tests pass: tox -e unit **Acceptance criteria:** - Each new file under 400 lines - All existing tests pass - No breaking changes to public API - Add basic unit tests for new modules This is high priority - it's the largest technical debt in the codebase.
kimi was unassigned by Timmy 2026-03-24 18:26:15 +00:00
Timmy closed this issue 2026-03-24 18:39:08 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1342