Exposed Internals (TaskFlow PR #4)
Tier 2 easy typescript · local · real merged PR from mikecann/cya-playground #15
Ground-truth defects
Whether tools detect that a cron-only maintenance function is incorrectly
exposed as a public `mutation` instead of `internalMutation`.
In Convex, `mutation` is callable from any client via the API.
`internalMutation` is only callable from other server-side functions
(crons, schedulers, other internal functions, or the Dashboard).
There are two signals pointing to the bug:
1. `maintenance.ts` uses `mutation` instead of `internalMutation`
2. `crons.ts` references it via `api.maintenance.*` instead of `internal.maintenance.*`
The existing codebase already uses `internalMutation` correctly for similar
cleanup operations:
- `tasks.cleanupTaskChildren` (internalMutation)
- `projects.cleanupProjectChildren` (internalMutation)
The change under review
diff
new file mode 100644 @@ -0,0 +1,12 @@ +import { cronJobs } from "convex/server"; +import { api } from "./_generated/api"; + +const crons = cronJobs(); + +crons.hourly( + "cleanup old activity", + { minuteUTC: 0 }, + api.maintenance.cleanupOldActivity, +); + +export default crons; new file mode 100644 @@ -0,0 +1,21 @@ +import { mutation } from "./_generated/server"; + +const BATCH_SIZE = 100; +const MAX_AGE_DAYS = 90; + +export const cleanupOldActivity = mutation({ + args: {}, + handler: async (ctx) => { + const cutoff = Date.now() - MAX_AGE_DAYS * 24 * 60 * 60 * 1000; + + const oldEntries = await ctx.db + .query("activityLog") + .withIndex("by_creation_time", (q) => q.lt("_creationTime", cutoff)) + .order("asc") + .take(BATCH_SIZE); + + for (const entry of oldEntries) { + await ctx.db.delete("activityLog", entry._id); + } + }, +});
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% | 3 | 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 | Mjolnir (Opus 5.5) | solved | 1/1 | 100.0% | 5 | 0 |
| 7 | Mjolnir (Sonnet 5.5) | solved | 1/1 | 100.0% | 3 | 0 |
| 8 | qodo | solved | 1/1 | 100.0% | 2 | 0 |
| 9 | greptile | solved | 1/1 | 100.0% | 3 | 1 |
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 |
The cleanup is declared with the public `mutation` builder, and the cron reaches it through `api.*`. That means any client can trigger bulk deletes of activityLog rows. It should be an `internalMutation` called through `internal.*`. The change introduced this. [grounded: diff] [consensus 3/3: valid=3]
BATCH_SIZE is 100 and the cron runs hourly, so each run deletes at most 100 rows. When a batch fills, the code does not reschedule itself. That caps cleanup at 2,400 rows a day, so at higher volume the backlog of expired rows keeps growing. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
`cleanupOldActivity` is a public `mutation` with no auth check, so any client can call `api.maintenance.cleanupOldActivity` and delete activity-log data whenever it likes. A job that only the cron should run must be an `internalMutation`, and the cron should reference it through `internal.maintenance.cleanupOldActivity`. `projects.ts` already uses `internalMutation` for its cleanup.
The cron calls the job through `api.*`, which only works because the cleanup is exposed as a public function. Once the mutation is made internal, change this reference to `internal.maintenance.cleanupOldActivity`.
Each run deletes at most 100 rows (`BATCH_SIZE`) and runs once an hour, so it removes no more than 2,400 rows a day. When it fills a batch, it does not schedule a follow-up run (e.g. `ctx.scheduler.runAfter(0, ...)`). If more than about 2,400 activity entries are created per day, the backlog of expired rows keeps growing and the 90-day retention is never met.
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=cb2816c3-fad0-4939-9d62-cb97e50c0976 -->
<!-- cubic:review-run=a2961130-fb54-546b-809e-c48ca1be93ca -->
<!-- metadata:{"confidence":9} -->
P2: This exposes a destructive maintenance operation to every client. Define `cleanupOldActivity` with `internalMutation` and invoke it through the internal cron reference instead of publishing it as a public mutation.
<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/maintenance.ts, line 1:
<comment>This exposes a destructive maintenance operation to every client. Define `cleanupOldActivity` with `internalMutation` and invoke it through the internal cron reference instead of publishing it as a public mutation.</comment>
<file context>
@@ -0,0 +1,21 @@
+import { mutation } from "./_generated/server";
+
+const BATCH_SIZE = 100;
</file context>
```
</details>
<!-- 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/maintenance.ts">
<violation number="1" location="convex/maintenance.ts:1">
P2: This exposes a destructive maintenance operation to every client. Define `cleanupOldActivity` with `internalMutation` and invoke it through the internal cron reference instead of publishing it as a public mutation.</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/82/ai_pr_review_github_delivery_4b4acb73c08b948986c490b8b75923f7b95679208b14d67d9e8315817d4b79ad?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F82)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_4b4acb73c08b948986c490b8b75923f7b95679208b14d67d9e8315817d4b79ad:d816cdc521753d694b3b13ba5a337eccf4858356:a2961130-fb54-546b-809e-c48ca1be93ca -->
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)
### Public cleanup mutation lacks access control
**High Severity**
<!-- DESCRIPTION START -->
`cleanupOldActivity` is a public `mutation` with no auth check, so any client that knows the deployment URL can delete activity log rows. Nearby background jobs such as `activity.log` and `cleanupProjectChildren` are `internalMutation`s, which clients cannot call.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 92b1621f-3832-485f-bda8-d17df91b5b26 -->
<!-- LOCATIONS START
convex/maintenance.ts#L5-L20
convex/crons.ts#L1-L9
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`convex/crons.ts#L1-L9`](https://github.com/drape-io/crbench-cursor-2026-09/blob/41ef1a7367eba909a7ba2db65afd47d27cfc4c06/convex/crons.ts#L1-L9)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYxZmQyMGI5LWRjNmEtNDk0ZS1iYzM1LWY3MWU3YTY2ZmM0ZiIsImVuY3J5cHRpb25LZXkiOiJzVjN6eDhGZDF4VnpxQ25XbTB3YkhJNlVDSjBYSGhfVG9oSXotVzR4RVhJIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDQtZXhwb3NlZC1pbnRlcm5hbHMiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" 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=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYxZmQyMGI5LWRjNmEtNDk0ZS1iYzM1LWY3MWU3YTY2ZmM0ZiIsImVuY3J5cHRpb25LZXkiOiJzVjN6eDhGZDF4VnpxQ25XbTB3YkhJNlVDSjBYSGhfVG9oSXotVzR4RVhJIiwiYnJhbmNoIjoidDItdGFza2Zsb3ctMDQtZXhwb3NlZC1pbnRlcm5hbHMiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjo4NCwiY29tbWl0U2hhIjoiNDFlZjFhNzM2N2ViYTkwOWE3YmEyZGI2NWFmZDQ3ZDI3Y2ZjNGMwNiIsInByb3ZpZGVyIjoiZ2l0aHViIn19" 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 41ef1a7367eba909a7ba2db65afd47d27cfc4c06. 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=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo4Yzk0YjRlMS00MDUyLTRkZTktOTE5YS04MGM4NjJkNGQ4OTAiLCJlbmNyeXB0aW9uS2V5IjoiajZTbU5aVDV0dzVWdDd2enp6b0x3clFiXzFiUFF1T3RMcXNxYk9ZeV9SMCIsImJyYW5jaCI6InQyLXRhc2tmbG93LTA0LWV4cG9zZWQtaW50ZXJuYWxzIiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" 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 41ef1a7367eba909a7ba2db65afd47d27cfc4c06. 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 | ✓ | off by one |
The new mutation deletes at most BATCH_SIZE (100) entries per hourly cron run and never reschedules itself when the batch is full. Unlike cleanupProjectChildren, it has no runAfter, so any backlog above about 2,400 entries a day is never cleared. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
**Activity cleanup is callable by any client**
`cleanupOldActivity` is a public `mutation` with no auth check, so any unauthenticated client can invoke it as often as they like to purge the activity log and load the database. The cron only needs an internal function. Make it an `internalMutation` and reference it via `internal.maintenance.cleanupOldActivity` in crons.ts.
```
convex/maintenance.ts:1 import { mutation } from "./_generated/server";
convex/maintenance.ts:6 export const cleanupOldActivity = mutation({
convex/maintenance.ts:7 args: {},
convex/maintenance.ts:8 handler: async (ctx) => {
convex/activity.ts:38 export const log = internalMutation({
convex/projects.ts:144 export const cleanupProjectChildren = internalMutation({
```
**Cleanup never catches up on large backlogs**
Only 100 entries are deleted per hourly run (2,400/day) and nothing reschedules when the batch is full, so any backlog or daily volume above that grows forever. `cleanupProjectChildren` reschedules itself when a batch fills. If `oldEntries.length === BATCH_SIZE`, schedule this function again with `ctx.scheduler.runAfter(0, ...)`.
```
convex/maintenance.ts:3 const BATCH_SIZE = 100;
convex/maintenance.ts:11 const oldEntries = await ctx.db
convex/maintenance.ts:12 .query("activityLog")
convex/maintenance.ts:13 .withIndex("by_creation_time", (q) => q.lt("_creationTime", cutoff))
convex/projects.ts:213 if (activities.length === BATCH_SIZE) hasMore = true;
convex/projects.ts:215 // If any batch was full, there might be more to clean up
convex/projects.ts:216 if (hasMore) {
convex/projects.ts:217 await ctx.scheduler.runAfter(
convex/projects.ts:218 0,
convex/projects.ts:219 internal.projects.cleanupProjectChildren,
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | off by one |
The new mutation deletes at most BATCH_SIZE=100 entries per run, and the new cron runs it only hourly. Nothing reschedules it when the batch is full, so if more than 100 entries per hour age past the cutoff, the backlog grows without limit. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
**Cleanup cannot keep up with a backlog**
Each hourly run deletes at most 100 entries and never reschedules itself when the batch is full. Any activity rate above 100 entries per hour makes the backlog grow without bound, and old entries are never fully purged. When the batch is full, schedule the mutation again with ctx.scheduler.runAfter(0, ...).
```
convex/maintenance.ts:4 const MAX_AGE_DAYS = 90;
convex/maintenance.ts:11 const oldEntries = await ctx.db
convex/maintenance.ts:12 .query("activityLog")
convex/maintenance.ts:13 .withIndex("by_creation_time", (q) => q.lt("_creationTime", cutoff))
```
**Cleanup mutation is public and unauthenticated**
`cleanupOldActivity` is registered with `mutation`, so any client can call it with no auth check. It is only meant for the cron and should be an `internalMutation`, with the cron using `internal.maintenance...`. Use internalMutation and reference it via `internal` in crons.ts.
```
convex/maintenance.ts:1 import { mutation } from "./_generated/server";
convex/maintenance.ts:3 const BATCH_SIZE = 100;
convex/maintenance.ts:4 const MAX_AGE_DAYS = 90;
convex/maintenance.ts:6 export const cleanupOldActivity = mutation({
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
`by_creation_time` is a system index that Convex creates automatically on every table, ordered by `_creationTime`. It doesn't need to be declared in the schema, so the query is valid and will deploy and run. [invalid: contradiction] [consensus 3/3: invalid=3]
The cron runs hourly and each run deletes at most BATCH_SIZE=100 entries. Nothing schedules a follow-up batch, so if more than 100 entries per hour pass the 90-day cutoff, the backlog grows without bound. [grounded: diff] [consensus 3/3: valid=3]
raw comments (4)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> <a href="#"><img alt="security" src="https://greptile-static-assets.s3.amazonaws.com/badges/Security.svg?v=2" align="top"></a> **Public Maintenance Mutation**
`cleanupOldActivity` is declared as a public `mutation`, even though the cron is its only repository caller. Because the empty-argument handler has no authorization check, any client can repeatedly trigger database queries and deletion batches outside the intended schedule. Use an internal mutation and call it through Convex's internal API.
**How this was verified:** The generated server contract makes `mutation` client-accessible, while this empty-argument handler immediately queries and deletes activity records without checking authorization.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Missing Activity Index**
This query uses `by_creation_time`, but the `activityLog` schema declares only `by_projectId`. Convex validates index names against the table definition, so the cleanup cannot successfully deploy or execute until the creation-time index is declared or the query is changed.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Cleanup Cannot Catch Up**
Each hourly run deletes at most 100 expired entries and does not schedule another batch. Because normal project, task, and comment operations create activity entries, a sustained rate above 100 entries per hour makes expiration outpace deletion and causes the over-90-day backlog to grow indefinitely. Continue processing full batches until fewer than 100 entries remain.
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>
This PR adds an hourly Convex cron and a maintenance mutation intended to delete activity-log entries older than 90 days in batches of 100.
- Registers an hourly activity cleanup job.
- Adds cutoff-based querying and deletion of old activity records.
- Requires changes before merging because the query references an undeclared index, the maintenance mutation is publicly exposed, and its fixed hourly capacity cannot keep up with realistic sustained activity volume.
<h3>Confidence Score: 1/5</h3>
The PR is not safe to merge until the missing index, public maintenance endpoint, and non-converging cleanup batching are corrected.
The cleanup cannot run against the declared schema, unauthorized clients can invoke its destructive database work, and an activity rate above 100 records per hour causes expired data to accumulate permanently.
**Files Needing Attention:** convex/maintenance.ts and convex/crons.ts
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| convex/crons.ts | Registers the hourly cleanup but calls a maintenance operation exposed through the public API and provides no continuation for full batches. |
| convex/maintenance.ts | Adds age-based deletion, but uses an undeclared index, exposes destructive maintenance publicly, and caps cleanup throughput at 100 records per hour. |
</details>
<details open><summary><h3>Flowchart</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart LR
C[Hourly cron] --> M[cleanupOldActivity mutation]
U[Public client] -->|currently exposed| M
M --> Q[Query activityLog by_creation_time]
Q -->|index currently undeclared| F[Validation or execution failure]
Q --> B[Delete at most 100 rows]
B -->|no continuation| R[Wait until next hour]
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update convex/crons.ts and 1 more files"](https://github.com/drape-io/crbench-greptile-2026-09/commit/c9b3c64b42e87c671cfaf7d204464c674f138987) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284899)</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 |
The cleanup is registered as a public mutation with no auth check, so any client can call it and trigger deletes. The repo's rules say internal functions like this should use internalMutation. [grounded: diff] [consensus 3/3: valid=3]
The cron calls the function through the public `api` object, and that only works because the function is public. The repo rules show cron jobs calling internal functions through `internal`. This is the other half of finding 0. [grounded: diff] [consensus 3/5: valid=3, minor=2]
Each hourly run deletes at most 100 rows and never reschedules itself, so throughput is capped at about 2,400 deletions a day. That cannot clear an existing backlog or keep up with high volume. [grounded: diff] [consensus 3/3: valid=3]
The repo's rules (line 243) forbid crons.hourly. This is a guideline violation, not a behaviour bug. [grounded: diff] [consensus 3/3: minor=3]
raw comments (5)
[P1] Cleanup mutation is public, so any client can trigger deletes
`cleanupOldActivity` is registered with `mutation`, which makes it part of the app's public API. Any unauthenticated client can call `api.maintenance.cleanupOldActivity` whenever it likes. Each call deletes up to 100 activity-log entries older than 90 days, with no auth check. It is only meant to run from the cron, so it should be registered with `internalMutation`, and the cron should reference it as `internal.maintenance.cleanupOldActivity` (see crons.ts below). The repo's Convex rules say not to use `query`/`mutation`/`action` for sensitive internal functions and to use `internalMutation` instead ([.cursor/rules/convex_rules.mdc:88-89](.cursor/rules/convex_rules.mdc)).
[P2] Cron schedules the cleanup through the public `api` object
The cron imports `api` and schedules `api.maintenance.cleanupOldActivity`. Scheduling the job through `api` only works because the target is public, so this ties the cron to the exposed endpoint above. Once the function becomes an `internalMutation`, this reference has to change to `internal.maintenance.cleanupOldActivity`, imported from `./_generated/api`. The repo's cron guidance shows cron jobs calling internal functions through the `internal` object ([.cursor/rules/convex_rules.mdc:261-266](.cursor/rules/convex_rules.mdc)).
[P1] Cleanup mutation is public, so any client can trigger deletions
`cleanupOldActivity` is registered with `mutation`, which makes it part of the public API, and it checks neither auth nor membership. Any unauthenticated client can call `api.maintenance.cleanupOldActivity` as often as it likes. Each call deletes up to 100 activity-log entries older than 90 days across every project, and the repeated calls also drive database load. This is a maintenance job that only the cron should run, so it should be registered with `internalMutation`, and the cron should reference `internal.maintenance.cleanupOldActivity`. The repo rules say not to use `query`/`mutation`/`action` for sensitive internal functions and to call private functions through `internal` (.cursor/rules/convex_rules.mdc:88-89, .cursor/rules/convex_rules.mdc:122).
[P2] Cleanup is capped at 100 rows per hour and never catches up on a backlog
Each run deletes at most `BATCH_SIZE` (100) expired entries and then stops. Nothing reschedules it when the batch comes back full, so throughput is capped at about 2,400 deletions a day. When the job is first deployed, every log row already older than 90 days is in the backlog. After that, any day with more than ~2,400 new activity entries (every task, comment and label change writes one) adds rows faster than the job removes them. In either case the table keeps growing and retention is never enforced. A common fix is to have the mutation reschedule itself with `ctx.scheduler.runAfter(0, internal.maintenance.cleanupOldActivity, {})` when `oldEntries.length === BATCH_SIZE`.
[P3] Cron uses `crons.hourly`, which the project's Convex rules forbid
The project's Convex guidelines say to schedule cron jobs only with `crons.interval` or `crons.cron`, not the `crons.hourly`/`daily`/`weekly` helpers (.cursor/rules/convex_rules.mdc:243). This job should use `crons.interval("cleanup old activity", { hours: 1 }, internal.maintenance.cleanupOldActivity, {})` or an equivalent `crons.cron` expression.
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 |
The new mutation deletes at most 100 rows each time it runs and does not reschedule itself. The cron runs it hourly, so it can remove at most about 2,400 rows a day, and any higher volume or initial backlog will keep growing. [grounded: diff] [consensus 3/3: valid=3]
The function is declared with the public `mutation` builder and has no auth check, so any client can call it repeatedly and delete activityLog rows across all projects. The cron also references it through `api.`. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
[P1] Cron cleanup is a public, unauthenticated mutation
(also convex/crons.ts:8) `cleanupOldActivity` is registered with `mutation`, so it is exposed as `api.maintenance.cleanupOldActivity`. Any client, including an unauthenticated one, can call it. It deletes activity-log rows with no auth check. The cron only schedules it and does not need it to be public. Callers can repeatedly trigger deletions of audit data older than 90 days, across all projects. Other internal-only functions in this repo use `internalMutation` (for example `activity.log` and `projects.cleanupProjectChildren`). This one should do the same, and `crons.ts` should reference `internal.maintenance.cleanupOldActivity`.
[P3] Cleanup only deletes 100 rows per hour
,15-17 The job takes one batch of 100 and never reschedules itself. That caps cleanup at about 2,400 rows a day. If activity volume exceeds that, or there is an initial backlog, expired entries accumulate indefinitely. A fix would reschedule with `ctx.scheduler.runAfter(0, ...)` when the batch comes back full.
[P1] Cleanup mutation is public and unauthenticated
`cleanupOldActivity` is declared with `mutation` instead of `internalMutation`, so it is exposed as a public API function with no auth check. Any client, including an unauthenticated one, can call `api.maintenance.cleanupOldActivity` and delete up to 100 of the oldest `activityLog` rows per call. The deletion is not scoped to a project or user, and a caller can loop to wipe audit history across all projects. The rest of the codebase uses `internalMutation` for server-only work (`activity.log`, `cleanupProjectChildren`, `cleanupTaskChildren`). The fix is to use `internalMutation` here and reference it as `internal.maintenance.cleanupOldActivity` in `convex/crons.ts:6-10`, which currently uses `api.`.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
The new cleanup deletes at most BATCH_SIZE=100 rows per run and is scheduled hourly with no rescheduling, so any sustained insert rate above 100/hour (inserts exist in convex/activity.ts) makes the backlog grow and the 90-day retention is never reached. [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\. Anyone can erase old audit history <code>🐞 Bug</code> <code>⛨ Security</code>
<pre>
<b><i>cleanupOldActivity</i></b> is exported with the public <b><i>mutation</i></b> builder and performs no authentication
or authorization check. Any client can repeatedly invoke it to delete every activity record older
than 90 days across all projects in batches of 100.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
`cleanupOldActivity` is a public client-accessible mutation even though it is intended only for scheduled maintenance, allowing callers to delete old audit records globally.
## Fix Focus Areas
- convex/maintenance.ts[1-7]
- convex/crons.ts[1-10]
## Recommended Fix
Declare the cleanup with `internalMutation` instead of `mutation`, import `internal` rather than `api` in the cron module, and schedule `internal.maintenance.cleanupOldActivity`.
```
<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\. Expired audit data grows without bound <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>cleanupOldActivity</i></b> deletes at most 100 expired entries while <b><i>crons.hourly</i></b> invokes it only once
each hour. When project, task, comment, and update activity collectively creates more than 100
records per hour, expired records accumulate faster than this cleanup can remove them.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The hourly cleanup has a hard throughput ceiling of 100 records per hour, so it cannot enforce retention when activity is generated faster than that rate.
## Fix Focus Areas
- convex/maintenance.ts[3-20]
- convex/crons.ts[6-10]
## Recommended Fix
After deleting a full batch, schedule the internal cleanup mutation to run again immediately with `ctx.scheduler.runAfter`; stop scheduling continuations once a batch contains fewer than 100 entries.
```
<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. Anyone can erase old audit history <code>🐞 Bug</code> <code>⛨ Security</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>cleanupOldActivity</i></b> is exported with the public <b><i>mutation</i></b> builder and performs no authentication
>or authorization check. Any client can repeatedly invoke it to delete every activity record older
>than 90 days across all projects in batches of 100.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[convex/maintenance.ts[R6-7]](https://github.com/drape-io/crbench-qodo-2026-09/pull/82/files#diff-abda0fd5c86307d4c05399fb9037378d7f1902266f00b0deaf09ecc703818d1eR6-R7)</code>
>
>```diff
>+export const cleanupOldActivity = mutation({
>+ args: {},
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The generated server declarations explicitly identify <b><i>mutation</i></b> as client-accessible and
><b><i>internalMutation</i></b> as server-only. The new handler uses the public builder and deletes globally
>queried records without checking identity or project membership, while existing background cleanup
>follows the internal-mutation pattern.
></pre>
>
> <code>[convex/maintenance.ts[1-19]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/maintenance.ts/#L1-L19)</code>
> <code>[convex/_generated/server.d.ts[45-62]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/_generated/server.d.ts/#L45-L62)</code>
> <code>[convex/schema.ts[66-73]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/schema.ts/#L66-L73)</code>
> <code>[convex/projects.ts[133-146]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/projects.ts/#L133-L146)</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
>`cleanupOldActivity` is a public client-accessible mutation even though it is intended only for scheduled maintenance, allowing callers to delete old audit records globally.
>
>## Fix Focus Areas
>- convex/maintenance.ts[1-7]
>- convex/crons.ts[1-10]
>
>## Recommended Fix
>Declare the cleanup with `internalMutation` instead of `mutation`, import `internal` rather than `api` in the cron module, and schedule `internal.maintenance.cleanupOldActivity`.
>```
> <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. Expired audit data grows without bound <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>cleanupOldActivity</i></b> deletes at most 100 expired entries while <b><i>crons.hourly</i></b> invokes it only once
>each hour. When project, task, comment, and update activity collectively creates more than 100
>records per hour, expired records accumulate faster than this cleanup can remove them.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[convex/maintenance.ts[R13-15]](https://github.com/drape-io/crbench-qodo-2026-09/pull/82/files#diff-abda0fd5c86307d4c05399fb9037378d7f1902266f00b0deaf09ecc703818d1eR13-R15)</code>
>
>```diff
>+ .withIndex("by_creation_time", (q) => q.lt("_creationTime", cutoff))
>+ .order("asc")
>+ .take(BATCH_SIZE);
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The new constant, query limit, and hourly schedule establish a maximum cleanup rate of 2,400 records
>per day. The repository records one activity entry from several ordinary user mutation paths without
>a corresponding application-level rate bound, and its existing batched project cleanup reschedules
>itself whenever a full batch indicates more data may remain.
></pre>
>
> <code>[convex/maintenance.ts[3-19]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/maintenance.ts/#L3-L19)</code>
> <code>[convex/crons.ts[6-10]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/crons.ts/#L6-L10)</code>
> <code>[convex/activity.ts[38-56]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/activity.ts/#L38-L56)</code>
> <code>[convex/projects.ts[63-81]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/projects.ts/#L63-L81)</code>
> <code>[convex/tasks.ts[114-130]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/tasks.ts/#L114-L130)</code>
> <code>[convex/comments.ts[62-74]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/comments.ts/#L62-L74)</code>
> <code>[convex/projects.ts[205-221]](https://github.com/drape-io/crbench-qodo-2026-09/blob/f637f6a141bf10318a107a70afb2953594618116/convex/projects.ts/#L205-L221)</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 hourly cleanup has a hard throughput ceiling of 100 records per hour, so it cannot enforce retention when activity is generated faster than that rate.
>
>## Fix Focus Areas
>- convex/maintenance.ts[3-20]
>- convex/crons.ts[6-10]
>
>## Recommended Fix
>After deleting a full batch, schedule the internal cleanup mutation to run again immediately with `ctx.scheduler.runAfter`; stop scheduling continuations once a batch contains fewer than 100 entries.
>```
> <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 scheduled destructive maintenance logic that deletes persisted activity records, so its data-retention and cron 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/f637f6a141bf10318a107a70afb2953594618116 -->
<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>