Skip to content

fix(#314): enforce maximum difficulty cap in recommendation fallback paths#339

Open
Sujini-kudupudi wants to merge 5 commits into
Coder-s-OG-s:mainfrom
Sujini-kudupudi:fix-recommendation-fallback-difficulty
Open

fix(#314): enforce maximum difficulty cap in recommendation fallback paths#339
Sujini-kudupudi wants to merge 5 commits into
Coder-s-OG-s:mainfrom
Sujini-kudupudi:fix-recommendation-fallback-difficulty

Conversation

@Sujini-kudupudi

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue where users could receive issues beyond their allowed difficulty cap (e.g. Level 0 receiving Medium or Hard issues) via fallback paths when the difficulty pool runs dry or when skipping an issue.

Type of Change

  • Bug fix
  • New feature
  • UI / UX improvement
  • Refactor
  • Documentation
  • Other

Related Issue

Closes #314

What was changed?

  • Updated filterAndRank in src/lib/pipeline/recommend.ts to strictly cap the fallback difficulty based on the user's level (e.g., Level 0 allows ['E'] only).
  • Updated the skipRecommendation action in src/app/actions/recommendations.ts to fetch the user's level from the profiles table.
  • Passed level into pickReplacement to calculate allowed difficulties and applied .in('difficulty', allowedDifficulties) during the broad pool fallback query.
  • Rewrote the fallback unit test in src/lib/pipeline/recommend.test.ts to correctly assert that the fallback mechanism respects the max difficulty cap.

Screenshots

N/A

Checklist

  • My code follows the project structure and conventions
  • I tested this locally (npm run dev)
  • No hardcoded secrets or credentials
  • I have updated documentation if needed

@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@Sujini-kudupudi is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Ayush-Patel-56

Copy link
Copy Markdown
Collaborator

@Sujini-kudupudi can you please fix the failing CI test

@Sujini-kudupudi

Copy link
Copy Markdown
Contributor Author

@Ayush-Patel-56 Could you please check it once?

@Ayush-Patel-56

Copy link
Copy Markdown
Collaborator

@Sujini-kudupudi its still failing

@nikhildhamdhere15

Copy link
Copy Markdown

@Sujini-kudupudi It looks like the CI pipeline is still failing on the CI / check step after your last commit. Could you check the build logs or test outputs again?

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
mergeship Ready Ready Preview, Comment Jun 20, 2026 4:40am

@jakharmonika364 jakharmonika364 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also this PR has a bunch of unrelated stuff mixed in (resend bump, the issues.ts Octokit rewrite, as any casts in supabase/server.ts) - can we split those out? Makes this harder to review than it needs to be.

The filterAndRank fix itself looks right.

Comment on lines +293 to +297
const { data: profile } = await service
.from('profiles')
.select('level')
.eq('user_id', user.id)
.single();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

profiles has no user_id column, it's id (every other lookup in the codebase uses .eq('id', user.id)). This silently fails and userLevel defaults to 0 always - error isn't checked. Should be .eq('id', user.id).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recommendation fallback can hand out Hard issues to Level 0 users

4 participants