Skip to content

[Bugfix:Autograding] Fix negative number tolerance#12569

Merged
bmcutler merged 9 commits into
Submitty:mainfrom
Akarshkushwaha:fix-negative-tolerance-grading-clean
May 1, 2026
Merged

[Bugfix:Autograding] Fix negative number tolerance#12569
bmcutler merged 9 commits into
Submitty:mainfrom
Akarshkushwaha:fix-negative-tolerance-grading-clean

Conversation

@Akarshkushwaha

@Akarshkushwaha Akarshkushwaha commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Why is this Change Important & Necessary?

Fixes #10702

Tolerance grading does not work correctly with negative numbers. When the expected output is a negative value like -5.5 with a tolerance, the isolateAlphanumAndNumberPunctuation function in grading/clean.cpp strips the leading minus sign, turning -5.5 into 5.5. This causes a student submitting 5.5 to incorrectly receive full credit when -5.5 is expected, because both values are compared as the same positive number.

What is the New Behavior?

The autograder now correctly preserves the leading minus sign on negative numbers during tolerance comparison. A student submitting 5.5 when -5.5 is expected will now correctly receive 0 points, as abs(-5.5 - 5.5) = 11.0 exceeds the tolerance.

What steps should a reviewer take to reproduce or test the bug or new feature?

  1. Create a gradeable with tolerance grading that expects a negative number (e.g., -5.5 with tolerance 0.5)
  2. Submit a solution that outputs the positive version (5.5)
  3. Before this fix: student receives full credit (incorrect)
image
  1. After this fix: student receives 0 points (correct)
image

Automated Testing & Documentation

  • Added negative_tolerance test case to the tolerance_check integration test suite
  • Added corresponding sample submission negative_tolerance.py
  • Ran standalone C++ unit tests covering positive numbers, negative numbers, and edge cases (--5, 1-2, -, empty string) — all passed

Other information

  • Not a breaking change
  • No migrations needed
  • No security concerns

@Akarshkushwaha

Copy link
Copy Markdown
Contributor Author

@williamjallen @JManion32
This PR fixes #10702 — tolerance grading was incorrectly accepting positive numbers when negative values were expected, due to the minus sign being stripped in [isolateAlphanumAndNumberPunctuation]. Would appreciate a review when you get a chance.

@codecov

codecov Bot commented Mar 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.64%. Comparing base (7f44c21) to head (c088c06).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main   #12569   +/-   ##
=========================================
  Coverage     21.64%   21.64%           
  Complexity     9654     9654           
=========================================
  Files           268      268           
  Lines         36244    36244           
  Branches        487      487           
=========================================
  Hits           7845     7845           
  Misses        27916    27916           
  Partials        483      483           
Flag Coverage Δ
autograder 21.32% <ø> (ø)
js 2.04% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.66% <ø> (ø)
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Eli-J-Schwartz Eli-J-Schwartz self-assigned this Mar 13, 2026
@Eli-J-Schwartz

Copy link
Copy Markdown
Contributor

Hi @Akarshkushwaha
I tried to test this PR locally, but the problem doesn't seem to be fixed, as shown in the screenshot below:
Screenshot 2026-03-13 at 15-21-26 neg_tol - Sample
I'm not sure if it's an issue in the code or with the way I tested the problem.
Here is my testing config.json:

{
    "assignment_message": "Calculate average and standard deviation given a list of number by filtering only positive numbers. Result expected with a precision of three decimal places.",
    "required_capabilities": "python",
    "autograding_method": "docker",
    "container_options": {
        "container_image": "submitty/python:latest"
    },
    "testcases": [
    {
      "title" : "Allow Minor Numeric Noise (+/-0.05 Tolerance)",
      "command" : [ "python3 *.py" ],
      "points" : 10,
      "validation": [
        {
          "description": "diff w/ tolerance=0.05",
          "method": "diff",
          "tolerance": 0.05,
          "actual_file": "STDOUT.txt",
          "expected_file": "test_output.txt",
          "deduction": 1,
          "failure_message":"These files have numeric errors > 0.05 or whitespace or text differences."
        }
      ]
    }
  ]
}

I rebuilt the autograder using submitty_install, but it's possible this didn't recompile the autograder correctly. Can you provide more specific details on how you compiled you change?

@Akarshkushwaha

Akarshkushwaha commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Eli-J-Schwartz Thankyou for testing this out locally.

Your config.json is perfectly correct! I believe the issue is simply with the way the C++ autograder builds local executables.

When you ran sudo submitty_install, the build system successfully ran CMake to compile my updated C++ changes into the core libsubmitty_grading.a library.

However, because Submitty's autograder relies on static linking, existing gradeables do not automatically inherit these changes. Their validate.out executables are still statically linked to the old, unpatched version of the library. Running submitty_install updates the core files, but it doesn't automatically recompile existing gradeables.

How to test the fix:

  1. Keep your exact config.json—it is correct!
  2. Go to your neg_tol gradeable in the web UI -> Edit Gradeable -> Autograding.
  3. Click the "Build Gradeable" button at the bottom.

Clicking "Build Gradeable" forces Submitty to re-run CMake specifically for that assignment, linking the newly patched libsubmitty_grading.a into a fresh validate.out executable.

Once I clicked "Build Gradeable" on my end using a config identical to yours, I submitted 5.5 against an expected -5.5. The autograder successfully preserved the minus sign, detected the error, and correctly gave me 0 points
image

Let me know if rebuilding the gradeable from the UI works for you

@automateprojectmangement automateprojectmangement Bot moved this from Seeking Reviewer to In Review in Submitty Development Mar 22, 2026

@Eli-J-Schwartz Eli-J-Schwartz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @Akarshkushwaha,
Thank you for the help on testing your changes. The tolerance check now works as intended for me; see the screenshots below for examples.

Image Image Image Image

The code also looks good; the changes are all clearly documented and seem to be free of bugs.

However, I noticed that the PR is failing a couple of tests. The CI / Cypress (Gradable) test is a known test failure on the main branch, and not a problem with your code. The CI / Integration test seems to be an issue with your modified testing code. It looks like your added test isn't integrated properly with the testing framework, causing an error. Additionally, it's possible that your changes have modified the output of earlier tests. Once the tests are fixed, I think this PR is good to merge.

@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Mar 24, 2026
@Akarshkushwaha
Akarshkushwaha force-pushed the fix-negative-tolerance-grading-clean branch from 8573553 to b8787ef Compare March 25, 2026 09:37
@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Mar 26, 2026

@Eli-J-Schwartz Eli-J-Schwartz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm glad to see that the tests are passing, and the new test you added seems like it's properly integrated with the rest of the tests as well. I think you might have accidentally removed the fewer spaces test; if you add it back I will approve this PR.

@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Mar 27, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Mar 28, 2026

@Eli-J-Schwartz Eli-J-Schwartz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All my previous requests were implemented as necessary. Everything else looks good.

@github-project-automation github-project-automation Bot moved this from In Review to Awaiting Maintainer Review in Submitty Development Mar 29, 2026
@williamjallen williamjallen moved this from Awaiting Maintainer Review to Ready to Merge in Submitty Development Mar 29, 2026
@bmcutler
bmcutler merged commit 621d276 into Submitty:main May 1, 2026
@github-project-automation github-project-automation Bot moved this from Ready to Merge to Done in Submitty Development May 1, 2026
prestoncarman added a commit that referenced this pull request May 21, 2026
* main: (50 commits)
  [Bugfix:Developer] Fix Broken CI (#12851)
  [Bugfix:System] Restore TCLAPP (#12850)
  [Bugfix:Submission] Fix non-VCS repo error (#12608)
  [Feature:Submission] Jupyter warnings outside notebook (#12523)
  [Bugfix:InstructorUI] Removed feature flag for Bulk Late Days (#12826)
  [Bugfix:Forum] Fix stats header rendering (#12698)
  [Bugfix:Autograding] Fix negative number tolerance (#12569)
  [Bugfix:HelpQueue] Always use Abbreviated Names in OH (#12820)
  [Bugfix:Autograding] Fix regrade team detection (#12737)
  [Dependency] Bump Lichen from v23.09.00 to v26.04.01 (#12823)
  [Dependency] Bump RainbowGrades from v25.10.00 to v26.04.01 (#12824)
  [Feature:Developer] Remove misc Java utils and TCLAPP (#12819)
  [Bugfix:TAGrading] Fix 2-panel open-document select (#12577)
  [Dependency] Bump AnalysisToolsTS from v23.10.00 to v26.04.00 (#12822)
  [Bugfix:Developer] Fix bump_repo permissions (#12821)
  [Bugfix:InstructorUI] Change Colors to match in Docker UI table (#12739)
  [Bugfix:Forum] Reduce Page Caching (#12339)
  [Bugfix:System] File lost when running install clean fix (#12158)
  [Bugfix:Submission] No File Rubric submit all user groups (#12812)
  [Dependency] Bump twig/markdown-extra from 3.23.0 to 3.24.0 in /site (#12721)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Fix Tolerance Grading for Negative Numbers

4 participants