Skip to content

Bump PF chatbot, update loading msgs and improve error handling#3100

Merged
openshift-merge-bot[bot] merged 1 commit intoopenshift-assisted:masterfrom
rawagner:chatbot_bump
Aug 7, 2025
Merged

Bump PF chatbot, update loading msgs and improve error handling#3100
openshift-merge-bot[bot] merged 1 commit intoopenshift-assisted:masterfrom
rawagner:chatbot_bump

Conversation

@rawagner
Copy link
Member

@rawagner rawagner commented Aug 6, 2025

Summary by CodeRabbit

  • New Features

    • Added a loading indicator to chatbot messages while responses are being generated.
  • Bug Fixes

    • Improved token expiration handling to ensure timely refresh.
    • Enhanced error handling and messaging when chatbot responses fail to load.
  • Chores

    • Updated chatbot-related dependencies to the latest versions for improved stability and compatibility.

@openshift-ci openshift-ci bot requested review from ammont82 and batzionb August 6, 2025 08:52
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

This update corrects the token expiration logic in the chatbot component, refines error handling and streaming response management in the chatbot window, and introduces a loading state to bot messages. It also updates the @patternfly-6/chatbot dependency to version 6.3.2 in relevant package files.

Changes

Cohort / File(s) Change Summary
Dependency Updates
apps/assisted-ui/package.json, libs/chatbot/package.json
Updated @patternfly-6/chatbot dependency from version 2.2.1 to 6.3.2. Minor reordering of dependencies in apps/assisted-ui/package.json.
Token Expiration Logic Fix
apps/assisted-ui/src/components/Chatbot.tsx
Corrected the logic for checking token expiration to ensure timely refresh before expiry.
BotMessage Loading State
libs/chatbot/lib/components/ChatBot/BotMessage.tsx
Added isLoading prop to BotMessage to display a loading indicator and disable actions while loading. Adjusted prop types accordingly.
ChatBotWindow Streaming and Error Handling
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
Improved streaming response handling with explicit end-of-stream detection, enhanced error parsing, and integration of the new isLoading prop for bot messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatBotWindow
    participant BotMessage
    participant TokenService

    User->>ChatBotWindow: Sends message
    ChatBotWindow->>TokenService: Check token expiration
    TokenService-->>ChatBotWindow: Return valid/refresh token
    ChatBotWindow->>BotMessage: Render with isLoading=true
    ChatBotWindow->>API: Send message, start streaming
    API-->>ChatBotWindow: Stream 'token' events
    ChatBotWindow->>BotMessage: Update with new tokens
    API-->>ChatBotWindow: Stream 'end' event
    ChatBotWindow->>BotMessage: Render with isLoading=false
    ChatBotWindow-->>User: Display final message or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

lgtm, size/M

Suggested reviewers

  • ElayAharoni
  • jgyselov
  • ammont82

Poem

A bunny hopped through code today,
Tweaked tokens so they won’t delay.
With loading spinners all aglow,
And errors clearer as they show.
Dependencies now fresh and neat—
This chatbot’s journey is complete!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bad3799 and 39a8ed7.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • apps/assisted-ui/package.json (1 hunks)
  • apps/assisted-ui/src/components/Chatbot.tsx (1 hunks)
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx (3 hunks)
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (6 hunks)
  • libs/chatbot/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • libs/chatbot/package.json
  • apps/assisted-ui/package.json
  • apps/assisted-ui/src/components/Chatbot.tsx
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 6, 2025
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 6, 2025
@openshift-ci
Copy link

openshift-ci bot commented Aug 6, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ammont82, rawagner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@coderabbitai coderabbitai bot left a comment

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 e25ad23 and bad3799.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • apps/assisted-ui/package.json (1 hunks)
  • apps/assisted-ui/src/components/Chatbot.tsx (1 hunks)
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx (3 hunks)
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (6 hunks)
  • libs/chatbot/package.json (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the assisted-installer-ui chatbot feedback implementation, the onfeedbacksubmit callback requires...
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.

Applied to files:

  • apps/assisted-ui/package.json
  • libs/chatbot/lib/components/ChatBot/BotMessage.tsx
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
🧬 Code Graph Analysis (1)
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (1)
libs/types/assisted-installer-service.d.ts (1)
  • Error (997-1018)
🔇 Additional comments (12)
apps/assisted-ui/package.json (1)

4-4: LGTM! Dependency reordering and version alignment.

The dependency reordering and @patternfly-6/chatbot version update to 6.3.2 aligns with the coordinated changes across the codebase to support enhanced chatbot functionality.

Also applies to: 6-6

apps/assisted-ui/src/components/Chatbot.tsx (1)

14-14: Excellent fix! Token expiration logic corrected.

The condition has been properly corrected to refresh tokens when they expire within the next 5 seconds (Date.now() > expiration - 5000). The previous logic (Date.now() - 5000 > expiration) was incorrect and would have caused authentication failures.

libs/chatbot/lib/components/ChatBot/BotMessage.tsx (3)

3-3: LGTM! Clean import for loading component.


59-59: LGTM! Well-designed loading prop addition.

The new isLoading boolean prop provides a clear interface for managing the loading state of bot messages.

Also applies to: 67-67


129-140: Excellent loading state implementation.

The conditional rendering properly handles the loading state by:

  • Disabling user actions when loading (line 133)
  • Showing the loading indicator with clear messaging (line 136)
  • Maintaining clean JSX structure with proper conditional logic
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (7)

111-111: Good addition for tracking stream completion.

The eventEnded flag provides proper tracking of whether the streaming response completed successfully.


139-147: Improved error handling with graceful fallback.

The enhanced error handling correctly attempts to parse detailed error messages from the response JSON while providing a safe fallback to generic messaging if parsing fails.


175-177: Proper stream completion detection.

Explicitly detecting the 'end' event and setting the eventEnded flag ensures reliable tracking of stream completion.


179-179: Good validation to prevent empty token processing.

Adding the check && !!ev.data.token prevents empty or falsy tokens from being processed, which could cause issues in the UI.


216-218: Essential error handling for incomplete streams.

This check ensures that if the stream doesn't properly end with an 'end' event, users receive appropriate feedback rather than being left in an uncertain state.


351-351: Perfect integration with BotMessage loading state.

The isLoading prop is correctly passed only to the last message during streaming, providing appropriate visual feedback to users.


363-363: More appropriate generic error message.

The change from "Failed to send the message" to "An error occurred" is more accurate since errors can happen during various phases of the interaction, not just message sending.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2025
@ammont82
Copy link
Member

ammont82 commented Aug 7, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 8500c47 into openshift-assisted:master Aug 7, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants