Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export function ExplorerDrawerContent({
errorStatusCode,
isTimedOut,
sendMessage,
startNewSession,
switchToRun,
startNewSession: startNewSessionBase,
switchToRun: switchToRunBase,
respondToUserInput,
createPR,
interruptRun,
Expand All @@ -75,6 +75,11 @@ export function ExplorerDrawerContent({
setOverrideCodeModeEnable,
} = useSeerExplorer();

const clearInput = () => setInputValue('');
const startNewSession = () => startNewSessionBase({onSuccess: clearInput});
const switchToRun = (newRunId: number | null) =>
switchToRunBase(newRunId, {onSuccess: clearInput});

const readOnly =
sessionData?.owner_user_id !== undefined &&
sessionData.owner_user_id !== null &&
Expand Down Expand Up @@ -202,7 +207,7 @@ export function ExplorerDrawerContent({

// Menu component
const {menu, closeMenu, openPRWidget} = useExplorerMenu({
clearInput: () => setInputValue(''),
clearInput,
inputValue,
focusInput,
textAreaRef: textareaRef,
Expand Down
11 changes: 9 additions & 2 deletions static/app/views/seerExplorer/hooks/useSeerExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export const useSeerExplorer = () => {

/** Switches to a different run and fetches its latest state. */
const switchToRun = useCallback(
(newRunId: number | null) => {
(newRunId: number | null, {onSuccess}: {onSuccess?: () => void} = {}) => {
if (newRunId === runId) {
return;
}
Comment on lines 392 to 394
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: When starting a new chat from an unsent session, the input field is not cleared because an early return in switchToRunBase prevents the onSuccess callback from firing.
Severity: LOW

Suggested Fix

In the switchToRunBase function, move the onSuccess?.() call to before the early-return guard if (newRunId === runId) { return; }. This will ensure the callback is executed even when switching to the same runId, which includes the case where both are null.

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: static/app/views/seerExplorer/hooks/useSeerExplorer.tsx#L392-L394

Potential issue: When `startNewSession` is called while a user is already in a new,
unsent session, the `runId` is `null`. The function calls `switchToRun(null, {onSuccess:
clearInput})`. Inside the `switchToRunBase` function, an early-return guard `if
(newRunId === runId)` evaluates to true because both `newRunId` and `runId` are `null`.
This causes the function to exit before the `onSuccess` callback (`clearInput`) is
invoked. As a result, if a user types text into the input field and clicks "New Chat"
without having first sent a message, the input field is not cleared.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is no-op, shouldnt clear

Expand All @@ -404,12 +404,19 @@ export const useSeerExplorer = () => {
queryKey: makeSeerExplorerQueryKey(orgSlug, newRunId),
});
}

onSuccess?.();
},
[orgSlug, queryClient, runId, setRunId]
);

/** Resets the hook state. The session isn't actually created until the user sends a message. */
const startNewSession = useCallback(() => switchToRun(null), [switchToRun]);
const startNewSession = useCallback(
({onSuccess}: {onSuccess?: () => void} = {}) => {
switchToRun(null, {onSuccess});
},
[switchToRun]
);

const sendMessage = useCallback(
(query: string, explicitInsertIndex?: number, explicitRunId?: number | null) => {
Expand Down
Loading