codeworksacademy / challenges.codeworksacademy.com

https://challenges.codeworksacademy.com
2 stars 2 forks source link

Bugs/Challenge grading crashes backend #28

Closed koreangeekman closed 8 months ago

koreangeekman commented 8 months ago

Describe the bug When we grade a challenge (manual, not auto-graded) with a 'completed' status, the backend crashes Happened twice on me today and seems to have been something that has happened before from a comment by AJ

Payload is sent, Response is received, then any attempt to pull data becomes unresponsive - finding the 'server' side no longer running in VSCode

koreangeekman commented 8 months ago

A quick follow of the debug and the entire process seems to run and even returns the expected data, matching the point where the client side receives a response - then right after crashes the back-end.

koreangeekman commented 8 months ago

Two called functions ran without awaits on the gradeParticipant function within the ChallengesService - applying awaits found an issue triggered from the awardExperience(participant) function and with this throws an error instead of crashing the backend.

awardExperience is functional with the auto-grade path but now seems to be an issue with this manual grading

gradeParticipant > awardExperience > accountService.calculateAccountRank

{
    "error": {
        "message": "MongoServerError: E11000 duplicate key error collection: 652ea751b7f6145c3e3066e1_evergreen.accounts index: subs_1 dup key: { subs: null }",
        "status": 400
    },
    "url": "/api/challenges/65ce48706534bf83cbb663f5/participants/65d3c9bdd789bfde8ebd2dca"
}
koreangeekman commented 8 months ago

Updating shared variable names: RANK_BADGE -> RANK_TITLE MILESTONE_BADGE -> MILESTONE_TIER

Resolved first issue with duplicate on null subs found in mergeSubsIfNeeded account function with a null check. Follow-up issue found with users of higher rank not able to progress further - issue related to users at rank Matrix Master All submissions before this rank progress

{
    "error": {
        "message": "TypeError: Cannot read properties of undefined (reading 'NAME')",
        "status": 400
    },
    "url": "/api/challenges/65d7c1dbdc54dbbf6045d488/submit"
}
koreangeekman commented 8 months ago

With further testing and shifting the point requirements, I believe the issue is related to there being no badge options beyond tier 12 and the challenge completions were pushing the xp count over tier 12 from tier 10 (points awarded are too high per completion + rank tiers were not spaced well by points originally) - which means there was no null-check and rank lookup prevention for xp above prescribed tiers.

koreangeekman commented 8 months ago

calculateAccountRank logic included necessary checks but didn't apply the resulting check to the account title save and so that final assign pre-save bypassed the checks causing the error. Bug fix to be included in Issue #27's branch.