Skip to content

Fix: Resolve 500 error in AI solver due to Neon/Drizzle initialization#288

Open
Krish-Makadiya wants to merge 4 commits into
knoxiboy:mainfrom
Krish-Makadiya:fix/issue-14-ai-solver-500
Open

Fix: Resolve 500 error in AI solver due to Neon/Drizzle initialization#288
Krish-Makadiya wants to merge 4 commits into
knoxiboy:mainfrom
Krish-Makadiya:fix/issue-14-ai-solver-500

Conversation

@Krish-Makadiya
Copy link
Copy Markdown
Contributor

Description

This PR resolves the 500 Internal Server Error that occurs when users submit questions to the AI solver.

The runtime crash was caused by the way drizzle-orm was initialized using the neon() helper from @neondatabase/serverless inside configs/db.tsx. To fix this, the configuration was updated to pass the connection string directly into the drizzle() initialization function, which is the recommended and stable syntax for modern drizzle-orm versions.

Additional Fixes Included to Unblock Builds:

  • Syntax Errors: Fixed severe syntax errors preventing successful builds, including duplicate component blocks and missing closing tags in app/(auth)/sign-in/[[...sign-in]]/page.tsx and app/(auth)/sign-up/[[...sign-up]]/page.tsx.
  • Duplicate Variables: Resolved duplicate replyId variable declarations in app/api/replies/action/[id]/route.ts and app/api/replies/vote/route.ts.
  • TypeScript Errors:
    • Fixed a strict TypeScript type-checking error in app/api/doubts/route.ts related to the dynamic replyCount property during the array .sort() operation.
    • Fixed an unused/invalid destructured property error from the validation schema in app/api/replies/action/[id]/route.ts.

Related Issue

Closes #14

@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

@Krish-Makadiya is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added size/m gssoc'26 GSSoC program issue level:intermediate Intermediate level task type:bug Bug fix labels May 24, 2026
@github-actions github-actions Bot requested a review from knoxiboy May 24, 2026 15:23
Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

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

Automated review: Thank you for starring the repository! The PR is approved.

Note: This PR currently has merge conflicts with the main branch. Please resolve the merge conflicts so we can complete the merge!

@knoxiboy knoxiboy added level:advanced Advanced level task and removed level:intermediate Intermediate level task labels May 25, 2026
@knoxiboy knoxiboy requested a review from Copilot May 25, 2026 10:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the AI solver /api/ask-ai 500 by adjusting the Neon/Drizzle database initialization, and includes additional TypeScript/syntax fixes to restore successful builds across several routes and auth pages.

Changes:

  • Update configs/db.tsx to initialize drizzle-orm/neon-http directly with the connection string (avoids Neon helper crash).
  • Clean up reply action/vote endpoints (remove duplicate/incorrect variable usage and align request parsing with schema validation).
  • Fix auth page syntax/structure issues and adjust doubts sorting code to satisfy TypeScript.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
configs/db.tsx Changes Drizzle initialization to use the connection string directly (addresses runtime crash source).
app/api/replies/vote/route.ts Removes redundant JSON parsing/validation in favor of centralized schema validation.
app/api/replies/action/[id]/route.ts Fixes duplicate replyId handling and narrows destructured schema fields to what’s used.
app/api/doubts/route.ts Adjusts sorting/pagination code to satisfy TS by casting (but reduces type safety).
app/(auth)/sign-up/[[...sign-up]]/page.tsx Fixes page structure/syntax issues and reinstates “Back to Home” link with themed Clerk UI.
app/(auth)/sign-in/[[...sign-in]]/page.tsx Fixes page structure/syntax issues and reinstates “Back to Home” link with themed Clerk UI.
Comments suppressed due to low confidence (1)

app/api/doubts/route.ts:149

  • The (doubts as any[]) cast on the sort drops type safety under strict and makes comparator logic easy to break (e.g., replyCount/createdAt typos won’t be caught). Prefer typing the mapped result as Array<typeof doubts[number] & { replyCount: number }> (or a dedicated DTO type) so both sort and the later slice can stay fully typed without any.
        doubts = (doubts as any[]).sort((a: any, b: any) => {
            const pinnedDiff = pinnedScore(b.isPinned) - pinnedScore(a.isPinned);
            if (pinnedDiff !== 0) return pinnedDiff;

            if (sort === "popular") {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread configs/db.tsx
Comment on lines 1 to 4
import { drizzle } from 'drizzle-orm/neon-http';
import { neon } from '@neondatabase/serverless';

const sql = neon(process.env.NEXT_PUBLIC_NEON_DB_CONNECTION_STRING!);
export const db = drizzle(sql);
export const db = drizzle(process.env.NEXT_PUBLIC_NEON_DB_CONNECTION_STRING!);

@knoxiboy
Copy link
Copy Markdown
Owner

Hi there! 👋 Thanks for your contribution to DoubtDesk.

It looks like there are currently some merge conflicts between your branch and the main branch. Could you please pull the latest changes from main, resolve the conflicts, and push the updates to this branch?

Once the conflicts are resolved and the PR is clean, we'll be able to merge it!

@Krish-Makadiya
Copy link
Copy Markdown
Contributor Author

Ready to be merged, solved the Conflicts!!

@github-actions github-actions Bot added size/s and removed size/m labels May 25, 2026
Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

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

Hi there! 👋 Thanks for your contribution to DoubtDesk.

It looks like there are currently some merge conflicts between your branch and the main branch. Could you please pull the latest changes from main, resolve the conflicts, and push the updates to this branch?

Once the conflicts are resolved and the PR is clean, we'll be able to merge it!

@knoxiboy
Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

@github-actions github-actions Bot requested a review from knoxiboy May 26, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc'26 GSSoC program issue level:advanced Advanced level task size/s type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AI solver returns 500 error when submitting prompts

3 participants