Skip to content

fix(copilot): fix new task error#4341

Merged
TheodoreSpeaks merged 2 commits intostagingfrom
fix/new-copilot-chat
Apr 29, 2026
Merged

fix(copilot): fix new task error#4341
TheodoreSpeaks merged 2 commits intostagingfrom
fix/new-copilot-chat

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

@TheodoreSpeaks TheodoreSpeaks commented Apr 29, 2026

Summary

Our recent fixes to copilot chat unintentionally broke the new copilot chat creation logic. Fixed the chat id selection logic so chat id is only set when its loaded.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Tested locally, validated that copilot chats can be sent, switching works as intended, and new chats don't break anything. Validated refreshes work.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 29, 2026 6:30pm

Request Review

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator Author

@BugBot review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 29, 2026

PR Summary

Low Risk
Low risk UI/state fix limited to Copilot chat selection and React Query caching; main risk is subtle regressions in chat auto-selection across workflow switches.

Overview
Fixes Copilot chat auto-selection so it only selects when the chat list has loaded (skipping selection when the list is empty).

When creating a new Copilot chat, it now seeds the new chat into the React Query list cache before selecting it, preventing the auto-select effect from immediately clearing the selected chatId due to a stale chat list.

Reviewed by Cursor Bugbot for commit 07ee8e5. Bugbot is set up for automated code reviews on this repo. Configure here.

@TheodoreSpeaks TheodoreSpeaks marked this pull request as ready for review April 29, 2026 18:32
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 07ee8e5. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR fixes two related regressions in the copilot chat panel. First, autoSelectAttemptedForRef was being marked before the empty-list guard, so a still-loading list would permanently suppress auto-selection. Second, creating a new chat would immediately be deselected because the auto-select effect saw an ID not yet present in the (stale) React Query list; the fix optimistically seeds the new item into the cache before calling setCopilotChatId, closing the race window.

Confidence Score: 5/5

Safe to merge — targeted, well-reasoned fix with no new logic risks introduced.

Both changes are minimal and directly address the described regressions. The optimistic cache seed correctly matches the CopilotChatListItem shape and is replaced by the server response after loadCopilotChats invalidates. The auto-select tracking order change is a simple guard reordering with no side-effects. No P1 or P0 issues found.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx Two-part bug fix: (1) defers auto-select tracking until the chat list is non-empty so stale-load doesn't permanently skip auto-selection; (2) optimistically seeds the new chat into the React Query cache before selecting it to prevent the auto-select effect from immediately deselecting the freshly created ID.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant C as handleCopilotNewChat
    participant QC as QueryClient cache
    participant S as setCopilotChatId
    participant E as autoSelect useEffect
    participant API as /api/copilot/chats

    U->>C: Click "New Chat"
    C->>API: POST /api/copilot/chats
    API-->>C: { id: "new-id" }
    C->>QC: setQueryData — prepend new chat to list
    C->>S: setCopilotChatId("new-id")
    C->>QC: invalidateQueries (loadCopilotChats)
    Note over E: Effect fires with updated list + copilotChatId set
    E->>E: copilotChatId found in list → no deselect
    QC-->>E: server refetch arrives, list still contains new chat
    E->>E: copilotChatId still set → return early ✓
Loading

Reviews (1): Last reviewed commit: "Keep recent copilot chat open on refresh" | Re-trigger Greptile

@TheodoreSpeaks TheodoreSpeaks merged commit 8d042f7 into staging Apr 29, 2026
14 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the fix/new-copilot-chat branch April 29, 2026 18:39
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.

1 participant