refactor: replace 11-branch messagesMatch with canonical clientId resolution#7
Merged
voidcommit-afk merged 3 commits intomainfrom Mar 22, 2026
Merged
refactor: replace 11-branch messagesMatch with canonical clientId resolution#7voidcommit-afk merged 3 commits intomainfrom
voidcommit-afk merged 3 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves reliability and maintainability in both backend and frontend code. On the backend, it refactors the
save_to_historyfunction 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_historysave_to_historyinapi/routers/query.pyto 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.api/tests/test_query_router.pyto verify thatsave_to_historylogs errors and does not raise exceptions when Supabase is unavailable or fetches fail.Frontend: Message identity and matching logic
resolveMessageKeyandmessagesMatchinsrc/lib/chatStoreUtils.tswith 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
src/stores/useChatStore.test.tsto verify correct message matching under various scenarios, including matching by client-generated ID, server ID, and ensuring non-matching for different IDs.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.