Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: cloud sync 'not logged in' bug - read fresh settings from store

Louis Beaumont21ca121a7b0e
diff --git a/.claude/agents/supabase.md b/.claude/agents/supabase.md
new file mode 100644
index 000000000..0b9c5f7bf
--- /dev/null
+++ b/.claude/agents/supabase.md
@@ -0,0 +1,231 @@
+---
+name: supabase
+description: Query Supabase for user data, subscriptions, credits, and support issues. Use when user asks about customers, credits, subscriptions, or needs to look up user information.
+tools: Bash, Read
+---
+
+# Supabase Database Skill
+
+Query and manage Supabase data for Screenpipe applications.
+
+## Configuration
+
+**URL:** Read `NEXT_PUBLIC_SUPABASE_URL` from `.env.local`
+**Service Key:** Read `SUPABASE_SERVICE_KEY` from `.env.local`
+
+### Loading Credentials
+
+**IMPORTANT:** Before running any Supabase query, load credentials:
+
+```bash
+export SUPABASE_URL=$(grep NEXT_PUBLIC_SUPABASE_URL .env.local | cut -d'"' -f2)
+export SUPABASE_KEY=$(grep SUPABASE_SERVICE_KEY .env.local | cut -d'"' -f2)
+```
+
+Or for screenpipe repo specifically:
+```bash
+export SUPABASE_URL=$(grep NEXT_PUBLIC_SUPABASE_URL /Users/louisbeaumont/Documents/screenpipe/.env.local | cut -d'"' -f2)
+export SUPABASE_KEY=$(grep SUPABASE_SERVICE_KEY /Users/louisbeaumont/Documents/screenpipe/.env.local | cut -d'"' -f2)
+```
+
+---
+
+## Database Schema Overview
+
+### Key Tables
+
+| Table | Purpose |
+|-------|---------|
+| `users` | User accounts (email, clerk_id, credits) |
+| `credits` | User credit balances |
+| `pending_credits` | Unclaimed purchases |
+| `cloud_subscriptions` | Active subscriptions |
+| `payments` | Payment history |
+
+### Key Functions (RPC)
+
+| Function | Purpose |
+|----------|---------|
+| `get_user_credit(user_email)` | Get user credit info |
+| `increase_user_credit(target_email, amount_to_add)` | Add credits |
+| `has_active_subscription_by_email(target_email)` | Check subscription |
+| `give_subscription_to_user_by_email(target_email, subscription_price_id)` | Grant subscription |
+| `get_subscription_details_by_email(target_email)` | Get subscription details |
+
+---
+
+## Common Queries
+
+### Look Up User by Email
+
+```bash
+curl -s "$SUPABASE_URL/rest/v1/users?email=eq.USER_EMAIL" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | python3 -m json.tool
+```
+
+### Get User Credit Balance
+
+```bash
+curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/get_user_credit" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"user_email": "USER_EMAIL"}' | python3 -m json.tool
+```
+
+### Check Credits Table Directly
+
+```bash
+# First get user ID, then query credits
+USER_ID="USER_UUID_HERE"
+curl -s "$SUPABASE_URL/rest/v1/credits?user_id=eq.$USER_ID" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | python3 -m json.tool
+```
+
+### Add Credits to User
+
+```bash
+curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/increase_user_credit" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"target_email": "USER_EMAIL", "amount_to_add": 100}'
+```
+
+### Check Subscription Status
+
+```bash
+curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/get_subscription_details_by_email" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"target_email": "USER_EMAIL"}' | python3 -m json.tool
+```
+
+### Check Pending Credits (Unclaimed Purchases)
+
+```bash
+curl -s "$SUPABASE_URL/rest/v1/pending_credits?email=eq.USER_EMAIL" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | python3 -m json.tool
+```
+
+---
+
+## Support Workflows
+
+### User Says "I Purchased But Have No Credits"
+
+1. Look up user:
+```bash
+curl -s "$SUPABASE_URL/rest/v1/users?email=eq.USER_EMAIL" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY"
+```
+
+2. Check credits table:
+```bash
+curl -s "$SUPABASE_URL/rest/v1/credits?user_id=eq.USER_ID" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY"
+```
+
+3. Check pending credits:
+```bash
+curl -s "$SUPABASE_URL/rest/v1/pending_credits?email=eq.USER_EMAIL&claimed=eq.false" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY"
+```
+
+4. If purchase verified (via Stripe), add credits:
+```bash
+curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/increase_user_credit" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"target_email": "USER_EMAIL", "amount_to_add": AMOUNT}'
+```
+
+### Grant Free Subscription
+
+```bash
+curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/give_subscription_to_user_by_email" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"target_email": "USER_EMAIL", "subscription_price_id": "PRICE_ID"}'
+```
+
+---
+
+## Admin Queries
+
+### List Recent Users
+
+```bash
+curl -s "$SUPABASE_URL/rest/v1/users?order=created_at.desc&limit=20" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | \
+ python3 -c "import sys,json; [print(f'{u[\"email\"]} - {u[\"created_at\"]}') for u in json.load(sys.stdin)]"
+```
+
+### List Users with Credits
+
+```bash
+curl -s "$SUPABASE_URL/rest/v1/credits?amount=gt.0&order=amount.desc&limit=20" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | python3 -m json.tool
+```
+
+### List Active Subscriptions
+
+```bash
+curl -s "$SUPABASE_URL/rest/v1/cloud_subscriptions?status=eq.active" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | python3 -m json.tool
+```
+
+### Get Sales Stats
+
+```bash
+curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/get_sales_stats" \
+ -H "apikey: $SUPABASE_KEY" \
+ -H "Authorization: Bearer $SUPABASE_KEY" | python3 -m json.tool
+```
+
+---
+
+## Query Syntax
+
+### Filters
+- `eq.VALUE` - Equals
+- `neq.VALUE` - Not equals
+- `gt.VALUE` - Greater than
+- `lt.VALUE` - Less than
+- `gte.VALUE` - Greater than or equal
+- `lte.VALUE` - Less than or equal
+- `like.*pattern*` - Pattern match
+- `ilike.*pattern*` - Case-insensitive pattern
+- `is.null` / `is.true` / `is.false`
+
+### Ordering
+- `order=column.asc`
+- `order=column.desc`
+
+### Pagination
+- `limit=N`
+- `offset=N`
+
+### Select Specific Columns
+- `select=col1,col2,col3`
+
+---
+
+## Important Notes
+
+1. **Service Key Required:** Use `SUPABASE_SERVICE_KEY` (not anon key) for admin operations
+2. **Never expose keys:** Always load from environment variables
+3. **User privacy:** Only query specific users when needed for support
+4. **Verify payments:** Cross-reference with Stripe before adding credits manually
diff --git a/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx b/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
index 320bba9d1..1bfeaa673 100644
--- a/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
+++ b/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
@@ -241,12 +241,12 @@ export const TimelineSlider = ({
// Calculate frame width based on zoom level
const frameWidth = useMemo(() => {
const baseWidth = 6; // 1.5 * 4 = 6px base (w-1.5 = 0.375rem = 6px)
- return Math.max(2, baseWidth * zoomLevel);
+ return Math.max(2, Math.round(baseWidth * zoomLevel));
}, [zoomLevel]);
const frameMargin = useMemo(() => {
const baseMargin = 2; // mx-0.5 = 0.125rem = 2px
- return Math.max(1, baseMargin * zoomLevel);
+ return Math.max(1, Math.round(baseMargin * zoomLevel));
}, [zoomLevel]);
// Animation state for new frames pulse
@@ -636,6 +636,10 @@ export const TimelineSlider = ({
? timeMarkers.find(m => m.position === visibleFrames.indexOf(frame))
: null;
+ const shouldShowTooltip = hoveredTimestamp
+ ? hoveredTimestamp === frame.timestamp
+ : frames[currentIndex]?.timestamp === frame.timestamp;
+
return (
<motion.div
key={`${frame.timestamp}-${frameIdx}`}
@@ -690,8 +694,7 @@ export const TimelineSlider = ({
)}
{/* Tooltip on hover */}
- {(hoveredTimestamp === frame.timestamp ||
- frames[currentIndex]?.timestamp === frame.timestamp) && (
+ {shouldShowTooltip && (
<div className="absolute bottom-full left-1/2 z-50 -translate-x-1/2 mb-2 w-max bg-popover border border-border rounded-lg px-3 py-2 text-xs shadow-2xl">
<div className="flex items-center gap-2 mb-1">
<img
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 48c5a3b7a..e4946fed9 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -8612,7 +8612,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.0.232"
+version = "2.0.234"
dependencies = [
"anyhow",
"async-stream",
@@ -8692,7 +8692,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"anyhow",
"bytemuck",
@@ -8740,7 +8740,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -8791,7 +8791,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"anyhow",
"chrono",
@@ -8815,7 +8815,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"anyhow",
"chrono",
@@ -8831,7 +8831,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"anyhow",
"image 0.25.5",
@@ -8846,7 +8846,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"anyhow",
"async-trait",
@@ -8910,7 +8910,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.26"
+version = "0.3.28"
dependencies = [
"accessibility-sys",
"anyhow",
diff --git a/screenpipe-app-tauri/src-tauri/src/sync.rs b/screenpipe-app-tauri/src-tauri/src/sync.rs
index 355291841..21ac52669 100644
--- a/screenpipe-app-tauri/src-tauri/src/sync.rs
+++ b/screenpipe-app-tauri/src-tauri/src/sync.rs
@@ -298,13 +298,18 @@ pub async fn remove_sync_device(
#[tauri::command]
#[specta::specta]
pub async fn init_sync(
- _app: AppHandle,
+ app: AppHandle,
state: State<'_, SyncState>,
- settings: State<'_, SettingsStore>,
+ _settings: State<'_, SettingsStore>,
password: String,
) -> Result<bool, String> {
- // Get auth token from settings
- let token = settings
+ // Get auth token from FRESH settings (not managed state which may be stale)
+ // The managed SettingsStore is loaded once at startup and doesn't update when user logs in
+ let fresh_settings = SettingsStore::get(&app)
+ .map_err(|e| format!("failed to read settings: {}", e))?
+ .ok_or_else(|| "settings not found".to_string())?;
+
+ let token = fresh_settings
.user
.token
.clone()
diff --git a/screenpipe-db/src/db.rs b/screenpipe-db/src/db.rs
index 97b2d0e0d..8ee604379 100644
--- a/screenpipe-db/src/db.rs
+++ b/screenpipe-db/src/db.rs
@@ -61,7 +61,8 @@ impl DatabaseManager {
}
let pool = SqlitePoolOptions::new()
- .max_connections(50)
+ // SQLite only allows a single writer; keep the pool modest to reduce write contention.
+ .max_connections(10)
.min_connections(3) // Minimum number of idle connections
.acquire_timeout(Duration::from_secs(10))
.connect(&connection_string)
@@ -72,6 +73,11 @@ impl DatabaseManager {
.execute(&pool)
.await?;
+ // Give writers time to wait for the lock instead of failing immediately.
+ sqlx::query("PRAGMA busy_timeout = 5000;")
+ .execute(&pool)
+ .await?;
+
// Optimize SQLite for search performance
// cache_size: -64000 = 64MB page cache (negative = KB)
// mmap_size: 256MB memory-mapped I/O for faster reads