Skip to content

fix(copilot): scope panel chat drafts per chat - #7159

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/copilot-draft-per-chat
Aug 27, 2026
Merged

fix(copilot): scope panel chat drafts per chat#7159
waleedlatif1 merged 1 commit into
stagingfrom
fix/copilot-draft-per-chat

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The workflow panel keyed copilot drafts by workspace + workflow only. A draft is cleared on submit and never on chat switch, and the scope key is what remounts the input (key={draftScopeKey} in mothership-chat.tsx), so selecting a different chat in the same workflow carried the previous chat's typed text, contexts, and file attachments into it. The home chat already keys drafts per chat id — this brings the panel in line.
  • Deleting a chat now prunes its draft. With per-chat keys it would otherwise sit in persisted storage forever, unreachable.
  • A store migration drops drafts saved under the old workflow-only key instead of leaving them as entries nothing reads. Home drafts are untouched — their key shape did not change.
  • Hoisted the key builder to module scope and documented the keyspace on the store.

Known trade-off: when a workflow has no chat selected the key is …:new, so the first send flips the key once and remounts the input. Text typed in that window is flushed to the new bucket rather than the new chat's. The deeper fix is for UserInput to react to draftScopeKey changes (flush old, restore new) instead of relying on the key remount — that belongs in a follow-up covering both surfaces at once.

Type of Change

  • Bug fix

Testing

Tested manually. bun run type-check, bun run lint, and bun run check:audits (36 audits) pass. Added unit tests for the store migration, verified they fail when the key pattern is broken.

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)

The workflow panel's copilot draft key was scoped by workspace + workflow
only. A draft is cleared on submit and never on chat switch, and the scope
key is what remounts the input (`key={draftScopeKey}` in mothership-chat),
so selecting a different copilot chat in the same workflow carried the
previous chat's typed text, contexts, and file attachments into it. Key the
draft on the selected chat as well, matching the home chat.

Two consequences of per-chat keys handled here:
- deleting a chat now prunes its draft, which would otherwise be unreachable
  in persisted storage forever
- drafts persisted under the old workflow-only key are dropped by a store
  migration rather than left as unreadable entries
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 27, 2026 5:54am

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR scopes workflow-panel Copilot drafts by workspace, workflow, and chat, preventing text and attachments from carrying between chats.

  • Clears the corresponding persisted draft after a chat is deleted.
  • Adds a versioned store migration that removes obsolete workflow-only draft keys while preserving home and per-chat drafts.
  • Adds migration tests for legacy, home, per-chat, and empty persisted states.

Confidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations were identified.

The new key consistently scopes panel drafts to the active workflow and its workflow-scoped chat selection, deletion clears the key captured for the initiating workflow, and the migration preserves all currently consumed key shapes.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx Extends the panel draft key with the selected chat ID and removes that scoped draft after successful chat deletion.
apps/sim/stores/mothership-drafts/store.ts Documents draft key formats and adds a version-1 persistence migration that prunes obsolete workflow-only keys.
apps/sim/stores/mothership-drafts/store.test.ts Verifies migration behavior for legacy workflow drafts, home drafts, per-chat drafts, and missing state.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Selection[Selected workflow and chat] --> Key[Build workspace/workflow/chat key]
  Key --> Draft[Persist or restore scoped draft]
  Delete[Delete chat succeeds] --> Clear[Clear matching scoped draft]
  Legacy[Persisted v0 state] --> Migrate[Remove workflow-only keys]
  Migrate --> Drafts[Preserve home and per-chat keys]
Loading

Reviews (1): Last reviewed commit: "fix(copilot): scope panel chat drafts pe..." | Re-trigger Greptile

@waleedlatif1
waleedlatif1 merged commit 2fb768d into staging Aug 27, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/copilot-draft-per-chat branch August 27, 2026 06:43
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