Skip to content

fix(mothership): stabilize task sidebar ordering on selection#4309

Merged
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/audit-task-registry
Apr 27, 2026
Merged

fix(mothership): stabilize task sidebar ordering on selection#4309
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/audit-task-registry

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • drop keepPreviousData from useTasks — was on a static key, caused stale-then-snap reorders on invalidation
  • remove list invalidation from useMarkTaskRead/useMarkTaskUnread — server only flips lastSeenAt, optimistic update is sufficient
  • validate SSE task_status payload before invalidating the task list — drop bogus events instead of triggering a refetch
  • use selectTaskOnly in sidebar click handler so non-shift clicks match the rest of the selection model (clears workflow/folder selections, populates selectedTasks)

Type of Change

  • Bug fix

Testing

Tested manually. 8/8 unit tests pass (hooks/queries/tasks.test.ts, hooks/use-task-events.test.ts).

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 Apr 27, 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 27, 2026 7:27pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 27, 2026

PR Summary

Medium Risk
Touches task list caching/invalidation and SSE-driven refresh behavior, which can impact sidebar freshness and ordering if assumptions about server updates or event payloads are wrong. Changes are localized but affect core navigation UX.

Overview
Stabilizes the task sidebar by reducing unnecessary task-list refetches and aligning selection behavior.

useTasks no longer uses keepPreviousData, and useMarkTaskRead/useMarkTaskUnread now rely solely on optimistic updates (no list invalidation) to avoid refetch-driven reordering. handleTaskStatusEvent now validates/parses SSE payloads before invalidating the tasks list, and the sidebar’s normal click path uses useFolderStore.selectTaskOnly instead of manually resetting selection state.

Reviewed by Cursor Bugbot for commit f15f34b. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

Four targeted fixes that eliminate sidebar task-ordering jitter: drop keepPreviousData from the static-key useTasks query (per sim-queries.md), remove onSettled invalidation from the mark-read/unread mutations (optimistic update is provably equivalent to server state since only lastSeenAt is mutated), guard SSE task_status invalidation behind payload validation, and switch the sidebar single-click handler from a raw setState that cleared selectedTasks to selectTaskOnly which correctly adds the clicked task to the set and clears cross-entity selections.

Confidence Score: 5/5

Safe to merge — all changes are narrow, well-justified, and covered by existing tests.

No P0 or P1 findings. All four changes address a clear root cause with no observed regressions. The only remark is a P2 test-description nit.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx Replaces raw setState (which set selectedTasks to an empty Set) with selectTaskOnly, correctly populating selectedTasks and clearing cross-selection state.
apps/sim/hooks/queries/tasks.ts Removes keepPreviousData from static-key useTasks query (aligned with sim-queries.md) and drops onSettled invalidation from mark-read/unread mutations; both changes are well-justified in PR and thread.
apps/sim/hooks/use-task-events.ts Moves invalidateQueries to after payload validation so malformed SSE events no longer trigger spurious list refetches.
apps/sim/hooks/use-task-events.test.ts Tests updated to reflect new guard-before-invalidate behaviour; one test description is misleading about type-based branching that doesn't exist in the implementation.

Sequence Diagram

sequenceDiagram
    participant User
    participant Sidebar
    participant FolderStore
    participant SSE as SSE (task_status)
    participant TQ as TanStack Query
    participant Server

    User->>Sidebar: click task (no shift/meta)
    Sidebar->>FolderStore: selectTaskOnly(taskId)
    FolderStore-->>FolderStore: selectedTasks={taskId}, clear workflows/folders

    User->>Sidebar: mark task read
    Sidebar->>TQ: cancelQueries(taskList)
    TQ-->>TQ: optimistic update isUnread=false
    Sidebar->>Server: PATCH lastSeenAt
    Server-->>Sidebar: 200 OK
    Note over TQ: no invalidation — optimistic update is equivalent to server state

    SSE-->>Sidebar: task_status event
    Sidebar->>Sidebar: parseTaskStatusEventPayload(data)
    alt valid payload
        Sidebar->>TQ: invalidateQueries(taskList)
        TQ->>Server: refetch task list
    else invalid payload
        Sidebar->>Sidebar: log warn, return early
    end
Loading

Reviews (2): Last reviewed commit: "fix(mothership): stabilize task sidebar ..." | Re-trigger Greptile

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

@waleedlatif1 waleedlatif1 merged commit f62d274 into staging Apr 27, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/audit-task-registry branch April 27, 2026 19:42
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