Report
Send a weekly meal plan email to every user, Nov 30PushedNormal check1 s of 6 min
Fix before you push
1A timed job pays for AI even when nobody uses the app
The job calls the AI on a timer, whether or not there is anything new. It keeps costing money every hour, and more with every user it loops over.
1 AI call run from a scheduled/cron/polling job (GET).
- Where
app/api/cron/weekly/route.ts:7- Found by
- IntentiAI check: Timed job that calls the AI. Confidence: high.
Runs on a timer regardless of traffic: every tick pays; user-created schedules multiply it by users. Never appears in request traces.
How to fix it
Run it less often, only for active users, and skip the AI call when nothing changed.
Fix prompt
In app/api/cron/weekly/route.ts (around line 7), a scheduled job calls the AI model on every run. Make it run only as often as the feature really needs, skip the AI call when nothing has changed since the last run, and only process users who were active recently. Keep everything else working the same, and tell me what you changed.
Not urgent
4Fix soon and good to know
Fix soon2
One request per item makes the app slow and costly
Inside a loop, the code calls the database, another service or an AI model once for every item. With many items this gets slow, and paid calls multiply your bill.
An LLM completion runs once per iteration in route.ts
- Where
app/api/cron/weekly/route.ts:7- Found by
- IntentiAI check: One request per item. Confidence: high.
Every iteration is a separate model call, billed and rate-limited individually. A list that grows from 10 items to 500 turns one operation into 500 requests: fifty times the latency, fifty times the spend, and the provider's rate limiter starts rejecting the tail.
How to fix it
Fetch or send everything in app/api/cron/weekly/route.ts in one batch instead of once per item.
Fix prompt
In app/api/cron/weekly/route.ts around line 7, a database, network or AI model call happens once for every item in a loop. Rewrite it to handle all the items in one batch or a few, or run them with a sensible limit on how many happen at once. The result should stay the same.
AI answers have no length limit
Most answers are short, but now and then the AI can ramble up to its maximum length, and long answers are the most expensive part of the bill.
1 AI call with no output-token cap (line 7).
- Where
app/api/cron/weekly/route.ts:7- Found by
- IntentiAI check: No answer length limit. Confidence: high.
Output tokens are the expensive half; without a cap a verbose or runaway response bills up to the model's full output limit. Other call sites in this repo DO set a cap. These are outliers. (worst case $0.164/call if gpt-4o runs to its 16,384-token limit)
How to fix it
Set a maximum answer length that fits what this feature needs.
Fix prompt
In app/api/cron/weekly/route.ts (around line 7), AI calls have no maximum answer length. Set a maximum output length that fits each feature with some headroom, ask for the desired length in the prompt, and handle answers that get cut off. Keep everything else working the same, and tell me what you changed.
Good to know2
A background job loads every row at once
The job asks the database for every matching row, with no limit, so each run loads all of them. As the data grows the run needs more memory and time, and a host with a time limit stops it partway.
A job reads every matching row of "subscriptions" with no limit
- Where
app/api/cron/weekly/route.ts:5- Found by
- IntentiAI check: Other check. Confidence: medium.
The query has no limit, so each run loads every matching row of "subscriptions". It is fast with a few rows; as the data grows the run needs more memory and time, and on a host with a time limit it stops partway.
How to fix it
Process the rows in app/api/cron/weekly/route.ts in batches, for example 200 per run.
Fix prompt
In app/api/cron/weekly/route.ts around line 5, a background job loads every matching row with no limit. Process the rows in batches instead (for example 200 at a time, ordered by id or created date, continuing from the last one done), so each run finishes within the host's time limit and memory. Rows not done in one run should be picked up by the next.
Your server setup was changed
Files that define your servers, databases or cloud resources were edited. Applying them could change or delete real resources and add to your hosting bill.
Infrastructure definitions changed (1 file)
- Where
vercel.json:1- Found by
- IntentiAI check: Changes outside the task. Confidence: high.
These files describe the machines, containers and services your app runs on. A change here can resize, restart or replace running infrastructure when it is applied, affecting users who have nothing to do with this feature.
How to fix it
Check those extra changes were intended, and undo any that were not.
Fix prompt
This change edits files outside what the task needed, starting with vercel.json. List each of those changes with the reason it was needed, and undo any that were not part of the task.
Checked at commit 4f8880f.