Skip to content

refactor: replace 11-branch messagesMatch with canonical clientId resolution#7

Merged
voidcommit-afk merged 3 commits intomainfrom
dev
Mar 22, 2026
Merged

refactor: replace 11-branch messagesMatch with canonical clientId resolution#7
voidcommit-afk merged 3 commits intomainfrom
dev

Conversation

@voidcommit-afk
Copy link
Owner

@voidcommit-afk voidcommit-afk commented Mar 22, 2026

This pull request improves reliability and maintainability in both backend and frontend code. On the backend, it refactors the save_to_history function to ensure robust error handling and detailed logging, preventing failures from propagating and ensuring user history is not lost due to transient issues. On the frontend, it clarifies and simplifies the logic for matching messages by canonical IDs, and adds comprehensive tests to guarantee correctness. Additionally, new tests are introduced for both backend and frontend changes to verify error handling and message matching behavior.

Backend: Improved error handling and logging in save_to_history

  • Refactored save_to_history in api/routers/query.py to add detailed logging, robust error handling, and early returns on failure, ensuring that user history persistence failures do not crash the response task. Added context-aware logs for each failure point and normalized mode handling.
  • Enhanced the stream close message to include the response mode label for better user feedback.
  • Added new tests in api/tests/test_query_router.py to verify that save_to_history logs errors and does not raise exceptions when Supabase is unavailable or fetches fail.

Frontend: Message identity and matching logic

  • Improved resolveMessageKey and messagesMatch in src/lib/chatStoreUtils.ts with clearer documentation and a more robust, canonical approach to message identity resolution. The new logic ensures messages are matched by the most reliable identifiers and prevents accidental duplication or mismatches. [1] [2]

Frontend: Testing

  • Added comprehensive tests in src/stores/useChatStore.test.ts to verify correct message matching under various scenarios, including matching by client-generated ID, server ID, and ensuring non-matching for different IDs.
  • Improved test hygiene with proper cleanup (afterEach) for global stubs in streaming tests.

These changes collectively make the codebase more robust to backend failures and frontend message identity issues, and ensure these behaviors are well-tested.

@voidcommit-afk voidcommit-afk merged commit be999a7 into main Mar 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant