Skip to content

fix(performance): replace loopback fetches with direct function calls to prevent serverless deadlocks#2586

Open
VIDYANKSHINI wants to merge 4 commits into
Umbrella-io:mainfrom
VIDYANKSHINI:fix-ai-insights-deadlock
Open

fix(performance): replace loopback fetches with direct function calls to prevent serverless deadlocks#2586
VIDYANKSHINI wants to merge 4 commits into
Umbrella-io:mainfrom
VIDYANKSHINI:fix-ai-insights-deadlock

Conversation

@VIDYANKSHINI

Copy link
Copy Markdown
Contributor

Summary

This PR completely resolves the serverless function exhaustion issue (504 Gateway Timeouts) in the AI Insights route. The previous implementation erroneously made HTTP fetch() loopback calls to its own API endpoints, which quickly exhausts execution workers in serverless environments. The fix refactors /api/ai-insights/route.ts to directly invoke the underlying imported API handler modules (getContributions, getPrs, getStreak, getRepos) completely bypassing the network stack and redundant NextAuth session decryption.

Closes #


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

What Changed

  • Refactored src/app/api/ai-insights/route.ts to remove 4 parallel fetch() calls hitting ${baseUrl}.
  • Imported the GET route handlers directly from the respective metrics files (src/app/api/metrics/*/route.ts).
  • Created a simulated NextRequest with the inherited Headers and Cookie to directly inject the authenticated session into the underlying handlers.
  • Preserved existing JSON parsing flows without changing the response structure.

How to Test

  1. Load the developer dashboard locally.
  2. Observe the AI Mentor widget fetching and summarizing metrics successfully.
  3. Inspect network tools; there should no longer be an explosion of loopback calls originating from the server context targeting /api/metrics/....

Expected result: The AI Mentor dashboard continues to work identically, but the backend is significantly more resilient and returns responses faster with zero serverless deadlocks.

Copilot AI review requested due to automatic review settings June 19, 2026 12:57

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:performance GSSoC type bonus: performance (+15 pts) type:feature GSSoC type bonus: new feature labels Jun 19, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants