-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
GET /v1/conversations returns 500 with "Response size was too large" for users with photo-heavy or long conversations. 20 failures in 24h, concentrated on 2 users. Even with limit=50, fully hydrated responses exceed Cloud Run's 32MB response size limit.
Current Behavior
- The endpoint returns
List[Conversation]with full model including all fields @with_photosdecorator (database/helpers.py:199-256) loads ALL photos with full base64 content for EACH conversation in the list — 50 separate Firestore sub-collection reads@prepare_for_readaddscopy.deepcopyoverhead- Estimated response size: 50 conversations × ~1.2MB each = ~60MB (1.9x over the 32MB limit)
- Cloud Run returns "Response size was too large" → 500
Expected Behavior
List endpoint should return lightweight conversation objects. Full details (photos, full transcripts) should be loaded on demand per conversation.
Affected Areas
| File | Line | Description |
|---|---|---|
backend/routers/conversations.py |
119 | Returns full List[Conversation] with no field filtering |
backend/database/conversations.py |
177-178 | @with_photos + @prepare_for_read decorators on get_conversations() |
backend/database/helpers.py |
199-256 | @with_photos loads all photos with full base64 per conversation |
backend/database/conversations.py |
141-147 | get_conversation_photos() streams full photo docs |
backend/models/conversation.py |
66-72, 290-328 | ConversationPhoto includes base64, full Conversation model |
Size Breakdown
| Component | Per Conversation | 50 Conversations |
|---|---|---|
| Metadata | 2-5 KB | 100-250 KB |
| Transcript segments | ~95 KB | ~4.7 MB |
| Photos (base64) | ~1 MB (10 photos) | ~50 MB |
| Other fields | ~40 KB | ~2 MB |
| Total | ~1.2 MB | ~57 MB |
Solution
Recommended: Create a ConversationLite response model for list endpoints that excludes:
- Photos base64 content (keep photo IDs/metadata only)
- Full transcript segment text (keep segment count/duration only)
- Large
plugins_resultscontent
Note: test commits for get_conversations_lite() exist (be1489a23, c391d21d8, a80fbdebf) but the function is not in the current codebase — appears incomplete or reverted.
Files to Modify
backend/models/conversation.py— addConversationLitemodelbackend/routers/conversations.py— use lite model for list endpointbackend/database/conversations.py— addget_conversations_lite()without@with_photos
Impact
Users with many photo-heavy conversations are locked out of their conversation list. Workaround: reduce limit parameter to 10-15.
Related
- GET /v1/conversations extreme latency (30-90s) from N+1 queries and full hydration #4904 — N+1 query extreme latency (same root cause: full hydration), PR fix(conversations): eliminate N+1 photo queries from list endpoints #5271 addresses with
get_conversations_lite - Optimize conversation prefetch in transcribe.py (memory pressure from 0.6s re-fetch cycle) #5373 — conversation prefetch memory pressure (related hydration issue)
- fix(backend): reduce Firestore hot-path costs ~15-20% (#5377) #5378 — Firestore hot-path cost reduction PR
by AI for @beastoin