Skip to content

fix: Quota tracking was a process-local Python dict (app/routes/api.py - #149

Open
singlaamitesh wants to merge 1 commit into
sugarlabs:mainfrom
singlaamitesh:fix/141-sugar-ai-141
Open

fix: Quota tracking was a process-local Python dict (app/routes/api.py#149
singlaamitesh wants to merge 1 commit into
sugarlabs:mainfrom
singlaamitesh:fix/141-sugar-ai-141

Conversation

@singlaamitesh

Copy link
Copy Markdown

Fixes #141

Summary

Quota tracking was a process-local Python dict (app/routes/api.py user_quotas) with no persistence and a read-modify-write race under FastAPI's threadpool-executed sync dependencies (empirically confirmed to allow quota bypass under concurrency); replaced it with a DB-backed APIQuota table and an atomic SQL check-and-increment (app/quota.py) wired into verify_api_key, so quota state now persists across restarts/reconnects and is race-safe across concurrent requests.

Changes

  • app/database.py
  • app/routes/api.py
  • app/quota.py
  • tests/test_quota.py
  • tests/test_verify_api_key.py

How this was tested

Ran the affected tests locally.

Copilot AI review requested due to automatic review settings July 18, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Quota Persistence and Inconsistent Quota State Across Sessions

2 participants