Skip to content

Fix ChatGPT auto-read aloud for existing conversations#246

Merged
rosscado merged 2 commits intomainfrom
fix/chatgpt-auto-read-existing-conversations
Oct 23, 2025
Merged

Fix ChatGPT auto-read aloud for existing conversations#246
rosscado merged 2 commits intomainfrom
fix/chatgpt-auto-read-existing-conversations

Conversation

@rosscado
Copy link
Copy Markdown
Contributor

Summary

Fixes #245 - Prevents auto-read aloud from triggering on previously completed messages when starting a voice call in an existing ChatGPT conversation.

Problem

When starting a voice call on first page load in an existing ChatGPT conversation, the last message was automatically read aloud even though it was already complete before the call started. This was inconsistent with Pi.ai's behavior, which only reads new streaming messages.

Solution

Added explicit tracking to distinguish between new/streaming messages and old/completed messages using a data-saypi-unread attribute:

  • New/streaming messages created by ChatHistoryNewMessageObserver are marked with data-saypi-unread="true"
  • Old/completed messages discovered on page load have no data-saypi-unread attribute
  • Auto-click logic now checks for this attribute before triggering Read Aloud
  • The attribute is cleared after clicking to prevent duplicate reads

Technical Changes

Core Implementation

  1. Chatbot Interface - Added optional isStreaming?: boolean parameter to getAssistantResponse()
  2. AbstractChatbot - Updated to pass isStreaming parameter through to implementations
  3. ChatGPTResponse - Sets data-saypi-unread="true" when isStreaming=true
  4. Auto-click Guards - All three methods now check for data-saypi-unread attribute:
    • tryClickNativeReadAloud()
    • autoClickNativeReadAloudWhenAvailable()
    • tryOpenMoreActionsAndClickReadAloud()
  5. ChatHistoryNewMessageObserver - Passes isStreaming=true for new messages
  6. Claude & Pi - Updated signatures (no functional changes)

Tests

  • Updated all test cases to pass isStreaming=true for new messages
  • Added new test case verifying old messages do NOT auto-click
  • All tests pass (6 passed, 1 skipped)

Result

✅ Auto-read aloud only triggers for new messages streaming during an active call
✅ Previously completed messages are NOT read when starting a call
✅ Behavior is consistent with Pi.ai's implementation
✅ All tests pass

Testing Instructions

  1. Open an existing ChatGPT conversation with completed messages
  2. Start a voice call using the Say, Pi button
  3. Verify the last message is NOT automatically read aloud
  4. Send a new message while call is active
  5. Verify the new message IS automatically read aloud

🤖 Generated with Claude Code

Prevents auto-read aloud from triggering on previously completed messages
when starting a voice call in an existing ChatGPT conversation.

## Problem
When starting a voice call on first page load in an existing ChatGPT
conversation, the last message was automatically read aloud even though
it was already complete before the call started. This was inconsistent
with Pi.ai's behavior, which only reads new streaming messages.

## Solution
Added explicit tracking to distinguish between new/streaming messages
and old/completed messages:

- Added `isStreaming?: boolean` parameter to Chatbot interface
- ChatHistoryNewMessageObserver passes `isStreaming=true` for new messages
- ChatGPTResponse sets `data-saypi-unread="true"` attribute on streaming messages
- Auto-click logic now checks for this attribute before triggering
- Attribute is cleared after clicking to prevent duplicate reads

## Changes
- Updated Chatbot interface and all implementations
- Modified ChatGPTResponse to track and check unread status
- Updated all auto-click guard methods to verify unread attribute
- Added test case for old messages (should NOT auto-click)
- Updated existing tests to pass isStreaming parameter

## Testing
- All existing tests pass (6 passed, 1 skipped)
- New test verifies old messages are not auto-read
- Behavior now matches Pi.ai implementation

Fixes #245

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rosscado rosscado requested a review from Copilot October 23, 2025 12:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where ChatGPT's auto-read aloud feature would incorrectly trigger for already-completed messages when starting a voice call in an existing conversation. The solution introduces a data-saypi-unread attribute to distinguish between new streaming messages (which should be read aloud) and old completed messages (which should not).

Key Changes:

  • Added isStreaming parameter to the chatbot interface hierarchy to identify new vs. existing messages
  • Implemented data-saypi-unread attribute tracking in ChatGPTResponse to mark streaming messages
  • Updated all auto-click methods to check for the data-saypi-unread attribute before triggering read aloud

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/chatbots/Chatbot.ts Added optional isStreaming parameter to interface method signature
src/chatbots/AbstractChatbots.ts Propagated isStreaming parameter through abstract base class
src/chatbots/ChatGPT.ts Updated createAssistantResponse to pass isStreaming to ChatGPTResponse
src/chatbots/chatgpt/ChatGPTResponse.ts Core logic: sets data-saypi-unread attribute for streaming messages and guards auto-click methods
src/chatbots/Claude.ts Updated method signature for consistency (no functional change)
src/chatbots/Pi.ts Updated method signature for consistency (no functional change)
src/dom/ChatHistory.ts Marks new messages as streaming when calling getAssistantResponse
test/chatbots/ChatGPTAutoReadAloud.spec.ts Updated all test cases to pass isStreaming flag and added test for old message behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rosscado rosscado merged commit fd122f5 into main Oct 23, 2025
1 check passed
@rosscado rosscado deleted the fix/chatgpt-auto-read-existing-conversations branch October 23, 2025 12:41
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.

ChatGPT Auto-Reads Last Message When Starting Call in Existing Conversation

2 participants