Skip to content

fix(tasks): show renames instantly in sidebar and never overwrite them#2154

Open
pauldambra wants to merge 3 commits into
mainfrom
posthog-code/fix-task-rename-instant-and-preserved
Open

fix(tasks): show renames instantly in sidebar and never overwrite them#2154
pauldambra wants to merge 3 commits into
mainfrom
posthog-code/fix-task-rename-instant-and-preserved

Conversation

@pauldambra
Copy link
Copy Markdown
Member

Summary

Two related bugs with manual task renames:

  1. Sidebar list lagged by up to 30s. The sidebar reads task names from the ["tasks", "summaries"] query cache (via useTaskSummaries), but the rename flow only touched ["tasks", "list"]. So the header updated instantly while the sidebar waited for the next poll. Now both caches are written optimistically in SidebarMenu.handleTaskEditSubmit, invalidated in useUpdateTask.onSuccess, and rolled back in the catch branch.
  2. Auto-title clobbered manual renames on first generation. useChatTitleGenerator had a !isFirstGeneration carve-out that bypassed the title_manually_set guard. If the user renamed a task before the first prompt's auto-title finished, their rename was overwritten. The carve-out is removed — title_manually_set is now respected unconditionally.

Files changed

  • apps/code/src/renderer/features/sidebar/components/SidebarMenu.tsx — optimistic write + rollback for the summaries cache.
  • apps/code/src/renderer/features/tasks/hooks/useTasks.ts — invalidate summaries in useUpdateTask.onSuccess.
  • apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts — drop the first-generation carve-out.
  • apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.test.ts — flipped the test that documented the old behavior.

Test plan

  • pnpm --filter code typecheck
  • pnpm --filter code test — 1224 tests pass
  • Lint passes on touched files
  • Manual: right-click rename a task in the sidebar → new title appears instantly in both header and sidebar list
  • Manual: double-click rename a task → same instant-update behavior
  • Manual: rename a freshly-created task before the first prompt's auto-title generates → rename is preserved (not overwritten)
  • Manual: rename failure path (force the PATCH to fail) → sidebar reverts to the old title

Two related issues with manual task renames:

1. The sidebar task list reads from the ["tasks", "summaries"] query cache
   (via useTaskSummaries), but the rename optimistic update and onSuccess
   invalidation only touched ["tasks", "list"]. The sidebar therefore waited
   up to 30s (the polling interval) to show the new title, even though the
   header updated instantly. Now both caches are updated optimistically and
   invalidated on success.

2. useChatTitleGenerator skipped the title_manually_set check on the first
   generation, so if a user renamed a task before the first prompt's auto-
   title finished, their rename got clobbered. title_manually_set is now
   respected unconditionally.

Generated-By: PostHog Code
Task-Id: 07a0cd34-65e0-4e58-bbc9-d9d103d1f251
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 17, 2026

Comments Outside Diff (1)

  1. apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts, line 83-91 (link)

    P2 Auto-title still skips summaries cache update

    After updating ["tasks", "list"], the auto-title path doesn't touch ["tasks", "summaries"] and doesn't use useUpdateTask, so the new onSuccess invalidation added in useTasks.ts won't fire here. For users where showAllUsers = false, the sidebar reads titles from useTaskSummaries (the summaries cache), meaning auto-generated titles still lag up to 30 s in the sidebar — the same root cause the PR is fixing for manual renames. Adding queryClient.invalidateQueries({ queryKey: ["tasks", "summaries"] }) alongside the existing setQueriesData call would close this gap.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts
    Line: 83-91
    
    Comment:
    **Auto-title still skips summaries cache update**
    
    After updating `["tasks", "list"]`, the auto-title path doesn't touch `["tasks", "summaries"]` and doesn't use `useUpdateTask`, so the new `onSuccess` invalidation added in `useTasks.ts` won't fire here. For users where `showAllUsers = false`, the sidebar reads titles from `useTaskSummaries` (the summaries cache), meaning auto-generated titles still lag up to 30 s in the sidebar — the same root cause the PR is fixing for manual renames. Adding `queryClient.invalidateQueries({ queryKey: ["tasks", "summaries"] })` alongside the existing `setQueriesData` call would close this gap.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts:83-91
**Auto-title still skips summaries cache update**

After updating `["tasks", "list"]`, the auto-title path doesn't touch `["tasks", "summaries"]` and doesn't use `useUpdateTask`, so the new `onSuccess` invalidation added in `useTasks.ts` won't fire here. For users where `showAllUsers = false`, the sidebar reads titles from `useTaskSummaries` (the summaries cache), meaning auto-generated titles still lag up to 30 s in the sidebar — the same root cause the PR is fixing for manual renames. Adding `queryClient.invalidateQueries({ queryKey: ["tasks", "summaries"] })` alongside the existing `setQueriesData` call would close this gap.

Reviews (1): Last reviewed commit: "fix(tasks): show renames instantly in si..." | Re-trigger Greptile

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 900df3ba1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The auto-title path calls client.updateTask directly (not via useUpdateTask),
so the onSuccess invalidation added earlier in this PR doesn't fire here.
Without this, an auto-generated title would still take up to 30 s to appear
in the sidebar — the same root cause this PR fixes for manual renames.

Generated-By: PostHog Code
Task-Id: 07a0cd34-65e0-4e58-bbc9-d9d103d1f251
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 17, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.test.ts:119-122
**Missing coverage for summaries cache update**

The PR's main new line in `useChatTitleGenerator.ts` — the `setQueriesData` call that updates `["tasks", "summaries"]` — has no corresponding test assertion. The "generates title on first prompt" test only verifies `mockUpdateTask` was called; it never checks that `mockSetQueriesData` was also called with `{ queryKey: ["tasks", "summaries"] }`. A test covering the happy path should assert that both the list and summaries caches are updated so future regressions to that line are caught.

Reviews (2): Last reviewed commit: "fix(tasks): also write auto-titles into ..." | Re-trigger Greptile

Regression guard for the previous commit so the summaries-cache write
in useChatTitleGenerator can't be silently dropped.

Generated-By: PostHog Code
Task-Id: 07a0cd34-65e0-4e58-bbc9-d9d103d1f251
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 17, 2026

Reviews (3): Last reviewed commit: "test(tasks): assert auto-title writes to..." | Re-trigger Greptile

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