Skip to content

Fix: sync soft cap trigger incorrectly locking conversations - #5896

Merged
beastoin merged 3 commits into
mainfrom
fix/sync-soft-cap-no-lock
Mar 22, 2026
Merged

beastoin merged 3 commits into
mainfrom
fix/sync-soft-cap-no-lock

Conversation

@beastoin

Copy link
Copy Markdown
Collaborator

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 #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

  • 26/26 unit tests pass (including new structural test)
  • py_compile verified on all router files
  • Deploy and verify no locked conversations for unlimited sync users

🤖 Generated with Claude Code

beastoin and others added 2 commits March 22, 2026 08:10
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-apps

greptile-apps Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a regression from #5878 where the sync endpoint was immediately locking conversations for any user who exceeded the daily soft cap, bypassing the intended graduated enforcement system (WARNING → THROTTLE → RESTRICT). The fix removes a single incorrectly-added should_lock = True line from the soft cap trigger block and adds a structural regression test.

  • Root cause fixed: should_lock = True was set when triggered_caps fired in sync.py, whereas transcribe.py (the WebSocket path) only fires trigger_classifier_if_needed async — the PR aligns the two paths.
  • Enforcement flow restored: After the fix, should_lock is only set to True via not has_transcription_credits(uid) (line 729). The classifier result from trigger_classifier_if_needed determines any subsequent enforcement action independently of the current request.
  • Regression test added: test_soft_cap_does_not_lock uses source-code structural parsing to assert that the triggered_caps block never sets should_lock. The test has a minor gap: if if triggered_caps: is ever removed from the source, the test silently passes without asserting anything (see inline comment).

Confidence Score: 5/5

  • Safe to merge — minimal one-line fix with a verified test suite and correct alignment to the existing enforcement architecture.
  • The change is a single-line deletion that restores the intended soft-cap behavior documented in the enforcement design. It is backed by a new structural test, has zero risk of side-effects on unrelated paths, and exactly mirrors the already-correct transcribe.py behavior. The only open item is a minor test robustness gap (P2) that doesn't affect production correctness.
  • No files require special attention beyond the minor test robustness note on backend/tests/unit/test_sync_fair_use_gate.py.

Important Files Changed

Filename Overview
backend/routers/sync.py Single-line fix removing should_lock = True from the soft cap trigger block, correctly aligning sync endpoint behavior with transcribe.py (WebSocket path).
backend/tests/unit/test_sync_fair_use_gate.py New structural test verifies the soft cap block never sets should_lock; minor robustness gap — the test silently passes if the if triggered_caps: block is removed entirely.

Sequence Diagram

sequenceDiagram
    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)
Loading

Last reviewed commit: "Add test: soft cap t..."

Comment on lines +282 to +297
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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:

Suggested change
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]>
@beastoin

Copy link
Copy Markdown
Collaborator Author

Workflow Checkpoints Complete

All checkpoints passed for PR #5896:

Checkpoint Status Evidence
CP7 — Reviewer APPROVED CODEx review: fix correct, edge cases verified, is_hard_restricted gate unaffected
CP8 — Tester APPROVED 31/31 tests pass, structural + behavioral coverage, test in test.sh
CP9A — L1 Local PASS AST verification: triggered_caps block has only logger.info + asyncio.create_task, no should_lock. All 43 routers py_compile clean
CP9B — L2 Integrated PASS Cross-file AST: sync.py and transcribe.py triggered_caps blocks structurally identical (2 Expr statements, no should_lock)

Changed-path coverage

Path ID Changed path Happy-path Non-happy-path Result
P1 sync.py:sync_local_files — removed should_lock=True AST: no should_lock in block Credits exhausted still locks (behavioral test) PASS
P2 test_sync_fair_use_gate.py:TestLockDecisionBehavior 5/5 tests pass N/A (test code) PASS
P3 test_sync_fair_use_gate.py:test_soft_cap_does_not_lock Structural assertion passes N/A (test code) PASS

Ready for merge. All checkpoints passed. Awaiting manager approval.

by AI for @beastoin

@beastoin

Copy link
Copy Markdown
Collaborator Author

lgtm

@beastoin
beastoin merged commit 6e632ba into main Mar 22, 2026
1 of 2 checks passed
@beastoin
beastoin deleted the fix/sync-soft-cap-no-lock branch March 22, 2026 08:24
beastoin added a commit that referenced this pull request Mar 22, 2026
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]>
beastoin added a commit that referenced this pull request Mar 22, 2026
…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
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…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)
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
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]>
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant