feat: User tier & limits system (#96)#98
Merged
DevanshuNEU merged 6 commits intoDec 13, 2025
Conversation
- Create UserLimitsService for centralized tier management - Define tier limits (free/pro/enterprise) - Add methods: check_repo_count, check_repo_size, get_usage_summary - Add Supabase migration for user_profiles table - Initialize service in dependencies.py Tiers: - Free: 3 repos, 500 files, 2000 functions - Pro: 20 repos, 5000 files, 20000 functions - Enterprise: Unlimited Used by OpenCodeIntel#93, OpenCodeIntel#94, OpenCodeIntel#95 for enforcing limits.
- Create routes/users.py with usage and limit check endpoints - GET /users/usage - returns tier, repo count, limits - GET /users/limits/check-repo-add - pre-check before adding repo - Register users_router in main.py
Comprehensive design covering: - All API endpoints and which need limit checks - Error response format - Redis key patterns - Frontend integration points - Implementation order - Files to create/modify checklist
- Changed all async def to def in user_limits.py - Removed await calls in routes/users.py - Matches codebase pattern (supabase_service.py uses sync)
Security Fixes: - Remove broken RLS UPDATE policy (was allowing any user to update any profile) - Tier updates now ONLY via service role key (payment webhooks) Code Quality: - Add input validation for user_id (empty/null check) - Add Sentry error capture for exceptions - Fail-CLOSED on DB errors during check_repo_count (prevent bypass) - Add LimitCheckError exception class - Add invalidate_tier_cache() method for tier upgrades - Add error_code field to LimitCheckResult - Add tier field to all responses for frontend upgrade prompts - Better Redis error handling (continue on failure) Documentation: - Fix date: 2024 → 2025 - Remove async references (code is sync) - Add fail-safe behavior table - Update error response format to match actual code - Add new error codes: INVALID_USER, SYSTEM_ERROR
- routes/users.py: Use TIER_LIMITS[UserTier.FREE] instead of hardcoded values - routes/users.py: Return tier and limit in check-repo-add for API key users - user_limits.py: Remove unused 'field' import from dataclasses
|
@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
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.
Summary
Implements centralized user tier and limits management system as foundation for #94, #95, and #93.
Tier System
New API Endpoints
Files Changed
New Files
backend/services/user_limits.pybackend/routes/users.pysupabase/migrations/001_user_profiles.sqlsupabase/README.mddocs/TIER_SYSTEM_DESIGN.mdModified Files
backend/dependencies.pybackend/main.pyProduction-Ready Features
Security
Error Handling
REPO_LIMIT_REACHED,REPO_TOO_LARGE,INVALID_USER,SYSTEM_ERRORObservability
user_limit_exceededwith tagsUsage Example
Database Migration
Run
supabase/migrations/001_user_profiles.sqlin Supabase SQL Editor:user_profilestableTesting Checklist
GET /users/usageendpointGET /users/limits/check-repo-addendpointRelated Issues
Closes #96