Repository navigation
fix(personality): load metrics in-process instead of loopback fetches - #3634
Merged
Priyanshu-byte-coder merged 2 commits intoNov 14, 2026
Conversation
…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>
officialasishkumar
requested a review
from Priyanshu-byte-coder
as a code owner
November 12, 2026 14:58
|
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 |
Priyanshu-byte-coder
approved these changes
Nov 14, 2026
Priyanshu-byte-coder
merged commit Nov 14, 2026
53f6722
into
Priyanshu-byte-coder:main
13 checks passed
|
🎉 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/personalitystill 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 existingloadInsightMetrics()helper to call the handlers in-process.Closes #2585
Type of Change
What Changed
src/app/api/personality/route.ts: replaced the fourfetch(${baseUrl}/api/metrics/...)calls withloadInsightMetrics(request); removed theNEXTAUTH_URLbase URL and cookie forwarding.Retry-Afterwhen 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
npx vitest run test/personality-route.test.ts test/insight-metrics.test.ts test/ai-insights-ownership.test.ts.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
console.log, debug code, or commented-out blocksnpm run lintpasses locallynpm run type-check)