feat(runner): add the own code runner contract, client and nsjail service

This commit is contained in:
shira committed 2026-10-11 08:23:42 +03:00
1 parent 5e1db37746
commit cdf6bcbb91
109 files changed
+24084 -28

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
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: ./schemas.yml#/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: ./schemas.yml#/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.
+452
View File
@@ -0,0 +1,452 @@
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
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: '#/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: '#/ProblemFieldError'
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
ProblemFieldError:
type: object
description: One reason why a request field or parameter is invalid.
additionalProperties: false
required:
- in
- pointer
- code
- message
properties:
in:
$ref: '#/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.
ProblemFieldLocation:
type: string
description: Part of the request that contains the invalid field.
enum:
- body
- query
- path
- header
- cookie
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: '#/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: '#/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: '#/TestGroup'
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.
TestGroup:
type: object
additionalProperties: false
required:
- id
- visibility
- checker
- tests
properties:
id:
$ref: '#/TestKey'
visibility:
$ref: '#/TestVisibility'
checker:
$ref: '#/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: '#/TestCase'
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
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: '#/CheckerKind'
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
TestCase:
type: object
additionalProperties: false
required:
- id
- input
- expected_output
properties:
id:
$ref: '#/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.
RunState:
type: string
description: '`running` until every group was evaluated or the run failed; `finished` when `result` is final.'
enum:
- running
- finished
RunStatus:
type: object
additionalProperties: false
required:
- run_id
- state
properties:
run_id:
type: string
format: uuid
state:
$ref: '#/RunState'
result:
$ref: '#/RunResult'
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
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
RunResult:
type: object
additionalProperties: false
required:
- outcome
- groups
- duration_ms
properties:
outcome:
$ref: '#/RunOutcome'
compile:
$ref: '#/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: '#/GroupResult'
duration_ms:
type: integer
format: int64
minimum: 0
description: Wall-clock time of the whole run in the runner.
CompileResult:
type: object
additionalProperties: false
required:
- outcome
properties:
outcome:
$ref: '#/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.
GroupResult:
type: object
additionalProperties: false
required:
- id
- visibility
- outcome
- passed_tests
- total_tests
- tests
properties:
id:
$ref: '#/TestKey'
visibility:
$ref: '#/TestVisibility'
outcome:
$ref: '#/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: '#/TestResult'
TestResult:
type: object
additionalProperties: false
required:
- id
- outcome
- time_ms
- wall_time_ms
- memory_kb
properties:
id:
$ref: '#/TestKey'
outcome:
$ref: '#/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: '#/TerminationLimit'
diagnostic:
type: string
maxLength: 2048
description: Truncated standard error of a failed public test. Hidden tests never carry it.
@@ -0,0 +1,22 @@
schemas:
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
@@ -0,0 +1,138 @@
schemas:
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: "#/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: "#/schemas/ProblemFieldError"
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
ProblemFieldError:
type: object
description: One reason why a request field or parameter is invalid.
additionalProperties: false
required:
- in
- pointer
- code
- message
properties:
in:
$ref: "#/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.
ProblemFieldLocation:
type: string
description: Part of the request that contains the invalid field.
enum:
- body
- query
- path
- header
- cookie
@@ -0,0 +1,347 @@
schemas:
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: "#/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: "#/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: "#/schemas/TestGroup"
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.
TestGroup:
type: object
additionalProperties: false
required:
- id
- visibility
- checker
- tests
properties:
id:
$ref: "#/schemas/TestKey"
visibility:
$ref: "#/schemas/TestVisibility"
checker:
$ref: "#/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: "#/schemas/TestCase"
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
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: "#/schemas/CheckerKind"
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
TestCase:
type: object
additionalProperties: false
required:
- id
- input
- expected_output
properties:
id:
$ref: "#/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.
RunState:
type: string
description: >-
`running` until every group was evaluated or the run failed;
`finished` when `result` is final.
enum:
- running
- finished
RunStatus:
type: object
additionalProperties: false
required:
- run_id
- state
properties:
run_id:
type: string
format: uuid
state:
$ref: "#/schemas/RunState"
result:
$ref: "#/schemas/RunResult"
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
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
RunResult:
type: object
additionalProperties: false
required:
- outcome
- groups
- duration_ms
properties:
outcome:
$ref: "#/schemas/RunOutcome"
compile:
$ref: "#/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: "#/schemas/GroupResult"
duration_ms:
type: integer
format: int64
minimum: 0
description: Wall-clock time of the whole run in the runner.
CompileResult:
type: object
additionalProperties: false
required:
- outcome
properties:
outcome:
$ref: "#/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.
GroupResult:
type: object
additionalProperties: false
required:
- id
- visibility
- outcome
- passed_tests
- total_tests
- tests
properties:
id:
$ref: "#/schemas/TestKey"
visibility:
$ref: "#/schemas/TestVisibility"
outcome:
$ref: "#/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: "#/schemas/TestResult"
TestResult:
type: object
additionalProperties: false
required:
- id
- outcome
- time_ms
- wall_time_ms
- memory_kb
properties:
id:
$ref: "#/schemas/TestKey"
outcome:
$ref: "#/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: "#/schemas/TerminationLimit"
diagnostic:
type: string
maxLength: 2048
description: >-
Truncated standard error of a failed public test. Hidden tests
never carry it.