Skip to content

Conversation

@Abhijay007
Copy link
Collaborator

closes #6087

Summary

Type of Change

  • Feature

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Screenshots/Demos (for UX changes)

Before:

After:

Copilot AI review requested due to automatic review settings January 4, 2026 18:01
@Abhijay007 Abhijay007 marked this pull request as draft January 4, 2026 18:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds auto-submit functionality for recipes that have been accepted, allowing recipe prompts to be automatically submitted when a session is opened with a recipe but no existing messages.

Key changes:

  • Added autoSubmit prop that flows from Pair.tsx through BaseChat.tsx to ChatInput.tsx
  • Implemented logic to determine when auto-submission should occur based on recipe presence and conversation state
  • Added useEffect in ChatInput to trigger submission when autoSubmit is true

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ui/desktop/src/components/Pair.tsx Added useChatStream hook and logic to calculate shouldAutoSubmit based on recipe and message state
ui/desktop/src/components/BaseChat.tsx Added autoSubmit prop to component signature and passed it to ChatInput; moved recipe variable declaration earlier
ui/desktop/src/components/ChatInput.tsx Added autoSubmit prop and useEffect to automatically submit initialValue when autoSubmit is true
ui/desktop/src/components/Hub.tsx Explicitly set autoSubmit={false} to maintain existing Hub behavior

}

export default function Pair({ setChat, sessionId, initialMessage }: PairProps) {
const { session } = useChatStream({ sessionId, onStreamFinish: () => {} });
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

This creates a second instance of useChatStream for the same sessionId. BaseChat already calls useChatStream internally, so this duplicates the session loading logic and could cause unnecessary API calls. Remove this hook and pass the autoSubmit logic directly to BaseChat, or have BaseChat expose the session data needed for this calculation.

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +25
const recipe = session?.recipe;
const hasMessages = (session?.conversation?.length ?? 0) > 0;
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The autoSubmit condition may evaluate before the session is fully loaded, causing shouldAutoSubmit to be false initially and then never re-evaluate to true. Since session is loaded asynchronously, the initial render will have session as undefined, causing shouldAutoSubmit to be false. When session loads, the useMemo will recalculate, but by then didAutoSubmit might already be set to true by the ChatInput useEffect, preventing the actual submission.

Suggested change
const recipe = session?.recipe;
const hasMessages = (session?.conversation?.length ?? 0) > 0;
if (!session) return undefined;
const recipe = session.recipe;
const hasMessages = (session.conversation?.length ?? 0) > 0;

Copilot uses AI. Check for mistakes.
Comment on lines +983 to +988
useEffect(() => {
if (!!autoSubmit && !didAutoSubmit) {
setDidAutoSubmit(true);
performSubmit(initialValue);
}
}, [autoSubmit, didAutoSubmit, initialValue, performSubmit]);
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The useEffect depends on performSubmit which is a useCallback with many dependencies. If any of those dependencies change, performSubmit gets recreated and this effect will re-run, potentially submitting multiple times even though didAutoSubmit is true. The effect runs before didAutoSubmit is set, so rapid dependency changes could cause race conditions. Consider using useRef for performSubmit or restructure to avoid including it in the dependency array.

Suggested change
useEffect(() => {
if (!!autoSubmit && !didAutoSubmit) {
setDidAutoSubmit(true);
performSubmit(initialValue);
}
}, [autoSubmit, didAutoSubmit, initialValue, performSubmit]);
const performSubmitRef = useRef<typeof performSubmit | null>(null);
useEffect(() => {
performSubmitRef.current = performSubmit;
}, [performSubmit]);
useEffect(() => {
if (!!autoSubmit && !didAutoSubmit) {
setDidAutoSubmit(true);
performSubmitRef.current?.(initialValue);
}
}, [autoSubmit, didAutoSubmit, initialValue]);

Copilot uses AI. Check for mistakes.
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.

Add auto submit for recipes that have been accepted

1 participant