Skip to content

HOTFIX: app starts even if Pinecone is unreachable#282

Merged
DevanshuNEU merged 1 commit into
OpenCodeIntel:mainfrom
DevanshuNEU:fix/lazy-pinecone-init
Mar 6, 2026
Merged

HOTFIX: app starts even if Pinecone is unreachable#282
DevanshuNEU merged 1 commit into
OpenCodeIntel:mainfrom
DevanshuNEU:fix/lazy-pinecone-init

Conversation

@DevanshuNEU

@DevanshuNEU DevanshuNEU commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator

PRODUCTION DOWN -- 502 on all endpoints

Root cause: OptimizedCodeIndexer.__init__() calls Pinecone API at import time via dependencies.py singleton. 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:

  • If Pinecone is reachable: works exactly as before
  • If Pinecone is unreachable: self.index = None, app starts, health check passes
  • Dashboard endpoints (repos, usage, settings) work fine
  • Search/indexing fail gracefully until Pinecone reconnects

Sentry errors this fixes

  • RuntimeError: Pinecone connection refused at pinecone-prod.svc.us-east1.aws:443 (47 events)

1 file changed: backend/services/indexer_optimized.py

Summary by CodeRabbit

  • Bug Fixes
    • Application now gracefully handles Pinecone indexing service unavailability during startup. If the indexing service is unreachable, the application will continue running with indexing functionality disabled, allowing other features to operate normally. Errors are logged appropriately for troubleshooting.

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.
@vercel

vercel Bot commented Mar 6, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Mar 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Changed Pinecone initialization in the OptimizedCodeIndexer class from eager to lazy-safe mode. Index creation now occurs within error handling, allowing the application to start even if Pinecone is unavailable. Added private attribute to store index name and public index attribute initialized to None.

Changes

Cohort / File(s) Summary
Pinecone Initialization Refactoring
backend/services/indexer_optimized.py
Deferred Pinecone index creation to a try/except block with error logging. Added _pinecone_index_name private attribute for storing index name and index public attribute initialized to None. Index assignment occurs only after successful Pinecone setup, preventing startup crashes if Pinecone is unavailable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hops with glee

Lazy loading's the name of the game,
No crashes when Pinecone's not in frame,
Errors caught with grace so fine,
Indexing waits for the perfect time,
Our service keeps hopping along!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: enabling graceful startup when Pinecone is unreachable, which is the core fix addressing the production incident.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f93099 and f942f49.

📒 Files selected for processing (1)
  • backend/services/indexer_optimized.py

Comment thread backend/services/indexer_optimized.py
Comment thread backend/services/indexer_optimized.py
@vercel

vercel Bot commented Mar 6, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
opencodeintel Ignored Ignored Preview Mar 6, 2026 9:59pm

@DevanshuNEU DevanshuNEU merged commit 20604de into OpenCodeIntel:main Mar 6, 2026
7 checks passed
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