feat(labs): describe the lab task contract and the provisioner port

This commit is contained in:
shira committed 2026-10-11 15:40:14 +03:00
1 parent 3de226b16c
commit 9fdaa62b9b
91 files changed
+19262 -155

No files matched your search

+507
View File
@@ -1201,6 +1201,8 @@ paths:
description: |-
Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token, an allowed Origin, and an Idempotency-Key. The body names the item and carries the answer in the format of that item: `choice`, `number`, `string`, `order`, `find_error`, `configuration`, or `practice`. It never carries a score, a duration, or a correctness flag; the server records the times itself and scores the answer with the key of the fixed item instance. Time never enters the ability estimate or the grade decision.
Lab: an item with format `lab` takes no answer here. Its lab is started with CreateMyAssessmentLab and submitted with SubmitMyAssessmentLab; any answer to a lab item answers 400 validation_failed with the pointer `/answer/format`, like an answer in the wrong format, and stores nothing.
The response is the attempt with the next item to answer. It never says whether the answer was correct. Items are answered in order and each answer is final.
A work command requires an active session. After `idle_timeout_seconds` of inactivity, the candidate calls StartMyAssessmentAttemptSession to explicitly start or resume a session; this answer command never starts one or consumes session quota. Reading the attempt or result is always read-only. A command that finds a due deadline transition may commit it before returning; a command that finds an expired idle session answers 409 until the candidate explicitly starts the next session.
@@ -3832,6 +3834,310 @@ paths:
$ref: '#/components/responses/NotFound'
default:
$ref: '#/components/responses/Problem'
/api/v1/me/assessment-attempts/{attempt_id}/labs:
post:
operationId: CreateMyAssessmentLab
summary: Start the lab of the current lab item of an assessment attempt.
description: |-
Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token, an allowed Origin, and an Idempotency-Key. The body names the current item, whose content has the format `lab`.
The server asks the lab provisioner for a lab of the variant fixed for this item instance and answers 201 with the lab `provisioning`; the client polls GetMyAssessmentLab until it is `ready`. The lab lives until `expires_at`, the earlier of the item's `time_limit_seconds` and the attempt deadline, and is then deleted with everything done in it. Creating a lab does not change the attempt version, the current item, or any answer.
One lab per item at a time. While the item has a lab in `provisioning`, `ready`, or `checking`, the server answers 200 with that lab and starts no second one. After a `failed` lab the candidate may start a new one while the item is current; after `submitted` or `expired` the item cannot start another lab (409 state_conflict).
Busy pool. When the lab pool of the provisioner has no free capacity, the server answers 503 service_unavailable with Retry-After, for example `{"type": "urn:lincodex:problem:service_unavailable", "title": "Service unavailable", "status": 503, "code": "service_unavailable", "detail": "No lab capacity is free. The attempt is unchanged; retry later."}`. Nothing was stored: no lab exists, the attempt version and the current item are unchanged, the lab lifetime has not started, and the attempt is not consumed; the client retries after Retry-After with a new Idempotency-Key. When labs are not enabled on this server, or the provisioner cannot be reached, the server answers 503 service_unavailable without Retry-After and stores nothing either. The attempt deadline keeps running in both cases.
Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400), account scenario (403 forbidden), the Idempotency-Key (422, 409 idempotency_in_progress, replay), the attempt and the item (404 not_found for an unknown attempt or item, or one of another candidate), the state (409 state_conflict: the attempt is terminal or its work session ended, the item is not current, its format is not `lab`, or its lab was submitted or expired), the rate limit (429), then the availability of labs and the capacity (503). Following the Idempotency-Key convention, 201, 200, 404, and 409 state_conflict are stored under the key and replayed; 400, 429, and 503 are not.
security:
- sessionCookie: []
sessionCsrf: []
tags:
- assessment
parameters:
- $ref: '#/components/parameters/AssessmentAttemptId'
- $ref: '#/components/parameters/IdempotencyKey'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLabCreate'
examples:
start:
summary: Start the lab of the current item.
value:
item_id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a61
responses:
'200':
description: The item already has an active lab; it is returned and no second lab is started.
headers:
Cache-Control:
$ref: '#/components/headers/CacheControlNoStore'
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLab'
'201':
description: The lab was requested and is provisioning.
headers:
Cache-Control:
$ref: '#/components/headers/CacheControlNoStore'
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLab'
examples:
provisioning:
summary: A lab of two routers that is being prepared.
value:
id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a80
item_id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a61
state: provisioning
nodes:
- name: r1
kind: mikrotik
- name: r2
kind: mikrotik
created_at: '2026-10-11T09:00:00Z'
ready_at: null
expires_at: '2026-10-11T09:45:00Z'
finished_at: null
failure_reason: null
'400':
$ref: '#/components/responses/ValidationFailed'
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/CsrfCheckFailedOrForbidden'
'404':
$ref: '#/components/responses/NotFound'
'409':
$ref: '#/components/responses/AssessmentCommandConflict'
'422':
$ref: '#/components/responses/UnprocessableContent'
'429':
$ref: '#/components/responses/TooManyRequests'
'503':
$ref: '#/components/responses/ServiceUnavailable'
default:
$ref: '#/components/responses/Problem'
/api/v1/me/assessment-attempts/{attempt_id}/labs/{lab_id}:
get:
operationId: GetMyAssessmentLab
summary: Read the lab of an assessment attempt item.
description: |-
Requires the session cookie of a candidate account. Returns the state of a lab started with CreateMyAssessmentLab: whether it is still provisioning, ready for the consoles, being checked after the submission, or ended. It never contains a node address, a credential, the seed, the checker state, or the result of the check. This GET is read-only; the server may record a due timer transition, such as `ready` to `expired`, before it answers.
A lab of another candidate's attempt, a lab of another attempt, and an unknown identifier all answer 404 not_found.
security:
- sessionCookie: []
tags:
- assessment
parameters:
- $ref: '#/components/parameters/AssessmentAttemptId'
- name: lab_id
in: path
required: true
description: Identifier of a lab of this attempt.
schema:
type: string
format: uuid
responses:
'200':
description: The lab.
headers:
Cache-Control:
$ref: '#/components/headers/CacheControlNoStore'
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLab'
examples:
ready:
summary: A ready lab whose consoles can be opened.
value:
id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a80
item_id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a61
state: ready
nodes:
- name: r1
kind: mikrotik
- name: r2
kind: mikrotik
created_at: '2026-10-11T09:00:00Z'
ready_at: '2026-10-11T09:00:40Z'
expires_at: '2026-10-11T09:45:00Z'
finished_at: null
failure_reason: null
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
default:
$ref: '#/components/responses/Problem'
/api/v1/me/assessment-attempts/{attempt_id}/labs/{lab_id}/console-sessions:
post:
operationId: CreateMyAssessmentLabConsoleSession
summary: Open a console session of one node of a ready lab.
description: |-
Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token, and an allowed Origin. The body names a node of the lab by its task name.
The response describes one console session: the client opens a WebSocket to `websocket_path` on the same origin before `expires_at`. The upgrade is authorized by the session cookie and the Origin check, and the server relays the serial console of the node through the lab provisioner. The response never carries a node address, a port, a password, a key, or a token; the browser never connects to a node or to the provisioner. Console traffic is not stored as an answer and is not logged.
The WebSocket relay is planned together with the candidate interface of labs; this contract fixes the session shape it uses.
Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400), account scenario (403 forbidden), the attempt and the lab (404 not_found for an unknown attempt, lab, or one of another candidate), the node (400 with the pointer `/node`), the state (409 state_conflict: the lab is not `ready`, the attempt is terminal, or its work session ended), the limit of open sessions per lab (429 rate_limited with Retry-After), then the provisioner (503 service_unavailable without Retry-After; nothing was opened).
security:
- sessionCookie: []
sessionCsrf: []
tags:
- assessment
parameters:
- $ref: '#/components/parameters/AssessmentAttemptId'
- name: lab_id
in: path
required: true
description: Identifier of a lab of this attempt.
schema:
type: string
format: uuid
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLabConsoleSessionCreate'
examples:
r1:
summary: Open the console of r1.
value:
node: r1
responses:
'201':
description: The console session was opened.
headers:
Cache-Control:
$ref: '#/components/headers/CacheControlNoStore'
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLabConsoleSession'
examples:
opened:
summary: A console session of r1.
value:
id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a90
node: r1
websocket_path: /api/v1/me/assessment-lab-consoles/0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a90
expires_at: '2026-10-11T09:02:00Z'
'400':
$ref: '#/components/responses/ValidationFailed'
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/CsrfCheckFailedOrForbidden'
'404':
$ref: '#/components/responses/NotFound'
'409':
$ref: '#/components/responses/StateConflict'
'429':
$ref: '#/components/responses/TooManyRequests'
'503':
$ref: '#/components/responses/ServiceUnavailable'
default:
$ref: '#/components/responses/Problem'
/api/v1/me/assessment-attempts/{attempt_id}/labs/{lab_id}/submission:
post:
operationId: SubmitMyAssessmentLab
summary: Submit the lab of the current lab item as its answer.
description: |-
Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token, an allowed Origin, and an Idempotency-Key. The body carries the attempt version last read and the answer with format `lab`, which names the lab.
The server closes the consoles, freezes the lab, and answers 202 with the lab `checking`; the checker of the task reads the state of the nodes asynchronously, the answer is recorded, and the lab becomes `submitted` and is deleted. The client polls GetMyAssessmentLab and then reads the attempt, which moves to the next item. Neither response says whether the answer was correct, and the candidate never sees the checker criteria or their results.
When the checker cannot reach the nodes because of the lab infrastructure, the lab becomes `failed` with `lab_error`: nothing is recorded or consumed, the attempt version is unchanged, and the candidate may start a new lab of the item while it is current. A failure of the infrastructure is never scored as a wrong answer.
Optimistic concurrency: `expected_version` must equal the current attempt version, otherwise the server answers 412 version_conflict and stores nothing.
Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400), account scenario (403 forbidden), the Idempotency-Key (422, 409 idempotency_in_progress, replay), the attempt and the lab (404 not_found for an unknown attempt or lab, or one of another candidate), the version (412), the state (409 state_conflict: the lab is not `ready`, `answer.lab_id` is not the lab in the path, the item is not current, the attempt is terminal, or its work session ended), then the provisioner (503 service_unavailable without Retry-After; nothing was stored and the lab keeps running). Following the Idempotency-Key convention, 202, 404, and 409 state_conflict are stored under the key and replayed; 400, 412, 429, and 5xx are not.
security:
- sessionCookie: []
sessionCsrf: []
tags:
- assessment
parameters:
- $ref: '#/components/parameters/AssessmentAttemptId'
- $ref: '#/components/parameters/IdempotencyKey'
- name: lab_id
in: path
required: true
description: Identifier of the lab to submit.
schema:
type: string
format: uuid
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLabSubmission'
examples:
submit:
summary: Submit the lab as the answer of its item.
value:
expected_version: 7
answer:
format: lab
lab_id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a80
responses:
'202':
description: The submission was accepted and the lab is being checked.
headers:
Cache-Control:
$ref: '#/components/headers/CacheControlNoStore'
content:
application/json:
schema:
$ref: '#/components/schemas/AssessmentLab'
examples:
checking:
summary: A submitted lab whose nodes are being checked.
value:
id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a80
item_id: 0192a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a61
state: checking
nodes:
- name: r1
kind: mikrotik
- name: r2
kind: mikrotik
created_at: '2026-10-11T09:00:00Z'
ready_at: '2026-10-11T09:00:40Z'
expires_at: '2026-10-11T09:45:00Z'
finished_at: null
failure_reason: null
'400':
$ref: '#/components/responses/ValidationFailed'
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/CsrfCheckFailedOrForbidden'
'404':
$ref: '#/components/responses/NotFound'
'409':
$ref: '#/components/responses/AssessmentCommandConflict'
'412':
$ref: '#/components/responses/AssessmentVersionConflict'
'422':
$ref: '#/components/responses/UnprocessableContent'
'429':
$ref: '#/components/responses/TooManyRequests'
'503':
$ref: '#/components/responses/ServiceUnavailable'
default:
$ref: '#/components/responses/Problem'
components:
schemas:
Problem:
@@ -5712,6 +6018,7 @@ components:
- $ref: '#/components/schemas/FindErrorItemContent'
- $ref: '#/components/schemas/ConfigurationItemContent'
- $ref: '#/components/schemas/PracticeItemContent'
- $ref: '#/components/schemas/LabItemContent'
AssessmentItem:
type: object
description: 'Item instance served to the candidate. The variant is fixed when it is first served: a reload, a retried request, or a resumed session returns the same instance with the same text and option order. The item never says whether an earlier answer was correct, and seed items, which are not scored, are indistinguishable from scored ones.'
@@ -10531,6 +10838,206 @@ components:
description: Identifier of the marked item.
read_at:
$ref: '#/components/schemas/Timestamp'
AssessmentLabNodeName:
type: string
minLength: 1
maxLength: 15
pattern: ^[a-z][a-z0-9-]{0,14}$
description: Name of a lab node as the task statement uses it, such as `r1` or `srv`. It is a label of the task, not a host name or an address.
AssessmentLabNodeKind:
type: string
description: |-
What the console of a node shows.
- mikrotik: a MikroTik router with the RouterOS console.
- ubuntu: a small Ubuntu server with a Linux login.
Adding a value is a contract change.
enum:
- mikrotik
- ubuntu
AssessmentLabNode:
type: object
description: A node of a lab by its task name and kind. It never carries an address, a MAC address, a port, a password, a key, or an infrastructure name.
additionalProperties: false
required:
- name
- kind
properties:
name:
$ref: '#/components/schemas/AssessmentLabNodeName'
kind:
$ref: '#/components/schemas/AssessmentLabNodeKind'
LabItemContent:
type: object
description: 'Practical lab: configure or repair a small network of virtual nodes through their consoles. The candidate starts the lab of the item with CreateMyAssessmentLab, works in the node consoles, and submits with SubmitMyAssessmentLab; the server then checks the state of the nodes. The content lists only the nodes the statement names and the lifetime of the lab, never the checker, its criteria, the seed, or an address. SubmitMyAssessmentAnswer takes no answer to a lab item; its result is submitted only with SubmitMyAssessmentLab.'
additionalProperties: false
required:
- format
- nodes
- time_limit_seconds
properties:
format:
type: string
enum:
- lab
nodes:
type: array
minItems: 1
maxItems: 8
description: Nodes of the lab in the order of the statement.
items:
$ref: '#/components/schemas/AssessmentLabNode'
time_limit_seconds:
type: integer
format: int32
minimum: 300
maximum: 14400
description: Lifetime of a lab of this item from its creation. The lab also ends no later than the attempt deadline.
LabAnswer:
type: object
description: 'Answer of a lab item: the state of the nodes of the named lab at the moment of submission. The server reads that state with the checker of the task; the body carries no configuration text, score, or correctness flag. Two answers are equal when they name the same lab. It is the answer of SubmitMyAssessmentLab only and is not a member of AssessmentAnswer.'
additionalProperties: false
required:
- format
- lab_id
properties:
format:
type: string
enum:
- lab
lab_id:
type: string
format: uuid
description: The lab of this item that the candidate worked in.
AssessmentLabState:
type: string
description: |-
State of a lab of an attempt item.
- provisioning: the nodes are being prepared; poll GetMyAssessmentLab.
- ready: the consoles can be opened until `expires_at`.
- checking: the answer was accepted; the consoles are closed and the server checks the nodes.
- submitted: the check finished and the answer is recorded; the lab is deleted. The state never says whether the answer was correct.
- expired: the lifetime or the attempt deadline ended before a submission; the lab is deleted and the item cannot start another lab.
- failed: the lab infrastructure failed, independently of the candidate; `failure_reason` is `lab_error`. Nothing was recorded or consumed, and the candidate may start a new lab of the same item while the item is current.
Adding a value is a contract change.
enum:
- provisioning
- ready
- checking
- submitted
- expired
- failed
AssessmentLabFailureReason:
type: string
description: 'Why a lab failed: `lab_error` for an infrastructure failure, such as a node that did not boot or a check that could not reach a node. It never depends on the candidate and is never a failed check.'
enum:
- lab_error
AssessmentLab:
type: object
description: Candidate view of the lab of one attempt item. It contains no node address, MAC address, port, password, key, token, seed, checker state, criteria, score, or infrastructure name.
additionalProperties: false
required:
- id
- item_id
- state
- nodes
- created_at
- ready_at
- expires_at
- finished_at
- failure_reason
properties:
id:
type: string
format: uuid
description: Identifier of the lab.
item_id:
$ref: '#/components/schemas/AssessmentItemId'
state:
$ref: '#/components/schemas/AssessmentLabState'
nodes:
type: array
minItems: 1
maxItems: 8
items:
$ref: '#/components/schemas/AssessmentLabNode'
created_at:
$ref: '#/components/schemas/Timestamp'
ready_at:
description: Time the lab became `ready`, or null before.
oneOf:
- $ref: '#/components/schemas/Timestamp'
- type: 'null'
expires_at:
description: 'Time the lab ends unless it was submitted before: the earlier of the lifetime of the item and the attempt deadline. It never moves.'
$ref: '#/components/schemas/Timestamp'
finished_at:
description: Time the lab reached `submitted`, `expired`, or `failed`, or null.
oneOf:
- $ref: '#/components/schemas/Timestamp'
- type: 'null'
failure_reason:
description: '`lab_error` when `state` is `failed`, otherwise null.'
oneOf:
- $ref: '#/components/schemas/AssessmentLabFailureReason'
- type: 'null'
AssessmentLabCreate:
type: object
description: Start the lab of the current lab item. Unknown fields are rejected.
additionalProperties: false
required:
- item_id
properties:
item_id:
$ref: '#/components/schemas/AssessmentItemId'
AssessmentLabConsoleSessionCreate:
type: object
description: Open a console of one node of a ready lab. Unknown fields are rejected.
additionalProperties: false
required:
- node
properties:
node:
$ref: '#/components/schemas/AssessmentLabNodeName'
AssessmentLabConsoleSession:
type: object
description: A console session of one node. The client opens a WebSocket to `websocket_path` on the same origin before `expires_at`; the session cookie and the Origin check authorize the upgrade, so no secret travels in the path, the body, or a query string. A session can be attached once and ends with the lab.
additionalProperties: false
required:
- id
- node
- websocket_path
- expires_at
properties:
id:
type: string
format: uuid
description: Identifier of the console session; it is not a secret.
node:
$ref: '#/components/schemas/AssessmentLabNodeName'
websocket_path:
type: string
maxLength: 128
pattern: ^/api/v1/me/assessment-lab-consoles/[0-9a-f-]{36}$
description: Same-origin path of the console WebSocket.
expires_at:
description: Time by which the WebSocket must be opened.
$ref: '#/components/schemas/Timestamp'
AssessmentLabSubmission:
type: object
description: Submit the lab of the current lab item as its answer. Unknown fields are rejected, so a request cannot send a score or a correctness flag.
additionalProperties: false
required:
- expected_version
- answer
properties:
expected_version:
$ref: '#/components/schemas/AssessmentAttemptVersion'
answer:
$ref: '#/components/schemas/LabAnswer'
HealthResponse:
type: object
additionalProperties: false