[loop-generated] [refactor] Break up CascadeRouter.complete() — 121 lines #507

Closed
opened 2026-03-19 23:09:58 +00:00 by Timmy · 1 comment
Owner

File: src/infrastructure/router/cascade.py:391

CascadeRouter.complete() is 121 lines. The router is critical infrastructure and should be well-factored.

Suggested approach:

  • Extract provider selection into _select_provider()
  • Extract request preparation into _prepare_request()
  • Extract retry logic into _attempt_with_retry()

Acceptance criteria:

  • complete() under 50 lines
  • All router tests pass
  • No behavior changes

Files: src/infrastructure/router/cascade.py

**File:** `src/infrastructure/router/cascade.py:391` `CascadeRouter.complete()` is 121 lines. The router is critical infrastructure and should be well-factored. **Suggested approach:** - Extract provider selection into `_select_provider()` - Extract request preparation into `_prepare_request()` - Extract retry logic into `_attempt_with_retry()` **Acceptance criteria:** - `complete()` under 50 lines - All router tests pass - No behavior changes **Files:** `src/infrastructure/router/cascade.py`
Author
Owner

Instructions for Kimi:

  1. Read src/infrastructure/router/cascade.py, find complete() at line 391 (121 lines)
  2. Extract into smaller functions within the CascadeRouter class:
    • _select_providers(content_type, ...) — determines provider order
    • _prepare_request(messages, provider, ...) — builds the request payload
    • _attempt_with_fallback(providers, request, ...) — tries providers with fallback
  3. complete() should orchestrate these and be under 50 lines
  4. Run tox -e unit to verify all tests pass
  5. No behavior changes — pure refactor

Files: src/infrastructure/router/cascade.py only

**Instructions for Kimi:** 1. Read `src/infrastructure/router/cascade.py`, find `complete()` at line 391 (121 lines) 2. Extract into smaller functions within the CascadeRouter class: - `_select_providers(content_type, ...)` — determines provider order - `_prepare_request(messages, provider, ...)` — builds the request payload - `_attempt_with_fallback(providers, request, ...)` — tries providers with fallback 3. `complete()` should orchestrate these and be under 50 lines 4. Run `tox -e unit` to verify all tests pass 5. No behavior changes — pure refactor **Files:** `src/infrastructure/router/cascade.py` only
kimi was assigned by Timmy 2026-03-19 23:10:25 +00:00
Timmy closed this issue 2026-03-19 23:24:38 +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#507