Skip to content

Use enums for message types and handle server failures - #31

Merged
eliotwrobson merged 2 commits into
mainfrom
claude/message-type-enum
Nov 5, 2026
Merged

eliotwrobson merged 2 commits into
mainfrom
claude/message-type-enum

Conversation

@eliotwrobson

@eliotwrobson eliotwrobson commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

MessageType enum. The runner compared message types to raw strings, so a typo would silently match nothing. The runner, fixture and request types now use MessageType. The values sent over the socket don't change.

Server failures. When the sandbox server hits its own error, it sends {"status": "failure", "message": ...} and closes the connection. The grader never handled that shape, so it reached tests as a KeyError, and later queries failed with socket errors.

Not changed:

Testing

  • New test_server_failure scenario passes an argument the sandbox can't load, then checks the error, later queries and the message a student sees.
  • uv run pytest tests -p no:prairielearn-grader on Python 3.14: all 73 passed on two runs after merging main. Before that merge, the first run in a fresh environment failed only test_matplotlib_plots, a first-run failure also seen without this change.
  • mypy src/ is clean, and ruff check shows nothing new.
  • Lite image built from this branch's docker/ files, with this branch's wheel installed over the PyPI package. I confirmed the installed package contains the enum. With PrairieLearn's square tests and a hand-written data.json, a correct submission scored 1.0, and x_sq = Thing() scored 0.0 with Return serialization failures from query_raw normally #30's message. The server failure path itself is covered by the scenario, not by an image run on this merged code.
  • This branch merges cleanly into main after Return serialization failures from query_raw normally #30. All tests passed on a trial merge with Protect grader data from student code and load data.json in images #27 and Return serialization failures from query_raw normally #30 together, with one import line in fixture.py resolved by hand.

The full image wasn't built.

🤖 Generated with Claude Code

eliotwrobson and others added 2 commits November 5, 2026 13:32
The runner compared message types to raw strings, so a typo would silently match
nothing. They now use a MessageType enum, as does the "failure" status the server
sends for its own errors.

The grader never handled that failure response, so it reached tests as a KeyError,
and later queries failed with socket errors. Queries now raise a RuntimeError with
the server's message, and later queries raise the same error.

query_setup_raw isn't changed, to keep PR #27, which rewrites it, merging cleanly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/pytest_prairielearn_grader/fixture.py
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 5, 2026 19:59
@eliotwrobson
eliotwrobson merged commit 9a8cbd9 into main Nov 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant