Skip to content

20 Troubleshooting

Vicky Patel edited this page Sep 14, 2026 · 1 revision

20. Troubleshooting & Common Solutions

Diagnostic guides and resolutions for common setup, database, testing, and build issues in PACT OS.


🛠️ Common Category Index

  1. #1 Database & Supabase RLS Issues
  2. #2 Timezone & Day Boundary Behavior
  3. #3 Local Setup & Dependency Errors
  4. #4 Next.js Turbopack & Build Errors

1. Database & Supabase RLS Issues

Symptom: error: infinite recursion detected in policy for relation "profiles"

  • Cause: A Row Level Security (RLS) policy on Table A queries Table B, whose policy in turn queries Table A, creating a circular dependency during policy evaluation.
  • Fix: Avoid cross-table policy queries. Reference auth.uid() directly or use security-definer helper functions:
    -- ✅ Recommended RLS Policy Pattern
    CREATE POLICY "Users can access own data"
      ON public.tasks FOR ALL
      USING (auth.uid() = user_id);

Symptom: Query returns 0 rows when data exists in database

  • Cause: User is not authenticated or auth.uid() does not match user_id on target rows.
  • Fix: Verify session token via supabase.auth.getUser(). Inspect RLS policies using tests/adversarial-rls-audit.sql.

2. Timezone & Day Boundary Behavior

Symptom: Habit streaks reset unexpectedly at midnight

  • Cause: Application clock evaluated in UTC instead of user's localized timezone (profiles.timezone).
  • Fix: Use localized day boundary conversions in src/lib/time.ts:
    import { localToUtc, utcToDatetimeLocalInput } from '@/lib/time';

3. Local Setup & Dependency Errors

Symptom: npm test fails due to missing Supabase credentials

  • Cause: Environmental assumption that tests require a cloud database connection.
  • Fix: All 56 domain test suites mock database dependencies locally and run 100% offline. Ensure dependencies are installed via npm install and run:
    npm test

4. Next.js Turbopack & Build Errors

Symptom: dunce::canonicalize OS permission error during next build on Windows

  • Cause: Windows OS path permission traversal constraints when running Next.js Turbopack in restricted sandbox environments.
  • Fix: Run build commands outside restricted sandboxes or bypass sandbox restrictions:
    node node_modules/next/dist/bin/next build

Clone this wiki locally