[chat] routes/chat_routes.py at 1110 lines exceeds AGENTS.md ~400 line limit #724

Closed
opened 2026-06-03 00:07:37 +02:00 by sleepy · 0 comments
Owner

Problem

routes/chat_routes.py is 1110 lines — nearly 3× the AGENTS.md ~400 line limit.

The file contains:

  1. Active stream tracking (_active_streams, _stream_set)
  2. Session endpoint cleanup (_session_url_matches_endpoint, _clear_orphaned_session_endpoint)
  3. Route setup function setup_chat_routes() with all routes defined as closures
  4. /api/chat — non-streaming chat endpoint
  5. /api/chat_stream — streaming chat endpoint (~600 lines of nested generator logic)
  6. Research orchestration inside the stream generator
  7. /api/chat/resume, /api/chat/stop, /api/chat/stream_status
  8. /api/inject_context
  9. /api/search — message search
  10. /api/rewrite — message rewrite

The chat_stream endpoint alone has the streaming generator, research polling loop, chat mode streaming, agent mode streaming, image generation routing, error handling, and partial-save logic — all as nested closures.

AGENTS.md violations

  • Split files exceeding ~400 lines or containing multiple concerns
  • Multiple concerns in one file

Suggested fix

Split into:

  • routes/chat/chat_stream.py — streaming chat endpoint + helpers
  • routes/chat/chat_sync.py — non-streaming /api/chat
  • routes/chat/chat_research.py — research integration within streams
  • routes/chat/stream_state.py — active stream tracking, resume/stop/status
  • routes/chat/chat_search.py — message search and rewrite
  • Keep routes/chat_routes.py as thin wiring that imports and registers
## Problem `routes/chat_routes.py` is 1110 lines — nearly 3× the AGENTS.md ~400 line limit. The file contains: 1. Active stream tracking (`_active_streams`, `_stream_set`) 2. Session endpoint cleanup (`_session_url_matches_endpoint`, `_clear_orphaned_session_endpoint`) 3. Route setup function `setup_chat_routes()` with all routes defined as closures 4. `/api/chat` — non-streaming chat endpoint 5. `/api/chat_stream` — streaming chat endpoint (~600 lines of nested generator logic) 6. Research orchestration inside the stream generator 7. `/api/chat/resume`, `/api/chat/stop`, `/api/chat/stream_status` 8. `/api/inject_context` 9. `/api/search` — message search 10. `/api/rewrite` — message rewrite The `chat_stream` endpoint alone has the streaming generator, research polling loop, chat mode streaming, agent mode streaming, image generation routing, error handling, and partial-save logic — all as nested closures. ## AGENTS.md violations - **Split files exceeding ~400 lines or containing multiple concerns** - Multiple concerns in one file ## Suggested fix Split into: - `routes/chat/chat_stream.py` — streaming chat endpoint + helpers - `routes/chat/chat_sync.py` — non-streaming `/api/chat` - `routes/chat/chat_research.py` — research integration within streams - `routes/chat/stream_state.py` — active stream tracking, resume/stop/status - `routes/chat/chat_search.py` — message search and rewrite - Keep `routes/chat_routes.py` as thin wiring that imports and registers
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
sleepy/odysseus#724
No description provided.