fix: preserve message history by merging instead of replacing after streaming
Fixed critical issue where all message history disappeared after streaming
completed, leaving users with only 5-10 visible messages.
Root cause:
- Stream completion called loadMessages() without parameters
- This replaced ALL messages with only INITIAL_LOAD_LIMIT (20) messages
- System messages and filtered content reduced visible count to 5-10
- Users lost all scrollback history
Solution:
- Fetch only recent 10 messages after streaming completes
- Merge with existing messages using Map to deduplicate by ID
- Sort merged messages by timestamp to maintain order
- Preserve all previously loaded message history
Changes:
- Add optional 'limit' parameter to loadMessages()
- Replace loadMessages() call with intelligent merge logic
- Use Map<id, message> to deduplicate and update existing messages
- Keep streaming state visible until merge completes
Now users retain full message history while getting finalized versions
of newly streamed messages with proper reasoning and metadata.