Files
lincodex/api/runner/openapi.bundle.yml
T

634 lines
24 KiB
YAML

openapi: 3.2.0
info:
title: Lincodex Code Runner API
version: 0.1.0
description: |-
Internal API of the own code runner. Only the Go backend calls it; it is
never exposed to browsers or to the public network.
Transport and authentication: the runner listens on a private network
interface of its dedicated host and serves HTTPS (TLS 1.3). Every
operation except the health routes requires `Authorization: Bearer
<token>`; the token is a shared random secret of at least 32 characters
that comes from the deployment secret store, never from this repository.
A missing or wrong token answers 401 `unauthenticated`. Plain HTTP exists
only behind an explicit development switch of the local Compose file.
Data minimization: a run carries only the language, the source code, the
limits, and the test groups. It has no candidate, account, attempt, or
task identifiers, names, or contacts. The run ID is a random UUID chosen
by the backend for idempotency; the runner keeps it only in memory.
Runs are asynchronous. SubmitRun accepts a run when a sandbox slot is free
and answers immediately; the caller polls GetRun until `state` is
`finished`. The runner does not queue runs: when every slot is busy it
answers 503 `runner_busy`, and the backend keeps the queue.
servers:
- url: /
security:
- bearerAuth: []
paths:
/healthz:
get:
operationId: GetRunnerHealthz
summary: Check whether the runner process is responding.
security: []
tags:
- health
responses:
'200':
description: The runner process is responding.
content:
application/json:
schema:
$ref: '#/components/schemas/RunnerHealthResponse'
default:
$ref: '#/components/responses/Problem'
/readyz:
get:
operationId: GetRunnerReadyz
summary: Check whether the sandbox is prepared to accept runs.
description: Ready means that the cgroup hierarchy, the work directory, and the sandbox binary were prepared at startup and the process is not draining. A busy runner is still ready; busy is reported by SubmitRun.
security: []
tags:
- health
responses:
'200':
description: The sandbox is prepared.
content:
application/json:
schema:
$ref: '#/components/schemas/RunnerReadinessResponse'
'503':
description: The sandbox is not prepared or the process is draining.
content:
application/json:
schema:
$ref: '#/components/schemas/RunnerReadinessResponse'
default:
$ref: '#/components/responses/Problem'
/v1/runs/{run_id}:
parameters:
- name: run_id
in: path
required: true
description: Random UUID chosen by the backend for one logical run. It is the idempotency key of SubmitRun and must not encode a candidate, attempt, or task identifier.
schema:
type: string
format: uuid
put:
operationId: SubmitRun
summary: Start a sandboxed run of one source against its test groups.
description: |-
Idempotent by `run_id`:
- a new ID with a free sandbox slot starts the run and answers 202 with `state: running`;
- the same ID with the same payload answers 200 with the current state of that run, including the finished result, without running it again;
- the same ID with a different payload answers 422 `idempotency_key_reused` and changes nothing;
- a new ID while every slot is busy, or while the runner is draining, answers 503 `runner_busy` with Retry-After; nothing is stored, so the caller retries with the same ID.
Payloads are compared by a SHA-256 fingerprint of the decoded request.
The runner keeps runs only in memory for a bounded time after they
finish; an ID that was forgotten or lost in a restart starts a new run.
Requests above the configured body limit (8 MiB by default) answer 413
`payload_too_large`. Semantic rules that the schema cannot express answer
400 `validation_failed`: group IDs are unique in a run, test IDs are
unique in a group, and the number of tests multiplied by
`limits.time_limit_ms` does not exceed 300000.
tags:
- runs
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/RunRequest'
responses:
'200':
description: A run with this ID and the same payload already exists.
content:
application/json:
schema:
$ref: '#/components/schemas/RunStatus'
'202':
description: The run was accepted and started.
content:
application/json:
schema:
$ref: '#/components/schemas/RunStatus'
'503':
$ref: '#/components/responses/RunnerBusy'
default:
$ref: '#/components/responses/Problem'
get:
operationId: GetRun
summary: Read the state and, when finished, the per-group result of a run.
description: Answers 404 `not_found` for an ID the runner does not hold, including a run forgotten after its retention time or lost in a restart.
tags:
- runs
responses:
'200':
description: The current state of the run.
content:
application/json:
schema:
$ref: '#/components/schemas/RunStatus'
default:
$ref: '#/components/responses/Problem'
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
description: 'Shared random service token sent as `Authorization: Bearer <token>` over TLS. The runner compares it in constant time and never logs it. Rotation replaces the secret on both sides; there are no per-user tokens.'
responses:
Problem:
description: Any error response. The body is a Problem whose `status` equals the HTTP status and whose `code` is one of ProblemCode.
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
examples:
validation_failed:
summary: Request fields do not match the contract
value:
type: urn:lincodex:problem:validation_failed
title: Request validation failed
status: 400
code: validation_failed
detail: One or more request fields are invalid.
errors:
- in: body
pointer: /groups/1/id
code: invalid
message: The value does not match the contract.
idempotency_key_reused:
summary: The run ID was used with a different payload
value:
type: urn:lincodex:problem:idempotency_key_reused
title: Run ID reused with a different payload
status: 422
code: idempotency_key_reused
detail: A run with this ID exists with a different payload.
RunnerBusy:
description: Every sandbox slot is busy or the runner is draining; code runner_busy. Nothing was stored. Retry with the same run ID after Retry-After.
headers:
Retry-After:
description: Number of seconds to wait before retrying the request.
required: true
schema:
type: integer
format: int32
minimum: 0
maximum: 3600
example: 2
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
examples:
runner_busy:
summary: No free sandbox slot
value:
type: urn:lincodex:problem:runner_busy
title: Runner busy
status: 503
code: runner_busy
detail: Every sandbox slot is busy. Retry later with the same run ID.
schemas:
ProblemCode:
type: string
description: |-
Stable error code of the runner API. Adding a code is a contract change; renaming or removing one is a breaking change. Clients must handle an unknown code by its HTTP status.
- validation_failed (400): parameters or body do not match the contract or a semantic rule of SubmitRun; `errors` points at the fields.
- unauthenticated (401): the bearer token is missing or wrong.
- not_found (404): the route or the run does not exist.
- method_not_allowed (405): the route does not support the method.
- payload_too_large (413): the request body exceeds the limit.
- unsupported_media_type (415): the request Content-Type is not accepted.
- idempotency_key_reused (422): the run ID was already used with a different payload.
- internal (500): unexpected server error.
- runner_busy (503): every sandbox slot is busy or the runner is draining; see Retry-After.
The Problem shape is the api/core shape; only this enum is specific to the runner.
enum:
- validation_failed
- unauthenticated
- not_found
- method_not_allowed
- payload_too_large
- unsupported_media_type
- idempotency_key_reused
- internal
- runner_busy
ProblemFieldLocation:
type: string
description: Part of the request that contains the invalid field.
enum:
- body
- query
- path
- header
- cookie
ProblemFieldError:
type: object
description: One reason why a request field or parameter is invalid.
additionalProperties: false
required:
- in
- pointer
- code
- message
properties:
in:
$ref: '#/components/schemas/ProblemFieldLocation'
pointer:
type: string
maxLength: 1024
pattern: ^(/([^~/]|~[01])*)*$
description: JSON Pointer (RFC 6901). For `body` it points into the request body document, for example `/limits/time_limit_ms`; an empty string means the whole body. For a parameter it is `/` followed by the parameter name, for example `/run_id`.
code:
type: string
minLength: 1
maxLength: 64
pattern: ^[a-z][a-z0-9_]*$
description: Stable field reason. Current values are `required` (missing value) and `invalid` (malformed value or a value outside the schema). Clients must tolerate new values.
message:
type: string
minLength: 1
maxLength: 500
description: Fixed English message that never echoes the submitted value.
Problem:
type: object
description: Problem details (RFC 9457) returned with the application/problem+json media type for every error response. This is the runner copy of the public api/core Problem schema; keep both copies identical except for descriptions and the ProblemCode enum. `code` is the stable, machine-readable reason; clients branch on it rather than on `title`, `detail`, or the HTTP status alone. The body never contains internal error text, stack traces, SQL, file paths, credentials, contact data, or echoed request values.
additionalProperties: false
required:
- type
- title
- status
- code
properties:
type:
type: string
format: uri-reference
maxLength: 256
description: URI that identifies the problem type. It has the form `urn:lincodex:problem:<code>` and is an identifier, not a link to dereference.
title:
type: string
minLength: 1
maxLength: 200
description: Short, fixed English summary of the problem type. It does not change between occurrences.
status:
type: integer
format: int32
minimum: 400
maximum: 599
description: HTTP status code generated by the origin server.
code:
$ref: '#/components/schemas/ProblemCode'
detail:
type: string
maxLength: 1000
description: Safe English explanation of this occurrence. It never contains internal error text or request values.
instance:
type: string
format: uri-reference
maxLength: 2048
description: URI reference that identifies this occurrence, when one exists.
trace_id:
type: string
minLength: 1
maxLength: 128
pattern: ^[A-Za-z0-9._-]+$
description: Request identifier of the call when the caller propagated one; it is not a secret.
errors:
type: array
maxItems: 100
description: Field-level reasons for validation_failed. Other codes omit it.
items:
$ref: '#/components/schemas/ProblemFieldError'
RunnerHealthResponse:
type: object
additionalProperties: false
required:
- status
properties:
status:
type: string
enum:
- ok
RunnerReadinessResponse:
type: object
additionalProperties: false
required:
- status
properties:
status:
type: string
enum:
- ready
- not_ready
RunState:
type: string
description: '`running` until every group was evaluated or the run failed; `finished` when `result` is final.'
enum:
- running
- finished
RunOutcome:
type: string
description: |-
Outcome of a test, a group, a compile step, or a whole run.
- accepted: the program exited with status 0 within every limit and the checker accepted the output.
- wrong_answer: the program exited with status 0 within every limit, but the checker rejected the output.
- compile_error: the source was rejected before any test ran (for Python, a syntax error).
- time_limit_exceeded: the CPU time limit or the wall-clock limit stopped the program.
- memory_limit_exceeded: the cgroup memory limit stopped the program.
- output_limit_exceeded: the program wrote more standard output than the limit.
- runtime_error: the program exited with a non-zero status, was killed by a signal, or reached the process limit.
- infrastructure_failure: the runner could not evaluate the source; the outcome says nothing about the program, and the caller may retry with a new run ID.
A run's outcome is compile_error or infrastructure_failure when that happened, otherwise the outcome of the first failed test in request order, otherwise accepted. A group's outcome is the outcome of its first failed test, otherwise accepted.
enum:
- accepted
- wrong_answer
- compile_error
- time_limit_exceeded
- memory_limit_exceeded
- output_limit_exceeded
- runtime_error
- infrastructure_failure
CompileResult:
type: object
additionalProperties: false
required:
- outcome
properties:
outcome:
$ref: '#/components/schemas/RunOutcome'
diagnostic:
type: string
maxLength: 4096
description: Compiler or syntax checker message for compile_error, truncated to the limit. It can quote the source, never test data.
TestKey:
type: string
minLength: 1
maxLength: 32
pattern: ^[a-z0-9][a-z0-9_-]{0,31}$
description: Opaque label chosen by the backend, for example `public` or `hidden-1`. It is not a database identifier.
TestVisibility:
type: string
description: '`public` tests may be shown to the person who wrote the source; their results may carry a diagnostic excerpt. `hidden` results never carry program output or diagnostics.'
enum:
- public
- hidden
TerminationLimit:
type: string
description: 'The limit that stopped a test: CPU time, wall-clock time, memory, standard output, or the number of processes and threads.'
enum:
- cpu_time
- wall_time
- memory
- output
- processes
TestResult:
type: object
additionalProperties: false
required:
- id
- outcome
- time_ms
- wall_time_ms
- memory_kb
properties:
id:
$ref: '#/components/schemas/TestKey'
outcome:
$ref: '#/components/schemas/RunOutcome'
time_ms:
type: integer
format: int64
minimum: 0
description: CPU time of every process of the test.
wall_time_ms:
type: integer
format: int64
minimum: 0
memory_kb:
type: integer
format: int64
minimum: 0
description: 'Peak memory of the test in KiB: the cgroup high-water mark of every process of the test, including the sandbox supervisor process and file cache charged to the test.'
exit_code:
type: integer
format: int32
description: Exit status when the program exited normally.
signal:
type: integer
format: int32
minimum: 1
maximum: 64
description: Signal number when the program was killed by a signal.
limit:
$ref: '#/components/schemas/TerminationLimit'
diagnostic:
type: string
maxLength: 2048
description: Truncated standard error of a failed public test. Hidden tests never carry it.
GroupResult:
type: object
additionalProperties: false
required:
- id
- visibility
- outcome
- passed_tests
- total_tests
- tests
properties:
id:
$ref: '#/components/schemas/TestKey'
visibility:
$ref: '#/components/schemas/TestVisibility'
outcome:
$ref: '#/components/schemas/RunOutcome'
passed_tests:
type: integer
format: int32
minimum: 0
maximum: 50
total_tests:
type: integer
format: int32
minimum: 0
maximum: 50
max_time_ms:
type: integer
format: int64
minimum: 0
description: Largest CPU time of an evaluated test of the group.
max_memory_kb:
type: integer
format: int64
minimum: 0
description: Largest peak memory of an evaluated test of the group.
tests:
type: array
maxItems: 50
description: Results of the evaluated tests in order. Tests after the first failed one are not run and not listed.
items:
$ref: '#/components/schemas/TestResult'
RunResult:
type: object
additionalProperties: false
required:
- outcome
- groups
- duration_ms
properties:
outcome:
$ref: '#/components/schemas/RunOutcome'
compile:
$ref: '#/components/schemas/CompileResult'
groups:
type: array
maxItems: 4
description: One result per requested group in request order. After compile_error or infrastructure_failure every group has that outcome and no tests.
items:
$ref: '#/components/schemas/GroupResult'
duration_ms:
type: integer
format: int64
minimum: 0
description: Wall-clock time of the whole run in the runner.
RunStatus:
type: object
additionalProperties: false
required:
- run_id
- state
properties:
run_id:
type: string
format: uuid
state:
$ref: '#/components/schemas/RunState'
result:
$ref: '#/components/schemas/RunResult'
RunLanguage:
type: string
description: Language and runtime of the source. `python3` runs the Python 3 interpreter of the runner image with isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error.
enum:
- python3
RunLimits:
type: object
description: Limits applied to every test of the run.
additionalProperties: false
required:
- time_limit_ms
- memory_limit_mb
- output_limit_kb
properties:
time_limit_ms:
type: integer
format: int32
minimum: 100
maximum: 10000
description: CPU time per test, including interpreter startup, summed over every process of the test. The wall-clock limit is twice this value plus a fixed startup allowance.
memory_limit_mb:
type: integer
format: int32
minimum: 32
maximum: 512
description: Memory of the test's processes in MiB, enforced by a cgroup v2 memory limit without swap. The limit also leaves a small fixed allowance for the sandbox supervisor process.
output_limit_kb:
type: integer
format: int32
minimum: 1
maximum: 1024
description: Standard output per test in KiB. The test is stopped as soon as it writes more.
CheckerKind:
type: string
description: |-
- exact: both texts are equal after replacing CRLF with LF, removing trailing spaces and tabs at the end of each line, and removing trailing empty lines.
- tokens: both texts split on ASCII whitespace give the same sequence of tokens.
enum:
- exact
- tokens
Checker:
type: object
description: How the standard output of a test is compared with `expected_output`. Future kinds, such as a float tolerance or a custom checker, add a `kind` value and their own optional parameters to this object.
additionalProperties: false
required:
- kind
properties:
kind:
$ref: '#/components/schemas/CheckerKind'
TestCase:
type: object
additionalProperties: false
required:
- id
- input
- expected_output
properties:
id:
$ref: '#/components/schemas/TestKey'
input:
type: string
maxLength: 262144
description: UTF-8 text written to the standard input of the program.
expected_output:
type: string
maxLength: 262144
description: UTF-8 text the checker compares with the standard output.
TestGroup:
type: object
additionalProperties: false
required:
- id
- visibility
- checker
- tests
properties:
id:
$ref: '#/components/schemas/TestKey'
visibility:
$ref: '#/components/schemas/TestVisibility'
checker:
$ref: '#/components/schemas/Checker'
tests:
type: array
minItems: 1
maxItems: 50
description: Tests in evaluation order. Test IDs are unique in a group. A group stops at its first failed test.
items:
$ref: '#/components/schemas/TestCase'
RunRequest:
type: object
description: One source and its test groups. The request has no field for a candidate, account, attempt, task, or company; the backend maps a run ID to its own records.
additionalProperties: false
required:
- language
- source
- limits
- groups
properties:
language:
$ref: '#/components/schemas/RunLanguage'
source:
type: string
minLength: 1
maxLength: 65536
description: Complete program text in UTF-8. The runner writes it to a read-only file inside the sandbox and never logs it.
limits:
$ref: '#/components/schemas/RunLimits'
groups:
type: array
minItems: 1
maxItems: 4
description: Test groups in evaluation order, for example one public group and three hidden groups. Group IDs are unique in a run.
items:
$ref: '#/components/schemas/TestGroup'