.collect() Just to Count (TaskFlow PR #6)
Tier 2 easy typescript · local · real merged PR from mikecann/cya-playground #17
Ground-truth defects
getProjectActivityCount loads every activityLog document via unbounded .collect() solely to return .length, wasting memory/performance when only a count is needed.
The change under review
diff
new file mode 100644 @@ -0,0 +1,26 @@ +import { query } from "./_generated/server"; +import { v } from "convex/values"; +import { getAuthUserId } from "@convex-dev/auth/server"; + +export const getProjectActivityCount = query({ + args: { projectId: v.id("projects") }, + handler: async (ctx, args) => { + const userId = await getAuthUserId(ctx); + if (!userId) return null; + + const membership = await ctx.db + .query("projectMembers") + .withIndex("by_projectId_and_userId", (q) => + q.eq("projectId", args.projectId).eq("userId", userId), + ) + .unique(); + if (!membership) return null; + + const allActivity = await ctx.db + .query("activityLog") + .withIndex("by_projectId", (q) => q.eq("projectId", args.projectId)) + .collect(); + + return { totalEvents: allActivity.length }; + }, +}); @@ -29,6 +29,9 @@ export function ProjectView({ const project = useQuery(api.projects.get, { projectId }); const tasks = useQuery(api.tasks.listByProject, { projectId }); const members = useQuery(api.members.listByProject, { projectId }); + const activityCount = useQuery(api.metrics.getProjectActivityCount, { + projectId, + }); const createTask = useMutation(api.tasks.create); const updateTask = useMutation(api.tasks.update); const { addToast } = useToast(); @@ -75,6 +78,11 @@ export function ProjectView({ <p className="text-sm text-slate-500 dark:text-slate-400"> {project.description} </p> + {activityCount && ( + <p className="text-xs text-slate-400 dark:text-slate-500"> + {activityCount.totalEvents} activity events + </p> + )} </div> </div> <div className="flex gap-2">
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% | 3 | 0 |
| 3 | cursor | solved | 1/1 | 100.0% | 1 | 0 |
| 4 | Drape (Deep Review) | solved | 1/1 | 100.0% | 1 | 0 |
| 5 | Drape (Review) | solved | 1/1 | 100.0% | 1 | 0 |
| 6 | greptile | solved | 1/1 | 100.0% | 1 | 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% | 2 | 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 | medium | ✓ | exact |
raw comments (1)
`getProjectActivityCount` loads every activityLog document for the project with `.collect()` just to read `.length`. activityLog only grows: every task create, update and comment adds a row, and nothing deletes them. This is a reactive query subscribed from ProjectView, so it re-reads the whole log every time any activity is logged, for every viewer of the project. Cost grows without bound, and on busy projects the query will eventually hit Convex's per-query document/byte read limits and throw, which breaks the ProjectView header. Elsewhere the code bounds reads (activity.listByProject uses `.take(50)`). Keep a denormalized counter on the project, use an aggregate/sharded counter, or cap the read (e.g. take(1000) and show '1000+').
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
The label is hardcoded as plural, so when totalEvents is 1 it shows "1 activity events". This is a real but cosmetic display bug added by this change. [grounded: diff] [consensus 5/5: valid=5]
This asks for the duplicated membership check to be moved into a shared helper. The finding does not claim the current code misbehaves, only that a future change could miss a copy, so it is a maintainability preference. [grounded: diff] [consensus 5/5: minor=5]
raw comments (4)
<!-- cubic:v=2c787427-9080-45ba-bebf-21fa0276fab8 -->
<!-- cubic:review-run=c888f271-ac1b-573d-9cd7-33ff0190d882 -->
<!-- metadata:{"confidence":8} -->
P2: `.collect()` reads the project's entire activityLog on every execution. Because activityLog grows without bound and Convex re-runs a query whenever any document it read changes, each new event makes the client re-read the whole log; once a busy project's log exceeds Convex's per-execution read limit the query throws, and `useQuery` re-throws that error in ProjectView, taking down the project view rather than just the count. Every other reader in convex/ caps its read (activity.ts `.take(50)`, tasks.ts `.take(200)`, members.ts `.take(100)`), so this is the only unbounded read in the codebase. Maintain the count instead of scanning: keep a counter updated in `activity.log`, or use `@convex-dev/aggregate`/`.paginate()` and count page by page.
<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/metrics.ts, line 22:
<comment>`.collect()` reads the project's entire activityLog on every execution. Because activityLog grows without bound and Convex re-runs a query whenever any document it read changes, each new event makes the client re-read the whole log; once a busy project's log exceeds Convex's per-execution read limit the query throws, and `useQuery` re-throws that error in ProjectView, taking down the project view rather than just the count. Every other reader in convex/ caps its read (activity.ts `.take(50)`, tasks.ts `.take(200)`, members.ts `.take(100)`), so this is the only unbounded read in the codebase. Maintain the count instead of scanning: keep a counter updated in `activity.log`, or use `@convex-dev/aggregate`/`.paginate()` and count page by page.</comment>
<file context>
@@ -0,0 +1,26 @@
+ const allActivity = await ctx.db
+ .query("activityLog")
+ .withIndex("by_projectId", (q) => q.eq("projectId", args.projectId))
+ .collect();
+
+ return { totalEvents: allActivity.length };
</file context>
```
</details>
<!-- cubic:v=744b22e6-94b9-40c0-86c1-a86434d9e2a2 -->
<!-- cubic:review-run=c888f271-ac1b-573d-9cd7-33ff0190d882 -->
<!-- metadata:{"confidence":9} -->
P3: The text always renders "{totalEvents} activity events", so a single event incorrectly shows as "1 activity events". Pluralize the label based on the count.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At src/components/ProjectView.tsx, line 83:
<comment>The text always renders "{totalEvents} activity events", so a single event incorrectly shows as "1 activity events". Pluralize the label based on the count.</comment>
<file context>
@@ -75,6 +78,11 @@ export function ProjectView({
</p>
+ {activityCount && (
+ <p className="text-xs text-slate-400 dark:text-slate-500">
+ {activityCount.totalEvents} activity events
+ </p>
+ )}
</file context>
```
</details>
<!-- cubic:v=6966aa30-66ea-4040-a493-4f082801c3dc -->
<!-- cubic:review-run=c888f271-ac1b-573d-9cd7-33ff0190d882 -->
<!-- metadata:{"confidence":7} -->
P3: This membership check is now the fourth copy of the same authorization gate (convex/members.ts:11-20, convex/activity.ts:8-17, convex/projects.ts:28-41). A future change to who may read project data — an archived-project check, for example — has to be made in four places, and a missed copy silently exposes project data. Extract a shared helper such as `getProjectMembership(ctx, projectId)` in convex/ and call it from each query.
<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/metrics.ts, line 11:
<comment>This membership check is now the fourth copy of the same authorization gate (convex/members.ts:11-20, convex/activity.ts:8-17, convex/projects.ts:28-41). A future change to who may read project data — an archived-project check, for example — has to be made in four places, and a missed copy silently exposes project data. Extract a shared helper such as `getProjectMembership(ctx, projectId)` in convex/ and call it from each query.</comment>
<file context>
@@ -0,0 +1,26 @@
+ const userId = await getAuthUserId(ctx);
+ if (!userId) return null;
+
+ const membership = await ctx.db
+ .query("projectMembers")
+ .withIndex("by_projectId_and_userId", (q) =>
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**3 issues 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="src/components/ProjectView.tsx">
<violation number="1" location="src/components/ProjectView.tsx:83">
P3: The text always renders "{totalEvents} activity events", so a single event incorrectly shows as "1 activity events". Pluralize the label based on the count.</violation>
</file>
<file name="convex/metrics.ts">
<violation number="1" location="convex/metrics.ts:11">
P3: This membership check is now the fourth copy of the same authorization gate (convex/members.ts:11-20, convex/activity.ts:8-17, convex/projects.ts:28-41). A future change to who may read project data — an archived-project check, for example — has to be made in four places, and a missed copy silently exposes project data. Extract a shared helper such as `getProjectMembership(ctx, projectId)` in convex/ and call it from each query.</violation>
<violation number="2" location="convex/metrics.ts:22">
P2: `.collect()` reads the project's entire activityLog on every execution. Because activityLog grows without bound and Convex re-runs a query whenever any document it read changes, each new event makes the client re-read the whole log; once a busy project's log exceeds Convex's per-execution read limit the query throws, and `useQuery` re-throws that error in ProjectView, taking down the project view rather than just the count. Every other reader in convex/ caps its read (activity.ts `.take(50)`, tasks.ts `.take(200)`, members.ts `.take(100)`), so this is the only unbounded read in the codebase. Maintain the count instead of scanning: keep a counter updated in `activity.log`, or use `@convex-dev/aggregate`/`.paginate()` and count page by page.</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/84/ai_pr_review_github_delivery_7f1dcdbc3b7f5f784238cbe1e495ef12d759f442949388ce2766ea403e142de5?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F84)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_7f1dcdbc3b7f5f784238cbe1e495ef12d759f442949388ce2766ea403e142de5:fb6e870c97e906fb4aa99cb3f7161470f6e737b1:c888f271-ac1b-573d-9cd7-33ff0190d882 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
raw comments (2)
### Unbounded activity count query
**Medium Severity**
<!-- DESCRIPTION START -->
`getProjectActivityCount` uses `.collect()` to load every `activityLog` document for a project just to return the array length. Activity is appended on each task, comment, and project action and is never pruned, so this query will eventually hit Convex's document-read limit and throw. `useQuery` then surfaces that error with no error boundary, which can take down the project view.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: b86f8e75-adfa-4c88-a774-7b4688ff1446 -->
<!-- LOCATIONS START
convex/metrics.ts#L18-L24
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjI1OTUzMzk0LTlkNGItNDZhNy1hNzkyLTdmNDc5ZDE3YmZkZCIsImVuY3J5cHRpb25LZXkiOiI0QUJfVjdTSnVUR1RaZUt6ZFphQy1BZGMyMGViV0NUOUZBamY5Y2lfZjFRIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDYtY29sbGVjdC10by1jb3VudCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" 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=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjI1OTUzMzk0LTlkNGItNDZhNy1hNzkyLTdmNDc5ZDE3YmZkZCIsImVuY3J5cHRpb25LZXkiOiI0QUJfVjdTSnVUR1RaZUt6ZFphQy1BZGMyMGViV0NUOUZBamY5Y2lfZjFRIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDYtY29sbGVjdC10by1jb3VudCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjg2LCJjb21taXRTaGEiOiIxOGU1Mzc0MGU0Njc0MTBlMmVhYTI0NzJmNTA3NWFlNmExMjMyMzVjIiwicHJvdmlkZXIiOiJnaXRodWIifX0" 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 18e53740e467410e2eaa2472f5075ae6a123235c. 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=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aToyNTI2ZWQzYS1hNzQyLTQwODctOTY3Ni00MTAzMWY2NWE2NzgiLCJlbmNyeXB0aW9uS2V5IjoiMDFmVXAwN1RLdGo3ZTlsdHB4SXU0QkhibjF0aEhGcU9ZSDBaSG4wbTMwdyIsImJyYW5jaCI6InQyLXRhc2tmbG93LTA2LWNvbGxlY3QtdG8tY291bnQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" 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 18e53740e467410e2eaa2472f5075ae6a123235c. 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 | medium | ✓ | exact |
raw comments (1)
**Activity count loads every log row per view**
`getProjectActivityCount` collects all of a project's activityLog rows just to count them, and reruns on every new event. The log only grows, so large projects hit Convex read limits and the query throws. Keep a counter that `activity.log` updates, or use a bounded `take(n)`.
```
convex/metrics.ts:19 const allActivity = await ctx.db
convex/metrics.ts:20 .query("activityLog")
convex/metrics.ts:21 .withIndex("by_projectId", (q) => q.eq("projectId", args.projectId))
convex/metrics.ts:22 .collect();
convex/metrics.ts:24 return { totalEvents: allActivity.length };
convex/activity.ts:19 const entries = await ctx.db
convex/activity.ts:20 .query("activityLog")
convex/activity.ts:21 .withIndex("by_projectId", (q) => q.eq("projectId", args.projectId))
convex/activity.ts:22 .order("desc")
convex/activity.ts:23 .take(50);
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
raw comments (1)
**Counting activity loads every log row**
`getProjectActivityCount` collects the whole `activityLog` for a project just to take its length. The activity log only grows, so this reads more and more documents, and it can hit Convex read limits on busy projects. Keep a running counter updated on insert, or cap with take(n) and display 'n+'.
```
convex/metrics.ts:19 const allActivity = await ctx.db
convex/metrics.ts:20 .query("activityLog")
convex/metrics.ts:21 .withIndex("by_projectId", (q) => q.eq("projectId", args.projectId))
convex/metrics.ts:22 .collect();
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | off by one |
raw comments (2)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Unbounded Activity Log Query**
The activity log grows throughout a project's lifetime, but this live query uses `.collect()` to load the entire history just to count it. Opening an active project therefore does progressively more work, and each new activity event can trigger another full read. For projects with enough events, the metric can become slow or exceed query read limits, preventing it from loading reliably. Maintain an aggregate count or use a counting mechanism that does not load every activity document.
<h3>Greptile Summary</h3>
Adds an authenticated project activity metric and displays it in the project header.
- Verifies project membership before returning the metric.
- Subscribes ProjectView to the new aggregate.
- Currently derives the aggregate by loading the project's complete activity history, which is unsafe as that history grows.
<h3>Confidence Score: 4/5</h3>
The PR is not safe to merge until the activity count stops materializing an unbounded project history.
The new live query rereads every activity document to obtain a count, so sustained project activity causes progressively more work and can eventually make the metric exceed query limits or fail to load.
**Files Needing Attention:** convex/metrics.ts
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| convex/metrics.ts | Adds a membership-protected activity count query, but computes the count through an unbounded collection of activity documents. |
| src/components/ProjectView.tsx | Subscribes to and renders the activity count in the project header. |
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update convex/metrics.ts and 1 more file..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/ccd62154bb9188efd4f8ce4a43a89c8a25985041) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284915)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
The new query reads every activityLog row for the project with an unbounded .collect() just to return its length. Because it is a reactive query, it re-runs whenever activity is logged. Its cost grows with the log, and once the log passes Convex's read limits the query will throw inside ProjectView. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P2] The count reads the whole activity log to produce one number
`getProjectActivityCount` loads every `activityLog` row for the project with `.collect()` and only uses `.length`. Every task change or comment adds a row to this log, and rows are never removed except when the project is deleted, so the cost of this query keeps growing with the project's age. Because it is a reactive `useQuery` on `ProjectView`, it also re-runs and re-reads the entire log every time any new activity is logged. Once a busy project's log gets past Convex's per-query document or byte read limits, the query will throw. `useQuery` re-throws that error inside `ProjectView`, so the whole project page breaks, not just the counter. The existing `activity.listByProject` reads the same index but caps it with `.take(50)`. A bounded read (for example, showing "50+"), a counter kept on the project document and updated in `activity.log`, or the Convex aggregate component would avoid the unbounded scan.
[P2] Unbounded `.collect()` on activityLog just to count rows
`getProjectActivityCount` loads every `activityLog` document for the project only to return `.length`. Nothing ever trims this table: `internal.activity.log` inserts a row on every task create, task update, comment and project action, and rows are only removed when the whole project is deleted. So the cost of this query keeps growing with the project's history. It is also a reactive `useQuery` in `ProjectView`, which means every new activity event re-runs it and re-reads the whole log for every viewer of the project. Once a long-lived project gets near Convex's per-query read limits (about 16k documents / 8 MiB), the query will throw and the project header will fail instead of just showing a number. `activity.listByProject` avoids this with `.take(50)`. A safer approach is to keep a count on the project document (or use a counter/aggregate component), or to cap the scan and show something like "1000+".
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
The new query reads every activityLog row for the project with .collect() just to count them, and nothing caps the read. ProjectView subscribes to it reactively, so each new event re-reads the whole log and the cost grows without bound until it hits Convex read limits. By contrast, the existing reader in convex/activity.ts caps its read with .take(50). [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P2] Unbounded collect of activityLog just to count rows
getProjectActivityCount` does `.collect()` on every activityLog row for the project and returns only `.length`. The activityLog is append-only, so it grows without limit. This is a reactive query subscribed from ProjectView, so every new activity event re-runs it and re-reads the whole history. As a project accumulates events, the query will approach Convex's per-function read limits (about 16k documents or 8MB) and then throw. The thrown error would surface in the ProjectView `useQuery` on a page that is otherwise unrelated to activity. Even before that, the cost grows linearly with project age. Convex has no cheap count. Either cap the read with `.take(N)` and display "N+", or keep a maintained counter on the project that is incremented where activity is inserted (convex/activity.ts). The other activityLog reader, `convex/activity.ts`, already bounds its read with `.take(50)
[P2] Unbounded `.collect()` used only to count activity log rows
`getProjectActivityCount` loads every `activityLog` document for the project with `.collect()` just to read `.length`. The log is append-only: `activity.log` inserts a row per action, and the only deletion is project deletion. The query is also subscribed from `ProjectView` through `useQuery`. Cost therefore grows with project age. Each new activity event invalidates and re-reads the whole set for every open viewer. Large projects will hit Convex's per-function read limits (documents and bytes), at which point the query throws and the header count breaks. The sibling `activity.listByProject` bounds its read with `.take(50)`. Cap the read (for example `.take(N)` and display "N+"), or maintain a denormalized counter updated in `activity.log`.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
The checked-in convex/_generated/api.d.ts only lists activity, auth, comments, http, labels, members, projects, tasks and users. It has no metrics module, and package.json's build runs `tsc -b && vite build`, so `api.metrics` fails type-checking until codegen is re-run and the result committed. Running `npx convex dev` regenerates the file, so the fix is easy, but the committed tree as it stands fails to build. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Frontend builds fail before deployment <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>ProjectView</i></b> accesses <b><i>api.metrics.getProjectActivityCount</i></b>, but the checked-in generated API type
does not expose a <b><i>metrics</i></b> module. Any build or lint invocation type-checks this access, so the
frontend fails before emitting an artifact.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The newly added metrics module is absent from the checked-in generated Convex API, causing the frontend's `api.metrics` reference to fail type-checking.
## Fix Focus Areas
- convex/_generated/api.d.ts[11-37]
- src/components/ProjectView.tsx[32-34]
## Recommended Fix
Run the repository's Convex code-generation command after adding `convex/metrics.ts`, then commit the regenerated API files so `metrics` and `getProjectActivityCount` are included in the typed API.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
2\. Project views slow as activity grows <code>🐞 Bug</code> <code>➹ Performance</code>
<pre>
<b><i>getProjectActivityCount</i></b> calls <b><i>collect()</i></b> over every activity document for the project and
materializes them solely to obtain the array length. Each mounted project view subscribes to this
scan, so the read work and reactive recomputation cost grow linearly with the project's historical
events for every viewer.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The activity-count query scans and materializes the complete project activity history on every reactive execution, making project-view cost grow with every logged event.
## Fix Focus Areas
- convex/metrics.ts[19-24]
- convex/activity.ts[38-55]
- convex/schema.ts[17-21]
- convex/projects.ts[63-81]
## Recommended Fix
Store a per-project activity count or use an aggregate counter, update it through the centralized activity logging mutation whenever an event is inserted, initialize it during project creation, and have the metrics query read that constant-size value instead of collecting activity documents.
```
<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 (2)</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. Frontend builds fail before deployment <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>ProjectView</i></b> accesses <b><i>api.metrics.getProjectActivityCount</i></b>, but the checked-in generated API type
>does not expose a <b><i>metrics</i></b> module. Any build or lint invocation type-checks this access, so the
>frontend fails before emitting an artifact.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[src/components/ProjectView.tsx[32]](https://github.com/drape-io/crbench-qodo-2026-09/pull/84/files#diff-ac8bd6bfe4577a7896156b7cdc030fd8afff3f22eee1cb0458544800a5afc6bbR32-R32)</code>
>
>```diff
>+ const activityCount = useQuery(api.metrics.getProjectActivityCount, {
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The changed component references <b><i>api.metrics</i></b>, while the generated API imports and registers every
>existing Convex module except <b><i>metrics</i></b>. The build and lint scripts both invoke TypeScript checking,
>making the omission a deterministic build failure.
></pre>
>
> <code>[src/components/ProjectView.tsx[29-34]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/src/components/ProjectView.tsx/#L29-L34)</code>
> <code>[convex/_generated/api.d.ts[11-19]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/_generated/api.d.ts/#L11-L19)</code>
> <code>[convex/_generated/api.d.ts[27-37]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/_generated/api.d.ts/#L27-L37)</code>
> <code>[package.json[6-12]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/package.json/#L6-L12)</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 newly added metrics module is absent from the checked-in generated Convex API, causing the frontend's `api.metrics` reference to fail type-checking.
>
>## Fix Focus Areas
>- convex/_generated/api.d.ts[11-37]
>- src/components/ProjectView.tsx[32-34]
>
>## Recommended Fix
>Run the repository's Convex code-generation command after adding `convex/metrics.ts`, then commit the regenerated API files so `metrics` and `getProjectActivityCount` are included in the typed API.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 2. Project views slow as activity grows <code>🐞 Bug</code> <code>➹ Performance</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>getProjectActivityCount</i></b> calls <b><i>collect()</i></b> over every activity document for the project and
>materializes them solely to obtain the array length. Each mounted project view subscribes to this
>scan, so the read work and reactive recomputation cost grow linearly with the project's historical
>events for every viewer.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[convex/metrics.ts[R19-22]](https://github.com/drape-io/crbench-qodo-2026-09/pull/84/files#diff-eba956351c828178525112c2f9524b7b8479776812079bd4a59ad55d8e9441a9R19-R22)</code>
>
>```diff
>+ const allActivity = await ctx.db
>+ .query("activityLog")
>+ .withIndex("by_projectId", (q) => q.eq("projectId", args.projectId))
>+ .collect();
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The metric collects the complete indexed result set, whereas the existing activity listing
>deliberately limits reads to 50 records. Activity is appended by a centralized mutation invoked for
>project creation, task creation and updates, and comments, while <b><i>ProjectView</i></b> establishes a
>reactive subscription whenever it mounts.
></pre>
>
> <code>[convex/metrics.ts[19-24]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/metrics.ts/#L19-L24)</code>
> <code>[src/components/ProjectView.tsx[29-34]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/src/components/ProjectView.tsx/#L29-L34)</code>
> <code>[convex/activity.ts[19-23]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/activity.ts/#L19-L23)</code>
> <code>[convex/activity.ts[38-55]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/activity.ts/#L38-L55)</code>
> <code>[convex/tasks.ts[114-130]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/tasks.ts/#L114-L130)</code>
> <code>[convex/tasks.ts[172-180]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/tasks.ts/#L172-L180)</code>
> <code>[convex/comments.ts[62-74]](https://github.com/drape-io/crbench-qodo-2026-09/blob/dea52a194bdc24b0a7ff8157fa105eb7d89d0036/convex/comments.ts/#L62-L74)</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 activity-count query scans and materializes the complete project activity history on every reactive execution, making project-view cost grow with every logged event.
>
>## Fix Focus Areas
>- convex/metrics.ts[19-24]
>- convex/activity.ts[38-55]
>- convex/schema.ts[17-21]
>- convex/projects.ts[63-81]
>
>## Recommended Fix
>Store a per-project activity count or use an aggregate counter, update it through the centralized activity logging mutation whenever an event is inserted, initialize it during project creation, and have the metrics query read that constant-size value instead of collecting activity documents.
>```
> <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 a new authenticated Convex query and UI data-fetching behavior, with authorization and query-performance correctness considerations beyond a trivial localized change.</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/dea52a194bdc24b0a7ff8157fa105eb7d89d0036 -->
<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>