Repository navigation
fix(backend): gate app generate and icon routes on chat quota - #12717
aryanorastar wants to merge 1 commit into
Conversation
Match /v1/app/generate and /v1/app/generate-icon to the description generators so free users past the monthly chat cap cannot trigger Omi-paid APP_GENERATOR LLM/image spend. Failure-Class: new
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
2 issues found across 3 files
Confidence score: 3/5
backend/routers/apps.pyperforms synchronous subscription and usage lookups inside async endpoints, so slow Firestore or Redis calls can block the event loop and stall unrelated requests; move the blocking work off the event-loop thread or use async clients.- The new quota gates in
backend/routers/apps.pyomitplatform, unlike sibling description routes, sois_trial_paywalledmay return false and allow trial requests through without the intended platform-specific enforcement; passx_app_platformconsistently.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/routers/apps.py">
<violation number="1" location="backend/routers/apps.py:1593">
P2: Every request to these async endpoints now runs synchronous subscription and usage lookups on the event-loop thread. A slow Firestore/Redis lookup can therefore stall unrelated requests handled by the same worker; run the gate through the backend’s blocking executor before awaiting provider work.</violation>
<violation number="2" location="backend/routers/apps.py:1593">
P2: The sibling description routes in the same router call `enforce_chat_quota(uid, platform=x_app_platform)`, but these two new gates pass only `uid`. Because `is_trial_paywalled` returns False when `platform` is None, the desktop 3-day trial paywall never applies to `/v1/app/generate` and `/v1/app/generate-icon`, so a desktop free user on trial can still trigger managed APP_GENERATOR/image spend here while the sibling description routes are blocked. The free monthly cap still enforces, but the gate is inconsistent with the pattern this fix claims to match. Accept the `X-App-Platform` header (as the description endpoints do) and pass it through, or document the divergence explicitly.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| # User-initiated LLM generation — same free-tier gate as chat (402 past cap). | ||
| # Sibling description generators already enforce; this path was left ungated. | ||
| enforce_chat_quota(uid) |
There was a problem hiding this comment.
P2: Every request to these async endpoints now runs synchronous subscription and usage lookups on the event-loop thread. A slow Firestore/Redis lookup can therefore stall unrelated requests handled by the same worker; run the gate through the backend’s blocking executor before awaiting provider work.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/routers/apps.py, line 1593:
<comment>Every request to these async endpoints now runs synchronous subscription and usage lookups on the event-loop thread. A slow Firestore/Redis lookup can therefore stall unrelated requests handled by the same worker; run the gate through the backend’s blocking executor before awaiting provider work.</comment>
<file context>
@@ -1588,6 +1588,10 @@ async def generate_app_endpoint(data: GenerateAppRequest, uid: str = Depends(aut
+ # User-initiated LLM generation — same free-tier gate as chat (402 past cap).
+ # Sibling description generators already enforce; this path was left ungated.
+ enforce_chat_quota(uid)
+
prompt = data.prompt.strip()
</file context>
|
|
||
| # User-initiated LLM generation — same free-tier gate as chat (402 past cap). | ||
| # Sibling description generators already enforce; this path was left ungated. | ||
| enforce_chat_quota(uid) |
There was a problem hiding this comment.
P2: The sibling description routes in the same router call enforce_chat_quota(uid, platform=x_app_platform), but these two new gates pass only uid. Because is_trial_paywalled returns False when platform is None, the desktop 3-day trial paywall never applies to /v1/app/generate and /v1/app/generate-icon, so a desktop free user on trial can still trigger managed APP_GENERATOR/image spend here while the sibling description routes are blocked. The free monthly cap still enforces, but the gate is inconsistent with the pattern this fix claims to match. Accept the X-App-Platform header (as the description endpoints do) and pass it through, or document the divergence explicitly.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/routers/apps.py, line 1593:
<comment>The sibling description routes in the same router call `enforce_chat_quota(uid, platform=x_app_platform)`, but these two new gates pass only `uid`. Because `is_trial_paywalled` returns False when `platform` is None, the desktop 3-day trial paywall never applies to `/v1/app/generate` and `/v1/app/generate-icon`, so a desktop free user on trial can still trigger managed APP_GENERATOR/image spend here while the sibling description routes are blocked. The free monthly cap still enforces, but the gate is inconsistent with the pattern this fix claims to match. Accept the `X-App-Platform` header (as the description endpoints do) and pass it through, or document the divergence explicitly.</comment>
<file context>
@@ -1588,6 +1588,10 @@ async def generate_app_endpoint(data: GenerateAppRequest, uid: str = Depends(aut
+ # User-initiated LLM generation — same free-tier gate as chat (402 past cap).
+ # Sibling description generators already enforce; this path was left ungated.
+ enforce_chat_quota(uid)
+
prompt = data.prompt.strip()
</file context>
| enforce_chat_quota(uid) | |
| enforce_chat_quota(uid, platform=x_app_platform) |
|
Thanks @aryanorastar — verified end to end; this closes a real managed-spend leak and matches the router's existing gate architecture. Per-file notes: backend/routers/apps.py — Correct. On main, Two notes on the earlier bot review's P2s, both non-blocking:
backend/tests/unit/test_free_quota_gate_wiring.py — Good wiring tests. The blocked cases assert both 402 propagation and .github/failure-classes/FC-sibling-managed-llm-missing-chat-quota-gate.json — Follows the established schema (violated_contract / canonical_prevention / canonical_prevention_artifact / scope_hints). One residual for maintainers (explicitly out of scope in #12715, so not a change request): No split needed — three files, one concern. Leaving for human maintainer merge sign-off since this sits on the billing/quota surface, alongside the minor product call on X-App-Platform parity above. — automated review on behalf of the Omi maintainers (AI-generated). by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Closing — superseded on The diagnosis held: on this PR's base ( #12739 also took the option I scoped out. I passed Two things from this PR that did not land in #12739, neither of which needs this branch:
|
|
Hey @aryanorastar 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Fixes #12715.
Summary
POST /v1/app/generateandPOST /v1/app/generate-iconbill managed LLM/image spend underFeatures.APP_GENERATORviatrack_usage, but never calledenforce_chat_quota. Sibling description generators in the same router already gate free users past the monthly chat cap with a 402.This adds the same
enforce_chat_quota(uid)call before provider work on those two endpoints.Change
backend/routers/apps.py—enforce_chat_quotaon generate + generate-iconbackend/tests/unit/test_free_quota_gate_wiring.py— blocked + allowed wiring coverage for both routes.github/failure-classes/FC-sibling-managed-llm-missing-chat-quota-gate.json— new failure classLeft alone on purpose:
/v1/app/generate-prompts,/v1/personas/twitter/initial-message. No OpenAPI/signature change (platform header not added) so free-tier gating lands without generated-client churn.Verification
main(fab60317): description endpoints callenforce_chat_quota; generate/generate-icon onlytrack_usage(no quota).track_usagedoes not enforce.pytest tests/unit/test_free_quota_gate_wiring.py::TestAppGeneratorGates→ 6 passed; full wiring file → 15 passedHonest gaps
X-App-Platforminto the gate (description siblings do); free monthly cap still enforces. Platform-aware trial paywall on these two routes can follow later if product wants parity.Failure-Class: new
Line-Count-Exception: backend/routers/apps.py | 2454 -> 2462 | reason: add enforce_chat_quota calls to generate and generate-icon to match sibling description generators; no safe split for a two-call-site wiring fix