Skip to content

fix: clamp recommended merge XP reward to difficulty tier cap (#216)#219

Open
Sujini-kudupudi wants to merge 6 commits into
Coder-s-OG-s:mainfrom
Sujini-kudupudi:fix-xp-rewards-cap
Open

fix: clamp recommended merge XP reward to difficulty tier cap (#216)#219
Sujini-kudupudi wants to merge 6 commits into
Coder-s-OG-s:mainfrom
Sujini-kudupudi:fix-xp-rewards-cap

Conversation

@Sujini-kudupudi
Copy link
Copy Markdown
Contributor

Summary

This PR resolves a data-integrity bug (issue #216) in the gamification reward pipeline. Previously, awardRecommendedMerge awarded the database-retrieved rec.xp_reward directly without validating it against the difficulty tier ceilings defined in XP_REWARDS.RECOMMENDED_MERGE.

This change introduces an application-layer clamp to ensure that recommendations with inflated XP amounts (due to manual DB edits, compromised migrations, or write-path errors) are capped safely.

Type of Change

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

Related Issue

Closes #216

What was changed?

  1. XP Clamping in Webhook Handler:

    • Imported XP_REWARDS into src/inngest/functions/process-pr-event.ts.
    • Clamped the database-retrieved rec.xp_reward to the difficulty tier ceiling (50 for Easy, 150 for Medium, 400 for Hard) as defined in XP_REWARDS.RECOMMENDED_MERGE.
    • Passed the clamped xpDelta to insertXpEvent and mapped the clamped value to xpAwarded in activity_log record details.
  2. Added Unit Tests:

    • Added 5 exhaustive unit test scenarios to src/inngest/functions/process-pr-event.test.ts to verify clamping behavior for Easy, Medium, and Hard difficulty levels, standard values under the cap, and null fallbacks.
  3. Verifications:

    • Verified that the full test suite (npm test) passes.
    • Verified TypeScript builds successfully with no errors (npm run typecheck).

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
Copy link
Copy Markdown
Contributor

vercel Bot commented May 25, 2026

@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.

Copy link
Copy Markdown
Collaborator

@Siddhartha-singh01 Siddhartha-singh01 left a comment

Choose a reason for hiding this comment

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

Nice clean fix @Sujini-kudupudi clamping at the application layer with
Math.min(rec.xp_reward ?? tierCap, tierCap) is the right defensive pattern, and
updating the activity_log to use xpDelta instead of the raw rec.xp_reward keeps
the audit trail consistent with what was actually credited. The XP_REWARDS lookup
with the xpForMerge fallback preserves the existing happy-path behavior, so this is
purely additive defense.

I checked the diff carefully recommendations.test.ts appears in the file list,
but the blob hash is identical to main's (PR #124 already landed there), so this is
just a three-dot diff artifact. Actual content delta is just process-pr-event.ts
(+11/-5) + process-pr-event.test.ts (+241). Clean scope.

Only thing before merge: CI hasn't run yet could a maintainer approve the workflow
so CI / check actually executes on the latest commit? Once it's green, this is
ready to merge.

LGTM once CI is green ✅

@Sujini-kudupudi
Copy link
Copy Markdown
Contributor Author

@Coder-s-OG-s/maintainers Thanks for the review, Siddhartha! Could a maintainer please approve the Vercel deployment and trigger the CI workflow for the latest commit? Once the checks are green, this should be ready to merge.

@Siddhartha-singh01
Copy link
Copy Markdown
Collaborator

@Sujini-kudupudi I have checked everything is actually working good don't worry we will good to merge this pr !

Thanks!

@Soumya-codr Soumya-codr added bug Something isn't working GSSOC26 GirlScript Summer of Code 2026 level:intermediate Intermediate level difficulty quality:clean Clean, well-structured contribution gssoc:approved Approved by GSSOC admin NSoC'26 NSoc level 1 labels May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gssoc:approved Approved by GSSOC admin GSSOC26 GirlScript Summer of Code 2026 level:intermediate Intermediate level difficulty NSoc level 1 NSoC'26 quality:clean Clean, well-structured contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] awardRecommendedMerge uses rec.xp_reward from the database without capping to the difficulty-tier maximum, enabling XP inflation

3 participants