rate-limit portrait/generate, fix admin N+1 + UUID type + remove shelved metrics - #33
Open
brooksRoley wants to merge 2 commits into
Open
rate-limit portrait/generate, fix admin N+1 + UUID type + remove shelved metrics#33brooksRoley wants to merge 2 commits into
brooksRoley wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Staff Engineer session — 2026-08-11
Four verified findings from today's security/performance audit, all shipped in this PR.
1.
POST /api/portrait/generate— missing rate limit (security)Every call to this endpoint fired an LLM request on the server key. An authenticated user could spam it at arbitrary rate, burning quota and inflating cost.
Fix:
@limiter.limit("5/hour")added, matching the auth endpoint pattern.Requestinjected as first param (slowapi requirement).Tests:
server/tests/test_portrait_ratelimit.py— 3 new tests (first call passes, 6th returns 429, Retry-After header present). Verified locally: 3/3 passing.2.
admin_connector_depth— correlated subquery N+1 (performance)The previous query ran one
SELECT COUNT(*) FROM oauth_tokens WHERE user_id = u.idsubquery per user row in the outer scan. With N users that's N+1 DB round-trips inside a single query execution.Fix: Replaced with a
LEFT JOINon a pre-aggregated subquery (GROUP BY user_id). One pass over oauth_tokens, joined once.3.
admin_user_connectors—user_id: strinstead ofUUID(correctness)An invalid UUID string passed to
vv.user_id = $1caused asyncpg to raise an exception → unhandled 500. FastAPI's path-parameter coercion withUUIDtype returns a clean 422 instead.Fix:
user_id: str→user_id: UUID.4. Shelved metric columns removed from
admin_users+admin_funnel(correctness)Five columns in
admin_usersqueriedkarma_ledger,match_interactions, andmessages— tables that exist in the DB but have been empty since the matching engine was shelved. They always returned 0, adding correlated subquery overhead and misleading the admin UI.Same issue in
admin_funnel: three funnel steps (played_game,got_mutual_match,sent_message) and their three LEFT JOINs always produced 0s.Fix: Removed all six shelved columns / three shelved steps. The real funnel steps (
opened_self_expression_view,completed_session,returned_next_day) remain untouched.Test results (full relevant suite)
Generated by Claude Code