Skip to content

fix(personality): load metrics in-process instead of loopback fetches - #3634

Merged
Priyanshu-byte-coder merged 2 commits into
Priyanshu-byte-coder:mainfrom
officialasishkumar:fix/personality-route-loopback-fetch
Nov 14, 2026
Merged

Priyanshu-byte-coder merged 2 commits into
Priyanshu-byte-coder:mainfrom
officialasishkumar:fix/personality-route-loopback-fetch

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Summary

/api/personality still called four of its own metric routes over HTTP (the same pattern that was removed from /api/ai-insights), which can exhaust serverless workers. It now uses the existing loadInsightMetrics() helper to call the handlers in-process.

Closes #2585


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ⚡ Performance improvement

What Changed

  • src/app/api/personality/route.ts: replaced the four fetch(${baseUrl}/api/metrics/...) calls with loadInsightMetrics(request); removed the NEXTAUTH_URL base URL and cookie forwarding.
  • Unavailable or incomplete metrics now return 503 (429 plus Retry-After when upstream is cooling down) instead of being treated as zero activity and cached for 24 hours as a report. This matches /api/ai-insights.
  • test/personality-route.test.ts: asserts no self-fetch, the happy path writes the report, and the 503/429 paths write nothing.

How to Test

  1. Run npx vitest run test/personality-route.test.ts test/insight-metrics.test.ts test/ai-insights-ownership.test.ts.
  2. Sign in and open the Developer Personality widget; it still generates a report.

Expected result: The report is generated without any self-referencing HTTP request, and a metrics outage shows an error instead of a cached empty report.


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

…r HTTP

/api/personality fetched four of the app's own metric routes through
NEXTAUTH_URL, forwarding the session cookie. On serverless hosts each
request therefore needed four extra workers, which can exhaust the
pool and time out. /api/ai-insights already fixed this by calling the
metric handlers in-process through loadInsightMetrics(); do the same
here.

This also stops a failed or partial metric response from being
silently treated as zero activity and cached for 24 hours as a
personality report: the route now returns 503 (or 429 with
Retry-After when upstream is cooling down) and caches nothing,
matching /api/ai-insights.

Adds route tests asserting no self-fetch happens, the happy path
caches the report, and the 503/429 paths do not write to the cache.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts) labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown

Hi @officialasishkumar — thanks for the PR! 🙌

DevTrack asks contributors to ⭐ star the repo before a PR can be merged. It takes two seconds and is the easiest way to support the project.

Once you've starred, the star-required check turns green automatically (give it a moment). Thanks for contributing!

@Priyanshu-byte-coder
Priyanshu-byte-coder merged commit 53f6722 into Priyanshu-byte-coder:main Nov 14, 2026
13 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Merged! Thanks for contributing to DevTrack.

If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers.

Keep an eye on open issues for your next contribution!

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

Labels

type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [CRITICAL] Serverless Function Deadlocks via Self-Loopback Fetches in AI Insights Route

2 participants