Skip to content

fix: resolve engineering debt — lazy init, auth unification, RAG fix#2

Open
ymstar wants to merge 2 commits into
masterfrom
fix/engineering-debt
Open

fix: resolve engineering debt — lazy init, auth unification, RAG fix#2
ymstar wants to merge 2 commits into
masterfrom
fix/engineering-debt

Conversation

@ymstar

@ymstar ymstar commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Changes

  1. Auth: merge auth.ts + user-sync.ts, real Clerk data on creation
  2. Supabase: lazy init to avoid import-time crash
  3. Embedding: fail loudly in production without OPENAI_API_KEY
  4. RAG: fix truncation direction (keep most relevant, not newest)
  5. pgvector: fix embedding type from number[] to string

Verification

  • tsc --noEmit: pass
  • vitest: 32/32 pass
  • next build: success
  • Browser: landing/sign-in/public API OK

ymstar added 2 commits June 4, 2026 09:33
1. auth.ts + user-sync.ts: merge into unified getDbUserId()
   - Now fetches real Clerk user data (email, name) on account creation
   - Removes user-sync.ts as redundant
   - Updates sync-user route to use getDbUserId()

2. embeddings.ts: replace scattered Supabase client with lazy getter
   - Module-level createClient() that read env vars at import time
     replaced with createServerClient() via lazy getter
   - Eliminates import-time crash when env vars are missing

3. embeddings.ts: fail loudly when OPENAI_API_KEY missing in production
   - Hash-based fallback now throws in NODE_ENV=production
   - Logs a warning in dev/test to make the fallback visible

4. rag.ts: fix truncation direction
   - slice(-MAX) kept the tail (least relevant); now slice(0, MAX)
     keeps the head (most relevant content from vector search)
The module-level createClient() with non-null assertions crashed
at import time when NEXT_PUBLIC_SUPABASE_URL was missing. This
blocked both dev server startup and production builds without env
vars configured.

- supabase export: changed from const to lazy getter function
- createServerClient(): reads env vars at call time, throws
  with clear error messages when vars are missing
- Nobody imports the supabase singleton directly; all callers
  use createServerClient()
@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aivault Ready Ready Preview, Comment Jun 4, 2026 2:10am

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