Missing Aggregate Update (TaskFlow PR #8)
Tier 2 easy typescript · local · real merged PR from mikecann/cya-playground #20
Ground-truth defects
The new `duplicate` mutation inserts into the `tasks` table but, unlike `create` and `remove`, fails to update the `taskCounts` aggregate, leaving the per-project task count out of sync.
The change under review
diff
@@ -137,6 +137,48 @@ export const create = mutation({ }, }); +export const duplicate = mutation({ + args: { taskId: v.id("tasks") }, + handler: async (ctx, args) => { + const userId = await getAuthUserId(ctx); + if (!userId) throw new Error("Not authenticated"); + + const task = await ctx.db.get("tasks", args.taskId); + if (!task) throw new Error("Task not found"); + + const membership = await ctx.db + .query("projectMembers") + .withIndex("by_projectId_and_userId", (q) => + q.eq("projectId", task.projectId).eq("userId", userId), + ) + .unique(); + if (!membership) throw new Error("Not a member of this project"); + if (membership.role === "viewer") { + throw new Error("Viewers cannot create tasks"); + } + + const newTaskId = await ctx.db.insert("tasks", { + title: `${task.title} (copy)`, + description: task.description, + status: task.status, + priority: task.priority, + projectId: task.projectId, + assigneeId: task.assigneeId, + dueDate: task.dueDate, + }); + + await ctx.runMutation(internal.activity.log, { + action: "duplicated_task", + userId, + projectId: task.projectId, + entityType: "task", + entityId: newTaskId, + }); + + return newTaskId; + }, +}); + export const update = mutation({ args: { taskId: v.id("tasks"), @@ -33,6 +33,7 @@ export function TaskDetail({ const addComment = useMutation(api.comments.create); const deleteComment = useMutation(api.comments.remove); const deleteTask = useMutation(api.tasks.remove); + const duplicateTask = useMutation(api.tasks.duplicate); const { addToast } = useToast(); const [commentText, setCommentText] = useState(""); @@ -189,6 +190,16 @@ export function TaskDetail({ Edit </button> )} + <button + onClick={() => { + duplicateTask({ taskId }) + .then(() => addToast("Task duplicated")) + .catch((err: Error) => addToast(err.message)); + }} + className="px-3 py-1 rounded bg-slate-100 dark:bg-slate-700 hover:bg-slate-200 dark:hover:bg-slate-600 text-sm transition-colors" + > + Duplicate + </button> <button onClick={() => { if (confirm("Delete this task?")) {
Leaderboard for this case
easy · 9 of 9 bots fully caught it (100% solve rate) · 100% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Claude Code (Opus 5.5) | solved | 1/1 | 100.0% | 1 | 0 |
| 2 | Cubic | solved | 1/1 | 100.0% | 1 | 0 |
| 3 | cursor | solved | 1/1 | 100.0% | 1 | 0 |
| 4 | Drape (Deep Review) | solved | 1/1 | 100.0% | 2 | 0 |
| 5 | Drape (Review) | solved | 1/1 | 100.0% | 2 | 0 |
| 6 | greptile | solved | 1/1 | 100.0% | 2 | 0 |
| 7 | Mjolnir (Opus 5.5) | solved | 1/1 | 100.0% | 2 | 0 |
| 8 | Mjolnir (Sonnet 5.5) | solved | 1/1 | 100.0% | 2 | 0 |
| 9 | qodo | solved | 1/1 | 100.0% | 1 | 0 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
raw comments (1)
`duplicate` adds the new task with `ctx.db.insert` but never calls `taskCounts.insert`. `create` does call it (line 126). There are two consequences. First, the project's task count from `taskCounts.getForProject`, shown on the Dashboard, doesn't include duplicated tasks. Second, `remove` calls `taskCounts.delete(ctx, task)` (line 260), and the aggregate component's `delete` throws when the key isn't in the aggregate. So deleting a duplicated task fails and its mutation rolls back, which leaves the task impossible to delete until someone runs a backfill. Fix: after the insert, fetch the new doc and call `await taskCounts.insert(ctx, newTask!)`, the same way `create` does.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | off by one |
raw comments (2)
<!-- cubic:v=f7cdf2cc-8f12-4cd4-a93a-e552316cf8fd -->
<!-- cubic:review-run=fe0195ab-41ea-5d17-98a2-adb205cb117e -->
<!-- metadata:{"confidence":10} -->
P2: Every duplicate inserts a task without registering it with `taskCounts`, so the project dashboard continues showing the pre-duplication task count. Load the inserted task and call `taskCounts.insert` immediately after the insert, as `create` does.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At convex/tasks.ts, line 160:
<comment>Every duplicate inserts a task without registering it with `taskCounts`, so the project dashboard continues showing the pre-duplication task count. Load the inserted task and call `taskCounts.insert` immediately after the insert, as `create` does.</comment>
<file context>
@@ -137,6 +137,48 @@ export const create = mutation({
+ throw new Error("Viewers cannot create tasks");
+ }
+
+ const newTaskId = await ctx.db.insert("tasks", {
+ title: `${task.title} (copy)`,
+ description: task.description,
</file context>
```
</details>
```suggestion
const newTaskId = await ctx.db.insert("tasks", {
title: `${task.title} (copy)`,
description: task.description,
status: task.status,
priority: task.priority,
projectId: task.projectId,
assigneeId: task.assigneeId,
dueDate: task.dueDate,
});
const newTask = await ctx.db.get("tasks", newTaskId);
await taskCounts.insert(ctx, newTask!);
```
<!-- cubic:review-summary:start -->
**1 issue found** across 2 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="convex/tasks.ts">
<violation number="1" location="convex/tasks.ts:160">
P2: Every duplicate inserts a task without registering it with `taskCounts`, so the project dashboard continues showing the pre-duplication task count. Load the inserted task and call `taskCounts.insert` immediately after the insert, as `create` does.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/98/ai_pr_review_github_delivery_8f68b0b5179a4fcfc82d415fad7ceeab8e519f69b05f6e1e8648b0e676e531ce?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F98)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_8f68b0b5179a4fcfc82d415fad7ceeab8e519f69b05f6e1e8648b0e676e531ce:50090a6559499dba58ce4eb805d34f9c6e721076:fe0195ab-41ea-5d17-98a2-adb205cb117e -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
raw comments (2)
### Duplicate skips task count update
**High Severity**
<!-- DESCRIPTION START -->
The `duplicate` mutation inserts a new task but never calls `taskCounts.insert`, unlike `create`. Project counts on the dashboard will be understated, and deleting a duplicated task will fail because `taskCounts.delete` throws when the document is missing from the aggregate.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 1f059022-9e02-4428-8354-40769c824d1a -->
<!-- LOCATIONS START
convex/tasks.ts#L159-L168
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjA1ZTQ3ZGU5LTNhNzAtNGQ5ZC1iNTQxLThiNjVlZDBhNzk4YyIsImVuY3J5cHRpb25LZXkiOiJJX2pvUGtrbWVTc2twdFNLOE9NU0x0VGw3QlN4dWRneDFuR1lkaFhPeTUwIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDgtbWlzc2luZy1hZ2dyZWdhdGUtdXBkYXRlIiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjA1ZTQ3ZGU5LTNhNzAtNGQ5ZC1iNTQxLThiNjVlZDBhNzk4YyIsImVuY3J5cHRpb25LZXkiOiJJX2pvUGtrbWVTc2twdFNLOE9NU0x0VGw3QlN4dWRneDFuR1lkaFhPeTUwIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDgtbWlzc2luZy1hZ2dyZWdhdGUtdXBkYXRlIiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6ODgsImNvbW1pdFNoYSI6IjE3MTJlM2U2MWYxMTgwMjZkZTg4OWQxMTMxMWU2ZTNkY2FkNzMzMzIiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1712e3e61f118026de889d11311e6e3dcad73332. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo3N2RmZDIyYi00ZGFiLTQwNTktYjQ2Ny01NmY3MzU3M2NlM2IiLCJlbmNyeXB0aW9uS2V5Ijoia0xwWUxod1FQak5TazBNWkw4WkxWYzFqcGFEdEdMQUNFSzhVWUQwTWIyWSIsImJyYW5jaCI6InQyLXRhc2tmbG93LTA4LW1pc3NpbmctYWdncmVnYXRlLXVwZGF0ZSIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1712e3e61f118026de889d11311e6e3dcad73332. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
The new duplicate mutation only inserts a tasks row and never queries or copies taskLabels via the by_taskId index, so the duplicated task has no labels. Whether that's a bug depends on what 'duplicate' is meant to mean, so it's real but low impact. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
**Duplicated tasks missing from aggregate; deleting them fails**
Unlike `create`, `duplicate` never calls `taskCounts.insert`. The dashboard count is too low, and `remove` later throws in `taskCounts.delete` because the aggregate never saw the copy. After the insert, load the new task and call `taskCounts.insert(ctx, newTask)`.
```
convex/tasks.ts:160 const newTaskId = await ctx.db.insert("tasks", {
convex/tasks.ts:161 title: `${task.title} (copy)`,
convex/tasks.ts:162 description: task.description,
convex/tasks.ts:163 status: task.status,
convex/tasks.ts:125 const newTask = await ctx.db.get("tasks", taskId);
convex/tasks.ts:126 await taskCounts.insert(ctx, newTask!);
convex/tasks.ts:260 await taskCounts.delete(ctx, task);
convex/taskCounts.ts:9 export const taskCounts = new TableAggregate<{
convex/taskCounts.ts:10 Namespace: Id<"projects">;
convex/taskCounts.ts:11 Key: null;
```
**Duplicate drops the task's labels**
`duplicate` copies the task's fields but not its `taskLabels` rows, so the copy has no labels even though the original has some. Copy the original's taskLabels rows (by_taskId index) onto the new task id, unless dropping labels is intended.
```
convex/tasks.ts:160 const newTaskId = await ctx.db.insert("tasks", {
convex/tasks.ts:161 title: `${task.title} (copy)`,
convex/tasks.ts:162 description: task.description,
convex/tasks.ts:163 status: task.status,
convex/schema.ts:81 taskLabels: defineTable({
convex/schema.ts:82 taskId: v.id("tasks"),
convex/schema.ts:83 labelId: v.id("labels"),
convex/schema.ts:84 })
convex/schema.ts:85 .index("by_taskId", ["taskId"])
convex/schema.ts:86 .index("by_labelId", ["labelId"])
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
The new Duplicate button has no role check, but the server's duplicate mutation throws 'Viewers cannot create tasks' for viewers, so viewers always get an error toast. The Edit and Delete buttons already behave the same way, which keeps the impact low, but this change added the new button. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
**Duplicated tasks missing from project task count**
`duplicate` inserts the new task but never calls `taskCounts.insert`, unlike `create`. The aggregate stays out of sync, and `remove` later calls `taskCounts.delete` on a doc that was never inserted. After the insert, fetch the new task and call `taskCounts.insert(ctx, newTask!)` as `create` does.
```
convex/tasks.ts:160 const newTaskId = await ctx.db.insert("tasks", {
convex/tasks.ts:161 title: `${task.title} (copy)`,
convex/tasks.ts:162 description: task.description,
convex/tasks.ts:163 status: task.status,
convex/tasks.ts:125 const newTask = await ctx.db.get("tasks", taskId);
convex/tasks.ts:126 await taskCounts.insert(ctx, newTask!);
convex/tasks.ts:260 await taskCounts.delete(ctx, task);
```
**Duplicate button shown to viewers**
The Duplicate button renders for every member, including viewers, though the server rejects them with 'Viewers cannot create tasks'. Viewers see a button that only ever fails with an error toast. Hide or disable the button when the current member's role is viewer.
```
src/components/TaskDetail.tsx:193 <button
src/components/TaskDetail.tsx:194 onClick={() => {
src/components/TaskDetail.tsx:195 duplicateTask({ taskId })
src/components/TaskDetail.tsx:196 .then(() => addToast("Task duplicated"))
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
The new Duplicate button is always rendered, with no role check, and the new mutation throws "Viewers cannot create tasks" for viewers. So a viewer who clicks it only gets an error toast. This is a minor UX issue, not a security hole: the backend enforces the rule, and the existing Edit and Delete buttons are also shown to viewers. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Duplicate skips task count**
When a task is duplicated, this code inserts the new task but does not register it with `taskCounts` as the normal creation path does. The dashboard reads that aggregate, so its displayed project count remains one below the actual task total for every duplication until a backfill occurs.
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Viewers see unusable action**
This button is shown to viewers even though the duplication mutation always rejects their role. A viewer can therefore click Duplicate only to receive an authorization error toast, unlike the existing New Task action that is hidden for viewers. Pass the available project role into this component and hide or disable Duplicate for viewers.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
<h3>Greptile Summary</h3>
Adds task duplication through a new authenticated Convex mutation and exposes it from the task-detail interface.
- Copies the source task into the same project and records a duplication activity.
- Restricts the backend operation to project members above the viewer role.
- Omits synchronization of the per-project task-count aggregate.
- Exposes the action to viewers despite the backend restriction.
<h3>Confidence Score: 4/5</h3>
The PR should not merge until duplicated tasks are registered with the per-project count aggregate; the viewer-facing action should also be gated by role.
The new mutation successfully creates task rows but bypasses the explicit aggregate update used by normal creation, causing persistent undercounting in the dashboard. The new button also exposes an operation to viewers that the backend always rejects.
**Files Needing Attention:** convex/tasks.ts, src/components/TaskDetail.tsx
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| convex/tasks.ts | Adds the duplication mutation, but its direct insert does not update the task-count aggregate maintained by the normal creation path. |
| src/components/TaskDetail.tsx | Adds a Duplicate button that invokes the mutation, but renders it for viewers who cannot successfully use it. |
</details>
<details open><summary><h3>Sequence Diagram</h3></summary>
```mermaid
sequenceDiagram
actor User
participant UI as TaskDetail
participant Mutation as tasks.duplicate
participant DB as tasks table
participant Counts as taskCounts aggregate
User->>UI: Click Duplicate
UI->>Mutation: "duplicate({ taskId })"
Mutation->>Mutation: Authenticate and authorize
Mutation->>DB: Insert copied task
Note over Mutation,Counts: Missing taskCounts.insert(newTask)
Mutation-->>UI: Return new task ID
UI-->>User: "Task duplicated"
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update convex/tasks.ts and 1 more files"](https://github.com/drape-io/crbench-greptile-2026-09/commit/43dcf58b2cb97b1450723fae4e226683212d76f7) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284935)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
`create` calls `taskCounts.insert(ctx, newTask!)` after it inserts, but the new `duplicate` mutation inserts the row without updating the aggregate. Duplicated tasks are therefore missing from the counts. Later, `remove` calls `taskCounts.delete(ctx, task)` on them, and `@convex-dev/aggregate`'s `delete` throws when the key is missing, which rolls the mutation back. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P1] Duplicated tasks are never added to the `taskCounts` aggregate
`create` follows its `ctx.db.insert` with `taskCounts.insert(ctx, newTask)`, but `duplicate` inserts the task and never touches the aggregate. Every duplicated task is therefore missing from `taskCounts.getForProject`, so the Dashboard task count comes out too low. The damage carries over to `remove` too: it calls `taskCounts.delete(ctx, task)` before deleting the document, and the aggregate's `delete` throws when the key is missing. That means a duplicated task can't be deleted until someone runs the backfill. The fix is to fetch the new document and call `taskCounts.insert` after the insert, the same way `create` does.
[P1] Duplicated task isn't added to the `taskCounts` aggregate
`duplicate` inserts a new task row but never calls `taskCounts.insert(ctx, newTask)`, unlike `create`, which does so right after its `ctx.db.insert` (convex/tasks.ts:125-126). Every duplicated task is therefore missing from the per-project count that `taskCounts.getForProject` returns, so the displayed task count is too low by one for each duplicate. It also causes a failure: `remove` calls `taskCounts.delete(ctx, task)` (convex/tasks.ts:260), and in `@convex-dev/aggregate` `delete` throws when the document isn't in the aggregate. That makes the whole mutation roll back, so a duplicated task can't be deleted from the UI until someone runs the backfill by hand. To fix it, fetch the new doc after the insert and call `taskCounts.insert`, the same way `create` does.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
`create` calls `taskCounts.insert(ctx, newTask!)` after inserting, but the new `duplicate` mutation inserts and never registers the doc with the aggregate. That makes the counts drift. Also, `remove` later calls `taskCounts.delete(ctx, task)` on a doc the aggregate never registered, which can throw. One detail in the finding is off: `update` does not call `replace`. The core failure still stands. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P1] Duplicated tasks are not added to the project task-count aggregate
The new `duplicate` mutation inserts a task row but never calls `taskCounts.insert(ctx, ...)`, which `create` does right after its insert. The `taskCounts` aggregate is the source for `taskCounts.getForProject`, so every duplicated task is missing from the project's count. The count drifts below the real number of tasks. A later `remove` presumably deletes the entry from the aggregate. That could fail or skew the count for a task that was never inserted. Fix: after the insert, fetch the new doc and call `taskCounts.insert(ctx, newTask!)
[P1] Duplicate task skips the taskCounts aggregate insert
`duplicate` inserts a task directly with `ctx.db.insert` but never calls `taskCounts.insert(ctx, ...)`, which `create` does right after its insert. The aggregate that backs per-project task counts is therefore never told about duplicated tasks. Any time a user duplicates a task, the count stays too low and drifts further out of sync with the real tasks table. If the copy is later updated or deleted and `update`/`remove` call `taskCounts.replace` or `taskCounts.delete` on it, those calls can throw or corrupt the aggregate because the document was never registered. Fix: fetch the inserted doc and call `taskCounts.insert(ctx, newTask!)` as `create` does.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
raw comments (2)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Project task totals undercount copies <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>duplicate</i></b> inserts a task document but does not add the inserted document to <b><i>taskCounts</i></b>, unlike
the established <b><i>create</i></b> path. Whenever a task is duplicated, the aggregate-backed dashboard total
remains one below the project's actual task count, with repeated duplications compounding the
discrepancy.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The duplicate mutation inserts a new task without registering it in the explicit `taskCounts` aggregate, leaving project totals stale.
## Fix Focus Areas
- convex/tasks.ts[160-176]
## Recommended Fix
After inserting the duplicate, load the new task document and call `taskCounts.insert(ctx, newTask)` before logging the activity and returning, matching the existing task creation path.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Project task totals undercount copies <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>duplicate</i></b> inserts a task document but does not add the inserted document to <b><i>taskCounts</i></b>, unlike
>the established <b><i>create</i></b> path. Whenever a task is duplicated, the aggregate-backed dashboard total
>remains one below the project's actual task count, with repeated duplications compounding the
>discrepancy.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[convex/tasks.ts[R160-163]](https://github.com/drape-io/crbench-qodo-2026-09/pull/86/files#diff-5e33afee3b933bec3e497e1894110d799ededad92ca67ee58aafbe37d8a44098R160-R163)</code>
>
>```diff
>+ const newTaskId = await ctx.db.insert("tasks", {
>+ title: `${task.title} (copy)`,
>+ description: task.description,
>+ status: task.status,
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>Normal creation explicitly reloads each inserted task and registers it with the aggregate, while the
>new duplicate path only inserts and logs it. The aggregate is keyed by project and directly supplies
>the count displayed on dashboard project cards, so omitted duplicates cannot appear in that total.
></pre>
>
> <code>[convex/tasks.ts[115-126]](https://github.com/drape-io/crbench-qodo-2026-09/blob/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5/convex/tasks.ts/#L115-L126)</code>
> <code>[convex/tasks.ts[160-178]](https://github.com/drape-io/crbench-qodo-2026-09/blob/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5/convex/tasks.ts/#L160-L178)</code>
> <code>[convex/taskCounts.ts[9-17]](https://github.com/drape-io/crbench-qodo-2026-09/blob/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5/convex/taskCounts.ts/#L9-L17)</code>
> <code>[convex/taskCounts.ts[19-34]](https://github.com/drape-io/crbench-qodo-2026-09/blob/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5/convex/taskCounts.ts/#L19-L34)</code>
> <code>[src/components/Dashboard.tsx[14-16]](https://github.com/drape-io/crbench-qodo-2026-09/blob/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5/src/components/Dashboard.tsx/#L14-L16)</code>
> <code>[src/components/Dashboard.tsx[31-34]](https://github.com/drape-io/crbench-qodo-2026-09/blob/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5/src/components/Dashboard.tsx/#L31-L34)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The duplicate mutation inserts a new task without registering it in the explicit `taskCounts` aggregate, leaving project totals stale.
>
>## Fix Focus Areas
>- convex/tasks.ts[160-176]
>
>## Recommended Fix
>After inserting the duplicate, load the new task document and call `taskCounts.insert(ctx, newTask)` before logging the activity and returning, matching the existing task creation path.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>⚖️ Balanced</code>: This adds authenticated task-duplication mutation logic with project authorization, data copying, activity logging, and a UI action, so it carries meaningful behavioral and permission risks despite being localized.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/07faf7ffcbe5adf737bd8c5a8f57648bb40e08f5 -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>