Skip to content

Fix bot name flickering during session initialization - #304

Open
Rahulmadiraju wants to merge 1 commit into
ELEVATE-Project:release-1.0.6.1from
Rahulmadiraju:fix/bot-name-flicker
Open

Fix bot name flickering during session initialization#304
Rahulmadiraju wants to merge 1 commit into
ELEVATE-Project:release-1.0.6.1from
Rahulmadiraju:fix/bot-name-flicker

Conversation

@Rahulmadiraju

@Rahulmadiraju Rahulmadiraju commented May 12, 2026

Copy link
Copy Markdown

Summary

  • Fixed bot name flickering issue in DynamicVoiceChat
  • Loader now waits until bot vernacular data is ready
  • Prevented temporary "Bot" fallback render before backend-provided name loads

Testing

  • Tested on Bihar student FGD flow
  • Verified using hard refresh and Slow 4G throttling
  • Confirmed no flicker during new session initialization

Summary by CodeRabbit

  • Bug Fixes

    • Improved audio playback auto-trigger behavior in voice chat sessions
  • Refactor

    • Enhanced bot information and message loading logic for better responsiveness
    • Refined loading state indicators during initialization

Review Change Stack

@Rahulmadiraju

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

DynamicVoiceChat migrates its company bot and intro message queries to use computed enabled flags and TanStack Query's isPending status fields. Bot name defaults transition from "Bot" to empty string at initialization and derivation. Audio auto-play logic is refactored to check isIntroMessagePending, and speaker-control eligibility is expanded. The loader UI now reflects the new query pending states.

Changes

Voice Chat Query and Playback Refactoring

Layer / File(s) Summary
Query architecture with computed enable flags and pending status
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js
TanStack useQuery setup refactored to introduce computed isCompanyBotQueryEnabled and isIntroQueryEnabled flags, and to use isPending status fields instead of prior loading flags for company bot and intro message queries.
Bot name initialization and derivation
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js
Bot name state initial value and fallback in introMessageData derivation both changed from hardcoded "Bot" to empty string, aligning with the new query structure.
Auto-play and speaker control eligibility
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js
Audio auto-play effect logic updated to use isIntroMessagePending instead of isIntroMessageLoading, and speaker-button auto-click eligibility expanded with an additional else if path when the last chat message is from the bot.
Loader UI condition using new query pending states
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js
Main loader/spinner conditional rendering updated to include new computed pending states (isCompanyBotPending, isIntroMessagePending) alongside existing initialization/loading/end-story checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Vinod-V3

Poem

🐰 A voice chat refactor, swift and clean,
Queries dance with flags we've never seen,
Empty names and isPending calls,
Auto-play when the bot enthralls! 🎙️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing bot name flickering during initialization by refactoring query logic and updating loader conditions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.2)
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js (1)

1502-1525: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use compound guard to check if intro query is actively fetching.

In TanStack Query v5, a disabled query with no cached data reports isPending: true even though isFetching is false. Using only !isIntroMessagePending here blocks speaker auto-play even when the intro query is merely disabled, not actively loading. Replace with the compound guard isIntroQueryEnabled && isIntroMessagePending that's already established in the loader (line 2279).

Three instances need updating (lines 1502, 1513, 1517):

🔧 Suggested change
   useEffect(() => {
+    const isIntroFetchInFlight = isIntroQueryEnabled && isIntroMessagePending
+
     let shouldPlay = false
     if (showFileInput) {
       shouldPlay = true
-    } else if ((noStoryFound || noStoryFound === null) && !isIntroMessagePending && !isLoading && !endStoryMutation.isPending) {
+    } else if ((noStoryFound || noStoryFound === null) && !isIntroFetchInFlight && !isLoading && !endStoryMutation.isPending) {
       const currentFlow = storageFlow

       if (currentFlow) {
         if (chatHistory.length > 0) {
           if (isStreamingComplete && chatHistory[chatHistory.length - 1]?.source === "bot") {
             shouldPlay = true
           }
         } else {
           shouldPlay = true
         }
-      } else if (chatHistory && chatHistory.length > 0 && chatHistory[chatHistory.length - 1]?.source === "bot" && !isIntroMessagePending && !isLoading && !endStoryMutation.isPending) {
+      } else if (chatHistory && chatHistory.length > 0 && chatHistory[chatHistory.length - 1]?.source === "bot" && !isIntroFetchInFlight && !isLoading && !endStoryMutation.isPending) {
         shouldPlay = true
       }
     }
-    if (isStreamingComplete && shouldPlay && !endStoryMutation.isPending && !isLoading && !isPdfDownloading && isMute && acceptedTnc && acceptedTnc !== "ONGOING" && !isIntroMessagePending) {
+    if (isStreamingComplete && shouldPlay && !endStoryMutation.isPending && !isLoading && !isPdfDownloading && isMute && acceptedTnc && acceptedTnc !== "ONGOING" && !isIntroFetchInFlight) {
       const speakerButtons = document.querySelectorAll(".button-11.button-3")
       const lastSpeakerButton = speakerButtons[speakerButtons.length - 1]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js` around lines 1502 -
1525, The effect currently uses the simple guard !isIntroMessagePending which
treats a disabled intro query as "pending"; replace each usage so the code
checks that the intro query is actively fetching by substituting the compound
guard !(isIntroQueryEnabled && isIntroMessagePending) (i.e., use
isIntroQueryEnabled && isIntroMessagePending to mean actively fetching). Update
all three occurrences inside the useEffect where !isIntroMessagePending appears
(the conditions that decide shouldPlay and the final autoplay guard) to use
!(isIntroQueryEnabled && isIntroMessagePending) instead, referencing the
existing variables isIntroMessagePending and isIntroQueryEnabled.
🧹 Nitpick comments (1)
src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js (1)

824-829: ⚡ Quick win

Use default_name as the post-load fallback.

Once the intro payload has resolved, name can still be empty while default_name is available on the same response. Falling back to default_name here avoids rendering a blank bot label without reintroducing the pre-load flicker.

💡 Suggested change
-    const botName = introMessageData[0]?.name || ""
+    const botName = introMessageData[0]?.name || introMessageData[0]?.default_name || ""
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js` around lines 824 -
829, The code sets botName from introMessageData[0]?.name which can be empty
even when introMessageData[0]?.default_name exists; update the assignment and
the display setter to use default_name as the post-load fallback (i.e., derive
botName and the value passed to setBotNameToDisplay from
introMessageData[0]?.name || introMessageData[0]?.default_name || ""), keep
setDefaultBotName(introMessageData[0]?.default_name) as-is, and ensure you
reference introMessageData, setBotName, setDefaultBotName, and
setBotNameToDisplay when making this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js`:
- Around line 1502-1525: The effect currently uses the simple guard
!isIntroMessagePending which treats a disabled intro query as "pending"; replace
each usage so the code checks that the intro query is actively fetching by
substituting the compound guard !(isIntroQueryEnabled && isIntroMessagePending)
(i.e., use isIntroQueryEnabled && isIntroMessagePending to mean actively
fetching). Update all three occurrences inside the useEffect where
!isIntroMessagePending appears (the conditions that decide shouldPlay and the
final autoplay guard) to use !(isIntroQueryEnabled && isIntroMessagePending)
instead, referencing the existing variables isIntroMessagePending and
isIntroQueryEnabled.

---

Nitpick comments:
In `@src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js`:
- Around line 824-829: The code sets botName from introMessageData[0]?.name
which can be empty even when introMessageData[0]?.default_name exists; update
the assignment and the display setter to use default_name as the post-load
fallback (i.e., derive botName and the value passed to setBotNameToDisplay from
introMessageData[0]?.name || introMessageData[0]?.default_name || ""), keep
setDefaultBotName(introMessageData[0]?.default_name) as-is, and ensure you
reference introMessageData, setBotName, setDefaultBotName, and
setBotNameToDisplay when making this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e6e51cd-99ab-4c99-8224-889c317705aa

📥 Commits

Reviewing files that changed from the base of the PR and between fe52ba2 and 12b5cff.

📒 Files selected for processing (1)
  • src/pages/ShikshalokamVoiceChat/dynamic-voice-chat.js

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