Skip to content

v0.6.62: fix new copilot chat creation and selection on refresh#4342

Merged
TheodoreSpeaks merged 1 commit intomainfrom
staging
Apr 29, 2026
Merged

v0.6.62: fix new copilot chat creation and selection on refresh#4342
TheodoreSpeaks merged 1 commit intomainfrom
staging

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

* fix(copilot): fix new task error

* Keep recent copilot chat open on refresh
@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:46pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 29, 2026

PR Summary

Low Risk
Scoped UI state/cache changes to Copilot chat selection; minimal blast radius, with main risk being incorrect list ordering or stale cache behavior.

Overview
Fixes a race in the Copilot panel where creating a new chat could immediately be de-selected because the selected chatId wasn’t yet present in the cached chat list.

The auto-select effect now waits for a non-empty list before selecting a default chat, and handleCopilotNewChat now seeds the new chat into the React Query cache (copilotChatsKeys.list(workflowId)) before setting copilotChatId, then triggers a refetch to reconcile.

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

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR correctly addresses two interlinked bugs in the copilot panel. Bug 1: autoSelectAttemptedForRef was marked before the empty-list check, so a workflow with an initially empty list would never auto-select once chats loaded. The fix moves the length === 0 guard before the ref mutation. Bug 2: newly created chats were immediately deselected because the auto-select effect saw a stale list and cleared copilotChatId. The fix optimistically seeds the new chat into the React Query cache via queryClient.setQueryData before calling setCopilotChatId, so the effect finds the chat in the list and leaves it selected.

Confidence Score: 5/5

Safe to merge — targeted, well-reasoned fixes with no regressions introduced.

Both changes are minimal and correct: the auto-select guard reordering is straightforwardly sound, and the optimistic cache seed matches the exact CopilotChatListItem shape. No new state is introduced and the subsequent invalidateQueries reconciles the cache with the server. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx Fixes two related copilot chat bugs: auto-select skipping on empty list at first render, and newly created chat being immediately deselected — resolved by reordering the guard and optimistically seeding the React Query cache before selecting

Sequence Diagram

sequenceDiagram
    participant U as User
    participant C as handleCopilotNewChat
    participant QC as QueryClient Cache
    participant S as setCopilotChatId
    participant E as Auto-select Effect
    participant API as /api/copilot/chats

    U->>C: clicks "New Chat"
    C->>API: POST /api/copilot/chats
    API-->>C: { id: "new-chat-id" }
    Note over C: Before fix: setCopilotChatId then loadCopilotChats
    C->>QC: setQueryData — seed new chat into list cache
    C->>S: setCopilotChatId("new-chat-id")
    S-->>E: triggers auto-select effect
    E->>QC: reads copilotChatList (contains seeded chat)
    Note over E: copilotChatId set AND found in list → no deselect
    C->>QC: invalidateQueries (loadCopilotChats)
    QC->>API: GET /api/copilot/chats
    API-->>QC: updated list (includes new chat)
Loading

Reviews (1): Last reviewed commit: "fix(copilot): fix new task error (#4341)" | Re-trigger Greptile

@TheodoreSpeaks TheodoreSpeaks merged commit ecbf5e5 into main Apr 29, 2026
31 checks passed
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