Skip to content

Update useChatWebhook to initialize reconnectCount at 1 and adjust re… - #213

Merged
Vinod-V3 merged 1 commit into
ELEVATE-Project:release-1.0.4from
VishnuKrishnathu:feature/ip-socket
Dec 11, 2025
Merged

Update useChatWebhook to initialize reconnectCount at 1 and adjust re…#213
Vinod-V3 merged 1 commit into
ELEVATE-Project:release-1.0.4from
VishnuKrishnathu:feature/ip-socket

Conversation

@VishnuKrishnathu

@VishnuKrishnathu VishnuKrishnathu commented Dec 11, 2025

Copy link
Copy Markdown

…connect logic. Enhance ShikshalokamVoiceChat by adding homepage visibility condition and updating WebSocket retry attempts from environment variable.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reconnection notification behavior to prevent duplicate final-attempt alerts when the retry limit is reached.
    • Enhanced chat history handling to properly display the homepage after chat cleanup during reconnection.
  • Improvements

    • Refined language selection logic to trigger only when chat history is empty.
    • Added configurable WebSocket reconnection retry attempts for better resilience.

✏️ Tip: You can customize this high-level summary in your review settings.

…connect logic. Enhance ShikshalokamVoiceChat by adding homepage visibility condition and updating WebSocket retry attempts from environment variable.
@coderabbitai

coderabbitai Bot commented Dec 11, 2025

Copy link
Copy Markdown

Walkthrough

The changes refactor WebSocket reconnection logic in the hook by reorganizing conditional checks into an if/else-if chain and adjusting the initial reconnect counter. The voice chat page adds reconnectAttempts configuration, modifies chat history cleanup behavior, and adjusts language selection triggers.

Changes

Cohort / File(s) Change Summary
Reconnection Logic Refactoring
src/hooks/useChatWebhook.js
Initializes reconnect counter from 0 to 1; restructures onclose flow from two separate conditionals to mutually exclusive if/else-if chain, ensuring final-reconnect notification fires only once when retry limit is reached.
WebSocket Configuration & Chat State Management
src/pages/ShikshalokamVoiceChat/voice-chat.js
Adds reconnectAttempts option to WebSocket initialization; alters chat history cleanup to show homepage when length equals 1; changes language selection trigger from <= 1 to empty check; adds state tracking logs for chat history with recordings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the reconnect counter initialization change and if/else-if reorganization produce the intended single final-notification behavior
  • Confirm chat history cleanup logic (length === 1 check) aligns with homepage display expectations
  • Validate that language selection trigger change (empty vs. <= 1) doesn't unintentionally alter user-facing behavior

Possibly related PRs

Suggested reviewers

  • Vinod-V3

Poem

🐰 A rabbit hops through reconnection's maze,
Counter ticks from zero, finding firmer ways,
If-else chains now dance in harmony,
Chat resets, language flows so free—
Connected once more, no loops in the fray! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: updating useChatWebhook to initialize reconnectCount at 1 and adjust reconnect logic, which aligns with the primary changes in the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@VishnuKrishnathu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 11, 2025

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 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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17b1237 and f9041f8.

📒 Files selected for processing (2)
  • src/hooks/useChatWebhook.js (2 hunks)
  • src/pages/ShikshalokamVoiceChat/voice-chat.js (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/pages/ShikshalokamVoiceChat/voice-chat.js (2)
src/hooks/useSmartChatStorage.js (1)
  • chatHistory (4-4)
src/pages/UnifiedChat/UnifiedVoiceBasedChat.jsx (1)
  • chatHistory (41-41)
🔇 Additional comments (4)
src/hooks/useChatWebhook.js (1)

49-56: LGTM! Correctly prevents double execution of final reconnect logic.

The change to else if ensures that onFinalReconnectAttempt is only called when the reconnect limit has been reached, and not during the same onclose event where a reconnection is attempted. This prevents potential race conditions or duplicate final-attempt notifications.

src/pages/ShikshalokamVoiceChat/voice-chat.js (3)

193-196: LGTM! Appropriate homepage display after reconnection cleanup.

When the WebSocket reconnection fails and chat history is cleaned, showing the homepage if only the intro message remains (length === 1) provides a clean user experience and prevents displaying a partial conversation state.


303-303: LGTM! WebSocket retry attempts now configurable via environment variable.

Sourcing reconnectAttempts from env.WEBSOCKET_RETRY_NUM() makes the retry behavior configurable per environment. The variable is properly defined in src/utils/env.js with a sensible default value of 2 and correctly parses the REACT_APP_WEBSOCKET_RETRY_NUM environment variable. Usage is consistent across lines 303 and 309.


1021-1021: Verify the language selection trigger condition change.

The condition was changed from chatHistory?.length <= 1 to !chatHistory.length, which significantly alters when language selection logic executes:

  • Old behavior: Triggers when chatHistory has 0 or 1 items (empty or with intro message)
  • New behavior: Triggers only when chatHistory is completely empty (0 items)

This means language selection will no longer re-trigger when the intro message is present. Confirm whether this aligns with the intended UX—specifically, that users who have already received the intro message should not have their language selection reset or re-initialized.


const ws = useRef(null)
const reconnectCount = useRef(0)
const reconnectCount = useRef(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent reconnectCount initialization.

Line 7 initializes reconnectCount.current to 1, but line 83 in the useEffect immediately resets it to 0 on mount. This makes the initial value of 1 effectively unused and creates confusion about the intended behavior.

If the intention is to start at 1 (as per the PR objectives), remove the reset on line 83:

 useEffect(() => {
-  reconnectCount.current = 0
   if (autoConnect) connect()

Otherwise, revert line 7 to initialize at 0 for consistency:

-const reconnectCount = useRef(1)
+const reconnectCount = useRef(0)

Also applies to: 83-83

🤖 Prompt for AI Agents
In src/hooks/useChatWebhook.js around lines 7 and 83, the ref reconnectCount is
initialized to 1 at line 7 but immediately reset to 0 on mount at line 83,
creating inconsistency; if the intended behavior is to start at 1 (per PR
objectives) remove the reset at line 83 so reconnectCount.current remains 1 on
mount, otherwise change the initialization at line 7 to useRef(0) to match the
reset and keep the existing line 83 as-is.

@Vinod-V3
Vinod-V3 merged commit f56ae2f into ELEVATE-Project:release-1.0.4 Dec 11, 2025
1 check passed
This was referenced Feb 11, 2026
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.

2 participants