valuecell
valuecell copied to clipboard
ConversationService.get_conversation_list ignores limit and offset, returning all conversations unconditionally`
Affected File & Lines
python/valuecell/server/services/conversation_service.py:53-95python/valuecell/server/api/routers/conversation.py:27-42
Severity & Impact
- Severity: High
- Impact: Broken API contract, performance degradation, and UI pagination malfunction. The REST endpoint
GET /conversations?limit={limit}&offset={offset}forwardslimitandoffsetparameters intoConversationService.get_conversation_list(). Because the service completely ignores both parameters, it returns the entire list of user conversations regardless of the requested page size or offset. Additionally, because the underlyinglist_user_conversationsdefaults to 100 items when called without arguments, users with more than 100 conversations cannot ever access conversations beyond the first 100.
Root Cause Analysis
In python/valuecell/server/services/conversation_service.py:53-95:
async def get_conversation_list(
self, user_id: Optional[str] = None, limit: int = 10, offset: int = 0
) -> ConversationListData:
# 1. Calls manager with no limit or offset (defaults to limit=100, offset=0)
conversations = await self.conversation_manager.list_user_conversations(
user_id=user_id
)
# 2. Exclude strategy conversations
conversations = [conv for conv in conversations if not ...]
# 3. Comment says "Apply pagination", but only total is assigned!
total = len(conversations)
# 4. Loops through ALL conversations without slicing [offset : offset + limit]!
conversation_items = []
for conv in conversations:
conversation_item = ConversationListItem(...)
conversation_items.append(conversation_item)
return ConversationListData(conversations=conversation_items, total=total)
Lines 76-80 calculate total = len(conversations) immediately after the comment # Apply pagination, but completely forget to slice conversations[offset : offset + limit].
Steps to Reproduce
Run the following script:
import sys
from datetime import datetime, timezone
sys.path.insert(0, r"python")
from valuecell.core.conversation.models import Conversation
from valuecell.server.services.conversation_service import ConversationService
class MockConversationManager:
async def list_user_conversations(self, user_id=None):
return [
Conversation(
conversation_id=f"conv_{i}",
user_id="u1",
agent_name="GeneralAgent",
title=f"Chat {i}",
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
)
for i in range(15)
]
service = ConversationService.__new__(ConversationService)
service.conversation_manager = MockConversationManager()
coro = service.get_conversation_list(user_id="u1", limit=3, offset=6)
try:
coro.send(None)
except StopIteration as e:
result = e.value
print(f"Requested: limit=3, offset=6")
print(f"Total count reported: {result.total}")
print(f"Conversations returned count: {len(result.conversations)}")
print(f"First ID returned: {result.conversations[0].conversation_id} (Expected conv_6)")
assert len(result.conversations) == 15, "Bug confirmed: returned 15 instead of 3"
Observed Behavior (Evidence)
Requested: limit=3, offset=6
Total count reported: 15
Conversations returned count: 15
First ID returned: conv_0 (Expected conv_6)
Expected Behavior
Requesting limit=3, offset=6 should return exactly 3 items starting from index 6 (conv_6, conv_7, conv_8), while reporting a total of 15.
Proposed Fix
--- a/python/valuecell/server/services/conversation_service.py
+++ b/python/valuecell/server/services/conversation_service.py
@@ -76,8 +76,9 @@ class ConversationService:
# Apply pagination
total = len(conversations)
+ paginated_conversations = conversations[offset : offset + limit]
# Convert to response format
conversation_items = []
- for conv in conversations:
+ for conv in paginated_conversations:
conversation_item = ConversationListItem(
conversation_id=conv.conversation_id,
title=conv.title or f"Conversation {conv.conversation_id}",