Repository navigation
Return serialization failures from query_raw normally - #30
Merged
Merged
Conversation
When a student variable couldn't be serialized, the sandbox sent a failure message without the usual response fields and closed the connection. query then failed with KeyError: 'value', and later queries crashed with socket errors. The sandbox now serializes inside a try and sends a normal response with QueryStatusCode.NOT_SERIALIZABLE and an error naming the variable and its type, and keeps the connection open. query raises a RuntimeError with that message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eliotwrobson
marked this pull request as ready for review
November 5, 2026 18:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a student variable couldn't be serialized,
sandbox.queryfailed withKeyError: 'value'. The sandbox sent a failure message without the usual fields and closed the connection, so later queries failed withConnection closed by peer before termination character was found.This is the same problem #29 fixed forquery_function.Changes
try, covering bothto_jsonandjson.dumps, and stays connected.query_rawreturnsQueryStatusCode.NOT_SERIALIZABLEwitherrorset to a message likeVariable 'x' has a value of type Thing, which can't be sent back to the grader: ....queryraises aRuntimeErrorwith that message, so students see it throughassert_equal(sandbox.query("x_sq"), ...).StudentQueryResponsegains anerrorfield, which isNoneotherwise.quick_start.mdsection onquerynow describes these errors. It also said a missing variable raisesRuntimeError, but it raisesNameError, so I corrected that.The status name and
errorfield match #27'squery_setupresponse.Testing
test_query_not_serializablescenario covers the raw response, nested and self-referencing values,query,assert_equal, missing variables and later queries.uv run pytest tests -p no:prairielearn-graderon Python 3.14: all 72 passed on the second run. The first run in a fresh environment failed onlytest_matplotlib_plots, a first-run failure also seen without this change.mypy src/is clean, andruff checkshows nothing new.docker/files, with this branch's wheel installed over the PyPI package. I confirmed the installed package contains the new message. Graded with PrairieLearn'ssquaretests from itsconvert-python-squarebranch, asag, with a hand-writtendata.json:x_sqx_sqx_sq = Thing()Variable 'x_sq' has a value of type Thing, which can't be sent back to the grader: ...x = Thing()andy = 5and a hand-written test, also in that image:query_raw("x")returned the new status,query("x")raised the message, andquery("y")then returned 5.The full image wasn't built.
🤖 Generated with Claude Code