Repository navigation
Add migration script to unlock conversations locked by sync soft cap bug - #5901
Conversation
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]>
Greptile SummaryThis PR adds a one-off migration script (
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Operator
participant Script as unlock_soft_cap_locked.py
participant Firestore
Operator->>Script: python script.py --uids-file /tmp/uids.txt [--execute]
Script->>Script: read_uids(filepath) → [uid1, uid2, ...]
loop for each UID
Script->>Firestore: users/{uid}.get(['subscription'])
Firestore-->>Script: {plan: 'unlimited'|'pro'|'basic'|null}
alt plan not in PAID_PLANS
Script->>Script: SKIP (log warning)
else plan in PAID_PLANS
Script->>Firestore: count_locked(uid, 'conversations')
Script->>Firestore: count_locked(uid, 'memories')
Script->>Firestore: count_locked(uid, 'action_items')
Firestore-->>Script: counts per collection
alt dry-run (default)
Script->>Script: log counts (no writes)
else --execute
Script->>Firestore: batch.update is_locked=False (conversations)
Script->>Firestore: batch.update is_locked=False (memories)
Script->>Firestore: batch.update is_locked=False (action_items)
Firestore-->>Script: commits acknowledged
end
end
end
Script->>Operator: Summary log (total processed / skipped / unlocked)
Reviews (1): Last reviewed commit: "Add migration script to unlock conversat..." | Re-trigger Greptile |
| def get_subscription_plan(db, uid: str) -> str | None: | ||
| """Read the user's subscription plan from Firestore.""" | ||
| doc = db.collection('users').document(uid).get(['subscription']) | ||
| if not doc.exists: | ||
| return None | ||
| data = doc.to_dict() | ||
| sub = data.get('subscription', {}) | ||
| return sub.get('plan') |
There was a problem hiding this comment.
Subscription validity (status/expiry) not checked
get_subscription_plan reads only the raw plan field from Firestore. It does not check status or current_period_end, so a user whose paid subscription has since expired (or is inactive) would still pass the PAID_PLANS gate and have their conversations unlocked.
The backend already has get_user_valid_subscription in database/users.py that enforces this: for paid plans it verifies current_period_end >= now() before returning a valid subscription.
This is likely acceptable given the narrow 8-user scope and tight timeline (bug was introduced and fixed within a short window), but it's worth a conscious decision either way. If any affected user's subscription lapsed between the bug being introduced (PR #5878) and this fix running, this script would still unlock their data. Conversely, if you believe the lock was wrong regardless of current subscription status, the current approach is intentionally permissive.
If you want to add the validity guard, get_subscription_plan could additionally check sub.get('status') == 'active' and validate current_period_end against the current timestamp for paid plans.
| if count % 499 != 0: | ||
| batch.commit() |
There was a problem hiding this comment.
Empty batch committed when count is 0
When count == 0 (no locked documents found), 0 % 499 == 0 is True, so the in-loop commit never fires — but if count % 499 != 0 is also False, meaning the trailing batch.commit() is correctly skipped. This is actually fine.
However, if count is exactly a multiple of 499 (e.g., 499, 998, …), the loop commits the last full batch and resets batch = db.batch(). After the loop, count % 499 == 0 again, so the guard correctly avoids committing the newly-created empty batch. The logic is sound, though it could be made more explicit by tracking whether the trailing batch is actually non-empty:
if count > 0 and count % 499 != 0:
batch.commit()This makes the intent clearer to readers and eliminates any confusion about the count == 0 case.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
POST /v1/admin/fair-use/user/{uid}/unlock — verifies paid subscription
(unlimited/pro) then unlocks conversations, memories, and action items.
Uses existing unlock functions from payment flow. Related: #5899.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Unlock is not a fair-use operation — it's a general admin remediation for the sync soft cap bug. Moving to users.py instead. Co-Authored-By: Claude Opus 4.6 <[email protected]>
General admin endpoint to unlock conversations, memories, and action items for paid users. Verifies subscription before unlocking. Used to remediate the sync soft cap locking bug. Related: #5899. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Manager prefers Cloud Run job pattern for one-off migrations over permanent admin endpoints. Script at scripts/unlock_soft_cap_locked.py will be run as a Cloud Run job instead. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
lgtm |
Migration CompleteCloud Run job Results
Timeline
No further action needed. All impacted paid users are fully restored. by AI for @beastoin |
…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
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)
Impact
Closes #5899