Task types API
Console routes for task type definitions, templates, typed task creation, lab task listing, and experiment adoption and verdicts.
What this API area is for
A task type defines the shape and defaults of a class of work. A task instance is one actual piece of work that follows that definition. The API separates defining the template from previewing and creating an instance.
The task types API sits under /api/task-types. It exposes console endpoints to list and define task types, manage templates and defaults, preview and create typed tasks, list lab parent tasks, and work with experiment tasks (adopt, read, record verdict). The module docstring states that types and templates create local tasks, and that research writes also require Lab permission.
Handlers delegate persistence and rules to recox.task_types, recox.lab_tasks, and recox.experiment_tasks via current_application().db. Write operations that accept a Request call require_console_write_trust before doing work. Several flows add Lab permission checks when the relevant type uses an experiment or lab handler, or when the route is explicitly experiment- or lab-oriented.
Routes
| Method | Path | Permission | Handler | What it does |
|---|---|---|---|---|
| GET | /api/task-types/lab/tasks | work.read | list_lab_tasks | Requires lab.read in the handler, then returns parent lab tasks from lab_tasks.list_parents, optionally filtered by lab_key and include_resolved. |
| GET | /api/task-types | work.read | list_task_types | Returns types from task_types.list_types and can_manage / can_manage_lab from authorization.authorize on principal.authorization_snapshot() for work.write and lab.write. |
| POST | /api/task-types | work.write | create_task_type | Calls require_console_write_trust, then requires lab.write when handler_key is experiment or lab; creates a type via task_types.create_type. |
| PATCH | /api/task-types/{type_key} | work.write | edit_task_type | Calls require_console_write_trust, then _behavior_access with lab.write (that helper calls _lab when the stored handler is experiment or lab), then task_types.update_type. |
| GET | /api/task-types/{type_key}/templates | work.read | list_templates | Lists templates for a type, with optional include_archived. |
| GET | /api/task-types/{type_key}/templates/{template_key} | work.read | get_template | Applies read-side lab access for experiment/lab types, then returns task_types.template_detail. |
| PATCH | /api/task-types/{type_key}/templates/{template_key} | work.write | edit_template | Trust check, lab write access for experiment/lab types, then task_types.update_template. |
| POST | /api/task-types/{type_key}/template-preview | work.read | preview_template | Lab read access when needed, then task_types.validate_defaults for the posted defaults. |
| POST | /api/task-types/{type_key}/templates | work.write | save_template | Trust check, lab write access, adds a template version via task_types.add_template_version; responds with version. |
| POST | /api/task-types/{type_key}/preview | work.read | preview_typed_task | Lab read access when needed, then task_types.preview (body excludes request_id from the domain call). |
| POST | /api/task-types/{type_key}/tasks | work.write | create_typed_task | Trust check, then _behavior_access with lab.write, then task_types.create with actor from the authorization snapshot and now set to the current UTC time. |
| POST | /api/task-types/experiment/adopt | work.write | adopt_experiment_task | Trust check, requires lab.write, then experiment_tasks.adopt. |
| GET | /api/task-types/experiment/tasks/{task_id} | work.read | get_experiment_task | Requires lab.read, then experiment_tasks.get. |
| POST | /api/task-types/experiment/tasks/{task_id}/verdict | work.write | record_experiment_verdict | Trust check, requires lab.write, then experiment_tasks.record_verdict. |
Request and response models
All JSON bodies use Pydantic models with extra='forbid'. Successful handlers return a dict; shape comes from the underlying task_types, lab_tasks, or experiment_tasks calls except where noted.
TypePayload (POST /api/task-types)
| Field | Type | Constraints |
|---|---|---|
type_key | str | min_length=1, max_length=100 |
display_name | str | min_length=1, max_length=200 |
handler_key | literal | One of general, experiment, lab, development, research |
MetadataPayload (PATCH type or template)
| Field | Type | Constraints |
|---|---|---|
display_name | str | min_length=1, max_length=200 |
active | bool | — |
expected_name | str | — |
expected_active | bool | — |
TemplatePayload (POST .../templates)
| Field | Type | Constraints |
|---|---|---|
template_key | str | min_length=1, max_length=100 |
name | str | min_length=1, max_length=200 |
defaults | dict | — |
expected_version | int | ge=0 |
DefaultsPayload (POST .../template-preview)
| Field | Type |
|---|---|
defaults | dict |
TypedTaskPayload (POST .../preview and .../tasks)
| Field | Type | Constraints |
|---|---|---|
overrides | dict | — |
request_id | str | None | Default None; when set, min_length=1, max_length=200 |
template_key | str | None | Default None |
template_version | int | None | Default None; when set, ge=1 |
AdoptionPayload (POST /experiment/adopt)
| Field | Type | Constraints |
|---|---|---|
task_id | str | — |
experiment_key | str | — |
expected_version | int | ge=1 |
VerdictPayload (POST .../verdict)
| Field | Type | Constraints |
|---|---|---|
expected_version | int | ge=1 |
outcome | str | — |
reason | str | min_length=1 |
evidence_runs | list[str] | — |
Query parameters
| Route | Parameters |
|---|---|
GET .../lab/tasks | lab_key: str | None, include_resolved: bool (default False) |
GET /api/task-types | include_archived: bool (default False) |
GET .../templates | include_archived: bool (default False) |
Notable response fields
| Route | Extra response shape |
|---|---|
GET /api/task-types | { types, can_manage, can_manage_lab } |
POST .../templates | { version } from add_template_version |
GET .../lab/tasks | { tasks: ... } |
GET .../templates | { templates: ... } |
Behaviour and errors
Lab permission. _lab(permission) calls authorization.authorize on the current authorization snapshot. When authorization fails, the handler raises HTTPException with status 403 and detail 'Lab permission is required'.
Experiment and lab types. _behavior_access(type_key, permission) loads the type with task_types.get_type. When handler_key is experiment or lab, it runs the same Lab check with the given permission (lab.read or lab.write depending on the route).
Domain errors. list_task_types and list_templates do not catch domain errors; get_experiment_task catches only LookupError and raises _error; the other task_types and experiment_tasks handlers catch ValueError and LookupError and raise _error from native_task_routes. The mapped HTTP status and body come from that helper, which is outside this module.
Console write trust. create_task_type, edit_task_type, edit_template, save_template, create_typed_task, adopt_experiment_task, and record_experiment_verdict invoke require_console_write_trust(request) before mutating state.
Validation. Request bodies are validated against the Pydantic models above; unknown JSON keys are rejected because extra='forbid'.
How the permission model applies
Console route permissions are declared in the route permission table. Each handler name is keyed as task_type_routes.<handler_name>. The app-wide gate dependency refuses signed-in users whose role does not hold the route permission (HTTP 403 with a denied error payload). That table is a ceiling: this module may narrow access further via Lab checks and write-trust, but not widen it.
For this module, route permissions are either work.read or work.write. In addition:
list_lab_tasks,get_template,preview_template,preview_typed_task, andget_experiment_taskrequirelab.readinside the handler when applicable.- Create and update paths for lab/experiment types, plus experiment adopt and verdict routes, require
lab.writeinside the handler. list_task_typesexposes whether the caller holdswork.writeandlab.writewithout requiring Lab permission to list.
With sign-in disabled, the route roles module documents that the caller is treated as OS admin on the machine; bearer-authenticated machine calls carry their own grants. Every endpoint in this module is listed in the permission table with a known permission.
How is this page?
Last updated on