Skip to Content
Recodocs

Local task API

Console HTTP routes for listing, editing, and promoting local-first tasks stored in the application database.

7 min read

The local task API is the console-facing surface for local-first tasks: records kept in the application database. Create, edit, delete, restore, checklist, development change, and research change pass actor from principal.authorization_snapshot().principal; promote does not receive an actor, and sign-in off uses the OS admin rather than a signed-in user. The module’s own description states that all external effects remain explicit and recoverable. Routes are mounted under the /api/tasks/local prefix.

What this API area is for

Local-first tasks are records owned by the application rather than a synchronization view. The API lets an authorized caller work with those records through explicit operations.

Use these endpoints for native local tasks, including an explicit Linear promotion call: paginated listing, creation, read and patch, soft delete with trash and restore, checklist updates, optional sync to Linear, reference-based previews, development metadata (repository and PR linkage), and research actions (notebooks and experiments). Supporting reads return active operational projects and the experiment options from research_tasks.experiment_options.

Most read paths need only the route-level permission. Several write paths additionally call require_console_write_trust on the incoming request. Lab type checks apply to get, preview, edit, delete, restore, checklist, and linear sync; experiment options always require lab.read, and research link or unlink requires lab.write regardless of type. _research_access loads the task and its type, then authorizes. Reference preview sets include_campaigns from marketing.read.

Routes

The Path column already shows full paths under the /api/tasks/local prefix.

MethodPathPermissionHandlerWhat it does
GET/api/tasks/localwork.readlist_local_tasksReturns tasks from native_tasks.list_tasks with limit and offset query parameters.
POST/api/tasks/localwork.writecreate_local_taskCreates a task from a native_tasks.TaskValues body; requires console write trust; uses the current principal as actor and UTC now.
GET/api/tasks/local/trashwork.readtrashed_local_tasksLists deleted tasks that can still be restored via native_tasks.list_trash.
GET/api/tasks/local/optionswork.readlocal_task_optionsReturns active operational_project rows with project_key and display_name, ordered by display_name.
GET/api/tasks/local/{task_id}work.readget_local_taskLoads one task; applies lab read access for lab/experiment types.
PATCH/api/tasks/local/{task_id}work.writeedit_local_taskUpdates a task from EditPayload; requires console write trust and lab write for lab/experiment types.
DELETE/api/tasks/local/{task_id}work.writedelete_local_taskSoft-deletes with query expected_version; passes admin=True only when snapshot.role == principal.ADMIN; lab write for lab/experiment types.
POST/api/tasks/local/{task_id}/restorework.writerestore_local_taskRestores a trashed task; console write trust and lab write where applicable.
POST/api/tasks/local/{task_id}/checklistwork.writeedit_local_checklistUpdates one checklist item via ChecklistPayload; console write trust and lab write where applicable.
POST/api/tasks/local/{task_id}/linear-syncwork.writesync_local_taskPromotes the task externally via native_task_promotion.promote using application settings secrets; lab write where applicable.
GET/api/tasks/local/reference/previewwork.readtask_reference_previewResolves a task reference for preview; validates reference length; may gate lab read; campaign inclusion depends on marketing.read.
GET/api/tasks/local/{task_id}/developmentwork.readget_task_developmentReturns the dict from development_tasks.get for that task id.
POST/api/tasks/local/{task_id}/developmentwork.writeupdate_task_developmentApplies a DevelopmentPayload through development_tasks.change; requires console write trust.
GET/api/tasks/local/research/experiment-optionswork.readresearch_experiment_optionsLists experiment options when the caller holds lab.read at the handler.
POST/api/tasks/local/{task_id}/researchwork.writeupdate_task_researchApplies ResearchPayload via research_tasks.change; link_experiment and unlink_experiment require lab.write in the handler.

Static segments such as trash, options, reference/preview, and research/experiment-options are registered alongside {task_id} routes in the module; callers should use the literal paths shown above.

Request and response models

Handlers return dict unless an error is raised. Shapes below are taken from the route module; deeper task fields come from the native_tasks, development_tasks, research_tasks, and task_previews packages invoked by each handler.

Query parameters

RouteParameterTypeConstraints
list_local_taskslimitintDefault 100 in the handler signature.
list_local_tasksoffsetintDefault 0 in the handler signature.
delete_local_taskexpected_versionintRequired query parameter.
task_reference_previewreferencestrRequired; rejected when empty or longer than 500 characters.

EditPayload (PATCH /{task_id})

FieldTypeNotes
expected_versionintMust be >= 1.
changesdictPassed through to native_tasks.update with actor and timestamp.

Model config: extra='forbid'.

ChecklistPayload (POST /{task_id}/checklist)

FieldTypeNotes
expected_versionintMust be >= 1.
item_keystrIdentifies the checklist item.
checkedboolDesired checked state.
expected_itemslist[dict]expected_items is a required list[dict] on ChecklistPayload.

Model config: extra='forbid'.

DevelopmentPayload (POST /{task_id}/development)

FieldTypeNotes
expected_versionintMust be >= 1.
actionliteralOne of repository, link_pr, unlink_pr, refresh, verify.
valuesdictDefault empty dict; forwarded to development_tasks.change.

Model config: extra='forbid'.

ResearchPayload (POST /{task_id}/research)

FieldTypeNotes
expected_versionintMust be >= 1.
actionliteralOne of notebook, link_experiment, unlink_experiment.
valuesdictDefault empty dict; forwarded to research_tasks.change.

Model config: extra='forbid'.

native_tasks.TaskValues (POST ``)

The create handler types its body as native_tasks.TaskValues. That model is not defined in this route file; the handler passes it to native_tasks.create with actor and UTC timestamp.

Documented response wrappers

HandlerTop-level keys
list_local_taskstasks
trashed_local_taskstasks
local_task_optionsprojects (rows with project_key, display_name)
research_experiment_optionsexperiments

All other successful handlers return the dict produced by the corresponding domain call (get, update, delete, restore, set_checklist_item, promote, read, development_tasks.get / change, research_tasks.change, etc.).

Behaviour and errors

Shared error mapping (_error)

Many handlers wrap domain exceptions with _error, which maps exception types to HTTP status codes and a structured detail from error_body:

  • LookupError → 404
  • PermissionError → 403
  • native_tasks.TaskConflict → 409 with conflict code in the error body
  • Other exceptions passed through this helper (typically ValueError) → 400 with an invalid code

_error passes 'conflict' for status 409 and 'invalid' otherwise, with str(exc) as the second argument to error_body.

Handler-specific refusals

  • task_reference_preview: If reference is empty or longer than 500 characters, the handler raises 400 with detail Invalid task reference (plain string, not error_body).
  • _research_access: For tasks whose type’s handler_key is lab or experiment, if authorization.authorize fails for the requested permission (lab.read or lab.write), the handler raises 403 with detail Lab permission is required.
  • research_experiment_options: Raises 403 with the same lab message when lab.read is not authorized.
  • update_task_research: For actions link_experiment or unlink_experiment, raises 403 with Lab permission is required when lab.write is not authorized.

Console write trust

These handlers call require_console_write_trust(request) before mutating: create_local_task, edit_local_task, delete_local_task, restore_local_task, edit_local_checklist, sync_local_task, update_task_development, and update_task_research. Failure behaviour for that guard lives in the shared console routes module imported by this file.

Delete semantics

delete_local_task reads principal.authorization_snapshot(), passes actor=snapshot.principal, and sets admin=True when snapshot.role == principal.ADMIN, in addition to expected_version from the query string.

Listing validation

list_local_tasks catches ValueError from native_tasks.list_tasks and re-raises via _error (typically 400).

Linear sync

sync_local_task loads the current application, calls _research_access with lab.write, then native_task_promotion.promote with the database, task id, secrets from app.settings.secrets(), and UTC now. ValueError and LookupError map through _error.

Reference preview

If native_identity returns a task id, _research_access requires lab.read only when that type's handler_key is lab or experiment. task_previews.read receives include_campaigns=True only when marketing.read is authorized.

How the permission model applies

Console routing uses a deny-by-default permission table: each handler must appear in ROUTE_PERMISSIONS with a known permission string, or startup checks refuse an incomplete table. For signed-in users, the global gate dependency compares the user’s role against the permission named for native_task_routes.<handler_name> and returns 403 with a denied error object when policy refuses the action.

For this module, table entries use work.read for list, get, trash, options, reference preview, development get, and research experiment options, and work.write for create, edit, delete, restore, checklist, linear sync, development update, and research update. That permission is a ceiling: a capability, the document kernel, or the route may narrow the mapped permission and must never widen it. This module adds lab checks, include_campaigns from marketing.read, and require_console_write_trust.

With sign-in off the caller is Recohut's OS admin on this computer, and a bearer-authenticated machine call carries its own grants. For a signed-in user, gate raises 403 when policy denies that route's own work.read or work.write permission; lab checks and console write trust run inside the handler.

Lab gating is orthogonal to work.read / work.write: _research_access loads the task and its type, inspects handler_key, and for lab and experiment types requires lab.read or lab.write explicitly via authorization.authorize, raising 403 with a fixed message if not satisfied.

How is this page?

Last updated on