Skip to content

fix: separate source import quota usage - #50

Merged
Programcode merged 2 commits into
mainfrom
fix/separate-import-source-quota
Sep 20, 2026
Merged

Programcode merged 2 commits into
mainfrom
fix/separate-import-source-quota

Conversation

@Programcode

@Programcode Programcode commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • scope daily usage counters by quota_key, defaulting existing callers and rows to ai
  • reserve URL imports against import_source without changing AI or import quota values
  • preserve service-role-only RPC access and return accurate counts under concurrent contention
  • add migration, authorization, caller, legacy-row, and deterministic concurrency coverage

Verification

  • PATH=/home/codex/.nvm/versions/node/v22.23.2/bin:$PATH npm ci
  • PATH=/home/codex/.nvm/versions/node/v22.23.2/bin:$PATH npm run test:edge (186 passed)
  • local Supabase migration replay and database gate (42 pgTAP assertions, legacy-row replay, deterministic lock contention)
  • PATH=/home/codex/.nvm/versions/node/v22.23.2/bin:$PATH npm run verify (1,061 Vitest, 186 Edge, build, 179 Chromium passed, 1 expected skip)
  • git diff --check

No staging or production migration/function deployment is included or authorized by this PR.

Summary by CodeRabbit

  • New Features

    • Daily usage limits are now tracked independently for different activities, including AI usage and source imports.
    • Source imports now return a clear “Too Many Requests” response when the daily quota is exceeded.
    • Existing daily usage records continue under the AI quota by default.
  • Bug Fixes

    • Improved concurrent quota handling to prevent multiple requests from exceeding the configured daily limit.
  • Tests

    • Added coverage for quota migration, enforcement, permissions, and concurrent requests.

Copilot AI lite review requested due to automatic review settings September 20, 2026 13:31
@vercel

vercel Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
debate-navigator Ready Ready Preview Sep 20, 2026 1:36pm UTC

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.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 2bf111b4-a1a3-44dc-930c-a40cd074411d

📥 Commits

Reviewing files that changed from the base of the PR and between 0c4406a and f36dad3.

📒 Files selected for processing (1)
  • scripts/test-daily-quota.sh
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 7abd5452-f1cd-406b-8f12-60b1fd43f1ce

📥 Commits

Reviewing files that changed from the base of the PR and between b2ba178 and 0c4406a.

📒 Files selected for processing (6)
  • package.json
  • scripts/test-daily-quota.sh
  • supabase/functions/import-source/index.ts
  • supabase/functions/import-source/index_test.ts
  • supabase/migrations/20260920125555_scope_daily_usage_counters.sql
  • supabase/tests/daily_usage_quota_test.sql

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change scopes daily usage counters by quota key, updates import-source to use import_source, adds quota and concurrency tests, and runs the new shell test with test:db.

Changes

Daily quota scoping

Layer / File(s) Summary
Quota counter schema and RPC
supabase/migrations/.../20260920125555_scope_daily_usage_counters.sql
The counter uses (user_id, usage_date, quota_key) as its primary key. The replacement RPC validates inputs, supports quota keys, performs atomic reservations, and is limited to service_role.
Import-source quota integration
supabase/functions/import-source/index.ts, supabase/functions/import-source/index_test.ts
import-source reserves the import_source quota. The request handler is exported and tested with mocked authentication and quota responses.
Quota behavior and concurrency validation
supabase/tests/daily_usage_quota_test.sql, scripts/test-daily-quota.sh, package.json
The tests validate schema, privileges, quota isolation, migration behavior, and concurrent reservations. test:db runs the shell harness after Supabase database tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant handleRequest
  participant consume_daily_quota
  participant daily_usage_counters
  Client->>handleRequest: Send authenticated import request
  handleRequest->>consume_daily_quota: Request import_source reservation
  consume_daily_quota->>daily_usage_counters: Atomically insert or increment counter
  daily_usage_counters-->>consume_daily_quota: Return allowed status and count
  consume_daily_quota-->>handleRequest: Return quota decision
  handleRequest-->>Client: Return HTTP response
Loading

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing.

Comment @coderabbitai help to get the list of available commands.

@Programcode

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Programcode
Programcode merged commit 73e1d92 into main Sep 20, 2026
7 checks passed
@Programcode
Programcode deleted the fix/separate-import-source-quota branch September 20, 2026 13:49

This branch was successfully deployed

1 active deployment
Preview — f36dad3c Deployed Sep 20, 2026 by vercel[bot]
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.

2 participants