Repository navigation
Revert "Sync: fair-use tracking with lock-on-exhaustion and soft cap gates" - #5875
Conversation
…gates (#…" This reverts commit f592c25.
Greptile SummaryThis PR reverts #5863 ("Sync: fair-use tracking with lock-on-exhaustion and soft cap gates"), removing the fair-use enforcement gates that were added to the Key changes:
Notable concern: The session-end flush of Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["POST /v1/sync-local-files"] --> B["Decode & VAD segment files"]
B --> C["process_segment per path"]
C --> D{"Closest existing\nconversation?"}
D -- Yes --> E["Update conversation\nsegments & timestamps"]
D -- No --> F["Create new conversation\nvia process_conversation"]
E --> G["Return updated/new\nmemory IDs"]
F --> G
subgraph "REVERTED (was in #5863)"
R1["is_hard_restricted check → 429"]
R2["should_lock = not has_transcription_credits"]
R3["record_speech_ms(uid, speech_ms, source='sync')"]
R4["check_soft_caps + trigger_classifier"]
R5["is_locked=True on CreateConversation"]
R6["record_usage(uid, transcription_seconds=...)"]
end
subgraph "transcribe.py — restored batching (#5854)"
T1["Audio chunk received"]
T1 --> T2["dg_usage_ms_pending += chunk_ms\n(DG / Soniox / Speechmatics)"]
T2 --> T3{"60 s timer fires?"}
T3 -- Yes --> T4["record_dg_usage_ms(uid, pending)\npending = 0"]
T3 -- No --> T5{"Session end\n(finally block)?"}
T5 -- "use_custom_stt=False" --> T4
T5 -- "use_custom_stt=True\n&& session < 60s" --> T6["⚠️ usage DROPPED"]
end
|
| # Flush pending DG usage accumulator (#5854) | ||
| if FAIR_USE_ENABLED and FAIR_USE_RESTRICT_DAILY_DG_MS > 0 and dg_usage_ms_pending > 0: | ||
| record_dg_usage_ms(uid, dg_usage_ms_pending) | ||
| dg_usage_ms_pending = 0 |
There was a problem hiding this comment.
dg_usage_ms_pending not flushed for use_custom_stt sessions shorter than 60 s
The session-end flush of dg_usage_ms_pending is nested inside if not use_custom_stt and last_usage_record_timestamp:. However, the Soniox and Speechmatics code paths in flush_stt_buffer both accumulate into dg_usage_ms_pending regardless of whether use_custom_stt is True.
This means:
- For sessions using Soniox or Speechmatics where
use_custom_stt=Trueand the session ends before the 60 s periodic flush fires, any accumulateddg_usage_ms_pendingis silently discarded and never written to Redis. - The periodic flush (line ~438) is intentionally placed before the
use_custom_sttguard with a comment# Placed before use_custom_stt guard so all STT paths get flushed— the session-end flush is missing the same treatment.
A straightforward fix is to move the dg_usage_ms_pending flush outside the if not use_custom_stt block, mirroring the periodic flush's intent:
# Flush pending DG/STT usage accumulator (#5854) — covers all STT paths
if FAIR_USE_ENABLED and FAIR_USE_RESTRICT_DAILY_DG_MS > 0 and dg_usage_ms_pending > 0:
record_dg_usage_ms(uid, dg_usage_ms_pending)
dg_usage_ms_pending = 0
if not use_custom_stt and last_usage_record_timestamp:
...…gates (#…" (BasedHardware#5875) This reverts commit f592c25.
…asedHardware#7125) * fix(sync): add missing record_usage to sync endpoints + deprecate v1 record_usage(uid, transcription_seconds, speech_seconds) was removed in PR BasedHardware#5875 revert and never re-added in BasedHardware#5878, leaving sync-local-file transcription invisible to the subscription credit system. Adds record_usage calls after segment processing in both v1 sync_local_files() and v2 _process_segments_background(). Marks v1 POST /v1/sync-local-files as deprecated — no Flutter or Desktop clients use it (all callers migrated to v2). Adds Deprecation header and warning log for monitoring remaining traffic. Closes BasedHardware#7123 Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(sync): add deprecation headers to all v1 response paths HTTPException paths in v1 sync-local-files were missing Deprecation headers because FastAPI drops response.headers on exceptions. Add headers param to all HTTPException raises and use a shared constant. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(sync): handle shared-helper HTTPExceptions and move record_usage after failure check - Wrap retrieve_file_paths/decode_files_to_wav calls in v1 with try/except to re-raise HTTPExceptions with deprecation headers (shared helpers can't have deprecation headers directly since v2 also uses them) - Move record_usage after the all-segments-failed guard so usage is only recorded when at least one segment succeeded - Apply same pattern to v2 background worker Co-Authored-By: Claude Opus 4.6 <[email protected]> * test(sync): add tests for record_usage placement and v1 deprecation 19 structural tests verifying: - record_usage import at module level - v1: record_usage called after all-segments-failed guard, not under fair_use_restrict_dg, wrapped in try/except with error logging - v2: record_usage after failed_segments check, guarded by successful_segments > 0, before mark_job_completed - v1 deprecation: deprecated=True, warning log, headers constant, all HTTPExceptions and JSONResponses carry deprecation headers, shared helper exceptions re-raised with headers Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore(test): add test_sync_record_usage.py to test.sh Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor(app): remove deprecated v1 syncLocalFiles function v1 POST /v1/sync-local-files is deprecated on the backend. Remove the unused client function — all callers already use syncLocalFilesV2. Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor(app): remove v1 syncLocalFiles from WAL exports Co-Authored-By: Claude Opus 4.6 <[email protected]> * docs(app): update comment to reference v2 sync endpoint Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
Reverts #5863