Skip to content

Conversation

@maxkosty
Copy link
Collaborator

@maxkosty maxkosty commented Jan 14, 2026

Goal

Show full-stack AI Agent architecture monitoring including frontend

Testing

./deploy --env=local react
Screenshot 2026-01-13 at 3 01 16 PM

sample trace

Screenshot 2026-01-14 at 3 17 43 PM

Related

@maxkosty maxkosty requested a review from ndmanvar as a code owner January 14, 2026 23:33
@vercel
Copy link
Contributor

vercel bot commented Jan 14, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
empower Ignored Ignored Jan 14, 2026 11:34pm

@maxkosty maxkosty requested review from ndmanvar and removed request for ndmanvar January 14, 2026 23:34
Comment on lines +117 to +126
useEffect(() => {
if (isOpen && conversationState === 'initial') {
// Show typing indicator
setMessages([{ type: 'typing', id: generateMessageId() }]);

setTimeout(() => {
// Remove typing indicator and show welcome message
addBotMessage("Hi, I can help you pick the right plants for your home", () => {
setMessages([
{
Copy link

Choose a reason for hiding this comment

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

Bug: The setTimeout calls in the chat initialization useEffect are not cleared when the chat is closed, leading to state updates on a hidden component and potential memory leaks.
Severity: HIGH

Suggested Fix

Store the setTimeout identifiers returned from the calls within the initialization useEffect in refs. Then, add logic to the endChatSession function or a cleanup function for the useEffect to call clearTimeout on these refs, ensuring all pending asynchronous operations are cancelled when the chat session ends.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: react/src/components/ChatWidget.jsx#L117-L126

Potential issue: The `useEffect` hook for chat initialization schedules several
`setTimeout` calls to display welcome messages. These timeout IDs are not stored or
tracked. If the user closes the chat widget before these timeouts complete, the cleanup
logic in `endChatSession` does not clear them. As a result, the timeout callbacks will
still fire, attempting to update the state of a hidden component. This can lead to
wasted resources, potential state inconsistencies upon reopening the chat, and a memory
leak if the user repeatedly opens and closes the widget.

Did we get this right? 👍 / 👎 to inform future reviews.

setMessages(prev => [
...prev.filter(msg => msg.type !== 'typing'),
{
type: 'bot',
Copy link

Choose a reason for hiding this comment

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

Bug: The fetch call to /api/v1/buy-plants does not check response.ok, which can lead to undefined being displayed in the chat if the API returns an error.
Severity: HIGH

Suggested Fix

After the fetch call and before parsing the body with response.json(), add a check for if (!response.ok). If the response is not ok, handle the error appropriately, for instance by setting an error state and displaying a message to the user, rather than proceeding with the success path.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: react/src/components/ChatWidget.jsx#L285

Potential issue: The `fetch` call to the `/api/v1/buy-plants` endpoint does not check
the `response.ok` status before parsing the JSON body with `response.json()`. If the API
returns an error status (e.g., 4xx or 5xx) with a valid JSON error message, the code
will not throw an exception. Instead, it will proceed to access `data.response` and
`data.agent_name` on a JSON object that lacks these properties, resulting in `undefined`
values being passed to `addBotMessage` and displayed to the user. This violates the
error handling pattern seen elsewhere in the application.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +308 to +318
// Opening the chat - start a new trace
Sentry.startNewTrace(() => {
const span = Sentry.startInactiveSpan({
op: 'ui.interaction.chat',
name: 'AI Agent Chat Session',
forceTransaction: true
});
chatSpanRef.current = span;
});
setIsOpen(true);
};
Copy link

Choose a reason for hiding this comment

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

Bug: The chat widget state is not reset when closed and reopened, causing the widget to be non-functional after the first conversation is completed.
Severity: CRITICAL

Suggested Fix

Modify the openChat function to reset the relevant state variables when a new chat session is initiated. Specifically, call setConversationState('initial') and setMessages([]) at the beginning of openChat to ensure every time the user opens the widget, they are presented with a fresh, functional chat session.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: react/src/components/ChatWidget.jsx#L307-L318

Potential issue: The chat widget's state, specifically `conversationState` and
`messages`, is not reset when the chat is closed. When a user completes a conversation,
`conversationState` is set to `'completed'`. If the user then closes and reopens the
chat, the `openChat` function only sets `isOpen` to `true` but does not reset the state.
Consequently, the initial welcome messages do not appear (as they require
`conversationState === 'initial'`), and the user input form is not rendered, leaving the
user with a non-functional chat window containing the previous conversation.

Did we get this right? 👍 / 👎 to inform future reviews.

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 0% with 160 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.75%. Comparing base (d1ce521) to head (ddd8712).
⚠️ Report is 8 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
react/src/components/ChatWidget.jsx 0.00% 159 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1160      +/-   ##
==========================================
- Coverage   24.64%   21.75%   -2.89%     
==========================================
  Files          41       42       +1     
  Lines        1205     1365     +160     
  Branches      137      173      +36     
==========================================
  Hits          297      297              
- Misses        883     1042     +159     
- Partials       25       26       +1     
Flag Coverage Δ
api 5.57% <ø> (ø)
frontend 32.88% <0.00%> (-8.11%) ⬇️
Components Coverage Δ
checkout_module 5.57% <ø> (ø)
product_component 26.56% <0.00%> (-11.13%) ⬇️
Files with missing lines Coverage Δ
react/src/components/Home.jsx 0.00% <ø> (ø)
react/src/index.js 0.00% <ø> (ø)
react/src/components/ChatWidget.jsx 0.00% <0.00%> (ø)

@maxkosty maxkosty merged commit edaaa13 into master Jan 14, 2026
18 of 21 checks passed
@maxkosty maxkosty deleted the agent-frontend branch January 14, 2026 23:50
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