Grading protocol 1
How a player that holds only the view gets verdicts from a backend. Any language can implement it; @astl/server
is the reference implementation for Fetch-API runtimes (Node 22+, Deno, Bun, Cloudflare Workers, Hono).
Endpoints
Section titled “Endpoints”{endpoint} identifies one attempt, for example https://api.example.com/attempts/123. How the request is
authorised (cookie, bearer token, signed URL) is the host's business, and so is identifying the attempt: the host maps
{endpoint} to the attempt it authorised and hands that attempt to the grader. A grader never derives the attempt
from anything else in the request (extra path segments, the query, the body); from the path it reads only the final
segment, the action.
| Method and path | Request body | Success |
|---|---|---|
POST {endpoint}/check |
CheckRequest |
200 CheckResponse |
POST {endpoint}/submit |
SubmitRequest |
200 SubmitResponse |
POST {endpoint}/hint |
HintRequest |
200 HintResponse |
- Request and response bodies are JSON (
Content-Type: application/json), UTF-8, at most 256 KiB. checkexists only under a practice policy. Under a test policy it answers403check_not_allowed, so a test never leaks verdicts before submission. Withelementit grades one interaction only, when the policy'scheckScopeisinteraction(the practice default); it counts againstmaxCheckslike any check. Withelementsit grades the interactions a Check for several questions names, at once, under the same rule: one check, counted once.- Upgrade the grader with the player or before it. A grader before 0.3 does not know
elementsand grades the whole exercise for such a check; a 0.3 player then takes only the results of the check's own questions. hintgives the next hint of one interaction or page, only when the practice policy offers hints (hints, on by default in practice). The grader records every hint it gives; later checks and the submit take their costs off.submitis final: a second submit answers409attempt_closed.- Responses never contain answer-key data. Solutions are sent only by
submitand only when the policy reveals answers. Hints, feedback texts and explanations are key-side data too: see Help for students.
Bodies
Section titled “Bodies”TypeScript definitions live in @astl/core (checker.ts, result.ts, answers.ts). JSON:
// CheckRequest: page, element or elements, all optional, at most one of them{ "answers": { "kd3f...": "Gray", "ka0b...": "true" }, "page": "k7q2..." }{ "answers": { "kd3f...": "Gray" }, "element": "kd3f..." }{ "answers": { "kd3f...": "Gray", "kx91...": "colour" }, "elements": ["kd3f...", "kx91..."] }
// CheckResponse{ "result": { "score": 1, "max": 2, "correct": false, "slots": { "kd3f...": "correct" }, "groups": [ { "id": "kd3f...", "verdict": "correct", "score": 1, "max": 1 }, { "id": "kx91...", "verdict": "incorrect", "score": 0, "max": 1 } ], "pages": { "k7q2...": { "score": 1, "max": 2 } }, "counts": { "correct": 1, "partial": 0, "incorrect": 1, "empty": 0, "total": 2 } }, "checksLeft": null, // only when the policy shows them now, and only those with a text "feedback": { "kd3f...": { "variant": "correct", "html": "Well done." } }, "explanations": { "kx91...": "<p>Grey is the British spelling.</p>" }}
// SubmitRequest{ "answers": { "kd3f...": "Gray" } }
// SubmitResponse (feedback and explanations as in CheckResponse, when the policy shows them at the hand-in){ "result": { "...": "as above" }, "solution": { "kd3f...": "grey" }, "passed": true, "submittedAt": "2026-10-29T08:00:00.000Z" }
// HintRequest: a view element id, or a view page id for the page's own hints{ "element": "kd3f..." }
// HintResponse: index is 0-based, left counts the hints still to come, cost is the fraction 0..1 it takes off{ "html": "It starts with <em>G</em>.", "index": 0, "left": 1, "cost": 0.25 }Answers are strings only:
| Slot kind | Answer |
|---|---|
text, number |
what the student typed |
choice |
opaque id of the picked option |
flag |
"true" when selected; absent otherwise |
letter |
one letter (a crossword square); compared in capitals of the content language |
open |
what the student wrote, for the teacher; never graded |
A missing key, "" or a value longer than its slot kind allows counts as unanswered: 500 characters, 2000 for an
open slot, counted in Unicode code points. Unknown slot ids are ignored. A server stores a submission's answers
within those limits only (open answers included: Metadata.open lists their ids).
Errors
Section titled “Errors”Errors are application/problem+json (RFC 9457) with a machine-readable code:
| Status | code |
When |
|---|---|---|
| 400 | invalid_request |
body is not JSON or does not match the schema (a check with more than one of page, element and elements, or elements that is not 1 to 1000 ids, too) |
| 401 | unauthorized |
the host cannot identify the attempt |
| 403 | check_not_allowed |
check under a non-practice policy, or of element or elements when checkScope is exercise |
| 403 | checks_exhausted |
practice maxChecks used up |
| 403 | hints_not_allowed |
hint under a policy without hints (tests, hints: false) or a grader that records none |
| 403 | hints_exhausted |
every hint of that interaction or page is used |
| 404 | not_found |
unknown attempt, page or element, or one of elements (for hint: one without hints) |
| 405 | method_not_allowed |
not POST |
| 409 | attempt_closed |
already submitted |
| 413 | payload_too_large |
body over 256 KiB |
| 500 | internal_error |
anything else |
{ "type": "urn:astrolabe:problem:check_not_allowed", "title": "Checking is not allowed in this attempt", "status": 403, "code": "check_not_allowed" }Grading rules
Section titled “Grading rules”The server grades with engine.grade(key, answers, { page, element, elements, hintsUsed }) from @astl/engine (or a port that
passes the conformance fixtures). Rules: see Scoring. Deadlines are enforced by
the server; the player only shows a countdown.
hintsUsed counts the hints given by view element or page id. Each hint has a cost, a fraction 0..1 of the points:
the first n hints of an interaction take their costs off each group of it, a page's hints off each group on that
page. A score never goes below 0 and the verdict stays as it was, so a student who needed every hint still sees that
the answer is right.
Help for students
Section titled “Help for students”Hints, an explanation and feedback texts (<astl-hint cost>, <astl-explanation>, <astl-feedback when> in the
content format) usually give the answer away, so compile moves them into the answer key
(AnswerKey.help). The view only says what an interaction or page offers: hints="0 0.25" (the cost of each hint),
explanation and feedback="correct incorrect". A grader sends them as the attempt's policy says:
AttemptPolicy field |
Values | Practice default | Test default |
|---|---|---|---|
hints |
true, false |
true |
false (never in a test) |
checkScope |
exercise, interaction |
interaction |
exercise (always in a test) |
feedback |
never, check, submit |
check |
submit |
explanations |
never, check, submit |
check |
submit |
The fields are optional: a policy without them gets its mode's defaults, so policies stored before keep working.
check sends help with check responses; submit (and check) with the submit response, and only when the policy
reveals answers (reveal: "answers"), since a feedback text names the right answer as surely as a solution does.
helpPolicy(policy) from @astl/core and helpShown(policy, "check" | "submit") from @astl/engine apply these
rules.
What a response carries is for what it graded: each graded interaction's feedback for its verdict and its explanation,
and, unless the check named element or elements, each graded page's own, its feedback picked by the page's overall
verdict.
The variants are correct, incorrect, partial (an interaction or page partly right; without its own text it gets
the incorrect one) and omitted (nothing answered). resultHelp(key, result, helpShown(policy, moment), element)
(element: the one id, or the list of elements)
and nextHint(key, id, used) from @astl/engine build these bodies.
A grader records hints itself: the request never says how many were used. @astl/server keeps them in
AttemptRecord.hintsUsed through the store's recordHint, and passes them to every later grade. A host that
re-grades a submission later passes them too: engine.grade(key, answers, { hintsUsed: record.hintsUsed }).