Repository navigation
feat(backend): plan-gate desktop Gemini generate for basic non-BYOK users (S14) - #12839
Conversation
…sers Free-tier S14: stop unpaid Gen-1 screen-intelligence spend at the proxy route. Completions stay open so the JIT ambient lane is not killed. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 3/5
- In
backend/routers/desktop_proxy.py, the plan-gated request returns the gate dictionary nested under FastAPI’sdetailfield instead of the documented wire body, which can break clients that parse the response schema; return aJSONResponsecontaining the gate dictionary directly or add a route-specific exception handler.
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/desktop_proxy.py">
<violation number="1" location="backend/routers/desktop_proxy.py:1661">
P2: The plan-gated request does not return the documented wire body: FastAPI wraps `_plan_gate_detail(decision)` inside `detail`. Return a `JSONResponse` with the gate dictionary (or add a route-specific exception handler) so clients receive the promised top-level fields.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| return | ||
| if decision.reason == 'authorization_unavailable': | ||
| raise HTTPException(status_code=503, detail='plan authorization is temporarily unavailable') | ||
| raise HTTPException(status_code=402, detail=_plan_gate_detail(decision)) |
There was a problem hiding this comment.
P2: The plan-gated request does not return the documented wire body: FastAPI wraps _plan_gate_detail(decision) inside detail. Return a JSONResponse with the gate dictionary (or add a route-specific exception handler) so clients receive the promised top-level fields.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/routers/desktop_proxy.py, line 1661:
<comment>The plan-gated request does not return the documented wire body: FastAPI wraps `_plan_gate_detail(decision)` inside `detail`. Return a `JSONResponse` with the gate dictionary (or add a route-specific exception handler) so clients receive the promised top-level fields.</comment>
<file context>
@@ -1622,11 +1623,51 @@ async def _authorized_desktop_user(uid: str = Depends(get_current_user_uid)) ->
+ return
+ if decision.reason == 'authorization_unavailable':
+ raise HTTPException(status_code=503, detail='plan authorization is temporarily unavailable')
+ raise HTTPException(status_code=402, detail=_plan_gate_detail(decision))
+
+
</file context>
There was a problem hiding this comment.
Settled, not a defect. FastAPI HTTPException(detail=dict) is the existing 402 wire on these endpoints and on chat ({"detail":{"error":"quota_exceeded","plan_type":"basic"}}). The 2026-09-04 free-tier note chose that shape on purpose so shipped desktop builds keep discriminating on a structured 402 body instead of learning a second status or a new top-level schema.
JSONResponse with top-level fields would break that contract. Tests pin exc.detail["error"] == "plan_gated", matching chat's handler that reads exc.detail.get("error").
|
CI is green on by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
S14 — server plan gate on desktop Gemini generate/stream
Shard S14 of the ratified local-models free-tier program (
omi-knowledge-base/projects/local-models-free-tier/implementation/60-shards.mdS14; spec30-desktop-proactivity.md§3.2), scoped to the Gen-1 Gemini proxy only.authorize_managed_computehas been onmainsince S1.POST /v1/proxy/gemini/**still spent Omi-billed Gemini for every basic non-BYOK desktop user (~37 generate calls per active hour). This PR closes that door at the route.What changed
gemini_proxyandgemini_stream_proxynow callauthorize_managed_computeongenerateContent/streamGenerateContentbefore_proxy.screen_frame_judge(the configured Gemini-provider key) so a request-scoped Gemini BYOK key counts; funding owner isbyokwhen that key is present, otherwiseomi.{'error': 'plan_gated', 'plan_type': 'basic', 'reason': ...}. 70-status 2026-09-04 settled this over the shard's original 403: these endpoints already return 402 fortrial_expired, and chat already discriminates on a structured 402 body. A new 403 would make every shipped desktop build learn a second refusal code.authorization_unavailableis 503, not a fall-through to a live key.embedContentis not gated (TBD-4 / S24).desktop_gemini_proxy.fallback_on_denymovesnone_unwired→http_402.Deliberately not this PR
desktop_proactivity.pycompletions are the JIT / context-bucket lane. S24 already warned that a blanket 403/402 onproactive_extractionkills the ambient nano triage, andtest_legacy_clients_are_not_gated_by_jit_rolloutexists because a previous 403 on that lane silently killed the shipped fleet. S14's remaining half waits on that lane's owner.Automatic-or-dead check
test_desktop_proxy.pynow drives the route functions (gemini_proxy/gemini_stream_proxy), not only_authorized_desktop_user:plan_gated,_proxynever runs_proxyruns_proxyruns, authorize seesfunding_owner=byokauthorization_unavailable→ 503,_proxynever runsRed-proof (in the generate test docstring): drop the
await _enforce_managed_plan_gateingemini_proxyand the test fails because it would reach_proxy.Proof
tests/unit/test_desktop_proxy.py106 passed (2m31s), including the six new route-level cases and the existing paywall test.test_inventory_surfaces_have_status_guardrails_and_resolvable_code_pathspassed after the inventory update.Live dest check after merge: a basic dogfood account hitting
POST /v1/proxy/gemini/models/gemini-2.5-flash:generateContentmust 402plan_gatedon the auto-deployed dev revision; a paid/BYOK account must still 200.Cut list
desktop_proactivitycompletions (JIT lane; S24 / other agent).embedContent/ screen-vector 403 (TBD-4 / S24)..planGated(S13).Line-count ratchet
Line-Count-Exception: backend/routers/desktop_proxy.py | 1632 -> 1673 | S14 route-level plan gate on generate/stream; the check lives next to the existing trial paywall, not in a new module
Product invariants
none
Failure class
Failure-Class: none