HOTFIX: app starts even if Pinecone is unreachable#282
Conversation
Root cause of production 502: OptimizedCodeIndexer.__init__() calls Pinecone API at import time (via dependencies.py singleton). When Pinecone connection is refused, entire app crashes before serving any requests. Railway health check never passes -> 502 on all endpoints. Fix: wrap Pinecone init in try/except. If connection fails: - self.index = None - App starts normally, health check passes - Dashboard (repos, usage, settings) works fine - Search/indexing return errors until Pinecone reconnects - Logged as error for monitoring This is the same pattern as our tree-sitter graceful fallback.
|
@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughChanged Pinecone initialization in the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@backend/services/indexer_optimized.py`:
- Around line 61-83: The startup code leaves self.index as None on Pinecone init
failure which causes later calls like self.index.upsert(...) to raise—add a
centralized guard: implement a private method _get_index() that returns a live
Pinecone Index or None and an _ensure_index(retry=False) helper that attempts to
(re)initialize Pinecone (using the same Pinecone(api_key...), list_indexes(),
create_index(...), and pc.Index(...) logic) with short retries/backoff and sets
self.index when successful; replace direct uses of self.index.upsert / query in
the indexing/query paths with a call to _ensure_index() or _get_index() and
short-circuit/skip the embedding/upsert work when it returns None (log a warning
and return early), so the process won't crash and will recover when Pinecone
becomes available again.
- Around line 64-81: The module-level initialization in OptimizedCodeIndexer is
doing synchronous Pinecone I/O (list_indexes, describe_index, create_index)
which blocks app startup; refactor to use Pinecone's async clients
(PineconeAsyncio and IndexAsyncio) and perform index setup asynchronously
(either lazy-initialize on first use or run inside the application's lifespan
startup task), e.g., replace synchronous Pinecone calls in the
OptimizedCodeIndexer constructor with an async init method (async_init or
ensure_index_async) that calls PineconeAsyncio.list_indexes(), describe_index(),
and create_index() and assigns IndexAsyncio to self.index, and ensure
dependencies.py stops instantiating OptimizedCodeIndexer at module import
(instantiate in lifespan or call the async init from the lifespan/startup task).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 18f8f90f-af62-4905-8075-a0f7f139a17d
📒 Files selected for processing (1)
backend/services/indexer_optimized.py
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
PRODUCTION DOWN -- 502 on all endpoints
Root cause:
OptimizedCodeIndexer.__init__()calls Pinecone API at import time viadependencies.pysingleton. When Pinecone returns 'connection refused' (see Sentry: RuntimeError 47 events), the entire app crashes before serving any requests.This is NOT caused by the tree-sitter changes. It's a pre-existing fragility exposed by the deploy restart.
Fix
Wrap Pinecone initialization in try/except:
self.index = None, app starts, health check passesSentry errors this fixes
1 file changed:
backend/services/indexer_optimized.pySummary by CodeRabbit