Repository navigation
[codex] Add Retry-After to sync fair-use restrictions - #7893
Git-on-my-level merged 4 commits into
Conversation
Greptile SummaryThis PR adds a
Confidence Score: 4/5Safe to merge; the new Retry-After logic is fail-open and cannot cause a 500. The only concerns are an extra Firestore round-trip per rejection and a new blocking I/O call on the already-deprecated v1 async handler. The feature works correctly and the tests are thorough. Two non-blocking observations prevent a clean score: the v2 path makes two sequential Firestore reads per hard-rejection when one would suffice, and the deprecated v1 async handler gains a new synchronous Firestore call that bypasses the thread-pool executor used consistently in v2. backend/routers/sync.py — v1 blocking-IO inconsistency and v2 double Firestore read on the rejection path. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant SyncV1 as sync_local_files (v1, async)
participant SyncV2 as sync_local_files_v2 (async)
participant FairUse as fair_use helpers
participant Firestore
Client->>SyncV1: POST /v1/sync-local-files
SyncV1->>FairUse: is_hard_restricted(uid) [blocking, no run_blocking]
FairUse->>Firestore: get_fair_use_state(uid) [read 1]
Firestore-->>FairUse: state
FairUse-->>SyncV1: True (restricted)
SyncV1->>FairUse: _hard_restriction_headers(uid) [blocking, no run_blocking]
FairUse->>Firestore: get_fair_use_state(uid) [read 2]
Firestore-->>FairUse: state (restrict_until)
FairUse-->>SyncV1: Retry-After N
SyncV1-->>Client: 429 + Retry-After + Deprecation headers
Client->>SyncV2: POST /v2/sync-local-files
SyncV2->>FairUse: "run_blocking -> is_hard_restricted(uid)"
FairUse->>Firestore: get_fair_use_state(uid) [read 1]
Firestore-->>FairUse: state
FairUse-->>SyncV2: True (restricted)
SyncV2->>FairUse: "run_blocking -> _hard_restriction_headers(uid)"
FairUse->>Firestore: get_fair_use_state(uid) [read 2]
Firestore-->>FairUse: state (restrict_until)
FairUse-->>SyncV2: Retry-After N
SyncV2-->>Client: 429 + Retry-After
|
kodjima33
left a comment
There was a problem hiding this comment.
Backend enhancement (Retry-After on sync fair-use restrictions) — approve only per policy.
b4ad57c to
243e01f
Compare
243e01f to
df5829d
Compare
kodjima33
left a comment
There was a problem hiding this comment.
Retry-After on sync fair-use restrictions — approve only (re-approve)
df5829d to
d535712
Compare
kodjima33
left a comment
There was a problem hiding this comment.
Re-approved on new commits; approve-only per area policy. (auto-review)
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the careful follow-up here. I re-reviewed the current head and this looks good to merge from the maintainer-review side: the sync hard-restriction path now returns Retry-After without adding the extra Firestore read that earlier feedback flagged, keeps the v1 deprecation headers, handles timezone-aware restrict_until values correctly, and includes focused unit coverage. The relevant backend unit tests pass locally (52 passed).
## Summary - Add `private_cloud_sync_enabled` to `CreateConversation` and propagate the user's private-cloud setting through v1/v2 file sync segment processing. - Preserve the current main-branch private-cloud chunk storage behavior while forwarding data-protection metadata and finalizing v1 audio metadata after chunk upload. - Cover the new conversation creation path, v1 private-cloud/data-protection wiring, and v2 background forwarding path with unit tests. - Refresh sync v2 test fixtures to use timestamp-shaped segment paths and align the storage executor worker-count assertion/docs with the current 128-worker config. - Harden the related sync/conversation tests for Windows/lightweight local runs by stubbing optional SDK imports and avoiding a real multipart parser dependency where the test only needs to exercise the endpoint coroutine. ## Current status - Rebased on `main` at `cc06c20fae75e88b15e220d57402f6f47591dd72`. - Current head: `962e7f6f55b6856cddab89aca86fcb9266c9d1c0`. - GitHub compare reports this branch as ahead 10 / behind 0; PR is mergeable. ## Validation - From `backend/`: `D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe -m pytest tests\unit\test_sync_transcription_prefs.py tests\unit\test_sync_v2.py tests\unit\test_conversation_model_split.py tests\unit\test_sync_silent_failure.py tests\unit\test_sync_cloud_tasks.py -q --tb=short` - 329 passed, 28 warnings - `D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe -m py_compile models\conversation.py routers\sync.py tests\unit\test_sync_transcription_prefs.py tests\unit\test_sync_v2.py tests\unit\test_conversation_model_split.py tests\unit\test_sync_silent_failure.py` - `D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe -m black --line-length 120 --skip-string-normalization --check models\conversation.py routers\sync.py tests\unit\test_sync_transcription_prefs.py tests\unit\test_sync_v2.py tests\unit\test_conversation_model_split.py tests\unit\test_sync_silent_failure.py` - 6 files would be left unchanged - `PYTHONUTF8=1 D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe backend\scripts\scan_async_blockers.py` - exit 0; existing async-blocker backlog reported, no new sync.py blocker - `git diff --check origin/main...HEAD` - `scripts/pre-commit` with the backend Windows venv and local Dart SDK on `PATH` ## Not run - `tests\unit\test_sync_fair_use_gate.py` in this branch: its Windows lightweight import isolation is handled in #7893 to avoid duplicating the same test-file changes across PRs.
d535712 to
927f0b1
Compare
927f0b1 to
497fdc2
Compare
|
Thanks for this — solid implementation, and the refresh cleanly resolves the two earlier concerns:
Minor notes (non-blocking):
The change is fail-open: the 429 still blocks when |
Summary
Retry-Aftervalue from an activerestrict_untiltimestamp.Retry-Afteron both deprecated/v1/sync-local-filesand current/v2/sync-local-fileshard-restriction 429 responses.Retry-Afterinstead of becoming a 500.restrict_untilvalues through UTC before comparing withdatetime.utcnow().This addresses the sync follow-up noted in #7531 where clients fell back to a generic cooldown because hard fair-use 429s did not expose a server-driven retry window.
Refresh
mainata13477934a2b2a7e0e6491af20deb47d5fd11150.497fdc251db13e9d1877a9b6364e3a9ada63872a.Review follow-up
get_hard_restriction_status(uid)for both the restricted boolean and retry window.tzinfo.Validation
backend/:D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe -m pytest tests\unit\test_sync_fair_use_gate.py tests\unit\test_fair_use_upgrade.py -q --tb=shortbackend/:D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe -m py_compile utils\fair_use.py routers\sync.py tests\unit\test_sync_fair_use_gate.py tests\unit\test_fair_use_upgrade.pybackend/:D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe -m black --line-length 120 --skip-string-normalization --check utils\fair_use.py routers\sync.py tests\unit\test_sync_fair_use_gate.py tests\unit\test_fair_use_upgrade.pyPYTHONUTF8=1 D:\codex-omi-work\.venvs\omi-backend-vad-refresh\Scripts\python.exe backend\scripts\scan_async_blockers.pysync.pyblockergit diff --check origin/main...HEADandgit diff --checkscripts/pre-commitwith the backend Windows venv and local Dart SDK onPATH