Skip to content

Enhance chat server reliability, fix crisis detection logic, and impr…#42

Open
navin-oss wants to merge 1 commit into
ZenYukti:mainfrom
navin-oss:enhance-chat-and-fix-bugs-11055238984175899358
Open

Enhance chat server reliability, fix crisis detection logic, and impr…#42
navin-oss wants to merge 1 commit into
ZenYukti:mainfrom
navin-oss:enhance-chat-and-fix-bugs-11055238984175899358

Conversation

@navin-oss
Copy link
Copy Markdown
Contributor

This PR addresses several critical issues and enhances the codebase:

  1. Chat System Improvements:

    • Database Schema: Added a nickname column to the messages table. This ensures that historical messages retain the sender's identity even without complex joins, which was a missing feature.
    • WebSocket Server: Migrated to WebSocketServer (fixing deprecation) and refactored connection management to use a Map based on userId. This prevents duplicate connections and fixes a race condition where a user reconnecting could be disconnected by their previous session closing.
    • Message Persistence: Now saves nickname with each message.
  2. Crisis Detection Enhancements:

    • Logic Fix: The keyword analysis now correctly scans all severity levels instead of stopping at the first match, ensuring the highest risk level is captured.
    • Integration: improved the logic that combines AI and keyword-based risk assessments.
  3. API Reliability:

    • Error Handling: Updated journal routes (PUT, DELETE) to correctly identify when a resource doesn't exist (using PostgREST error codes or checking returned data) and return a 404 status instead of 500 or success.
  4. Frontend Stability:

    • Resilience: Added fallback to "Anonymous" for messages without a nickname to prevent UI issues.
    • Type Safety: Fixed TypeScript errors in api.ts related to `HeadersInit

…ove error handling

- Database: Added `nickname` column to `messages` table for persistent chat history.
- Backend:
    - Refactored `ChatServer` to use `WebSocketServer` and fix race conditions in connection handling.
    - Improved `crisisDetection` logic to correctly aggregate keywords and prioritize risk levels.
    - Fixed `journal` API routes to return 404 for non-existent resources.
- Frontend:
    - Updated `ChatRoom` to gracefully handle missing nicknames.
    - Fixed TypeScript errors in API client.

Co-authored-by: navin-oss <181780004+navin-oss@users.noreply.github.com>
@ayushHardeniya ayushHardeniya added bug Something isn't working apertre3.0 Apertre 3.0 open source program medium features involving multiple files or logic. backend Server-side logic and APIs labels Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apertre3.0 Apertre 3.0 open source program backend Server-side logic and APIs bug Something isn't working medium features involving multiple files or logic. triage-needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants