Skip to Content
Recodocs

Task types API

Console routes for task type definitions, templates, typed task creation, lab task listing, and experiment adoption and verdicts.

5 min read

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

MethodPathPermissionHandlerWhat it does
GET/api/task-types/lab/taskswork.readlist_lab_tasksRequires 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-typeswork.readlist_task_typesReturns 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-typeswork.writecreate_task_typeCalls 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.writeedit_task_typeCalls 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}/templateswork.readlist_templatesLists templates for a type, with optional include_archived.
GET/api/task-types/{type_key}/templates/{template_key}work.readget_templateApplies read-side lab access for experiment/lab types, then returns task_types.template_detail.
PATCH/api/task-types/{type_key}/templates/{template_key}work.writeedit_templateTrust check, lab write access for experiment/lab types, then task_types.update_template.
POST/api/task-types/{type_key}/template-previewwork.readpreview_templateLab read access when needed, then task_types.validate_defaults for the posted defaults.
POST/api/task-types/{type_key}/templateswork.writesave_templateTrust check, lab write access, adds a template version via task_types.add_template_version; responds with version.
POST/api/task-types/{type_key}/previewwork.readpreview_typed_taskLab read access when needed, then task_types.preview (body excludes request_id from the domain call).
POST/api/task-types/{type_key}/taskswork.writecreate_typed_taskTrust 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/adoptwork.writeadopt_experiment_taskTrust check, requires lab.write, then experiment_tasks.adopt.
GET/api/task-types/experiment/tasks/{task_id}work.readget_experiment_taskRequires lab.read, then experiment_tasks.get.
POST/api/task-types/experiment/tasks/{task_id}/verdictwork.writerecord_experiment_verdictTrust 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)

FieldTypeConstraints
type_keystrmin_length=1, max_length=100
display_namestrmin_length=1, max_length=200
handler_keyliteralOne of general, experiment, lab, development, research

MetadataPayload (PATCH type or template)

FieldTypeConstraints
display_namestrmin_length=1, max_length=200
activebool—
expected_namestr—
expected_activebool—

TemplatePayload (POST .../templates)

FieldTypeConstraints
template_keystrmin_length=1, max_length=100
namestrmin_length=1, max_length=200
defaultsdict—
expected_versionintge=0

DefaultsPayload (POST .../template-preview)

FieldType
defaultsdict

TypedTaskPayload (POST .../preview and .../tasks)

FieldTypeConstraints
overridesdict—
request_idstr | NoneDefault None; when set, min_length=1, max_length=200
template_keystr | NoneDefault None
template_versionint | NoneDefault None; when set, ge=1

AdoptionPayload (POST /experiment/adopt)

FieldTypeConstraints
task_idstr—
experiment_keystr—
expected_versionintge=1

VerdictPayload (POST .../verdict)

FieldTypeConstraints
expected_versionintge=1
outcomestr—
reasonstrmin_length=1
evidence_runslist[str]—

Query parameters

RouteParameters
GET .../lab/taskslab_key: str | None, include_resolved: bool (default False)
GET /api/task-typesinclude_archived: bool (default False)
GET .../templatesinclude_archived: bool (default False)

Notable response fields

RouteExtra 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, and get_experiment_task require lab.read inside the handler when applicable.
  • Create and update paths for lab/experiment types, plus experiment adopt and verdict routes, require lab.write inside the handler.
  • list_task_types exposes whether the caller holds work.write and lab.write without 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