.filter() vs Index (TaskFlow PR #2)
Tier 2 easy typescript · local · real merged PR from mikecann/cya-playground #12
Ground-truth defects
The query uses `.filter()` to match projectId/userId, causing a full table scan; it should use `.withIndex()`, violating the codebase rule "Do NOT use filter in queries."
The change under review
diff
new file mode 100644 @@ -0,0 +1,25 @@ +import { internalQuery } from "./_generated/server"; +import { v } from "convex/values"; + +// Reporting queries for use via the Convex Dashboard + +export const getActivityForUser = internalQuery({ + args: { + projectId: v.id("projects"), + userId: v.id("users"), + }, + handler: async (ctx, args) => { + const activity = await ctx.db + .query("activityLog") + .order("desc") + .filter((q) => + q.and( + q.eq(q.field("projectId"), args.projectId), + q.eq(q.field("userId"), args.userId), + ), + ) + .take(50); + + return activity; + }, +});
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% | 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% | 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 | medium | ✓ | exact |
raw comments (1)
This query reads `activityLog` with `.filter()` and does not use the existing `by_projectId` index. Convex's `.filter()` does not narrow the scan: it reads every document in the table, newest first, until it finds 50 matches. If the user has fewer than 50 entries in the project, it reads the whole table. As the log grows, the query will get slow and can hit Convex's per-query read limits, so it fails outright. Use `.withIndex("by_projectId", q => q.eq("projectId", args.projectId))` and filter on `userId` after that. A better fix is to add a compound `["projectId", "userId"]` index and query on it.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
raw comments (2)
<!-- cubic:v=9fea5047-b3ba-4829-95a0-48e8d14ac11d -->
<!-- cubic:review-run=c3e56f9e-cd99-593a-b3bf-23fccf148ffa -->
<!-- metadata:{"confidence":8} -->
P2: `getActivityForUser` runs `.filter()` on an unindexed table scan, so each call reads `activityLog` documents in `_creationTime` order across every project and user until it finds 50 matches for the given `userId`. Use the existing `by_projectId` index first (as `activity.ts#listByProject` does) and keep only the `userId` check as a filter.
<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/reporting.ts, line 13:
<comment>`getActivityForUser` runs `.filter()` on an unindexed table scan, so each call reads `activityLog` documents in `_creationTime` order across every project and user until it finds 50 matches for the given `userId`. Use the existing `by_projectId` index first (as `activity.ts#listByProject` does) and keep only the `userId` check as a filter.</comment>
<file context>
@@ -0,0 +1,25 @@
+ },
+ handler: async (ctx, args) => {
+ const activity = await ctx.db
+ .query("activityLog")
+ .order("desc")
+ .filter((q) =>
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**1 issue found** across 1 file
<!-- 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/reporting.ts">
<violation number="1" location="convex/reporting.ts:13">
P2: `getActivityForUser` runs `.filter()` on an unindexed table scan, so each call reads `activityLog` documents in `_creationTime` order across every project and user until it finds 50 matches for the given `userId`. Use the existing `by_projectId` index first (as `activity.ts#listByProject` does) and keep only the `userId` check as a filter.</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/80/ai_pr_review_github_delivery_b51900ee30547b763d930a04cfee1693390e6b37762f3e88550c53c4004b8055?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F80)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_b51900ee30547b763d930a04cfee1693390e6b37762f3e88550c53c4004b8055:9004a2d319471f19250f8fb0ff318296ee07c7a2:c3e56f9e-cd99-593a-b3bf-23fccf148ffa -->
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)
### Query scans table without index
**Medium Severity**
<!-- DESCRIPTION START -->
`getActivityForUser` uses `.filter()` on `activityLog` instead of the existing `by_projectId` index. Convex still scans every document, including non-matches, so as the log grows this query can hit the document-read limit and throw instead of returning results.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 3b067320-ae7d-4c8a-b008-1b7f14c989a6 -->
<!-- LOCATIONS START
convex/reporting.ts#L11-L21
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjFiNTA1OGMzLTJlZGMtNGRjNi04MmVkLTFlYWJhNTJiY2QzMyIsImVuY3J5cHRpb25LZXkiOiJJNzFFeWpkZjdraF81VTl1ejI2bmFsejBLRTNPNHoyVVNfYzQzRnlKbHUwIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDItZmlsdGVyLXZzLWluZGV4IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" 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=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjFiNTA1OGMzLTJlZGMtNGRjNi04MmVkLTFlYWJhNTJiY2QzMyIsImVuY3J5cHRpb25LZXkiOiJJNzFFeWpkZjdraF81VTl1ejI2bmFsejBLRTNPNHoyVVNfYzQzRnlKbHUwIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDItZmlsdGVyLXZzLWluZGV4IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6ODIsImNvbW1pdFNoYSI6ImIyYTNkNGM4M2JiNDUwMDM3NjA5Mjk0NzdlMjVmZWMzMjUyN2U2YWIiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" 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 b2a3d4c83bb45003760929477e25fec32527e6ab. 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=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTpmYWFkNzQ3Zi03ZDdiLTQ1ZjEtYWNlYi0xYzQ1YjE4ODcyNGQiLCJlbmNyeXB0aW9uS2V5IjoiNFg5OFFFaDAyY1k2ZTZKaXp0UDNxMVZGQ0EwT2FWaFh5VWJ5ZUZsNWNDMCIsImJyYW5jaCI6InQyLXRhc2tmbG93LTAyLWZpbHRlci12cy1pbmRleCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" 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 b2a3d4c83bb45003760929477e25fec32527e6ab. 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 report scans the whole log table**
`getActivityForUser` filters without an index, so it reads activityLog rows from every project until it finds 50 matches. On a large table, it hits Convex's read limits and fails. Query via `withIndex("by_projectId", ...)`, or add a `by_projectId_and_userId` index.
```
convex/reporting.ts:12 const activity = await ctx.db
convex/reporting.ts:13 .query("activityLog")
convex/reporting.ts:14 .order("desc")
convex/reporting.ts:15 .filter((q) =>
convex/schema.ts:66 activityLog: defineTable({
convex/schema.ts:67 action: v.string(),
convex/schema.ts:68 userId: v.id("users"),
convex/schema.ts:69 projectId: v.id("projects"),
convex/schema.ts:70 entityType: v.string(),
convex/schema.ts:71 entityId: v.string(),
```
Drape (Review) · 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 (1)
**Full table scan on activityLog**
The query scans the whole `activityLog` table and filters in memory, even though a `by_projectId` index exists. On a large log it reads many documents and can hit Convex read limits. Use .withIndex("by_projectId", q => q.eq("projectId", args.projectId)) then filter on userId (or add a by_projectId_and_userId index).
```
convex/reporting.ts:12 const activity = await ctx.db
convex/reporting.ts:13 .query("activityLog")
convex/reporting.ts:14 .order("desc")
convex/reporting.ts:15 .filter((q) =>
convex/schema.ts:73 }).index("by_projectId", ["projectId"]),
convex/activity.ts:20 .query("activityLog")
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
raw comments (2)
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Unindexed Activity Log Scan**
The query applies both conditions with `filter` after starting an ordered scan. As the append-only `activityLog` grows, fetching one user's 50 records may read many unrelated entries, making this Dashboard report increasingly slow or expensive. Existing activity reads use the `by_projectId` index; this query should use that index at minimum or a composite project/user index.
<h3>Greptile Summary</h3>
Adds an internal Convex Dashboard query that returns the 50 newest activity-log records for a specified project and user.
- Accepts validated project and user IDs.
- Filters activity records by both identifiers and returns them newest-first.
- The current implementation does not use an available index, creating an avoidable scalability concern.
<h3>Confidence Score: 4/5</h3>
The PR appears safe to merge, though the reporting query should be indexed to avoid degraded Dashboard performance on a large activity log.
The query returns the intended records, but it scans globally rather than using the existing project index or a purpose-built project/user index; this is a non-blocking scalability concern.
**Files Needing Attention:** convex/reporting.ts
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| convex/reporting.ts | Adds the user-activity reporting query, with a non-blocking concern that its global filtered scan becomes increasingly expensive as activityLog grows. |
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update convex/reporting.ts"](https://github.com/drape-io/crbench-greptile-2026-09/commit/1a4550acc7e094a438d630a1b937b1fba8c4e299) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284875)</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 uses .filter() without a withIndex call, so it scans activityLog across every project. The by_projectId index exists in the schema, and the project's rules say not to use filter in queries. This is a real performance and read-limit problem. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P2] Activity lookup scans the whole activityLog table instead of using an index
`getActivityForUser` runs `.query("activityLog").order("desc").filter(...)` with no `withIndex`, so Convex reads every activityLog document across all projects, newest first, until it finds 50 matches. As the log grows, or when the user has fewer than 50 entries in the project, the query reads the entire table. That makes it slow and it can hit Convex's per-query document read limits. The table already has a `by_projectId` index, so `withIndex("by_projectId", q =› q.eq("projectId", args.projectId))` would limit the scan to one project. Adding a compound `["projectId", "userId"]` index to `convex/schema.ts` would remove the filter entirely. The project's Convex rules say not to use `filter` in queries and to define an index and use `withIndex` instead ([.cursor/rules/convex_rules.mdc:208](.cursor/rules/convex_rules.mdc)).
[P2] Full table scan of activityLog instead of using an index
`getActivityForUser` calls `ctx.db.query("activityLog").order("desc").filter(...)` without any index. Convex has to read activity log documents newest first, across every project and user, until it finds 50 that match. The schema already defines `activityLog.index("by_projectId", ["projectId"])`. If a user has little activity in a project, or the log is large, the query reads most or all of the table. That makes it slow, and it can fail once it hits Convex's per-query document/byte read limits, which a growing append-only log will eventually do. Use `.withIndex("by_projectId", (q) =› q.eq("projectId", args.projectId))`. Better still, add a `["projectId", "userId"]` index and use that, so only the matching rows are read. The repo's Convex rules say this explicitly: "Do NOT use `filter` in queries. Instead, define an index in the schema and use `withIndex` instead." ([.cursor/rules/convex_rules.mdc:209](.cursor/rules/convex_rules.mdc)).
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 uses `.filter` with no index on activityLog, and the schema shows activityLog only has `by_projectId`. When a user has fewer than 50 matching rows, the query scans the whole table. This also breaks the repo rule against using `filter` in queries. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P2] Full-table scan of activityLog via `.filter` instead of an index
The query calls `.query("activityLog").order("desc").filter(...)` with no `withIndex`, so Convex scans the table from newest to oldest and applies the projectId/userId predicate to each document. When a project or user has fewer than 50 matching rows, which is likely for a reporting query on a project or user with little activity, the scan reads the whole table. That costs a lot of reads, can hit Convex's per-query read limits as the log grows, and invalidates the query on any write to the table. `activityLog` already has a `by_projectId` index, so this can use `withIndex("by_projectId", ...)`. Filtering on `userId` can stay after that, or the schema can get a `by_projectId_and_userId` index. This violates the repo's Convex rule: [convex_rules.mdc:209](.cursor/rules/convex_rules.mdc) says "Do NOT use `filter` in queries. Instead, define an index in the schema and use `withIndex` instead."
[P2] Use an index instead of `.filter` in the activity query
`getActivityForUser` scans `activityLog` in descending order with `.filter` on `projectId` and `userId`, with no `withIndex`. Convex applies `filter` after the scan, so the query reads documents in the whole table, not only the matching rows. `.take(50)` stops the scan once 50 matches are found, but it won't stop early when a user has few matching entries or none. In that case the query reads the entire table, which can hit Convex read limits as the log grows. The repo's Convex rules say "Do NOT use `filter` in queries. Instead, define an index in the schema and use `withIndex` instead" ([.cursor/rules/convex_rules.mdc:209](.cursor/rules/convex_rules.mdc)). `activityLog` only has `by_projectId`, so this likely needs a new compound index such as `by_projectId_and_userId`. The query would then use `.withIndex(...)`, `.order("desc")` and `.take(50)`.
qodo · 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 (3)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Activity reports slow as logs grow <code>🐞 Bug</code> <code>➹ Performance</code>
<pre>
<b><i>getActivityForUser</i></b> orders the full <b><i>activityLog</i></b> stream and applies both identifiers through
<b><i>.filter()</i></b> instead of an index. When a user has fewer than 50 matching entries, the query can
examine accumulated activity from unrelated users and projects before returning, making dashboard
reporting progressively more expensive.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
`getActivityForUser` filters an ordered full-table stream, so its work grows with all activity records rather than the requested project and user.
## Fix Focus Areas
- convex/schema.ts[66-73]
- convex/reporting.ts[12-21]
## Recommended Fix
Add an `activityLog` compound index on `projectId` and `userId`, then replace `.filter()` with `.withIndex()` using equality constraints for both fields before applying descending ordering and `.take(50)`.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>PR Summary by Qodo</h3>
Add dashboard query for user activity reporting
<code>✨ Enhancement</code> <code>🕐 Less than 10 minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Adds an internal reporting query for project-specific user activity.
>• Returns the 50 newest matching activity records for dashboard analysis.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
graph TD
A["Convex Dashboard"] -->|"Runs internal query"| B["Reporting Query"] -->|"Filters latest 50"| C[("Activity Log")]
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Use a compound database index</b></summary>
<dl>
<dd>
- ➕ Avoids scanning unrelated activity records
- ➕ Scales better as the activity log grows
- ➕ Expresses the project-user lookup directly
- ➖ Requires a schema change and index deployment
- ➖ Adds another index with storage and write overhead
</dd>
</dl>
</details>
<details>
<summary><b>2. Use the existing project index</b></summary>
<dl>
<dd>
- ➕ Narrows scans to one project's activity
- ➕ Requires no schema migration
- ➖ Still filters user records after the index lookup
- ➖ May scan many project records for active projects
</dd>
</dl>
</details>
>**Recommendation:** The current filter-based query is adequate for small datasets or occasional dashboard reporting. For production-scale activity logs, add a compound `projectId` and `userId` index and use `withIndex`, preserving descending order and the 50-record limit while avoiding full-table scans.
</dd>
</dl>
</details>
<details>
<summary> Files changed (1) <code> +25 / -0 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (1) <code> +25 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>reporting.ts<code>Add project-user activity reporting query</code> <code>+25/-0</code></summary>
<br/>
>Add project-user activity reporting query
>
><pre>
>• Introduces an internal Convex query for dashboard reporting. It validates project and user IDs, filters the activity log by both fields, and returns the 50 newest matching records.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/80/files#diff-7977fc178efdf33fba46dafcdafcc695226e3edf43ec28da61acacc13ae3164c'>convex/reporting.ts</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</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. Activity reports slow as logs grow <code>🐞 Bug</code> <code>➹ Performance</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>getActivityForUser</i></b> orders the full <b><i>activityLog</i></b> stream and applies both identifiers through
><b><i>.filter()</i></b> instead of an index. When a user has fewer than 50 matching entries, the query can
>examine accumulated activity from unrelated users and projects before returning, making dashboard
>reporting progressively more expensive.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[convex/reporting.ts[R13-15]](https://github.com/drape-io/crbench-qodo-2026-09/pull/80/files#diff-7977fc178efdf33fba46dafcdafcc695226e3edf43ec28da61acacc13ae3164cR13-R15)</code>
>
>```diff
>+ .query("activityLog")
>+ .order("desc")
>+ .filter((q) =>
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The new query has no <b><i>.withIndex()</i></b> and filters both identifiers after starting a globally ordered
>activity query. The schema provides only a project index, while the existing project activity query
>demonstrates the indexed access pattern; activity records are retained for active projects and
>therefore accumulate.
></pre>
>
> <code>[convex/reporting.ts[12-21]](https://github.com/drape-io/crbench-qodo-2026-09/blob/e54f84e69fcc90811aad5cfac7019faf79c07206/convex/reporting.ts/#L12-L21)</code>
> <code>[convex/schema.ts[66-73]](https://github.com/drape-io/crbench-qodo-2026-09/blob/e54f84e69fcc90811aad5cfac7019faf79c07206/convex/schema.ts/#L66-L73)</code>
> <code>[convex/activity.ts[19-23]](https://github.com/drape-io/crbench-qodo-2026-09/blob/e54f84e69fcc90811aad5cfac7019faf79c07206/convex/activity.ts/#L19-L23)</code>
> <code>[convex/activity.ts[38-55]](https://github.com/drape-io/crbench-qodo-2026-09/blob/e54f84e69fcc90811aad5cfac7019faf79c07206/convex/activity.ts/#L38-L55)</code>
> <code>[convex/projects.ts[205-213]](https://github.com/drape-io/crbench-qodo-2026-09/blob/e54f84e69fcc90811aad5cfac7019faf79c07206/convex/projects.ts/#L205-L213)</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
>`getActivityForUser` filters an ordered full-table stream, so its work grows with all activity records rather than the requested project and user.
>
>## Fix Focus Areas
>- convex/schema.ts[66-73]
>- convex/reporting.ts[12-21]
>
>## Recommended Fix
>Add an `activityLog` compound index on `projectId` and `userId`, then replace `.filter()` with `.withIndex()` using equality constraints for both fields before applying descending ordering and `.take(50)`.
>```
> <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 runtime reporting query with user/project filtering and activity-log access, so correctness and data-isolation behavior warrant a complete review.</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/e54f84e69fcc90811aad5cfac7019faf79c07206 -->
<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>