{"record":{"id":"80c1837861adcba7","repo":"instructure/canvas-lms","slug":"grading-could-not-be-completed-please-try-again","errorCode":null,"errorMessage":"Grading could not be completed. Please try again.","messagePattern":"Grading could not be completed\\. Please try again\\.","errorType":"exception","errorClass":"CedarAi::Errors::GraderError","httpStatus":null,"severity":"error","filePath":"app/services/auto_grade_orchestration_service.rb","lineNumber":98,"sourceCode":"    missing_criteria = get_criteria_missing_grades(auto_grade_result.grade_data, rubric)\n\n    if missing_criteria.any?\n      # filter rubric to only include missing criteria\n      relevant_rubric = rubric.data.select { |item| missing_criteria.include?(item[:description]) }\n\n      grade_data = GradeService.new(\n        assignment: assignment_text,\n        essay: self.class.extract_essay_text(submission),\n        rubric: relevant_rubric,\n        root_account_uuid:,\n        current_user: @current_user\n      ).call\n\n      merged_data = merge_new_grade_data_with_existing(grade_data, auto_grade_result.grade_data || [])\n\n      unless get_criteria_missing_grades(merged_data, rubric).empty?\n        Rails.logger.warn(\"[AutoGrade] Criteria count mismatch for submission #{submission.id}: got #{merged_data.length}, expected #{rubric.data.length}\")\n        raise CedarAi::Errors::GraderError, I18n.t(\"Grading could not be completed. Please try again.\")\n      end\n\n      auto_grade_result.update!(\n        root_account_id: submission.course.root_account_id,\n        grade_data: merged_data,\n        error_message: nil,\n        grading_attempts: auto_grade_result.grading_attempts + 1\n      )\n    end\n\n    auto_grade_result if auto_grade_result.persisted?\n  rescue => e\n    retryable = e.is_a?(CedarAi::Errors::GraderError)\n    handle_grading_failure(\n      error_message: \"Grading failed: #{e.message}\",\n      submission:,\n      auto_grade_result:,\n      progress:,","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/auto_grade_orchestration_service.rb#L80-L116","documentation":"AutoGradeOrchestrationService#get_grade_data (invoked by run_auto_grader) merges the AI grader's returned grade_data with existing grades, then validates that every rubric criterion has a grade. If get_criteria_missing_grades is non-empty (criteria count mismatch between merged data and rubric.data), it raises CedarAi::Errors::GraderError with a user-friendly retry message, treating the grader output as incomplete/invalid.","triggerScenarios":"Run the auto grader (Cedar AI) on a submission whose rubric expects N criteria but the grader's grade_data (after merge) covers fewer criteria or omits some criterion ids — e.g. the model returned a partial or malformed grade payload.","commonSituations":"LLM/ Cedar grader returning truncated JSON; rubric edited (criteria added/removed) after the grader prompt was built; rubric criteria whose descriptions the grader failed to match; retryable transient model output issues.","solutions":["Retry the auto-grading run — the message is explicitly 'Please try again'; transient grader output issues often resolve on a subsequent attempt.","Check the rubric criteria vs the grader output in AutoGradeResult.grade_data/logs and identify which criterion ids are missing.","If the rubric was recently edited, re-run grading so prompts are rebuilt from the current rubric.data.","Catch CedarAi::Errors::GraderError in the orchestration caller and fall back to manual grading or mark the auto-grade attempt failed."],"exampleFix":"// before\nresult = AutoGradeOrchestrationService.new(submission:).run_auto_grader # may raise GraderError\n\n// after\nbegin\n  result = AutoGradeOrchestrationService.new(submission:).run_auto_grader\nrescue CedarAi::Errors::GraderError => e\n  Rails.logger.warn(\"Auto-grade failed for submission #{submission.id}: #{e.message}\")\n  AutoGradeOrchestrationService.new(submission:).run_auto_grader # retry once\nend","handlingStrategy":"retry","validationCode":"merged = merge_new_grade_data_with_existing(grade_data, existing)\nmissing = get_criteria_missing_grades(merged, rubric)\nraise CedarAi::Errors::GraderError, \"missing criteria: #{missing.join(',')}\" unless missing.empty?","typeGuard":"def complete_grade_data?(grade_data, rubric)\n  grade_data.is_a?(Array) && grade_data.length == rubric.data.length\nend","tryCatchPattern":"begin\n  service.run_auto_grader\nrescue CedarAi::Errors::GraderError => e\n  Rails.logger.warn(\"Auto-grade incomplete: #{e.message}\")\n  service.run_auto_grader # retry; grader output is often transiently partial\nend","preventionTips":["Retry transient GraderErrors — the message itself requests it.","Re-run grading after any rubric edit so prompts match current criteria.","Log AutoGradeResult.grade_data on failure to identify which criteria the grader omitted."],"tags":["ai-grading","rubric","validation","auto-grader"],"backgroundTag":"unexpected-response-shape","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}