Local task API
Console HTTP routes for listing, editing, and promoting local-first tasks stored in the application database.
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.
| Method | Path | Permission | Handler | What it does |
|---|---|---|---|---|
| GET | /api/tasks/local | work.read | list_local_tasks | Returns tasks from native_tasks.list_tasks with limit and offset query parameters. |
| POST | /api/tasks/local | work.write | create_local_task | Creates 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/trash | work.read | trashed_local_tasks | Lists deleted tasks that can still be restored via native_tasks.list_trash. |
| GET | /api/tasks/local/options | work.read | local_task_options | Returns active operational_project rows with project_key and display_name, ordered by display_name. |
| GET | /api/tasks/local/{task_id} | work.read | get_local_task | Loads one task; applies lab read access for lab/experiment types. |
| PATCH | /api/tasks/local/{task_id} | work.write | edit_local_task | Updates a task from EditPayload; requires console write trust and lab write for lab/experiment types. |
| DELETE | /api/tasks/local/{task_id} | work.write | delete_local_task | Soft-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}/restore | work.write | restore_local_task | Restores a trashed task; console write trust and lab write where applicable. |
| POST | /api/tasks/local/{task_id}/checklist | work.write | edit_local_checklist | Updates one checklist item via ChecklistPayload; console write trust and lab write where applicable. |
| POST | /api/tasks/local/{task_id}/linear-sync | work.write | sync_local_task | Promotes the task externally via native_task_promotion.promote using application settings secrets; lab write where applicable. |
| GET | /api/tasks/local/reference/preview | work.read | task_reference_preview | Resolves a task reference for preview; validates reference length; may gate lab read; campaign inclusion depends on marketing.read. |
| GET | /api/tasks/local/{task_id}/development | work.read | get_task_development | Returns the dict from development_tasks.get for that task id. |
| POST | /api/tasks/local/{task_id}/development | work.write | update_task_development | Applies a DevelopmentPayload through development_tasks.change; requires console write trust. |
| GET | /api/tasks/local/research/experiment-options | work.read | research_experiment_options | Lists experiment options when the caller holds lab.read at the handler. |
| POST | /api/tasks/local/{task_id}/research | work.write | update_task_research | Applies 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
| Route | Parameter | Type | Constraints |
|---|---|---|---|
list_local_tasks | limit | int | Default 100 in the handler signature. |
list_local_tasks | offset | int | Default 0 in the handler signature. |
delete_local_task | expected_version | int | Required query parameter. |
task_reference_preview | reference | str | Required; rejected when empty or longer than 500 characters. |
EditPayload (PATCH /{task_id})
| Field | Type | Notes |
|---|---|---|
expected_version | int | Must be >= 1. |
changes | dict | Passed through to native_tasks.update with actor and timestamp. |
Model config: extra='forbid'.
ChecklistPayload (POST /{task_id}/checklist)
| Field | Type | Notes |
|---|---|---|
expected_version | int | Must be >= 1. |
item_key | str | Identifies the checklist item. |
checked | bool | Desired checked state. |
expected_items | list[dict] | expected_items is a required list[dict] on ChecklistPayload. |
Model config: extra='forbid'.
DevelopmentPayload (POST /{task_id}/development)
| Field | Type | Notes |
|---|---|---|
expected_version | int | Must be >= 1. |
action | literal | One of repository, link_pr, unlink_pr, refresh, verify. |
values | dict | Default empty dict; forwarded to development_tasks.change. |
Model config: extra='forbid'.
ResearchPayload (POST /{task_id}/research)
| Field | Type | Notes |
|---|---|---|
expected_version | int | Must be >= 1. |
action | literal | One of notebook, link_experiment, unlink_experiment. |
values | dict | Default 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
| Handler | Top-level keys |
|---|---|
list_local_tasks | tasks |
trashed_local_tasks | tasks |
local_task_options | projects (rows with project_key, display_name) |
research_experiment_options | experiments |
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→ 404PermissionError→ 403native_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: Ifreferenceis empty or longer than 500 characters, the handler raises 400 with detailInvalid task reference(plain string, noterror_body)._research_access: For tasks whose type’shandler_keyislaborexperiment, ifauthorization.authorizefails for the requested permission (lab.readorlab.write), the handler raises 403 with detailLab permission is required.research_experiment_options: Raises 403 with the same lab message whenlab.readis not authorized.update_task_research: For actionslink_experimentorunlink_experiment, raises 403 withLab permission is requiredwhenlab.writeis 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