fix: clamp recommended merge XP reward to difficulty tier cap (#216)#219
fix: clamp recommended merge XP reward to difficulty tier cap (#216)#219Sujini-kudupudi wants to merge 6 commits into
Conversation
|
@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. |
Siddhartha-singh01
left a comment
There was a problem hiding this comment.
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 ✅
|
@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. |
|
@Sujini-kudupudi I have checked everything is actually working good don't worry we will good to merge this pr ! Thanks! |
Summary
This PR resolves a data-integrity bug (issue #216) in the gamification reward pipeline. Previously,
awardRecommendedMergeawarded the database-retrievedrec.xp_rewarddirectly without validating it against the difficulty tier ceilings defined inXP_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
Related Issue
Closes #216
What was changed?
XP Clamping in Webhook Handler:
XP_REWARDSintosrc/inngest/functions/process-pr-event.ts.rec.xp_rewardto the difficulty tier ceiling (50 for Easy, 150 for Medium, 400 for Hard) as defined inXP_REWARDS.RECOMMENDED_MERGE.xpDeltatoinsertXpEventand mapped the clamped value toxpAwardedinactivity_logrecord details.Added Unit Tests:
src/inngest/functions/process-pr-event.test.tsto verify clamping behavior for Easy, Medium, and Hard difficulty levels, standard values under the cap, and null fallbacks.Verifications:
npm test) passes.npm run typecheck).Screenshots
N/A
Checklist
npm run dev)