Repository navigation
Fix: sync soft cap trigger incorrectly locking conversations - #5896
Conversation
Soft cap triggers should only run the classifier async — not immediately lock conversations. This matches transcribe.py behavior where soft caps never set should_lock. The bug caused unlimited users to get conversations locked when exceeding the 2h daily soft cap via sync, bypassing the graduated enforcement system entirely. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Structural test verifies the triggered_caps block in sync.py does not contain should_lock, matching transcribe.py behavior. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Greptile SummaryThis PR fixes a regression from #5878 where the
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant sync.py
participant fair_use
participant Classifier
Client->>sync.py: POST /v1/sync-local-files
sync.py->>fair_use: is_hard_restricted(uid)
fair_use-->>sync.py: false (proceed)
sync.py->>fair_use: has_transcription_credits(uid)
fair_use-->>sync.py: bool → should_lock (credits only)
Note over sync.py: VAD + speech measurement
sync.py->>fair_use: record_speech_ms(uid, total_speech_ms)
sync.py->>fair_use: check_soft_caps(uid)
fair_use-->>sync.py: triggered_caps (may be non-empty)
alt triggered_caps non-empty
Note over sync.py: ✅ AFTER FIX: should_lock unchanged
sync.py-)Classifier: asyncio.create_task(trigger_classifier_if_needed)
Note over Classifier: Runs async — may escalate enforcement<br/>in a future request, not this one
end
sync.py->>sync.py: is_locked = should_lock
sync.py->>sync.py: process_segment(..., is_locked)
sync.py-->>Client: response (conversations processed)
Last reviewed commit: "Add test: soft cap t..." |
| def test_soft_cap_does_not_lock(self): | ||
| """Soft cap trigger must NOT set should_lock — only classifier/stage should lock.""" | ||
| source = self._read_sync_source() | ||
| # Find the soft cap block: between 'if triggered_caps:' and the next unindented line | ||
| lines = source.split('\n') | ||
| in_triggered_block = False | ||
| for line in lines: | ||
| stripped = line.strip() | ||
| if stripped.startswith('if triggered_caps:'): | ||
| in_triggered_block = True | ||
| continue | ||
| if in_triggered_block: | ||
| if stripped and not stripped.startswith('#') and not line.startswith(' ' * 16): | ||
| break # exited the block | ||
| assert 'should_lock' not in stripped, \ | ||
| "soft cap trigger must not set should_lock — matches transcribe.py behavior" |
There was a problem hiding this comment.
Structural test won't fail if the block disappears
If if triggered_caps: is ever removed or renamed in sync.py (e.g., during a future refactor), in_triggered_block will never become True, the loop body never asserts, and the test silently passes — giving false confidence that the invariant holds.
Add a post-loop guard to ensure the block was actually found:
| def test_soft_cap_does_not_lock(self): | |
| """Soft cap trigger must NOT set should_lock — only classifier/stage should lock.""" | |
| source = self._read_sync_source() | |
| # Find the soft cap block: between 'if triggered_caps:' and the next unindented line | |
| lines = source.split('\n') | |
| in_triggered_block = False | |
| for line in lines: | |
| stripped = line.strip() | |
| if stripped.startswith('if triggered_caps:'): | |
| in_triggered_block = True | |
| continue | |
| if in_triggered_block: | |
| if stripped and not stripped.startswith('#') and not line.startswith(' ' * 16): | |
| break # exited the block | |
| assert 'should_lock' not in stripped, \ | |
| "soft cap trigger must not set should_lock — matches transcribe.py behavior" | |
| def test_soft_cap_does_not_lock(self): | |
| """Soft cap trigger must NOT set should_lock — only classifier/stage should lock.""" | |
| source = self._read_sync_source() | |
| # Find the soft cap block: between 'if triggered_caps:' and the next unindented line | |
| lines = source.split('\n') | |
| in_triggered_block = False | |
| for line in lines: | |
| stripped = line.strip() | |
| if stripped.startswith('if triggered_caps:'): | |
| in_triggered_block = True | |
| continue | |
| if in_triggered_block: | |
| if stripped and not stripped.startswith('#') and not line.startswith(' ' * 16): | |
| break # exited the block | |
| assert 'should_lock' not in stripped, \ | |
| "soft cap trigger must not set should_lock — matches transcribe.py behavior" | |
| assert in_triggered_block, "Expected 'if triggered_caps:' block in sync.py — was it removed?" |
Tests verify: credits+softcap=no-lock, no-credits+no-cap=lock, no-credits+softcap=lock (from credits), credits+disabled=no-lock. Addresses tester feedback on missing runtime edge tests. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Workflow Checkpoints CompleteAll checkpoints passed for PR #5896:
Changed-path coverage
Ready for merge. All checkpoints passed. Awaiting manager approval. by AI for @beastoin |
|
lgtm |
Reads UIDs from a file, verifies paid subscription (unlimited/pro only), then unlocks conversations, memories, and action items. Supports dry-run. No UIDs hardcoded. Related: #5899, PR #5896. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…bug (#5901) ## Summary Migration script to unlock conversations, memories, and action items incorrectly locked by the sync soft cap bug (PR #5878, fixed in PR #5896). Script at `backend/scripts/unlock_soft_cap_locked.py` — reads UIDs from a file, verifies paid subscription (unlimited/pro), then unlocks all 3 collections. Dry-run by default. ## Usage (Cloud Run job) ```bash python scripts/unlock_soft_cap_locked.py --uids-file /tmp/impacted_uids.txt # dry-run python scripts/unlock_soft_cap_locked.py --uids-file /tmp/impacted_uids.txt --execute # apply ``` ## Impact - 8 users identified from prod logs, 6 are paid (unlimited), 2 basic (skipped) - 692 total items to unlock (649 conversations, 17 memories, 26 action items) Closes #5899
…rdware#5896) ## Summary - Removed `should_lock = True` from the soft cap trigger block in `sync.py` - Soft cap triggers now only run the classifier async (matching `transcribe.py` behavior) - Added structural test to prevent regression ## Root Cause PR BasedHardware#5878 incorrectly set `should_lock = True` when soft caps triggered in the sync endpoint. This caused unlimited users exceeding the 2h daily soft cap via sync to get all conversations immediately locked — bypassing the graduated enforcement system (WARNING → THROTTLE → RESTRICT). The equivalent code in `transcribe.py` (WebSocket) correctly only triggers the classifier without locking. ## Impact With `FAIR_USE_ENABLED=true` in production, any user exceeding the daily soft cap through sync had their conversations locked immediately, regardless of subscription tier or classifier result. ## Test plan - [x] 26/26 unit tests pass (including new structural test) - [x] `py_compile` verified on all router files - [ ] Deploy and verify no locked conversations for unlimited sync users 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reads UIDs from a file, verifies paid subscription (unlimited/pro only), then unlocks conversations, memories, and action items. Supports dry-run. No UIDs hardcoded. Related: BasedHardware#5899, PR BasedHardware#5896. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…bug (BasedHardware#5901) ## Summary Migration script to unlock conversations, memories, and action items incorrectly locked by the sync soft cap bug (PR BasedHardware#5878, fixed in PR BasedHardware#5896). Script at `backend/scripts/unlock_soft_cap_locked.py` — reads UIDs from a file, verifies paid subscription (unlimited/pro), then unlocks all 3 collections. Dry-run by default. ## Usage (Cloud Run job) ```bash python scripts/unlock_soft_cap_locked.py --uids-file /tmp/impacted_uids.txt # dry-run python scripts/unlock_soft_cap_locked.py --uids-file /tmp/impacted_uids.txt --execute # apply ``` ## Impact - 8 users identified from prod logs, 6 are paid (unlimited), 2 basic (skipped) - 692 total items to unlock (649 conversations, 17 memories, 26 action items) Closes BasedHardware#5899
Summary
should_lock = Truefrom the soft cap trigger block insync.pytranscribe.pybehavior)Root Cause
PR #5878 incorrectly set
should_lock = Truewhen soft caps triggered in the sync endpoint. This caused unlimited users exceeding the 2h daily soft cap via sync to get all conversations immediately locked — bypassing the graduated enforcement system (WARNING → THROTTLE → RESTRICT).The equivalent code in
transcribe.py(WebSocket) correctly only triggers the classifier without locking.Impact
With
FAIR_USE_ENABLED=truein production, any user exceeding the daily soft cap through sync had their conversations locked immediately, regardless of subscription tier or classifier result.Test plan
py_compileverified on all router files🤖 Generated with Claude Code