Repository navigation
backend: track mobile custom-STT users on the user doc (#7690 step 1) - #7723
Conversation
Greptile SummaryThis PR persists mobile custom-STT usage onto the Firestore user document so that custom-STT users are queryable and meterable (prerequisite for #7690). Writes are conditional — only when
Confidence Score: 5/5Safe to merge — the tracking write is fully isolated from the WebSocket session via try/except, so no Firestore failure can affect users. The change is additive and narrowly scoped: it reads one extra field from Firestore and conditionally fires a best-effort write that can never crash the session. The previous concern about an unguarded write propagating out of the handler has been resolved. The remaining note is about future call-site safety for No files require special attention; Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Mobile App
participant WS as _stream_handler (transcribe.py)
participant DB as Firestore (users.py)
App->>WS: "WebSocket connect (custom_stt=enabled)"
WS->>DB: get_user_transcription_preferences(uid)
DB-->>WS: "{uses_custom_stt: false, ...}"
Note over WS: use_custom_stt (True) != stored (False) → change detected
WS->>DB: run_blocking → set_user_custom_stt_usage(uid, True)
DB-->>WS: "write {uses_custom_stt:true, custom_stt_since: now()} [best-effort]"
Note over WS: Session continues regardless of write success/failure
App->>WS: "WebSocket connect (custom_stt=disabled)"
WS->>DB: get_user_transcription_preferences(uid)
DB-->>WS: "{uses_custom_stt: true, ...}"
Note over WS: use_custom_stt (False) != stored (True) → change detected
WS->>DB: run_blocking → set_user_custom_stt_usage(uid, False)
DB-->>WS: "write {uses_custom_stt:false, custom_stt_since: null}"
Reviews (2): Last reviewed commit: "backend: guard custom-STT tracking write..." | Re-trigger Greptile |
| if use_custom_stt != transcription_prefs.get('uses_custom_stt', False): | ||
| await run_blocking(db_executor, user_db.set_user_custom_stt_usage, uid, use_custom_stt) |
There was a problem hiding this comment.
Unguarded write can drop the WebSocket session
This run_blocking call sits in the pre-setup section of _stream_handler, before the main try/finally block that starts at the "# Start" comment (~line 2665). An unhandled exception here propagates straight out of _stream_handler without any cleanup, aborting the WebSocket connection for the user. Because set_user_custom_stt_usage is a non-critical metadata write (the session needs no return value from it), a transient Firestore error during high load or a network hiccup would silently drop users who are toggling custom STT for the first time, with no indication other than a failed connection. Wrap it the same way send_credit_limit_notification is wrapped a few lines above: catch, log, and continue.
|
@greptile-apps re-review |
Why
Mobile custom‑STT usage is currently not recorded anywhere — the app only sends a per‑session
custom_stt=enabledWS param, so there's no way to query "who uses custom STT" or meter it. This blocks acting on #7690 (custom‑STT users get uncapped Omi LLM post‑processing on the free tier). Step 1 is to make these users identifiable.What
Persist custom‑STT usage onto the user doc, written from the listen handler only when it changes (kept off the hot path):
transcription_preferences.uses_custom_stt— bool, current state (defaults to false / absent).transcription_preferences.custom_stt_since— timestamp the current custom‑STT streak began (set on off→on, cleared on on→off).Changes:
database/users.py: newset_user_custom_stt_usage(uid, uses_custom_stt);get_user_transcription_preferencesnow returns the two fields.routers/transcribe.py: after reading prefs, ifuse_custom_sttdiffers from the stored value, write viarun_blocking(db_executor, …). Steady‑state users (no change) trigger no extra write.routers/users.py:TranscriptionPreferencesResponseexposes the two fields via the existing GET endpoint.Notes
byok.active(desktop, keys) is a separate system.Refs #7690.