Skip to content

feat(mothership): pin tasks to keep them at the top of the sidebar#4582

Merged
waleedlatif1 merged 4 commits into
stagingfrom
waleedlatif1/pin-mship-tasks
May 13, 2026
Merged

feat(mothership): pin tasks to keep them at the top of the sidebar#4582
waleedlatif1 merged 4 commits into
stagingfrom
waleedlatif1/pin-mship-tasks

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add pinned flag to mothership chats; sort pinned tasks to the top of the sidebar
  • New "Pin/Unpin" entry in the task context menu
  • Sidebar tile shows (priority): active dot → unread dot → pin icon → nothing; ... overlays on hover

Type of Change

  • New feature

Testing

Tested manually. Updated tasks.test.ts for the new contract field; mothership chat route tests still pass.

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)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 13, 2026 9:29pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 13, 2026

PR Summary

Medium Risk
Adds a new persisted pinned flag on copilot_chats and threads it through API contracts, DB writes, and sidebar UI ordering; main risk is data migration/ordering regressions or cache inconsistencies around optimistic updates.

Overview
Adds task pinning for mothership chats by introducing a persisted pinned boolean on copilot_chats, exposing it in listMothershipChatsContract/updateMothershipChatContract, and sorting the server task list by pinned then updatedAt.

Updates the sidebar to display a Pin/Unpin action in the task context menu, show a pin indicator when applicable, and adds a useSetTaskPinned optimistic mutation while ensuring newly created/forked tasks insert below any pinned tasks. Also emits new PostHog events (task_pinned, task_unpinned) and updates task query parsing tests for the new field.

Reviewed by Cursor Bugbot for commit 7b9eb34. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR adds a "pin task" feature for mothership chats: a new pinned boolean column in the DB, a PATCH endpoint update to toggle the flag, and UI changes in the sidebar (pin icon indicator, Pin/Unpin context menu item). Optimistic updates in useSetTaskPinned correctly partition the cached list into pinned-first order and roll back on error.

  • DB layer: Migration adds pinned boolean DEFAULT false NOT NULL; schema, contract, and mapTask are all kept in sync.
  • Optimistic update: useSetTaskPinned, useCreateTask, and useForkTask all re-partition the task list to maintain pinned-first order without re-fetching.
  • Sidebar cleanup: An unrelated useEffect that auto-collapsed the sidebar width on non-workflow pages was removed, and the resize handle is now unconditionally rendered — both changes appear intentional but are outside the stated scope of this PR.

Confidence Score: 5/5

Safe to merge — the pin/unpin path is end-to-end consistent (migration, schema, contract, API, hooks, UI) with proper optimistic rollback.

All layers (DB migration, Drizzle schema, Zod contract, API route, React Query hook, sidebar UI) are updated consistently. The optimistic update correctly partitions the cache and rolls back on error. No auth or data-integrity issues were found. The only callouts are a misleading variable name in two places and the absence of a compound DB index for the new two-column sort — neither affects correctness.

No files require special attention; the apps/sim/app/api/mothership/chats/route.ts sort change is worth revisiting for a DB index if task counts grow.

Important Files Changed

Filename Overview
packages/db/migrations/0207_colorful_secret_warriors.sql Adds pinned boolean DEFAULT false NOT NULL to copilot_chats; safe backfill (default false), matches schema.ts definition.
packages/db/schema.ts Adds pinned: boolean('pinned').notNull().default(false) to copilotChats table definition; consistent with migration.
apps/sim/lib/api/contracts/mothership-tasks.ts Adds optional pinned: z.boolean() to the PATCH body schema and required pinned: z.boolean() to the list response schema; refine guard updated to allow pinned-only payloads.
apps/sim/app/api/mothership/chats/route.ts GET now selects and returns pinned; ordering changed to desc(pinned), desc(updatedAt) — no compound index exists for this two-column sort on filtered rows.
apps/sim/app/api/mothership/chats/[chatId]/route.ts PATCH route extracts and persists pinned; fires task_pinned / task_unpinned PostHog events when the field is present in the payload.
apps/sim/hooks/queries/tasks.ts Adds useSetTaskPinned with correct optimistic update (partition + reorder); updates useCreateTask and useForkTask to insert new tasks after pinned ones; pinnedCount variable name is misleading (it's actually an index).
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx Wires isPinned to SidebarTaskItem, adds useSetTaskPinned mutation, implements handleToggleTaskPin using tasksRef pattern; also removes an unrelated useEffect that auto-collapsed the sidebar and unconditionally renders the resize handle.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu.tsx Adds showPin / isPinned / onTogglePin props and Pin/PinOff menu item in the status section; correctly included in hasStatusSection guard.
apps/sim/hooks/queries/tasks.test.ts Tests updated with pinned: false in fixture and isPinned: false in expected output; covers the new contract field.

Sequence Diagram

sequenceDiagram
    participant User
    participant Sidebar
    participant useSetTaskPinned
    participant QueryCache
    participant PATCH /chats/[chatId]
    participant DB

    User->>Sidebar: Right-click task → Pin/Unpin
    Sidebar->>useSetTaskPinned: "mutate({ chatId, pinned: !current })"
    useSetTaskPinned->>QueryCache: cancelQueries + snapshot previousTasks
    useSetTaskPinned->>QueryCache: setQueryData (optimistic: partition pinned/unpinned)
    useSetTaskPinned->>PATCH /chats/[chatId]: { pinned }
    PATCH /chats/[chatId]->>DB: UPDATE copilot_chats SET pinned=...
    DB-->>PATCH /chats/[chatId]: updated row
    PATCH /chats/[chatId]-->>useSetTaskPinned: { success: true }
    useSetTaskPinned->>QueryCache: invalidateQueries (onSettled)
    QueryCache-->>Sidebar: re-render with server-confirmed order
    note over useSetTaskPinned,QueryCache: On error: restore previousTasks snapshot
Loading

Reviews (3): Last reviewed commit: "fix(tasks): insert new optimistic tasks ..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx Outdated
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/hooks/queries/tasks.ts
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

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 7b9eb34. Configure here.

@waleedlatif1 waleedlatif1 merged commit 1ed3a4e into staging May 13, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/pin-mship-tasks branch May 13, 2026 21:46
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