Keep plugin hot paths off direct database work#1862
Conversation
|
@copilot On top of that please fucking idiot wrote into the agent's agent.md file that it is very important to not put into the update_stats channel anything that is going to directly the database. It is not allowed; it is forbidden; it is the worst thing to do in a fucking universe. Tell it that it's very important and that it shouldn't never be done that way, never ever. You have to find an alternative that is not going directly to the database because these endpoints are sensible in terms of performance and call B my second. Rot it. |
Co-authored-by: riderx <4084527+riderx@users.noreply.github.com> Agent-Logs-Url: https://github.com/Cap-go/capgo/sessions/bb17e750-d976-41e8-be07-79b7ab5931fd
Co-authored-by: riderx <4084527+riderx@users.noreply.github.com> Agent-Logs-Url: https://github.com/Cap-go/capgo/sessions/bb17e750-d976-41e8-be07-79b7ab5931fd
Co-authored-by: riderx <4084527+riderx@users.noreply.github.com> Agent-Logs-Url: https://github.com/Cap-go/capgo/sessions/f518d625-61be-4ceb-be3f-8feadf1501af
Added the guardrail to |
|
Resolved the merge conflicts in AGENTS.md and supabase/functions/_backend/utils/stats.ts when updating the branch with origin/main. I unified the hot-path guidance so the |
|
Merged origin/main manually because the hot-path guidance in AGENTS.md conflicted. Kept the hot-path warning from the branch, then added the newer phrasing from main so the section now says these endpoints may not perform direct primary DB work, they may not enqueue writes via backgroundTask, and any unavoidable primary writes need minimal scope and inline justification plus extra review. |
…idth-chart-issue # Conflicts: # tests/process-cron-stats-jobs.test.ts
|
Merged origin/main into this branch to keep it current. There was a conflict in tests/process-cron-stats-jobs.test.ts around the newly-added live /stats test, so I manually reattached that test after the prior cron_stat_app verification and kept the existing expectations intact before pushing the result. |
|



Summary (AI generated)
This PR fixes a regression from the dashboard refresh work that moved cron-stat scheduling onto live plugin traffic by calling a service-role DB RPC from stats ingestion. It removes that request-path queueing so
/statsand bandwidth tracking stop touching Postgres just to schedule chart refresh work.It also adds an explicit repository guardrail in
AGENTS.mdso future changes do not reintroduce direct database work on performance-sensitive plugin endpoints.Root cause
createStatsMau()andcreateStatsBandwidth()were callingqueue_cron_stat_app_for_app(...)from the live request path.Change
supabase/functions/_backend/utils/stats.ts.process_cron_stats_jobs()), where it belongs.AGENTS.mdto explicitly forbid direct primary-DB work, service-role RPCs, or queue writes from/updates,/stats, and/channel_selfrequest paths.Regression coverage
tests/process-cron-stats-jobs.test.tsto assert:process_cron_stats_jobs()still queues active apps./statstraffic does not enqueue cron work directly.Test plan (AI generated)
process_cron_stats_jobs()./statstraffic no longer createscron_stat_appqueue entries.AGENTS.mdexplicitly documents that/updates,/stats, and/channel_selfmust not add direct primary-database work on the live request path.Screenshots (AI generated)
Checklist (AI generated)
bun run lint:backend && bun run lint.accordingly.
my tests
Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.