Repository navigation
Description
Context
The Tasks screen must "show which tasks are assigned to which user(s)" and offer a filter for "my" tasks, all tasks, or tasks assigned to specific selected users. The projection and the store landed in the previous two tasks; this task exposes them through GET /api/tasks so the Web UI, the CLI and MCP can all read and filter on assignment.
getTasksFromDb in packages/api/routes/taskHelpers.ts already has the shape this needs: a TaskQuery with repository, status, search and review filters, a selection phase that works at either run or task granularity, and an enrichTaskPage step that attaches presentation data to exactly the page being returned. Assignees belong in that enrichment step, and the assignee filter belongs beside the existing status and repository selection.
Two details matter for correctness. First, me must be resolved from the authenticated session server-side; a client must not be able to read another user's queue by editing the query string. Second, the filter must participate in the existing selection phase rather than filtering the page after the fact, or total and the page boundary would disagree with what is shown - the same mistake the attention filter comment in taskHelpers.ts already warns about.
Requirements
- Extend
TaskQuerywithassignee?: TaskAssignmentFilterand anactingUserIdused to resolve themescope. - Apply the filter during selection, for both run paging and
groupByTaskpaging, sototal, the page and the footer count agree. - Support
all,me,unassignedand an explicit login list; resolve logins to stable ids before querying. - Attach
assignees: AttributedUser[]to every task in the returned page through the existingenrichTaskPagebatch step, with one query for the page. - Validate the
assigneequery parameter intaskRoutes.getTasksusing the shared parser, answering 400 on malformed input, and return 400 whenmeis requested without an authenticated user. - Delete
task_assigneesrows intaskRoutes.deleteTask, inside the existing transaction. - Expose
GET /api/tasks?assignee=...through the existing route entry; no new route is needed. - Add a
syncAssigneesopt-in that refreshes a single task's assignment from GitHub when the detail route asks for it (used by the next task), but never on the list path. - Tests in
packages/api/test/covering each scope, themeauthorisation rule, filter/count agreement undergroupByTask, and malformed input.
Implementation Specification
Files modified
packages/api/routes/taskHelpers.ts- selection filter plus enrichment.packages/api/routes/taskRoutes.ts- query validation,meresolution, delete cleanup.packages/api/routes/taskGrouping.ts- carry the assignee predicate into task-level selection.packages/api/test/taskAssigneeFilter.test.ts(new file).
Step-by-step
- In
taskHelpers.ts, add the filter to theSelectionFiltersinterface, resolve it into a task id set viataskIdsAssignedTo, and apply it in bothapplyRunSelectionandtaskSelection, exactly asattentionTaskIdsalready is. - For
unassigned, use awhereNotExistssubquery rather than a NOT IN list, so the predicate stays indexed and bounded regardless of how many tasks have assignees. - In
enrichTaskPage, callloadTaskAssignees(taskIds)alongside the existing batch reads and merge the result ingetTasksFromDb. - In
taskRoutes.getTasks, parseassigneewithparseTaskAssignmentFilter, rejectnullwith 400, and rejectmewithoutreq.userwith 400. - In
taskRoutes.deleteTask, addawait trx('task_assignees').where({ task_id: taskId }).delete();inside the existing transaction. - Add the test file.
Acceptance Criteria
npm run typecheck,npm run lintand the API tests pass.GET /api/taskswithoutassigneebehaves exactly as before, includingtotal,offset,limitandtotalRuns.- Every returned task carries an
assigneesarray, empty when the task has no assignees. assignee=mereturns only tasks assigned to the authenticated user's GitHub id, and returns 400 when there is no authenticated user.assignee=octocat,hubotreturns the union of their tasks; an unknown login yields an empty page rather than an error.assignee=unassignedreturns only tasks with notask_assigneesrows.assignee=not+a+loginreturns 400 with a clear message.- With
groupBy=task,totalcounts tasks matching the assignee filter and the page contains all runs of those tasks;totalRunscounts their runs. - The assignee filter composes with
repository,status,search,forReviewandexcludeMerged. - Assignee enrichment issues one query per page, not one per task, and never calls GitHub.
- Deleting a task removes its
task_assigneesrows.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 8, 2026
Suggested Implementation:
Implementation Approach
The filter has to live in
getTasksFromDb's selection phase, not in a post-filter over the returned page.taskHelpers.tsalready documents why, in the comment aboveATTENTION_STATUS: a filter applied after paging makes the count that opens a view disagree with the list it opens. The same trap applies here, and it is worse undergroupByTask, where a page is whole tasks with all their runs.Two shapes were considered for resolving the filter into SQL:
task_assigneesinto the base query. Rejected: withgroupByTaskthe base query is already carrying a correlated latest-history join, and a second join multiplies rows per assignee, which would corrupt bothtotaland the run count. Every existing filter in this file either constrains a column or useswhereExists.t.task_id. Chosen formeand explicit logins: it is exactly the patternattentionTaskIdsalready uses, it keeps the base query's row shape untouched, and the id set is bounded by the indexedtask_assignees.github_user_idlookup.unassignedis the exception: an id set would mean "every task that is not in this set", which inverts into an unbounded list. It useswhereNotExistsinstead, which stays indexed and does not grow with the table.meis resolved fromreq.useron the server. Accepting a client-supplied id would turn the filter into a way to read another user's queue, so the wire format only ever carries the literal stringme.Enrichment goes through the existing
enrichTaskPagebatch step rather than per row, and usesloadTaskAssignees(cache-only) rather thanresolveTaskAssignees. A list render must never make a GitHub call; that was the whole reason for the profile cache in the first task.File:
packages/api/routes/taskHelpers.tsWhy this file: this is where task selection and page enrichment already live, so both halves of the feature belong here. Putting the filter anywhere else would reintroduce the count/page disagreement the file already guards against.
Extend the selection filters so the assignee predicate travels with the others:
@@ interface SelectionFilters { attentionTaskIds: string[] | null; /** The latest states the status filter asks for. */ states: string[] | null; reviewStates: string[] | null; search: string; + /** + * Task ids the assignment filter admits, or null when it does not constrain + * tasks. Resolved up front for the same reason attentionTaskIds is: it keeps + * the base query's row shape untouched, where a join to task_assignees would + * multiply rows per assignee and corrupt both total and the run count. + */ + assignedTaskIds: string[] | null; + /** `unassigned` is a NOT EXISTS, not an inverted id list, so it stays bounded. */ + requireUnassigned: boolean; }/** Without grouping, each filter picks runs. */ function applyRunSelection(db: Knex, query: Knex.QueryBuilder, filters: SelectionFilters): void { if (filters.attentionTaskIds) query.whereIn('t.task_id', filters.attentionTaskIds); + if (filters.assignedTaskIds) query.whereIn('t.task_id', filters.assignedTaskIds); + if (filters.requireUnassigned) { + // NOT EXISTS rather than NOT IN: the set of assigned tasks grows without + // bound as the instance is used, and an inverted list would grow with it. + query.whereNotExists( + db('task_assignees as unassigned_check').select(db.raw('1')).whereRaw('unassigned_check.task_id = t.task_id'), + ); + } if (filters.states) query.whereIn('h.state', filters.states);function taskSelection({ attentionTaskIds, states, reviewStates, search }: SelectionFilters): TaskSelection { +function taskSelection({ attentionTaskIds, states, reviewStates, search, assignedTaskIds, requireUnassigned }: SelectionFilters): TaskSelection { return { ...(states || reviewStates ? { newestRunState: (state: string) => (!states || states.includes(state)) && (!reviewStates || reviewStates.includes(state)), } : {}), ...(attentionTaskIds ? { anyRunIn: new Set(attentionTaskIds) } : {}), + // Assignment belongs to the GitHub subject, which is shared by every run + // of a task, so any run matching means the whole task matches. + ...(assignedTaskIds ? { anyRunIn: new Set(assignedTaskIds) } : {}), + ...(requireUnassigned ? { requireUnassigned: true } : {}), ...(search ? { search } : {}), }; }Resolve the filter before selection, and short-circuit an empty result the way the attention filter does:
@@ in getTasksFromDb, after the attention resolution const filters: SelectionFilters = { attentionTaskIds, states: attentionTaskIds || !status || status === 'all' ? null : resolveStatusStates(status) ?? [status], reviewStates: forReview ? ['completed', 'failed'] : null, search: search?.trim() || '', + ...await resolveAssigneeSelection(query), }; + // An explicit assignee filter that matches nothing returns an empty page + // directly, so the count and the page agree without running the join. + if (filters.assignedTaskIds?.length === 0) { + return { tasks: [], total: 0, offset, limit, ...(groupByTask ? { totalRuns: 0 } : {}) }; + }Attach assignees in the existing batch enrichment, so the cost is one query per page:
interface TaskPageEnrichment { historyByTask: Map<string, Record<string, unknown>>; planStatusByTask: Map<string, unknown>; commentMetadataByTask: Map<string, unknown>; scoreByTask: Map<string, number>; + /** Empty for a task with no assignees, so the projection can always spread it. */ + assigneesByTask: Map<string, AttributedUser[]>; } @@ in enrichTaskPage const scoreByTask = await loadRunScores(db, taskIds); + // Cache-only read: a list render must never make a GitHub call, which is + // the reason the profile cache exists at all. + const assigneesByTask = await loadTaskAssignees(taskIds); - return { historyByTask, planStatusByTask, commentMetadataByTask, scoreByTask }; + return { historyByTask, planStatusByTask, commentMetadataByTask, scoreByTask, assigneesByTask }; }@@ in getTasksFromDb, building the response rows const tasks = pageTasks.map((row: Record<string, unknown>, index: number) => ({ ...mapDbTaskToResponse({ ...row, ...historyByTask.get(String(row.task_id)), plan_issue_status: planStatusByTask.get(String(row.task_id)) ?? null, }), score: scoreByTask.get(String(row.task_id)) ?? null, + // Always present, so the UI never has to distinguish "no assignees" from + // "assignees not loaded". + assignees: assigneesByTask.get(String(row.task_id)) ?? [], ...(media[index].previews.length ? { previewMedia: media[index].previews } : {}), }));File:
packages/api/routes/taskGrouping.tsWhy this file: task-level selection is evaluated here, so the
unassignedpredicate has to be understood here too. Without it,groupBy=taskwould silently ignore the filter and return a page that disagrees with its own count.In the task-level narrowing query, add the same
whereNotExiststhe run path uses, so both granularities agree:@@ if (selection.anyRunIn) query.whereIn('t.task_id', [...selection.anyRunIn]); + if (selection.requireUnassigned) { + query.whereNotExists( + db('task_assignees as unassigned_check').select(db.raw('1')).whereRaw('unassigned_check.task_id = t.task_id'), + ); + }File:
packages/api/routes/taskRoutes.tsWhy this file: this is the HTTP boundary that validates query parameters and holds the session identity, so it is the only place that can safely turn the literal
meinto a user id. It is also wheredeleteTaskenumerates the dependent tables, so the new table must be added there.@@ in deleteTask's transaction await db.transaction(async (trx) => { await trx('llm_execution_details') .whereIn('execution_id', function() { this.select('execution_id').from('llm_executions').where({ task_id: taskId }); }) .delete(); await trx('llm_executions').where({ task_id: taskId }).delete(); + // Deleted explicitly, like every other dependent table here: the + // projection has no foreign key, so nothing removes these rows for us. + await trx('task_assignees').where({ task_id: taskId }).delete(); await trx('task_history').where({ task_id: taskId }).delete(); await trx('tasks').where({ task_id: taskId }).delete(); });File:
packages/api/test/taskAssigneeFilter.test.ts(new file)Why this file: the risk in this task is not the happy path, it is the filter/count agreement under
groupByTaskand themeauthorisation rule. Both are invisible in a single-task fixture, so the tests seed several tasks with several runs and asserttotalagainst the page contents.propr-dev commentedon Oct 9, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52890/claude-opus-5-5-project-assignees-onto-th-20261009-0042-9j92888-epic-task-assignment-1m4issue-2890-20261009-0042-claude-opus-5-5-9j9🔍 Track Task Execution