feat(tasks): add toggle for internal tasks in sidebar for staff#1952
feat(tasks): add toggle for internal tasks in sidebar for staff#1952
Conversation
Mirrors the upstream PostHog/posthog#56943 toggle so the desktop app can surface internal tasks for local debugging. The toggle lives in the sidebar's task filter menu, only renders when import.meta.env.DEV is true, and bypasses the workspace-existence filter so server-side internal tasks (which won't have a local workspace) are visible. The backend already gates internal=true behind DEBUG, so this stays a no-op in production. Generated-By: PostHog Code Task-Id: 10e42168-e889-48c0-a19e-bf07d32c2b37
908fba3 to
799a9c0
Compare
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/tasks/hooks/useTasks.ts:39-40
**`createdBy` not cleared when fetching internal tasks**
When `showInternal` is `true` but `showAllUsers` is `false`, `createdBy` is still set to `currentUser?.id`. Internal tasks are created by the agent service (not the current user), so the backend receives both `internal=true` and `created_by=<userId>` — and applying both filters together will likely return an empty result set. `createdBy` should be `undefined` whenever `showInternal` is `true`.
```suggestion
const createdBy = filters?.showAllUsers || filters?.showInternal ? undefined : currentUser?.id;
```
### Issue 2 of 2
apps/code/src/renderer/features/sidebar/components/TaskListView.tsx:199-222
**Toggle visible in production for staff users but silently non-functional**
The existing "Show all users" toggle is gated by `import.meta.env.DEV`, but this new toggle uses `isStaff`. Staff users in production builds will see "Task visibility" in the filter menu; however, the backend only honours `internal=true` when `settings.DEBUG` is enabled, so the toggle silently does nothing in production. Consider aligning the guard with the existing pattern (`import.meta.env.DEV`) or adding an `import.meta.env.DEV` check alongside `isStaff` to avoid showing a non-functional control to production staff.
Reviews (1): Last reviewed commit: "show for staff users" | Re-trigger Greptile |
| const createdBy = filters?.showAllUsers ? undefined : currentUser?.id; | ||
| const internal = filters?.showInternal ? true : undefined; |
There was a problem hiding this comment.
createdBy not cleared when fetching internal tasks
When showInternal is true but showAllUsers is false, createdBy is still set to currentUser?.id. Internal tasks are created by the agent service (not the current user), so the backend receives both internal=true and created_by=<userId> — and applying both filters together will likely return an empty result set. createdBy should be undefined whenever showInternal is true.
| const createdBy = filters?.showAllUsers ? undefined : currentUser?.id; | |
| const internal = filters?.showInternal ? true : undefined; | |
| const createdBy = filters?.showAllUsers || filters?.showInternal ? undefined : currentUser?.id; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/tasks/hooks/useTasks.ts
Line: 39-40
Comment:
**`createdBy` not cleared when fetching internal tasks**
When `showInternal` is `true` but `showAllUsers` is `false`, `createdBy` is still set to `currentUser?.id`. Internal tasks are created by the agent service (not the current user), so the backend receives both `internal=true` and `created_by=<userId>` — and applying both filters together will likely return an empty result set. `createdBy` should be `undefined` whenever `showInternal` is `true`.
```suggestion
const createdBy = filters?.showAllUsers || filters?.showInternal ? undefined : currentUser?.id;
```
How can I resolve this? If you propose a fix, please make it concise.| </DropdownMenuRadioGroup> | ||
| </> | ||
| )} | ||
|
|
||
| {isStaff && ( | ||
| <> | ||
| <DropdownMenuSeparator /> | ||
|
|
||
| <MenuLabel>Task visibility</MenuLabel> | ||
| <DropdownMenuRadioGroup | ||
| value={showInternal ? "internal" : "external"} | ||
| onValueChange={(value) => setShowInternal(value === "internal")} | ||
| > | ||
| <DropdownMenuRadioItem value="external"> | ||
| External | ||
| </DropdownMenuRadioItem> | ||
| <DropdownMenuRadioItem value="internal"> | ||
| Internal | ||
| </DropdownMenuRadioItem> | ||
| </DropdownMenuRadioGroup> | ||
| </> | ||
| )} | ||
| </DropdownMenuContent> | ||
| </DropdownMenu> |
There was a problem hiding this comment.
Toggle visible in production for staff users but silently non-functional
The existing "Show all users" toggle is gated by import.meta.env.DEV, but this new toggle uses isStaff. Staff users in production builds will see "Task visibility" in the filter menu; however, the backend only honours internal=true when settings.DEBUG is enabled, so the toggle silently does nothing in production. Consider aligning the guard with the existing pattern (import.meta.env.DEV) or adding an import.meta.env.DEV check alongside isStaff to avoid showing a non-functional control to production staff.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/sidebar/components/TaskListView.tsx
Line: 199-222
Comment:
**Toggle visible in production for staff users but silently non-functional**
The existing "Show all users" toggle is gated by `import.meta.env.DEV`, but this new toggle uses `isStaff`. Staff users in production builds will see "Task visibility" in the filter menu; however, the backend only honours `internal=true` when `settings.DEBUG` is enabled, so the toggle silently does nothing in production. Consider aligning the guard with the existing pattern (`import.meta.env.DEV`) or adding an `import.meta.env.DEV` check alongside `isStaff` to avoid showing a non-functional control to production staff.
How can I resolve this? If you propose a fix, please make it concise.
Summary
Adds a dev-only toggle to the sidebar's task filter menu for showing internal tasks. Mirrors PostHog/posthog#56943, which adds the equivalent toggle to the main tasks page in the PostHog app — making PostHog Code usable as a debug UI for internal task runs locally.
The backend (
products/tasks/backend/api.py) already gatesinternal=truebehindsettings.DEBUG, so this is a no-op in production builds even ifimport.meta.env.DEVsomehow evaluated true.Changes
Tasktype: add optionalinternal?: booleanfield.posthogClient.getTasks: forward an optionalinternalquery param.useTaskshook: acceptshowInternaland pass through to the API + query key.sidebarStore: persistshowInternalflag alongside the other filter state.useSidebarData: whenshowInternalis on, bypass the local-workspace filter (internal tasks are server-side and won't have a workspace).TaskListView'sTaskFilterMenu: new "Internal tasks" radio group (Hide/Show), rendered only whenimport.meta.env.DEV, sitting next to the existing dev-only "Show all users" toggle.Test plan
internal=trueand only internal tasks render (created by the agent service / etc.).sidebar-storage.Created with PostHog Code