Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Voice mode broken because it fails auth check.

Type of Change

  • Bug fix

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 13, 2025 8:25pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 13, 2025

Greptile Overview

Greptile Summary

Fixed voice mode authentication failure by replacing hybrid auth with chat-specific authentication in the TTS proxy endpoint, and enhanced session security by including password hash in auth tokens to invalidate sessions on password change.

Key Changes:

  • Modified TTS proxy (/api/proxy/tts/stream) to validate chat auth cookies instead of using hybrid auth
  • Enhanced auth token format to include password hash, enabling automatic session invalidation when passwords change
  • Threaded chatId through voice interface → chat client → audio streaming hook → TTS API
  • Added validateChatAuth function in TTS proxy that checks chat existence, active status, auth type, and cookie validity
  • Updated all setChatAuthCookie and validateAuthToken calls to accept optional password parameter
  • Race condition fix: added isCallEndedRef flag in voice interface to prevent speech recognition restart after call ends

Non-critical changes:

  • Updated GitHub star counts from 18.6k/14.5k to 19.4k across landing page and API fallbacks

Confidence Score: 3/5

  • This PR fixes the critical voice mode bug but has a backwards compatibility issue that will break existing user sessions
  • The authentication logic is sound and properly fixes the voice mode issue, but the token format change will invalidate all existing auth cookies when users have password-protected chats, forcing them to re-authenticate. The fix is straightforward but should be tested carefully.
  • Pay close attention to apps/sim/app/api/chat/utils.ts - the token validation logic has a backwards compatibility issue with the password hash

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/chat/utils.ts 4/5 Enhanced auth token validation with password hash to invalidate sessions on password change, fixing security issue where old tokens remained valid
apps/sim/app/api/proxy/tts/stream/route.ts 4/5 Replaced hybrid auth with chat-specific authentication to fix voice mode auth failures, now validates chat cookies properly
apps/sim/app/chat/hooks/use-audio-streaming.ts 5/5 Added chatId parameter to TTS requests to enable proper authentication validation
apps/sim/app/api/chat/[identifier]/route.ts 5/5 Updated auth cookie functions to include password parameter for session invalidation on password change

Sequence Diagram

sequenceDiagram
    participant User
    participant VoiceInterface
    participant Chat
    participant AudioHook
    participant TTSProxy
    participant DB
    participant ElevenLabs

    User->>Chat: Authenticate with password/email
    Chat->>DB: Validate credentials
    DB-->>Chat: Auth successful
    Chat->>Chat: setChatAuthCookie(chatId, authType, password)
    Note over Chat: Cookie includes password hash for invalidation

    User->>VoiceInterface: Start voice mode
    VoiceInterface->>Chat: Send voice transcript
    Chat->>AudioHook: streamTextToAudio(text, voiceId, chatId)
    
    AudioHook->>TTSProxy: POST /api/proxy/tts/stream
    Note over AudioHook,TTSProxy: Includes chatId in request body
    
    TTSProxy->>DB: Query chat record (id, authType, password)
    DB-->>TTSProxy: Return chat data
    
    TTSProxy->>TTSProxy: validateChatAuth(request, chatId)
    Note over TTSProxy: Check authType and validate cookie
    TTSProxy->>TTSProxy: validateAuthToken(cookie, chatId, password)
    Note over TTSProxy: Verify password hash matches
    
    alt Auth valid
        TTSProxy->>ElevenLabs: Request TTS stream
        ElevenLabs-->>TTSProxy: Audio stream
        TTSProxy-->>AudioHook: Audio stream
        AudioHook-->>VoiceInterface: Play audio
        VoiceInterface-->>User: Hear response
    else Auth invalid
        TTSProxy-->>AudioHook: 401 Unauthorized
        AudioHook-->>User: Error
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@icecrasher321
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit 73940ab into staging Dec 13, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/deployed-chat-voice branch December 14, 2025 03:23
Copy link

@MuhammadMustafa770 MuhammadMustafa770 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

3 participants