agentscope-ai / agentscope-ai/QwenPaw
[Bug] Chat API returns all messages without pagination + no virtual scrolling causes 1GB+ Chrome memory
- Vorherrschende Sprache
- Python
- Sterne
- 34.9k
- Forks
- 3.1k
- Ø Merge
- 1 T. 15 Std.
- Gemergte PRs (30 T.)
- 225
Beschreibung
# [Bug] Web Console: Chat API returns all messages without pagination + no virtual scrolling → 1GB+ Chrome memory for long chats
## Environment
- **QwenPaw version**: 1.1.4.post2
- **OS**: Windows 11
- **Browser**: Chrome (latest)
- **Chat size**: 635 messages (30 user + 432 assistant + 173 system)
- **Memory**: Chrome tab consuming ~1GB
## Problem
The chat history API (`GET /api/chats/{id}`) returns **all messages with no pagination**, and the frontend renders **every message into the DOM** with no virtual scrolling. For a chat with 635 messages (30 actual user turns), this creates:
| Component | Memory Impact |
|-----------|---------------|
| Chat JSON response | 648 KB |
| Parsed JS objects | ~8-12 MB |
| React component tree (635 Ant Design cards) | ~200-400 MB |
| DOM nodes (~60K+) | ~50-150 MB |
| Ant Design 8MB bundle JIT compiled | ~50-80 MB |
| 2.5s polling GC fragmentation | ~50-100 MB |
| **Total** | **~500-900 MB → 1GB** |
## Root Causes
### 1. Backend: No pagination on chat history API
The `GET /api/chats/{id}` endpoint returns **all messages** regardless of count. A chat with 635 messages returns a single 648KB JSON response.
**Related**: PR #1360 ("Feat/upstream/retry fallback history pagination") added `offset`/`limit` params but was **closed without merging** (`merged_at: null`).
### 2. Frontend: No virtual scrolling
The chat view renders all 635 messages as Ant Design React components in the DOM. With ~100 DOM nodes per message card, this creates ~60K+ DOM nodes.
**Related**: Issue #3915 filed today about the same problem with virtual scrolling proposal.
### 3. Message inflation: system overhead 20x user messages
The user sent only 30 messages, but the system stored 605 additional messages (system prompts, reasoning traces, context compaction events, tool results). This 20:1 inflation means even short conversations become massive data loads.
### 4. Large vendor bundle: Ant Design 8MB
`ui-vendor-D38L3WKF.js` is 8,022 KB — almost certainly the entire Ant Design library with minimal tree-shaking.
## Suggested Fix
1. **Backend pagination** (revive PR #1360): Add `?offset=N&limit=M` to `GET /api/chats/{id}`, return pagination metadata
2. **Frontend virtual scrolling** (as proposed in #3915): Use `react-window` or `react-virtuoso` for the chat message list
3. **Lazy-load chat history**: Load last 50 messages initially, load more on scroll up
4. **Filter internal messages from API response**: System/reasoning messages add 20x overhead; consider a `?include_system=false` param
5. **Tree-shake Ant Design**: The 8MB vendor chunk suggests the full library is bundled
## Chat Data (reference)
All 12 chats on a typical v1.1.4.post2 instance:
| Chat | Messages | User | System | JSON Size |
|------|----------|------|--------|-----------|
| 0827790e... | 635 | 30 | 173 | 648 KB |
| f8846b72... | 528 | 28 | 144 | 528 KB |
| e52b6f82... | 394 | 29 | 105 | 386 KB |
| 2e6cd601... | 290 | 8 | 85 | 356 KB |
| 8ea0e03e... | 239 | 11 | 66 | 365 KB |
| cfa399e4... | 232 | 10 | 59 | 212 KB |
| 89ab59e6... | 214 | 12 | 58 | 208 KB |
| e0db9f14... | 214 | 4 | 67 | 213 KB |
| e5c81a2e... | 189 | 30 | 34 | 127 KB |
| cae2388f... | 156 | 10 | 42 | 177 KB |
| Others (<30) | — | — | — | <70 KB |
Configuration: `history_max_length: 10000`, `compact_threshold_ratio: 0.8`, `context_manager_backend: "light"`.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.